其他分享
首页 > 其他分享> > Cesium加载3dtiles并调整位置

Cesium加载3dtiles并调整位置

作者:互联网

效果展示

在这里插入图片描述

代码

  1. 平移模型核心代码
   const _tx=tx?tx:0;
   const _ty=ty?ty:0;
   const _tz=tz?tz:0;
   const tempTranslation = new Cesium.Cartesian3(_tx, _ty, _tz);
   const offset =Cesium.Matrix4.multiplyByPoint(m, tempTranslation, new Cesium.Cartesian3(0,0,0));
   const translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
   tileSet.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
  1. 旋转及缩放模型核心代码
if(rx){
     const mx = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(rx));
     const rotate= Cesium.Matrix4.fromRotationTranslation(mx);
     Cesium.Matrix4.multiply(m, rotate, m);
   }
  
   if(ry){
     const my = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(ry));
     const rotate= Cesium.Matrix4.fromRotationTranslation(my);
     Cesium.Matrix4.multiply(m, rotate, m);
   }
  
   if(rz){
     const mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(rz));
     const rotate= Cesium.Matrix4.fromRotationTranslation(mz);
     Cesium.Matrix4.multiply(m, rotate, m);
   }
  
   if(scale){
     const _scale = Cesium.Matrix4.fromUniformScale(scale);
     Cesium.Matrix4.multiply(m, _scale, m);
   }
 
   tileSet._root.transform = m;

完整代码示例

请参考在线示例

标签:rotate,const,multiply,scale,3dtiles,Cesium,Matrix4,加载
来源: https://blog.csdn.net/qq_19689967/article/details/121144419