Skip to content

Commit 4774c04

Browse files
vincentfretinclaude
andcommitted
Fix editor focus for scaled targets
EditorControls.focus used target.localToWorld to place the camera, which multiplied the world-space bbox-derived offset by the target's world scale. Focusing a model scaled by N ended up N times too far. Decompose matrixWorld instead and rotate the offset by the target's world rotation only. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8b25c8b commit 4774c04

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/lib/EditorControls.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ THREE.EditorControls = function (_object, domElement) {
3434
var pointerOld = new THREE.Vector2();
3535
var spherical = new THREE.Spherical();
3636
var sphere = new THREE.Sphere();
37+
var focusWorldPos = new THREE.Vector3();
38+
var focusWorldQuat = new THREE.Quaternion();
39+
var focusWorldScale = new THREE.Vector3();
40+
var focusOffset = new THREE.Vector3();
3741

3842
this.isOrthographic = false;
3943
this.rotationEnabled = true;
@@ -73,11 +77,17 @@ THREE.EditorControls = function (_object, domElement) {
7377
localCenterY = target.position.y;
7478
}
7579

76-
object.position.copy(
77-
target.localToWorld(
78-
new THREE.Vector3(0, localCenterY + distance * 0.5, distance * 2.5)
79-
)
80+
// Offset in world units (localCenterY / distance come from the world-space bbox), rotated
81+
// by the target's world rotation but NOT multiplied by its world scale.
82+
target.matrixWorld.decompose(
83+
focusWorldPos,
84+
focusWorldQuat,
85+
focusWorldScale
8086
);
87+
focusOffset
88+
.set(0, localCenterY + distance * 0.5, distance * 2.5)
89+
.applyQuaternion(focusWorldQuat);
90+
object.position.copy(focusWorldPos).add(focusOffset);
8191
object.lookAt(center);
8292

8393
scope.dispatchEvent(changeEvent);

0 commit comments

Comments
 (0)