Hi:
My scene uses a gizmo with 3 position gizmo and a rotation-y gizmo, the configure is like below:
const gizmoMgr = new GizmoManager(scene);
gizmoMgr.scaleGizmoEnabled = false;
gizmoMgr.positionGizmoEnabled = true;
gizmoMgr.rotationGizmoEnabled = true;
gizmoMgr.usePointerToAttachGizmos = false;
gizmoMgr.gizmos.rotationGizmo!.xGizmo.isEnabled = false;
gizmoMgr.gizmos.rotationGizmo!.zGizmo.isEnabled = false;
When I use the rotation-y gizmo, the mesh in the scene works well, but the rotationQuaternion.toEulerAngles()
always return a rotation-z(negative PI) and a rotation-y.
I know it is about the rotation order, but can I recaculate it as rotation-Y only? my database uses only rotation Y.
my code is like this:
// the Load-and-Show phase
// worldInfo is from db, the rotation contains string "0" as rotation.x and rotation.y
const { position, rotation, scaling } = nodeInfo.worldInfo;
const rotationArray = [rotation.x, rotation.y, rotation.z].map((v) => toRad(Number(v))) as [
number,
number,
number,
];
// and this is where the gizmo attached
this.rootNode.rotationQuaternion = Quaternion.RotationAxis(Axis.Y, rotationArray[1]);
// the Export phase
this.rootNode.computeWorldMatrix(true);
const { position } = this.rootNode;
const quaternion = this.rootNode.rotationQuaternion!;
quaternion.normalize();
const quaternionRotation = quaternion.toEulerAngles();
return {
soulCode: this.nodeInfo.soulCode,
worldInfo: {
position: getStringCoord(position),
rotation: getStringCoord(quaternionRotation, true), // parse an x,y,z like object to string and turn it into degree (the 2nd arg)
scaling: getStringCoord(scaling),
},
};