简体   繁体   English

3D 型号中的三框工具提示

[英]Threebox Tooltip in 3D models

I´ve been trying to enable tooltips on some imported 3D models, but it isnt working.我一直在尝试在一些进口的 3D 模型上启用工具提示,但它不起作用。

I already enabled tooltips in threbox, and I enabled tooltips in the options for the 3d element, as shown below.我已经在 threbox 中启用了工具提示,并且我在 3d 元素的选项中启用了工具提示,如下所示。

tb = new Threebox(
    map,
        mbxContext,
    {
        realSunlight: true,
        enableSelectingFeatures: true, //change this to false to disable fill-extrusion features selection
        enableTooltips: true // change this to false to disable default tooltips on fill-extrusion and 3D models 
    }
);
var proptions = {
    obj: './models/er.glb',
    type: 'gltf',
    scale: 10,
    units: 'meters',
    rotation: { x: 90, y: 0, z: 0 }, //default rotation
    anchor: 'center',
    adjustment: { x: 0, y: 0, z: 0.4 },
    enableToltips: true
}

When i load the object i did the following:当我加载 object 时,我执行了以下操作:

tb.loadObj(proptions, function (model) {
    model.setCoords(place);
    model.addTooltip("A radar in the middle of nowhere", true);
    model.setRotation({ x: 0, y: 0, z: Math.floor(Math.random() * 100) })
    tb.add(model);
});

Although the object appears in the render, when I put the mouse above or i click it nothing shows the tooltip.尽管 object 出现在渲染中,但当我将鼠标放在上方或单击它时,没有显示工具提示。

What am I missing?我错过了什么?

EDIT:编辑:

Following @jscastro response i changed the import in the top of my html page to <link href="./threebox-plugin/examples/css/threebox.css" rel="stylesheet" /> (the path is the correct to where the file is)在@jscastro 响应之后,我将 html 页面顶部的导入更改为<link href="./threebox-plugin/examples/css/threebox.css" rel="stylesheet" /> (路径正确到 where文件是)

I also removed the enableTooltip: true in proptions.我还删除了属性中的 enableTooltip: true 。

Despite that it still does not work, Below i will leave the code as it is:尽管它仍然不起作用,下面我将保留代码原样:

var origin = [-8.4, 41.20, 1];
var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v11',
    center: origin,
    zoom: 11,
    pitch: 30,
    antialias: true
});

//Things related to dateTime ommited

window.tb = new Threebox(
    map,
    map.getCanvas().getContext('webgl'),
    {
        realSunlight: true,
        enableSelectingFeatures: true, //change this to false to disable fill-extrusion features selection
        enableTooltips: true // change this to false to disable default tooltips on fill-extrusion and 3D models 
    }
);

map.on('style.load', async function () {
    await importarLinhas();
    // stats
    // stats = new Stats();
    // map.getContainer().appendChild(stats.dom);
    animate();

            
    map.addLayer({
        id: 'custom_layer',
        type: 'custom',
        renderingMode: '3d',
        onAdd: function (map, mbxContext) {

            var eroptions = {
                obj: './models/stationBus.fbx',
                type: 'fbx',
                scale: 0.01,
                units: 'meters',
                rotation: { x: 90, y: 20, z: 0 }, //default rotation
                anchor: 'center',
                adjustment: { x: -0.1, y: -0.1, z: 0.4 }
            }

            var poptions = {
                obj: './models/Busstop.fbx',
                type: 'fbx',
                scale: 0.03,
                units: 'meters',
                rotation: { x: 90, y: 20, z: 0 }, //default rotation
                anchor: 'center',
                adjustment: { x: -0.1, y: -0.1, z: 0.1 }
            }

            var proptions = {
                obj: './models/er.glb',
                type: 'gltf',
                scale: 2.7,
                units: 'meters',
                rotation: { x: 90, y: 0, z: 0 }, //default rotation
                anchor: 'center',
                adjustment: { x: 0, y: 0, z: 0.4 }
            }

                allNos.forEach((element) => { //For each one of a list that i fill first
                    //center of where the objects are
                    var place = [element.lng, element.lat, 0];

                    //cylinder as "base" for each one of the 3d Models 
                    **//in here i cant do the Tooltip for the object**
                    const geometry = new THREE.CylinderGeometry(0.6, 0.6, 0.15, 32);
                    const material = new THREE.MeshLambertMaterial({ color: 0x5B5B5B });
                    const cylinder = new THREE.Mesh(geometry, material);

                    var baseOptions = {
                        obj: cylinder,
                        anchor: 'center',
                        adjustment: { x: 0, y: 0, z: -0.4 }
                    }

                    let base = tb.Object3D(baseOptions);
                    base.setCoords(place);
                    base.setRotation({ x: 90, y: 0, z: 0 })
                    //The text is just for the test
                    base.addTooltip("A radar in the middle of nowhere", true);
                    // base.castShadow = true;
                    window.tb.add(base);
                    
                    //next i check what type of element it is 
                    //it can only be one at the same time, so i use different models for each type
                    if (element.tipo === "p") {
                        window.tb.loadObj(poptions, function (model) {
                            model.setCoords(place);
                            model.addTooltip("A radar in the middle of nowhere", true);
                            model.setRotation({ x: 0, y: 0, z: Math.floor(Math.random() * 100) })
                            // model.castShadow = true;
                            window.tb.add(model);
                        });
                    }
                    if (element.tipo === "er") {
                        window.tb.loadObj(eroptions, function (model) {
                            model.setCoords(place);
                            model.addTooltip("A radar in the middle of nowhere", true);
                            model.setRotation({ x: 0, y: 0, z: Math.floor(Math.random() * 100) })
                            // model.castShadow = true;
                            window.tb.add(model);
                        });
                    }
                    if (element.tipo === "pr") {
                        window.tb.loadObj(proptions, function (model) {
                            model.setCoords(place);
                            model.addTooltip("A radar in the middle of nowhere", true);
                            model.setRotation({ x: 0, y: 0, z: Math.floor(Math.random() * 100) })
                            // model.castShadow = true;
                            window.tb.add(model);
                        });
                    }

                });

        },

        render: function (gl, matrix) {
            window.tb.setSunlight(date, origin.center);
            window.tb.update();
        }

    })
    map.addLayer(createCompositeLayer());

    map.on('SelectedFeatureChange', onSelectedFeatureChange);
});

EDIT I downloaded the page you shared in the chat, and I found many different issues and mistakes in your code.编辑我下载了您在聊天中共享的页面,我在您的代码中发现了许多不同的问题和错误。

1. You're using the wrong property to enable the selection of 3D objects, you use enableSelectingFeatures: true, //change this to false to disable fill-extrusion features selection , that is for Mapbox fill-extrusions features as said in the comment, but not for 3D models and objects, you have to use enableSelectingObjects: true . 1.您使用错误的属性来启用 3D 对象的选择,您使用enableSelectingFeatures: true, //change this to false to disable fill-extrusion features selection ,即评论中所述的 Mapbox 填充挤出功能,但不适用于 3D 模型和对象,您必须使用enableSelectingObjects: true Only adding this, your problem with the tooltips on mouse over will be solved.只有添加这个,您的鼠标悬停工具提示问题才会得到解决。

tb = new Threebox(
    map,
        mbxContext,
    {
        realSunlight: true,
        enableSelectingObjects: true, //enable 3D models over/selection
        enableTooltips: true // enable default tooltips on fill-extrusion and 3D models 
    }
);

But I have found other issues...但是我发现了其他问题...
2. Your models scale initialization is too small, so you are hiding them below the big shapes you have created. 2.您的模型scale初始化太小,因此您将它们隐藏在您创建的大形状下方。 The scale of your bus stop is scale: 0.01 and you define a place which is on the ground var place = [element.lng, element.lat, 0];你的公交车站的比例是scale: 0.01并且你定义了一个在地面上的地方var place = [element.lng, element.lat, 0]; , so it's hidden inside this CylinderGeometry , 所以它隐藏在这个CylinderGeometry里面在此处输入图像描述 If you use scale: 1 you will see how your bus stops raises from the cylinder.如果你使用scale: 1你会看到你的公共汽车站是如何从圆柱体中升起的。 在此处输入图像描述

3. Same with the bus, you initialize them with scale: 1, which make them be hidden below the tubes and cylinders you have created. 3.与总线相同,您使用scale: 1,这使它们隐藏在您创建的管子和圆柱体下方。 If you initialize them with scale: 10, and you elevate them 5 meters from the floor let truck = model.setCoords([lngB, latB, 4]);如果你用scale: 10,然后将它们提升到离地面 5 米的位置, let truck = model.setCoords([lngB, latB, 4]); then you will see them raising.然后你会看到他们加注。 在此处输入图像描述

4. Your models have a wrong initialization params mixing anchor and adjustment . 4.你的模型有一个错误的初始化参数混合anchoradjustment anchor: center will center the pivotal center of your object properly, but then you apply negative values to x and y (which means decenter the object), and az value that elevates the pivotal center adjustment: { x: -0.1, y: -0.1, z: 0.4 } . anchor: center将使 object 的枢轴中心正确居中,但随后将负值应用于 x 和 y(这意味着使对象偏心),以及提升枢轴中心adjustment: { x: -0.1, y: -0.1, z: 0.4 } If you want your model on altitude use the 3rd coord in setCoords .如果您希望 model 位于海拔高度,请使用setCoords中的第三个坐标。

5. Your Cylinders and Tubes for the bus stops and bus lines are huge, and also they have the wrong init params, as you set them below the ground level -0.4 units adjustment: { x: 0, y: 0, z: -0.4 } (something supported by Mapbox but very bad resolved and producing weird effects. My recommendation would be to make them almost flat and at the ground level with no adjustment param. const geometry = new THREE.CylinderGeometry(0.6, 0.6, 0.01, 32); . 5.你的公交车站和公交线路的圆柱体和管子很大,而且它们的初始参数错误,因为你将它们设置在地面以下-0.4个单位adjustment: { x: 0, y: 0, z: -0.4 } (Mapbox 支持的东西,但解决得非常糟糕并产生奇怪的效果。我的建议是让它们几乎平坦并且在地面上没有adjustment参数const geometry = new THREE.CylinderGeometry(0.6, 0.6, 0.01, 32); .

Summarizing, check all of these changes and let me know if it works.总结一下,检查所有这些变化,让我知道它是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM