Skip to content

Commit

Permalink
Keep the camera position when switching to inspector (fix aframevr#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentfretin committed May 23, 2024
1 parent 575c910 commit 7aac171
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/cameras.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,9 @@ function setOrthoCamera(camera, dir, ratio) {
camera.position.copy(info.position);
camera.rotation.copy(info.rotation);
}

export function copyCameraPosition(sourceCamera, targetCamera) {
sourceCamera.getWorldPosition(targetCamera.position);
sourceCamera.getWorldQuaternion(targetCamera.quaternion);
targetCamera.updateMatrixWorld();
}
5 changes: 5 additions & 0 deletions src/lib/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import TransformControls from './TransformControls.js';
import EditorControls from './EditorControls.js';

import { copyCameraPosition } from './cameras';
import { initRaycaster } from './raycaster';
import Events from './Events';

Expand Down Expand Up @@ -225,6 +226,10 @@ export function Viewport(inspector) {
.forEach((element) => {
element.style.display = 'none';
});
copyCameraPosition(
inspector.cameras.original.object3D,
inspector.cameras.perspective
);
} else {
disableControls();
inspector.cameras.original.setAttribute('camera', 'active', 'true');
Expand Down

0 comments on commit 7aac171

Please sign in to comment.