Hi everyone,
I am currently facing an issue where the model disappears when i apply any sort of rotation to my 3DTileset based on mouse movement. Previously i have been able to update the height of the model in a relatively straightforward way but for rotation if i update the modelMatrix the model disappears from the viewer.
I have shared the loading of my 3dtileset as well as part of the rotation code below:
let tileset = this._viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
url: _tile_path,
geometricError: 0.001,
skipLevelOfDetail : true,
baseScreenSpaceError : 1024,
skipScreenSpaceErrorFactor : 16,
skipLevels : 1,
immediatelyLoadDesiredLevelOfDetail : false,
cullWithChildrenBounds : true,
maximumScreenSpaceError : 4,
})
);
this._clickHandler.setInputAction(async (click) => {
const pickedObject = this._viewer.scene.pick(click.position);
if (this._enableTransformEditor && pickedObject && !pickedObject.id) {
this.selectedTileset = pickedObject.primitive;
this.initialMousePosition = Cesium.Cartesian2.clone(click.position);
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this._clickHandler.setInputAction((click) => {
this.selectedTileset = null;
this.initialMousePosition = null;
}, Cesium.ScreenSpaceEventType.LEFT_UP);
this._clickHandler.setInputAction((movement) => {
if (this.selectedTileset && this.initialMousePosition) {
const translation = new Cesium.Cartesian3();
Cesium.Matrix4.getTranslation(this.selectedTileset.modelMatrix, translation);
const dx = movement.endPosition.x - this.initialMousePosition.x;
// Convert the dx value to a yaw rotation angle
const yaw = Cesium.Math.toRadians(dx / 100);
// Step 1: Translate to Origin
const translationToOrigin = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(-translation.x, -translation.y, -translation.z));
const translatedModelMatrix = new Cesium.Matrix4();
Cesium.Matrix4.multiply(this.selectedTileset.modelMatrix, translationToOrigin, translatedModelMatrix);
// Step 2: Rotate using yaw, pitch, and roll (in this case, just yaw)
const rotationMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(Cesium.Cartesian3.ZERO, new Cesium.HeadingPitchRoll(yaw, 0, 0));
const rotatedModelMatrix = new Cesium.Matrix4();
Cesium.Matrix4.multiply(translatedModelMatrix, rotationMatrix, rotatedModelMatrix);
// Step 3: Translate back to original position
const translationBack = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(translation.x, translation.y, translation.z));
const newModelMatrix = new Cesium.Matrix4();
Cesium.Matrix4.multiply(rotatedModelMatrix, translationBack, newModelMatrix);
// Apply the new model matrix
this.selectedTileset.modelMatrix = newModelMatrix;
// Update initialMousePosition for the next movement
this.initialMousePosition = Cesium.Cartesian2.clone(movement.endPosition);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
Your feedback would be highly appreciated in this regard.