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);
相关推荐
starsongda7 小时前
VR科技展厅重塑科技展示新风貌,引领未来展示潮流
科技·3d·vr
兔老大的胡萝卜7 小时前
threejs 数字孪生,制作3d炫酷网页
前端·3d
CV-X.WANG11 小时前
【详细 工程向】基于Smart3D的五镜头相机三维重建
数码相机·3d
JoeyKo18 小时前
国内版Sketchfab平台 - CG美术之家(3D编辑发布篇)
3d·3d建模·3dsmax·3d渲染·模型·3d模型·cg模型
mirrornan20 小时前
3D互动+AR试戴,重塑线上珠宝营销新体验!
3d·ar
DisonTangor1 天前
腾讯混元3D-1.0:文本到三维和图像到三维生成的统一框架
人工智能·3d·aigc
坠金2 天前
【3D】基础概念
3d
小白菜学前端2 天前
ThreeJS创建一个3D物体的基本流程
3d·three.js
梦想的理由3 天前
3D人体建模的前沿探索:细数主流模型与技术进展
3d
吃个糖糖3 天前
Halcon 3D表面匹配
3d