Cesium--旋转3dtiles

以下代码来自Cesium 论坛:3DTileset rotation - CesiumJS - Cesium Community

在1.118中测试可行,可直接在Sandcastle中运行:

const viewer = new Cesium.Viewer("cesiumContainer", {
  terrain: Cesium.Terrain.fromWorldTerrain(),
});

// Disable the ("globe") rotation for left mouse drags
viewer.scene.screenSpaceCameraController.enableRotate = false;

let tileset = viewer.scene.primitives.add(
  await Cesium.Cesium3DTileset.fromIonAssetId(40866)
);

// Store the transform of the root node of the
// tileset as the "root transform", assign this
// as the initial model matrix, and set the
// transform of the root node to be the identity
const rootTransform = Cesium.Matrix4.clone(tileset.root.transform);
tileset.modelMatrix = Cesium.Matrix4.clone(rootTransform);
tileset.root.transform = Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY);
const fullRotationMatrix = Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY);

let selectedTileset;
let initialMousePosition;
const enableTransformEditor = true;

const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);

handler.setInputAction(async (click) => {
  const pickedObject = viewer.scene.pick(click.position);
  if (enableTransformEditor && pickedObject && !pickedObject.id) {
    selectedTileset = pickedObject.primitive;
    initialMousePosition = Cesium.Cartesian2.clone(click.position);
  }
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);

handler.setInputAction((click) => {
  selectedTileset = null;
  initialMousePosition = null;
}, Cesium.ScreenSpaceEventType.LEFT_UP);

handler.setInputAction((movement) => {
  if (selectedTileset && initialMousePosition) {
    const translation = new Cesium.Cartesian3();
    Cesium.Matrix4.getTranslation(selectedTileset.modelMatrix, translation);

    const dx = movement.endPosition.x - initialMousePosition.x;
    const yaw = Cesium.Math.toRadians(dx);

    // Compute the rotation matrix, and multiply it
    // to the "full rotation matrix"
    const rotation3 = Cesium.Matrix3.fromRotationZ(yaw);
    const rotationMatrix = Cesium.Matrix4.fromRotation(rotation3);

    Cesium.Matrix4.multiply(
      fullRotationMatrix,
      rotationMatrix,
      fullRotationMatrix
    );

    // Compute the new model matrix from the
    // root transform and the full rotation matrix
    const newModelMatrix = Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY);
    Cesium.Matrix4.multiply(rootTransform, fullRotationMatrix, newModelMatrix);

    // Apply the new model matrix
    selectedTileset.modelMatrix = newModelMatrix;

    // Update initialMousePosition for the next movement
    initialMousePosition = Cesium.Cartesian2.clone(movement.endPosition);
  }
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

viewer.zoomTo(tileset);
相关推荐
前端Hardy3 小时前
HTML&CSS:惊!3D 折叠按钮
css·3d·html
工业3D_大熊5 小时前
【CAE开发SDK】CEETRON Envision:适用于桌面端、Web端的数据可视化与分析
3d·数据分析·虚拟仿真·cae·cae系统开发·cae可视化·cae数据分析
天天进步20156 小时前
使用 Three.js 创建一个 3D 人形机器人仿真系统
3d
亿达四方SOLIDWORKS9 小时前
3D制图软件SOLIDWORKS:开启高效设计与创新的新纪元
3d·csdn开发云
supermapsupport17 小时前
iClient3D for Cesium在Vue中快速实现场景卷帘
前端·vue.js·3d·cesium·supermap
火星机器人life18 小时前
基于ceres优化的3d激光雷达开源算法
算法·3d
jndingxin1 天前
OpenCV相机标定与3D重建(26)计算两个二维点集之间的部分仿射变换矩阵(2x3)函数 estimateAffinePartial2D()的使用
opencv·3d
烧技湾1 天前
RTMW:实时多人2D和3D 全人体姿态估计
3d·全人体关键点检测
十年一梦实验室2 天前
【C++】sophus : rxso3.hpp 实现了 3D 空间中的旋转和缩放操作的 RxSO3 类 (二十一)
开发语言·c++·人工智能·算法·3d