Skip to content

editor: restore saved camera projection and lens on open and view - #1305

Open
kruschdev wants to merge 4 commits into
pascalorg:mainfrom
kruschdev:fix/saved-camera-projection-lens
Open

kruschdev wants to merge 4 commits into
pascalorg:mainfrom
kruschdev:fix/saved-camera-projection-lens

Conversation

@kruschdev

@kruschdev kruschdev commented Nov 22, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes #1280

When opening a project with a saved camera view (site.camera or building.camera) or invoking the saved-camera view actions (camera-controls:view, Preview mode, and header/room frameViewerNode framing), only position and target were previously applied, and handleNodeCapture only recorded position, target, and mode without fov or zoom. Views saved in orthographic mode or with a custom lens therefore reopened in the active projection and lens instead of the saved one.

I updated the saved-camera capture and restore paths so projection and lens round-trip together while keeping older saved views backwards-compatible:

  • Saved camera capture and application (packages/editor/src/components/editor/saved-camera-view.ts, custom-camera-controls.tsx): captureSavedCameraView records fov in perspective mode and settled zoom in orthographic mode alongside position, target, and mode. CustomCameraControls switches cameraMode when needed and defers pose + lens application until the matching Three.js camera and CameraControls instance mount across project open (openingFrame), camera-controls:view (handleNodeView), Preview entry, and camera-controls:frame (handleFrame), while ignoring initial null to level_0 floor hydration so off-floor saved targets are not reset to targetY.
  • Views bar / node framing (packages/core/src/events/bus.ts, packages/viewer/src/ui/lib/viewer-selection.ts): CameraControlFrameEvent.pose and viewerFrameEvent forward optional mode, fov, and zoom from node.camera, and frameViewerCamera applies perspective fov and orthographic zoom when present.
  • Stable default camera prop (packages/viewer/src/components/viewer/viewer-camera.tsx): Hoisted DEFAULT_CAMERA_POSITION so React Three Fiber prop reconciliation does not reset camera.position to [10, 10, 10] when ViewerCamera re-renders after a non-transitioned camera restore.
  • Public schema change (packages/core/src/schema/camera.ts, camera.test.ts): Changed CameraSchema.mode from .default('perspective') to .optional(). For @pascal-app/core consumers and MCP clients reading node.camera.mode, legacy { position, target } cameras now parse with mode: undefined instead of 'perspective' so restoring an older saved view preserves the active projection and lens. Added packages/core/src/schema/camera.test.ts verifying legacy cameras parse without mode and round-trip cleanly.
  • Backwards compatibility: Older saved views that omit mode, fov, or zoom keep the active projection and lens unchanged and apply position and target as before.

How to test

  1. Run bunx biome check on the modified files in packages/core, packages/viewer, and packages/editor (0 errors, 0 warnings).
  2. Run bunx turbo run build check-types test --filter=@pascal-app/core --filter=@pascal-app/viewer --filter=@pascal-app/editor and bun run check:render-bundle.
  3. Verify the new #1280 round-trip suite in packages/editor/src/components/editor/saved-camera-view.test.tsx: perspective views with custom fov and orthographic views with custom zoom round-trip across capture, project open, camera-controls:view, and frameViewerNode, while legacy { position, target } views preserve the current projection and lens.

Screenshots / screen recording

Screen recording: cold project open on saved orthographic view (zoom = 85), switching via the views bar to Studio saved in perspective mode (fov = 24), switching back to Studio House (orthographic, zoom = 85), and reloading the project:

Saved orthographic zoom and perspective FOV restored on open, views bar, and reload

Project opened cold with site.camera saved in orthographic mode at zoom = 85 (position: [12, 10, 12], target: [2, 1.2, -1.5]):

Project cold open on orthographic saved view at zoom = 85

After switching to Perspective and clicking Scene -> Site -> Camera snapshot -> View snapshot (restores identical orthographic projection and zoom = 85):

Restored orthographic saved view via View snapshot

Checklist

  • I've tested this locally with bun dev
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch

Note

Medium Risk
Touches core camera schema semantics and many editor camera lifecycle paths (open, preview, framing); behavior change for legacy node.camera without mode, mitigated by tests but worth regression on navigation edge cases.

Overview
Extends saved node cameras so projection and lens settings round-trip with position/target: orthographic zoom and perspective FOV are captured on snapshot, restored on project open, View snapshot, preview, and views-bar / frameViewerNode framing, with deferred application when cameraMode must switch first.

A new saved-camera-view module centralizes read/capture/apply (including settled orthographic zoom via camera-controls’ _zoomEnd). CustomCameraControls routes opening frame, preview, capture/view, and frame events through applyOrDeferSavedView and tightens level-follow so initial floor hydration does not stomp off-floor saved targets. CameraControlFrameEvent.pose and frameViewerCamera forward and apply optional mode, fov, and zoom. CameraSchema.mode is optional (no default 'perspective') so legacy { position, target } data keeps the active projection/lens on restore. ViewerCamera hoists default position to avoid R3F resetting the camera after instant restores.

Added schema and integration tests covering legacy cameras and #1280 round-trips (open, view, framing, preview exit).

Reviewed by Cursor Bugbot for commit 783208b. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kruschdev for taking #1280, and for keeping older saved views (position + target only) working. Capturing fov/zoom with the view and forwarding them through CameraControlFrameEvent.pose is the right shape. A few points before this can go in:

  1. Schema change in CameraSchema: dropping .default('perspective') from mode changes what every parsed node looks like. Old saved cameras now parse with mode: undefined instead of 'perspective'. I see why you want that (an old view shouldn't force perspective), but it's a public schema change for @pascal-app/core consumers and MCP clients that read node.camera.mode. Please call it out in the description, and add a schema test showing an old camera parses without mode and still round-trips.
  2. _zoomEnd: captureSavedCameraView reads a private CameraControls field. If camera-controls renames it, the code silently falls back to camera.zoom, which can be mid-transition. Could you capture after the zoom settles, or keep this behind a small helper with a comment and a test that fails if the field disappears?
  3. Screen recording: this changes what the user sees on project open and from the views bar. Please add a short clip showing an orthographic view with custom zoom, and a perspective view with a non-default FOV, saved, then reopened and restored from the views bar.
  4. Small: saved-camera-view.ts has its import statements split around a type declaration. Biome may not catch that, but grouping the imports at the top reads better.

I couldn't run saved-camera-view.test.tsx locally (it needs built viewer packages), so CI will be the check. It's waiting on maintainer approval for this fork.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cd93aaa. Configure here.

kruschdev added a commit to kruschdev/editor that referenced this pull request Nov 23, 2026
@kruschdev

Copy link
Copy Markdown
Author

Thanks @Aymericr! I addressed all four points in cd93aaa and updated the PR description:

  1. Public CameraSchema change & schema test: Called out the CameraSchema.mode change (.default('perspective') -> .optional()) in the PR description for @pascal-app/core consumers and MCP clients, and added packages/core/src/schema/camera.test.ts verifying that legacy { position, target } cameras parse with mode: undefined and round-trip cleanly through JSON serialization and SiteNode.parse.
  2. _zoomEnd helper & regression guard: Extracted readSettledOrthographicZoom in saved-camera-view.ts with a comment explaining why it reads camera-controls's private _zoomEnd field (with fallback to camera.zoom), and added explicit assertions in saved-camera-view.test.tsx checking '_zoomEnd' in orthoControls and its mid-transition value so the test fails loudly if camera-controls ever renames or removes that field.
  3. Screen recording: Added a short recording to the PR description showing cold project open landing on a saved orthographic view (zoom = 85), restoring Studio from the views bar in perspective mode with a non-default fov = 24, restoring Studio House back to orthographic (zoom = 85), and reloading the project.
  4. Import grouping: Grouped all import statements at the top of saved-camera-view.ts above type SavedCameraData.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Maintainer] Saved camera views should restore projection and lens, not just position and target

2 participants