How to get primitive orientation?

Hi.

I want to get primitive’s orientation and transform to Heading, Pitch, Roll.

const tileset = viewer.scene.primitives.add(
      new Cesium.Cesium3DTileset({
        url: Cesium.IonResource.fromAssetId(933228),
      }),
    );

// What I need to do next

Hi there,

3D tilesets in particular have a modelMatrix property which describes the transformation. A bit verbose, but you can turn this into HeadingPitchRoll like so:

const rotation = Cesium.Matrix4.getMatrix3(modelMatrix, new Cesium.Matrix3());
const quaternion = Cesium.Quaternion.fromRotationMatrix(rotation);
const hpr = Cesium.HeadingPitchRoll.fromQuaternion(quaternion);

Hi Gabby_Getz

This is my 3d tile in Cesium Ion


This model heading is 90 degree

I follow your example and get this result

    const viewer = new Cesium.Viewer('cesium-viewer');
    const tileset = viewer.scene.primitives.add(
      new Cesium.Cesium3DTileset({
        url: Cesium.IonResource.fromAssetId(933228),
      }),
    );
    const rotation = Cesium.Matrix4.getMatrix3(
      tileset.modelMatrix,
      new Cesium.Matrix3(),
    );
    const quaternion = Cesium.Quaternion.fromRotationMatrix(rotation);
    const hpr = Cesium.HeadingPitchRoll.fromQuaternion(quaternion);

    console.log('modelMatrix', tileset.modelMatrix);
    /* Matrix4
     [
         1, 0, 0, 0
         0, 1, 0, 0
         0, 0, 1, 0
         0, 0, 0, 1
     ]
    */
    console.log('hpr', hpr);
    // HeadingPitchRoll {heading: -0, pitch: -0, roll: 0}

Hi @steven11329,

To clarify: do you want to get the orientation of the models within the tileset? I’m afraid you can’t access individual models through the public API, but you can find the transform of the tile that contains the geometry.

For example, if the root tile of the tileset has geometry, you can fetch it via tileset.root and get its transform. If the geometry is located in its children instead, you can access them via tile.children. Hope that helps!

Also Transforms.fixedFrameToHeadingPitchRoll is an easier way to get the heading, pitch, and roll values from the original matrix.

Yes, I want to get rotation info like Cesium Ion (I posted photo before) by public API.
If no way, It’s OK.