cesium使用Cesium3DTileset添加3dTiles模型

因为项目中有需要在三维地图添加模型的功能,因此记录下添加模型的方法。添加模型使用的是cesium的Cesium3DTileset方法。

代码如下:

          const tileseDntWater = new Cesium.Cesium3DTileset({
            url: 模型地址,  // 例如:XXX/DN/tileset.json"
            maximumMemoryUsage: 2048,
          });
           //下面代码可以设置模型的高程
          tileseDntWater.readyPromise.then(function () {
          var heightOffset = -500;  //修改值可以调整模型高程
            //计算tileseDntWater的绑定范围
          var boundingSphere = tileseDntWater.boundingSphere;
          //计算中心点位置
          var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
          //计算中心点位置的地表坐标
          var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
            //偏移后的坐标
          var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
          var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
          //tileseDntWater.modelMatrix转换
          tileseDntWater.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
            // self.viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius));
            // self.viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
          }).otherwise(function (error) {
              throw(error);
          });
          //模型添加到地图中
          this.viewer.scene.primitives.add(tileseDntWater);
          this.waterGround.push(tileseDntWater);


    //设置show为false可以隐藏模型,为true显示模型
         for (let i = 0; i < this.waterGround.length; i++) {
          this.waterGround[i].show = false;
        }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值