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

Open
github-bot wants to merge 1 commit from github-bot/gh-2136 into main AGit
Owner

@⁠syfyra on GitHub · 2026-11-25 22:29 UTC · original
syfyra:fix/studio-fit-clip-planes → main · +28 −1 · 2 files · 1 commits · draft

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

**@⁠syfyra** on GitHub · 2026-11-25 22:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2136) `syfyra:fix/studio-fit-clip-planes` → `main` · +28 −1 · 2 files · 1 commits · draft 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)
The model viewer creates its camera once with near 0.1 and far 1000, and
the auto-fit then places it at maxDim * (1.5, 1.2, 1.8), about 2.63 x
maxDim from the model's centre, without touching either plane. Every
point of the model lies within half its diagonal of that centre, so a
model under about 6 cm sat wholly in front of the near plane and one over
about 290 m wholly beyond the far plane: the canvas stayed empty. A 2 cm
prop's depth range is 0.036..0.070, a 600 x 40 x 600 m terrain tile's is
1,194..1,965; the gallery sorts such models into its own categories
(farlod, terrain, road, level).

The fit now sets near to 1/1000 and far to 100 x its distance and
rebuilds the projection, which leaves room to zoom in and out.

Tested: node --test tests/test_viewer_studio.cjs (Node 26). The new test
fits a 2 cm cube, a 5 m car-sized box and a 600 m tile and checks the
model's depth range lies between the planes; it fails on main (near 0.1
clips the 2 cm cube) and all 13 tests pass with the change. The harness
camera gains near, far and updateProjectionMatrix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:19:24 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2136/head:github-bot/gh-2136'
git switch 'github-bot/gh-2136'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2136'
git switch 'github-bot/gh-2136'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2136'
git switch 'github-bot/gh-2136'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2136'
git switch 'main'
git merge --squash 'github-bot/gh-2136'
git switch 'main'
git merge --ff-only 'github-bot/gh-2136'
git switch 'main'
git merge 'github-bot/gh-2136'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.