Skip to content

Commit 39a5c67

Browse files
author
Yuri Pourre
committed
Avoid using absoluteRotation
1 parent 2e13582 commit 39a5c67

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

editor/src/editor/layout/graph.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,19 +910,25 @@ export class EditorGraph extends Component<IEditorGraphProps, IEditorGraphState>
910910
// Store the current world transform
911911
const worldPosition = node.getAbsolutePosition();
912912
const worldRotation = node.rotationQuaternion || node.rotation.toQuaternion();
913-
const worldScaling = node.absoluteScaling;
913+
const worldScaling = node.absoluteScaling.clone();
914914

915915
// Set the new parent
916916
node.parent = newParent;
917917

918918
// Restore the world transform
919919
node.setAbsolutePosition(worldPosition);
920920

921+
// Compute the local rotation based on the parent's rotation
922+
let localRotation = worldRotation;
923+
if (newParent instanceof TransformNode) {
924+
const parentRotation = newParent.absoluteRotationQuaternion;
925+
localRotation = parentRotation.conjugate().multiply(worldRotation);
926+
}
927+
921928
if (node.rotationQuaternion) {
922-
node.absoluteRotationQuaternion.copyFrom(worldRotation);
929+
node.rotationQuaternion.copyFrom(localRotation);
923930
} else {
924-
const rotationVector = worldRotation.toEulerAngles();
925-
node.rotation.copyFrom(rotationVector);
931+
node.rotation.copyFrom(localRotation.toEulerAngles());
926932
}
927933

928934
node.scaling.copyFrom(worldScaling);

0 commit comments

Comments
 (0)