3D模型中的Threebox工具提示

tiagofonseca1109

我一直在尝试在某些导入的3D模型上启用工具提示,但是它不起作用。

我已经在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
}

当我加载对象时,我执行以下操作:

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);
});

尽管对象出现在渲染中,但当我将鼠标放在上方或单击时,没有任何内容显示工具提示。

我想念什么?

编辑:

在@jscastro响应之后,我将html页面顶部的导入更改为<link href="./threebox-plugin/examples/css/threebox.css" rel="stylesheet" />(该路径是文件所在位置的正确路径)

我还删除了proptions中的enableTooltip:true。

尽管它仍然不起作用,但下面的代码将保持原样:

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);
});
杰斯卡斯特罗

编辑我下载了您在聊天中共享的页面,并且在代码中发现了许多不同的问题和错误。

1.您使用了错误的属性来启用对3D对象的选择enableSelectingFeatures: true, //change this to false to disable fill-extrusion features selection,即使用,即针对注释中所述的Mapbox填充-拉伸特征,而对于3D模型和对象则没有使用enableSelectingObjects: true仅添加此内容即可解决鼠标悬停时工具提示的问题。

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 
    }
);

但是我发现了其他问题...
2.您的模型scale初始化太小,因此将它们隐藏在创建的大形状下。公共汽车站的比例为,scale: 0.01并且您定义了一个在地面上的位置var place = [element.lng, element.lat, 0];,因此它隐藏在其中。CylinderGeometry 在此处输入图片说明如果使用,scale: 1您将看到公共汽车站如何从圆柱体上抬起。在此处输入图片说明

3.与总线相同,您scale: 1,可以对其进行初始化,以使其隐藏在创建的管和圆柱体下方。如果使用进行初始化,scale: 10,并且将它们从地板上抬高5米,let truck = model.setCoords([lngB, latB, 4]);则会看到它们抬起。在此处输入图片说明

4. Your models have a wrong initialization params mixing anchor and adjustment. 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 a z value that elevates the pivotal center adjustment: { x: -0.1, y: -0.1, z: 0.4 }. If you want your model on altitude use the 3rd coord in 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);.

Summarizing, check all of these changes and let me know if it works.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Threebox 3D模型上的CastShadow

来自分类Dev

Highcharts 3D散点在工具提示中未显示名称

来自分类Dev

图表中的D3工具提示

来自分类Dev

Highcharts-如何在3D散点图上的点工具提示(弹出窗口)中设置自定义内容,或如何自定义点工具提示信息?

来自分类Dev

Helix工具包Rotate 3D模型

来自分类Dev

在工具提示中显示D3 SVG

来自分类Dev

D3工具提示未在Firefox中显示

来自分类Dev

D3中的工具提示如何动态获取数据?

来自分类Dev

在D3中生成动态数据的工具提示

来自分类Dev

如何在d3.js工具提示中换行?

来自分类Dev

在d3.js中的节点上显示工具提示

来自分类Dev

显示工具提示d3中的数据内容

来自分类Dev

在d3.js的工具提示中绘制

来自分类Dev

在 d3tip 工具提示中嵌入 svg 形状

来自分类Dev

多环图 d3js 中的工具提示

来自分类Dev

在3D对象的鼠标悬停时显示工具提示

来自分类Dev

我可以使用哪种语言/工具在网站上生成动态3D模型

来自分类Dev

设置d3的工具提示样式

来自分类Dev

D3 Heatmap画布的工具提示

来自分类Dev

使用Matplotlib在3D中绘制线性模型

来自分类Dev

在3D圆柱模型中避免接缝

来自分类Dev

在凹面3D模型中检查内部/外部点

来自分类Dev

如何在WPF 3d中调整模型大小?

来自分类Dev

隐藏3D模型中的节点-forgeviewer

来自分类Dev

在浏览器中查看3D模型

来自分类Dev

了解Libgdx中的3D模型和节点

来自分类Dev

OpenGL 3D中的平滑模型运动

来自分类Dev

嵌入在Canvas自动旋转中的3D模型

来自分类Dev

如何在颤振中显示 3D 模型?