Repository navigation
fix(three-live): pre-load camera-orbit clamp; make auto-rotate match a camera orbit - #131
Merged
Merged
Conversation
…a camera orbit
Two viewer bugs reported from the Three-Architecture live hero (a two-story
house, `camera-orbit="28deg 19deg 23.47m"`, `auto-rotate`, `shadow-intensity`):
1. Wrong initial zoom. `camera-orbit` is applied in `initViewer()` before the
model exists, so `setInitialCamera` clamped 23.47 m against the placeholder
`radius = 1` bounds (`baseMax = 8 m`) and froze it as `customDistance`;
`loadGLBData` never re-resolved it. ThreeView now keeps the raw
distance/zoom request and resolves it against the real bounds on load
(unless the user/API has since changed the distance). Small models are no
longer clamped up to 0.5 m. `min/max-camera-orbit` still apply.
2. A deep false shadow at the second-floor joint that appeared only while
auto-rotating, never when orbiting with the mouse. Three causes; the
turntable is now equivalent to orbiting the camera (the documented
`auto-rotate` contract):
- Scene-authored lights (KHR_lights_punctual, scene-script lights) stayed
fixed in world space while `modelRootMatrix` turned the model, sweeping
facades through sun angles the scene never authored (and invalidating
solar studies). New `src/model-lights.ts` (`resolveWorldLights`) maps
authored lights through the model root on the WebGL2 path, the WebGPU
path, and in shadow-map planning, keeping slot order aligned. The
viewer's default studio lights and WebXR light estimates are tagged
`worldSpace: true` (mirroring `MeshGpu.worldSpace`) and stay fixed; the
IBL environment also stays fixed (model-viewer turntable semantics).
- Shadow frustums were fit to the axis-aligned world AABB, which inflates
~30% at oblique turntable angles, changing texel size, normal bias, and
PCF radius every frame. They are now fit in model-root space
(`computeModelSceneBounds`) and mapped back through `inverse(root)`.
- The WebGL2 `contact-shadow` plugin classified casters by world AABB, so
thin walls became "casters" mid-rotation and stamped a dark quad at the
upper-floor slab height (the visible band). It now classifies and
clusters in root space and rotates its quads with the model.
Verified with a headless-Chrome repro of the real scene: initial distance
8 m -> 23.47 m; mean |mouse-orbit - auto-rotate| RGB delta at 60deg
27.6 -> 2.2 (the remainder is the intentionally world-fixed IBL; 0.55 with
the environment off).
Tests: shadow_maps_test (resolveWorldLights semantics; bias, PCF radius and
model-space shadow map invariant under turntable; light follows model;
worldSpace lights fixed; scaled AR placement) and three_view_test (pre-load
camera-orbit, resetCamera, user zoom survives reload, small model,
max-camera-orbit clamp, default lights worldSpace, contact-shadow quads
rotate rigidly). `npm test` passes.
…o-root lookup - Dedupe the turntable shadow-fit helpers into model-lights (rotateDir / transformPoint) and simplify resolveWorldLights, trimming the WebGPU bundle; raise its gzip budget 25 -> 26 KB (scripts/build.js, README, AGENTS) for the light/shadow correctness fix (~0.8 KB gz). - scene_edits_test: walk up from the test entry point, cwd, and __dirname to find the repo root so the package-exports check also works from bundled / symlinked runfiles trees (google3 Blaze).
RealityKit mesh/material generation aborts the process on a GPU-less simulator host (standalone simctl spawn, as in google3 Blaze), which crashed the whole ThreeCompilerTests bundle. Add requireMetalDevice() and use it in the three tests that build RealityKit entities, matching the existing Metal guard in testMakeTextureKeepsRawBytesAndColorAlpha.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(three-live): pre-load camera-orbit clamp; make auto-rotate match a camera orbit
Two viewer bugs reported from the Three-Architecture live hero (a two-story
house,
camera-orbit="28deg 19deg 23.47m",auto-rotate,shadow-intensity):Wrong initial zoom.
camera-orbitis applied ininitViewer()before themodel exists, so
setInitialCameraclamped 23.47 m against the placeholderradius = 1bounds (baseMax = 8 m) and froze it ascustomDistance;loadGLBDatanever re-resolved it. ThreeView now keeps the rawdistance/zoom request and resolves it against the real bounds on load
(unless the user/API has since changed the distance). Small models are no
longer clamped up to 0.5 m.
min/max-camera-orbitstill apply.A deep false shadow at the second-floor joint that appeared only while
auto-rotating, never when orbiting with the mouse. Three causes; the
turntable is now equivalent to orbiting the camera (the documented
auto-rotatecontract):fixed in world space while
modelRootMatrixturned the model, sweepingfacades through sun angles the scene never authored (and invalidating
solar studies). New
src/model-lights.ts(resolveWorldLights) mapsauthored lights through the model root on the WebGL2 path, the WebGPU
path, and in shadow-map planning, keeping slot order aligned. The
viewer's default studio lights and WebXR light estimates are tagged
worldSpace: true(mirroringMeshGpu.worldSpace) and stay fixed; theIBL environment also stays fixed (model-viewer turntable semantics).
~30% at oblique turntable angles, changing texel size, normal bias, and
PCF radius every frame. They are now fit in model-root space
(
computeModelSceneBounds) and mapped back throughinverse(root).contact-shadowplugin classified casters by world AABB, sothin walls became "casters" mid-rotation and stamped a dark quad at the
upper-floor slab height (the visible band). It now classifies and
clusters in root space and rotates its quads with the model.
Verified with a headless-Chrome repro of the real scene: initial distance
8 m -> 23.47 m; mean |mouse-orbit - auto-rotate| RGB delta at 60deg
27.6 -> 2.2 (the remainder is the intentionally world-fixed IBL; 0.55 with
the environment off).
Tests: shadow_maps_test (resolveWorldLights semantics; bias, PCF radius and
model-space shadow map invariant under turntable; light follows model;
worldSpace lights fixed; scaled AR placement) and three_view_test (pre-load
camera-orbit, resetCamera, user zoom survives reload, small model,
max-camera-orbit clamp, default lights worldSpace, contact-shadow quads
rotate rigidly).
npm testpasses.