Skip to content

[Maintainer] editor: restore scene auto-framing on load - #1244

Merged
Aymericr merged 10 commits into
mainfrom
cursor/scene-auto-framing-11c1
Nov 10, 2026
Merged

Aymericr merged 10 commits into
mainfrom
cursor/scene-auto-framing-11c1

Conversation

@Aymericr

@Aymericr Aymericr commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Maintainer port of #766 by @ActArtech, brought up to current main. The contributor's commits are kept with their authorship.

Opening a project now frames the scene instead of leaving the camera at the default pose:

  • EditorContent mounts useAutoFrame() and sends camera-controls:fit-scene again once per load, when the viewer reports the scene ready.
  • Bounds are in world space (3fe423cd, Codex P1): computeSceneBoundsXZ accumulates each ancestor's position and rotation yaw, so a moved or rotated building frames on where it actually is.
    • Doors, windows and wall items are bounded by their wall, not by their wall-local position (dd0570c3).
  • Orthographic zoom is fitted (cd4f3cf1, Codex P1): the fit plan includes a sphere centred on the pivot, and an orthographic camera gets fitToSphere after setLookAt, the same way frameViewerCamera does it. Perspective is unchanged.
  • Level follow (1df23a00): a pure planLevelFollow decides between the default pose (first run, empty scene), a pivot rest (first run over a loaded scene, or a level, level-mode or camera change), or nothing. When the controls rebuild, for example after leaving XR, the pivot rests on the level instead of staying at the origin.
    • The merge keeps main's sticky lastLevelId, keepEyeOverGround and the pivot re-rest when a new controls instance is built.
  • Fit planning lives in pure helpers in fit-scene-framing.ts. A fit requested in first-person, or before the orbit controls mount, is queued and applied when orbit resumes. Framing rests the pivot on the selected level's ground.
  • window.__pascalCameraControls stays dev-only.

How to test

  1. bun dev, open a project with content far from the origin, e.g. /project/villa-offset or /project/seattle-parking.
  2. Don't touch the canvas: the camera animates to frame the scene. On main it stays on the default pose (zoomed into the middle of the site).
  3. Switch to the orthographic camera and open a differently sized project: the zoom fits the new scene.
  4. Switch levels and toggle Stack / Full height: the camera follows the level.
  5. Enter first-person, load another project, exit first-person: the new scene is framed.
  6. bun test packages/editor/src/components/editor/fit-scene-framing.test.ts packages/editor/src/lib/scene-bounds.test.ts

Screenshots / screen recording

Scene Before (main) After (this PR)
villa-offset before after
seattle-parking before after

Load of seattle-parking, before then after (no input):

pr766_load_framing_before_after.mp4

These captures predate the bounds, zoom and level-follow commits.

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

Local bun run ci passed on dd0570c3 (exit 0). Remaining follow-ups:

  • Follow Pascal treats the automatic fit as the person taking over.
  • The pending-fit retry is a single animation frame.
  • Stair segments placed relative to the previous one, and openings on roof faces, are bounded approximately.

Supersedes #766. Credit: @ActArtech.

Co-authored-by: ActArtech [email protected]

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

Note

Medium Risk
Changes core editor camera behavior on every project load and level/camera transitions; regressions would affect framing, orthographic zoom, or first-person/orbit handoff rather than security.

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

ActArtech and others added 6 commits September 13, 2026 02:53
…obbering it

useAutoFrame was accidentally removed in e688792, so nothing emitted camera-controls:fit-scene on load; the level-follow effect's first-run default pose then reset the camera after framing on fast client-side navigations. Restore the hook, gate the default pose to scene-less editors, skip the initial null->level transition, and re-emit fit-scene once the viewer signals scene-ready.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <[email protected]>
Assert EditorContent mounts useAutoFrame and re-emits fit-scene on
viewer scene-ready, and that CustomCameraControls keeps the
__pascalCameraControls helper ungated by NODE_ENV.
Bugbot on #766: the level-follow early return treated every same-id rerun
and every null->level as a no-op. Keep the first auto-select skip so
auto-frame still owns load, but follow exploded/stacked Y changes and a
level pick after building/breadcrumb/resetSelection.
Bugbot on #766: skipping the first null->level in the controls lifetime
also dropped a real pick when load restored site phase (levelId null).
Keep first-load auto-frame / empty-scene default pose; after that, pan
on level or levelMode changes. Y-idempotence still swallows no-ops.
Queue fit-scene while orbit controls are unmounted (first-person or
pre-ref), flush on orbit resume, and cover the FP->orbit transition
with a behavioral helper test for Aymericr's #766 review.
Resolves the conflicts with main's camera rework:
- Level-follow keeps the PR's "pan only on a real change" rule, but uses
  main's sticky last level and also re-rests the pivot when drei builds a
  new controls instance for a new default camera.
- Fit-scene framing rests the pivot on the selected level's ground and keeps
  the eye over the ground, as main's handler did.
- Keeps main's dev-only gate on window.__pascalCameraControls and drops the
  source-string wiring test that asserted the gate was gone.
- The scene-ready re-emit fires once per load, not on every viewer remount.

Co-authored-by: ActArtech <[email protected]>
@Aymericr Aymericr added the bot:maintainer label Nov 9, 2026 — with Cursor
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T21:47:52.993829Z 112fda7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 112fda792e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@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 112fda7. Configure here.

cursoragent and others added 4 commits November 9, 2026 23:24
computeSceneBoundsXZ mixed a building's world position with its
descendants' building-local wall endpoints and polygons, so a moved
building framed the span between the origin and the building, and a
rotated one ignored the turn. Compose each node's parent chain
(position plus rotation yaw, via core's turnPlanPoint/yawOf, the
BuildingRenderer convention) before extending the bounds.

Co-authored-by: ActArtech <[email protected]>
setLookAt moves only the eye and target, so a persisted orthographic
camera kept the previous project's zoom and could open a differently
sized scene empty or cropped. The fit-scene look-at now carries a
footprint sphere centred on the pivot, and the orthographic apply path
fits it with fitToSphere as frameViewerCamera does. Perspective framing
is unchanged.

Co-authored-by: ActArtech <[email protected]>
…oaded

The level-follow effect's first run returned early for any non-empty
scene, skipping the default pose and the rest-pivot-on-floor step. Its
controls remount on leaving XR or after error-boundary recovery while
the once-per-load fit-scene re-emit does not fire again, so the fresh
pivot stayed at the origin. planLevelFollow now keeps the default pose
for an empty first load only and treats a loaded first run like a
camera change (a real load's later scene-ready fit still wins). The
previous-value bookkeeping moves after the controls guard.

Co-authored-by: ActArtech <[email protected]>
Doors, windows and wall items carry a wall-local position; reading it as
level-local pulled the frame towards the origin. The wall's endpoints
already bound them.

Co-authored-by: ActArtech <[email protected]>
@Aymericr
Aymericr merged commit 34c4546 into main Nov 10, 2026
4 checks passed
@Aymericr
Aymericr deleted the cursor/scene-auto-framing-11c1 branch November 10, 2026 00:02
cursor Bot pushed a commit that referenced this pull request Nov 10, 2026
…ments

Conflicts:
- packages/editor/src/i18n/locales/{en,en-XA}/messages.ts: compiled
  catalogs conflicted on both branches' new messages; regenerated with
  `bun run i18n:extract` rather than hand-merged. `bun run i18n:check`
  passes.

Everything else auto-merged; `bun run ci` covers the files both sides
touched (core/index.ts, floating-action-menu.tsx, en/messages.po).

Co-authored-by: sudhir <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants