Skip to content

Commit

Permalink
fix rotation then translation of the box helper
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentfretin committed Jun 14, 2024
1 parent af41f6a commit 996b3b5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/editor/lib/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { sendMetric } from '../services/ga.js';

const auxEuler = new THREE.Euler();
const auxPosition = new THREE.Vector3();
const auxLocalPosition = new THREE.Vector3();
const origin = new THREE.Vector3();
const auxScale = new THREE.Vector3();
const auxQuaternion = new THREE.Quaternion();
const identityQuaternion = new THREE.Quaternion();
Expand All @@ -21,14 +23,16 @@ class MyBoxHelper extends THREE.BoxHelper {
// We also undo the parent world rotation.
if (this.object !== undefined) {
auxEuler.copy(this.object.rotation);
auxLocalPosition.copy(this.object.position);
this.object.rotation.set(0, 0, 0);
this.object.position.set(0, 0, 0);

this.object.parent.matrixWorld.decompose(
auxPosition,
auxQuaternion,
auxScale
);
auxMatrix.compose(auxPosition, identityQuaternion, auxScale);
auxMatrix.compose(origin, identityQuaternion, auxScale);
this.object.parent.matrixWorld.copy(auxMatrix);
}

Expand All @@ -42,7 +46,9 @@ class MyBoxHelper extends THREE.BoxHelper {
auxScale
);
this.object.rotation.copy(auxEuler);
this.object.position.copy(auxLocalPosition);
this.rotation.copy(auxEuler);
this.object.getWorldPosition(this.position);
this.updateMatrix();
}
}
Expand Down

0 comments on commit 996b3b5

Please sign in to comment.