Skip to content

viewer: reset Studio camera to the selected model fit (BUILD-1516) - #5017

Open
Misha0009 wants to merge 1 commit into
ItsNotRexed:mainfrom
Misha0009:fix/studio-camera-reset
Open

Misha0009 wants to merge 1 commit into
ItsNotRexed:mainfrom
Misha0009:fix/studio-camera-reset

Conversation

@Misha0009

Copy link
Copy Markdown

viewer: reset Studio camera to the selected model fit (BUILD-1516)

Item: BUILD-1516. Claim: coordination issue #4933.

Problem

The Studio's Reset Camera button calls OrbitControls.reset(). After a model loads, the page positions the camera to fit that model, but Reset Camera still restores the startup pose (0, 2, 5). This can put the camera inside or immediately against a larger model instead of showing the complete object.

On upstream 3faac557, the synthetic Studio regression loads a model with maximum dimension 30, which fits at (45, 36, 54). After panning/moving the camera and activating Reset Camera, the actual position is (0, 2, 5).

Root cause and fix

The Studio loads Three.js r128 OrbitControls, whose constructor captures the initial camera position, target and zoom for reset(). The API's saveState() method updates that snapshot. See OrbitControls r128 source.

Save the new fitted state immediately after the successful model-load callback updates the controls. Reset then uses the fit for the active model, including after selecting another model of a different size. Before any successful load, the initial empty-scene reset behaviour is unchanged.

Verification

Synthetic regression tests execute viewer/studio.html's actual load and reset handlers via Node's VM, with lightweight GLTFLoader, Box3 and OrbitControls stubs. The OrbitControls stub implements the snapshot semantics in r128. No browser, network, external assets or game files are used.

  • On upstream 3faac557, adding the new test before the fix yields one failure ((0, 2, 5) instead of (45, 36, 54)) and one passing control case (reset with no loaded model).
  • With the fix, the test checks the fitted view and a zero target after loading, moving, and resetting two different model sizes; the no-model reset remains unchanged.
  • node --test tests/test_viewer_studio_camera.cjs tests/test_viewer_streaming.cjs: 53/53 passed (Node v26.10.0, Apple M5, macOS 27.2.1).
  • python3 -I tests/test_ci_registration.py: 11/11 passed. The new root-level JS test is already included by the existing node --test tests/test_*.cjs CI command.
  • python3 -I scripts/check_no_game_data.py viewer/studio.html tests/test_viewer_studio_camera.cjs: passed.
  • git diff --check: clean.

Independent review confirmed the r128 OrbitControls snapshot/restore contract and reran both new tests and all 11 CI registration checks successfully.

No visual or real WebGL driver behaviour is claimed; the tested defect is the camera-reset snapshot, not the transient effects of OrbitControls damping or active auto-rotation. This is distinct from #3923 (stale model requests and disposal). Its current patch overlaps the fitted-camera callback and its test stub does not yet implement saveState(), so integration will need a small reconciliation (including the stub); there is no functional dependency between the repairs. The final audit reproduced the one baseline failure and one passing control, reran all 53 Node and 11 CI-registration tests, and rechecked the clean diff.

AI-assisted (Codex). No game data, keys, decryption or protected files were used.

@Atomic258

Copy link
Copy Markdown
Contributor

Independent check — pass (Node 22 test runner, no game files).

Environment: Windows 11, Node.js.

  • node --test tests/test_viewer_studio_camera.cjs → 2 pass, 0 fail on the PR head
  • Negative control: same test against main's viewer/studio.html → 1 fail — the Studio camera doesn't reset to the selected model's fit on the parent (BUILD-1516)

AI-assisted (Devin).

@whattheflop

Copy link
Copy Markdown
Contributor

T3 Preview check of 86047cb0 with #4763 ee259056 on 3faac557, clean merged tree 0f14fd5b. With the stock local Gallery route and actual Three.js r128 OrbitControls, I loaded two synthetic GLBs from the model list, changed camera position, target, and zoom, then used Reset Camera. All three selections (2-unit, 40-unit, then 2-unit pyramid) restored the exact fitted position, target, and zoom. Fitted positions were [3, 2.4, 3.6] and [60, 48, 72]. The scratch Gallery served integrity-checked copies of the pinned Three.js scripts locally because the CDN fallback did not load here. All 63 combined Node tests passed. AI-assisted, synthetic inputs only.

@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Studio camera integration check

Confirmed the test integration reported in #5083 (comment) using an isolated local tree combining:

Retain #5017's controls.saveState() after controls.update() and #5083's clip-plane changes and projection refresh. Add the projection method to the camera mock in tests/test_viewer_studio_camera.cjs:

-    const camera = { position: new Vector3(0, 2, 5), zoom: 1 };
+    const camera = { position: new Vector3(0, 2, 5), zoom: 1, updateProjectionMatrix() {} };

On Windows 11 with Node 24.18.0, the stock combined command node --test tests/test_viewer_studio_camera.cjs tests/test_viewer_studio_clipping.cjs gives 5 passes and 1 failure: TypeError: camera.updateProjectionMatrix is not a function. With only the mock-method addition, the same command passes all 6 tests. The clipping test remains byte-identical to #5083, and git diff --check passes.

This is a test-stub integration change. Both published branches were left unchanged; no competing PR was created. The relevant source is viewer/studio.html, so the separate map-streaming suite was not rerun. Synthetic CPU callback tests only; no browser, WebGL, GPU, driver, or game-data validation claimed. AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 86047cb on Windows Server 2022, CPython 3.13.12: pass

  • node tests/test_viewer_studio_camera.cjs -> pass 2, fail 0 (Node v24.22.2)
  • Negative control (viewer/studio.html swapped to upstream/main): pass 1, fail 1

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

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.

4 participants