studio: scale the camera's near and far planes with the model fit (STUDIO-FIT-CLIP-PLANES) #2136

Merged
syfyra merged 1 commit from upstream-pr/2136 into main 2026-12-02 11:46:29 +00:00
syfyra commented 2026-11-25 22:29:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by syfyra on 2026-11-25T22:29:18Z.


Claimed in the coordination issue as: STUDIO-FIT-CLIP-PLANES (claim comment to follow)

What and why

viewer/studio.html creates its camera once with near = 0.1 and far = 1000. The auto-fit in loadModel then places it at maxDim * (1.5, 1.2, 1.8), about 2.63 x maxDim from the model's centre, and never changes either plane. Every point of the model lies within half its box diagonal of that centre, so:

model depth range after the fit result on main
2 cm cube (a ring, a cartridge) 0.036 .. 0.070 wholly in front of the near plane: empty canvas
5 m car-sized box about 10.7 .. 15.6 fine
600 x 40 x 600 m terrain tile 1,194 .. 1,965 wholly beyond the far plane: empty canvas

Clipping starts below about 6 cm and above about 290 m. The gallery sorts such models into categories of their own (farlod, terrain, road, level in tools/gallery.py).

The fit now sets near to 1/1000 and far to 100 times its distance and calls updateProjectionMatrix(), which leaves room to zoom 1000x in and 100x out from the fitted view.

This is separate from #1490 (STUDIO-RESET-CAMERA-FIT, Reset Camera returning to the fitted view). Both extend the test harness's fake camera on the same line, so whichever lands second needs a one-line rebase of tests/test_viewer_studio.cjs; viewer/studio.html merges cleanly with it.

Tested

  • node --test tests/test_viewer_studio.cjs (Node 26): a new test fits a 2 cm cube, a 5 x 1.5 x 2 m box and a 600 x 40 x 600 m tile and checks the model's whole depth range lies between the near and far planes and that the projection was rebuilt. It fails on main (0.02 m: near 0.1 clips the model); with the change all 13 tests pass. The harness camera gains near, far and updateProjectionMatrix.
  • Not checked in a browser: the change is three assignments on the three.js r128 PerspectiveCamera the page already uses.
  • scripts/check_no_game_data.py on both files.

GPUs tested: n/a (viewer logic, Node harness)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5500277476 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2136). Originally posted by [syfyra](https://github.com/syfyra) on 2026-11-25T22:29:18Z. --- Claimed in the coordination issue as: STUDIO-FIT-CLIP-PLANES (claim comment to follow) ### What and why `viewer/studio.html` creates its camera once with `near = 0.1` and `far = 1000`. The auto-fit in `loadModel` then places it at `maxDim * (1.5, 1.2, 1.8)`, about 2.63 x maxDim from the model's centre, and never changes either plane. Every point of the model lies within half its box diagonal of that centre, so: | model | depth range after the fit | result on `main` | |---|---|---| | 2 cm cube (a ring, a cartridge) | 0.036 .. 0.070 | wholly in front of the near plane: empty canvas | | 5 m car-sized box | about 10.7 .. 15.6 | fine | | 600 x 40 x 600 m terrain tile | 1,194 .. 1,965 | wholly beyond the far plane: empty canvas | Clipping starts below about 6 cm and above about 290 m. The gallery sorts such models into categories of their own (`farlod`, `terrain`, `road`, `level` in `tools/gallery.py`). The fit now sets `near` to 1/1000 and `far` to 100 times its distance and calls `updateProjectionMatrix()`, which leaves room to zoom 1000x in and 100x out from the fitted view. This is separate from #1490 (STUDIO-RESET-CAMERA-FIT, Reset Camera returning to the fitted view). Both extend the test harness's fake camera on the same line, so whichever lands second needs a one-line rebase of `tests/test_viewer_studio.cjs`; `viewer/studio.html` merges cleanly with it. ### Tested - `node --test tests/test_viewer_studio.cjs` (Node 26): a new test fits a 2 cm cube, a 5 x 1.5 x 2 m box and a 600 x 40 x 600 m tile and checks the model's whole depth range lies between the near and far planes and that the projection was rebuilt. It fails on `main` (`0.02 m: near 0.1 clips the model`); with the change all 13 tests pass. The harness camera gains `near`, `far` and `updateProjectionMatrix`. - Not checked in a browser: the change is three assignments on the three.js r128 `PerspectiveCamera` the page already uses. - `scripts/check_no_game_data.py` on both files. GPUs tested: n/a (viewer logic, Node harness) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
aslan2142 commented 2026-12-01 12:01:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:01:08Z.

Review: COMMENTED


Draft review against current main: scaling camera.near/camera.far with fitDistance in viewer/studio.html:779-785 looks clean and clean-room verified, but this branch currently conflicts with main and has no CI run yet. Please rebase onto current main and mark Ready for Review so CI runs green.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130859502 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2136#pullrequestreview-6130859502). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:01:08Z. **Review:** COMMENTED --- Draft review against current `main`: scaling `camera.near`/`camera.far` with `fitDistance` in `viewer/studio.html:779-785` looks clean and clean-room verified, but this branch currently conflicts with `main` and has no CI run yet. Please rebase onto current `main` and mark Ready for Review so CI runs green. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 12:23:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:23:09Z.


Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7311055921 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2136#issuecomment-7311055921). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:23:09Z. --- Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 13:00:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T13:00:45Z.

Review: CHANGES_REQUESTED


Now ready for review, requesting changes before merge:

  • Merge conflicts (CONFLICTING/DIRTY): conflicts with main in viewer/studio.html / tests/test_viewer_studio.cjs. The camera near/far clip scaling in viewer/studio.html:779-785 looks clean once rebased.
  • CI: no CI runs on the current head. Please rebase onto current main and get fresh green CI.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6131745778 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2136#pullrequestreview-6131745778). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T13:00:45Z. **Review:** CHANGES_REQUESTED --- Now ready for review, requesting changes before merge: - **Merge conflicts (`CONFLICTING`/`DIRTY`)**: conflicts with `main` in `viewer/studio.html` / `tests/test_viewer_studio.cjs`. The camera near/far clip scaling in `viewer/studio.html:779-785` looks clean once rebased. - **CI**: no CI runs on the current head. Please rebase onto current `main` and get fresh green CI. *(AI-assisted review.)*
MoonEyes commented 2026-12-02 10:32:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:32:30Z.


For information: this pull request is carried in #3092, which merges your head (your commits are kept) into current main, resolves the conflicts keeping both sides, and fixes the points raised in review here (details in its description). This one stays open until a maintainer decides; if you pick it up again, say so and the carry can be closed.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7342620886 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2136#issuecomment-7342620886). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T10:32:30Z. --- For information: this pull request is carried in #3092, which merges your head (your commits are kept) into current `main`, resolves the conflicts keeping both sides, and fixes the points raised in review here (details in its description). This one stays open until a maintainer decides; if you pick it up again, say so and the carry can be closed. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2136
No description provided.