mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
PageScene: read camera/freeCamState/focalLengthToFov from CameraController
Phase 1 moved camera, freeCamState, and focalLengthToFov off Editor and onto CameraController, but two camera-update blocks in PageEditor (handleSelectCamera and handleAddCamera) still read editorEngine.camera, editorEngine.focalLengthToFov, and editorEngine.freeCamState. Those fields are undefined now, so the cam-update guards short-circuited and the reset/random-camera buttons silently did nothing. Sweep both blocks to read from editorEngine.cameraController.* and collapse the chain into a local `cam` const.
This commit is contained in:
1 parent
b95f6fdf91
commit
aff4a5616e
1 file changed
+16
-18
@@ -186,32 +186,30 @@ export const PageEditor = () => {
|
||||
}, 1500);
|
||||
|
||||
// Update the main camera to match the selected camera's properties
|
||||
if (editorEngine.camera) {
|
||||
// First update position and lookAt
|
||||
editorEngine.camera.position.set(
|
||||
const cam = editorEngine.cameraController.camera;
|
||||
if (cam) {
|
||||
cam.position.set(
|
||||
selectedCamera.position.x,
|
||||
selectedCamera.position.y,
|
||||
selectedCamera.position.z,
|
||||
);
|
||||
editorEngine.camera.lookAt(
|
||||
cam.lookAt(
|
||||
selectedCamera.lookAt.x,
|
||||
selectedCamera.lookAt.y,
|
||||
selectedCamera.lookAt.z,
|
||||
);
|
||||
|
||||
// Update FOV
|
||||
editorEngine.camera.fov = editorEngine.focalLengthToFov(
|
||||
cam.fov = editorEngine.cameraController.focalLengthToFov(
|
||||
selectedCamera.focalLength,
|
||||
);
|
||||
editorEngine.camera.updateProjectionMatrix();
|
||||
cam.updateProjectionMatrix();
|
||||
|
||||
// Reset free-cam motion so a switch doesn't carry over a
|
||||
// half-applied drag from the previous camera.
|
||||
if (editorEngine.freeCamState) {
|
||||
editorEngine.freeCamState.velocity.set(0, 0, 0);
|
||||
if (editorEngine.cameraController.freeCamState) {
|
||||
editorEngine.cameraController.freeCamState.velocity.set(0, 0, 0);
|
||||
}
|
||||
|
||||
// Force a render to update the view
|
||||
editorEngine.renderScene();
|
||||
}
|
||||
|
||||
@@ -262,19 +260,19 @@ export const PageEditor = () => {
|
||||
setSelectedCameraId(newId);
|
||||
|
||||
// Update the engine camera to match the new camera's properties
|
||||
if (editorEngine && editorEngine.camera) {
|
||||
editorEngine.camera.position.set(randomX, randomY, randomZ);
|
||||
editorEngine.camera.lookAt(0, 0, 0);
|
||||
editorEngine.camera.fov = editorEngine.focalLengthToFov(24);
|
||||
editorEngine.camera.updateProjectionMatrix();
|
||||
const cam = editorEngine?.cameraController.camera;
|
||||
if (editorEngine && cam) {
|
||||
cam.position.set(randomX, randomY, randomZ);
|
||||
cam.lookAt(0, 0, 0);
|
||||
cam.fov = editorEngine.cameraController.focalLengthToFov(24);
|
||||
cam.updateProjectionMatrix();
|
||||
|
||||
// Reset free-cam motion so the camera doesn't drift after
|
||||
// teleport.
|
||||
if (editorEngine.freeCamState) {
|
||||
editorEngine.freeCamState.velocity.set(0, 0, 0);
|
||||
if (editorEngine.cameraController.freeCamState) {
|
||||
editorEngine.cameraController.freeCamState.velocity.set(0, 0, 0);
|
||||
}
|
||||
|
||||
// Force a render to update the view
|
||||
editorEngine.renderScene();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user