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);
相关推荐
魔珐科技1 小时前
当产业经济插上“数字羽翼”,魔珐有言AIGC“3D视频创作大赛”成功举办
3d·aigc·音视频
tealcwu6 小时前
【Unity踩坑】出现d3d11问题导致编辑器崩溃
3d
前端Hardy15 小时前
纯HTML&CSS实现3D旋转地球
前端·javascript·css·3d·html
mirrornan19 小时前
什么是Web3D?有何优势?有哪些应用场景?
3d·web3·webgl·3d模型
工业3D_大熊20 小时前
3D可视化引擎HOOPS Luminate场景图详解:形状的创建、销毁与管理
java·c++·3d·docker·c#·制造·数据可视化
前端Hardy2 天前
HTML&CSS:数据卡片可以这样设计
前端·javascript·css·3d·html
小彭努力中2 天前
138. CSS3DRenderer渲染HTML标签
前端·深度学习·3d·webgl·three.js
AI生成未来2 天前
斯坦福&UC伯克利开源突破性视觉场景生成与编辑技术,精准描绘3D/4D世界!
3d·3d场景·4d
汪洪墩3 天前
【Mars3d】实现这个地图能靠左,不居中的样式效果
前端·javascript·vue.js·3d·webgl·cesium
Bearnaise3 天前
GaussianDreamer: Fast Generation from Text to 3D Gaussians——点云论文阅读(11)
论文阅读·人工智能·python·深度学习·opencv·计算机视觉·3d