如何在cesium中加载3dtiles模型数据?

groundOffset = 0; //地形抬高的高度
tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
                    url: '../terra_b3dms/tileset.json'
                }));

//定位到模型位置
 tileset.readyPromise.then(function (tileset) {
 let boundingSphere = tileset.boundingSphere; // 模型的范围
                    let cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center); 
                    let surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
                    let offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, groundOffset); 
                    let translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
                    tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
                    viewer.flyTo(tileset, {
                        offset: new Cesium.HeadingPitchRange(
                            0.5,
                            -0.2,
                            tileset.boundingSphere.radius * 3.0
                        ),
                        duration: 2
                    });
                    viewer.flyTo(tileset, {
                        offset: new Cesium.HeadingPitchRange(
                            0.5,
                            -0.2,
                            tileset.boundingSphere.radius * 3.0
                        ),
                        duration: 2
                    });
                });

在这里插入图片描述

如此,一个模型就加载好了。
这里要注意的是,地形深度检测的开启,可能会影像到模型的高度问题,可根据实际情况,来判断是否要开启地形检测,以及groundOffset的值

viewer.scene.globe.depthTestAgainstTerrain = true;
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐