美文网首页
三、加载模型,并进行火星偏移

三、加载模型,并进行火星偏移

作者: 仙人掌开不了花 | 来源:发表于2020-03-25 16:56 被阅读0次
let tileset = new Cesium.Cesium3DTileset({
    url: "http://.../3DTiles.json",
    maximumScreenSpaceError: 1
})
viewer.scene.primitives.add(tileset);
tileset.readyPromise.then(function (tileset) {
    //将视野缩放到模型范围内
    viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.5, -0.2, tileset.boundingSphere.radius * 1.0));    
}).otherwise(function (e) {
    throw e
})

如若想更改模型的位置,可以根据前后经纬度和高度计算变换矩形——平移矩阵
1.根据tileset的边界球体中心点的笛卡尔坐标得到经纬度坐标
2.根据经纬度和高度0,得到地面笛卡尔坐标
3.根据经纬度和需要的高度,得到偏移后的笛卡尔坐标
4.计算坐标变换,得到新的笛卡尔坐标
5.根据变换得到Matrix4变换矩阵

具体代码如下:

tileset.readyPromise.then(function (tileset) {
    // 模型中心点
    var surface = tileset.boundingSphere.center;
    // 模型中心点的笛卡尔坐标
    var cartographic = Cesium.Cartographic.fromCartesian(surface);
    // 中心点的经纬度坐标
    let lng = Cesium.Math.toDegrees(cartographic.longitude)
    let lat = Cesium.Math.toDegrees(cartographic.latitude)
    // 将经纬度坐标转为火星坐标
    let newLatlng = coordinateTools.wgs84togcj02(lng,lat)
    // 将火星坐标转为笛卡尔坐标
    var offset = Cesium.Cartesian3.fromDegrees(newLatlng[0], newLatlng[1], 70);
    // 计算原中心点偏移到火星坐标的偏移量
    var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
    // 将模型进行偏移
    tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
    //修改模型的位置后,将模型添加到地图中
    viewer.scene.primitives.add(tileset);
}).otherwise(function (e) {
    throw e
})
参考文档

1.Cesium如何修改3dtiles的位置信息偏移经纬度高度和旋转角度

相关文章

网友评论

      本文标题:三、加载模型,并进行火星偏移

      本文链接:https://www.haomeiwen.com/subject/zzmjyhtx.html