Skip to content

objects_3d: use the xb BVH helper instead of patching THREE inline - #378

Merged
ruofeidu merged 4 commits into
google:mainfrom
salmanmkc:feat/objects-3d-followup
Jun 17, 2026
Merged

objects_3d: use the xb BVH helper instead of patching THREE inline#378
ruofeidu merged 4 commits into
google:mainfrom
salmanmkc:feat/objects-3d-followup

Conversation

@salmanmkc

@salmanmkc salmanmkc commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

objects_3d was wiring three-mesh-bvh onto THREE.BufferGeometry itself to speed up the per-object raycasts in detect. now that #372 landed the SDK helper, switch to xb.enableAcceleratedRaycast() so the demo doesn't carry its own copy of that.

also awaits BVH readiness in detect() before raycasting: enableAcceleratedRaycast() imports three-mesh-bvh dynamically, so the first press used to race the import and fall back to the slow path.

stacks on #363, rebase once that lands. (the draggable panel work moved to #379.)

… THREE inline

google#372 landed the BVH helpers in the SDK (utils/BVHRaycast). drop the
direct three-mesh-bvh import + manual Mesh/BufferGeometry prototype
patch and call xb.enableAcceleratedRaycast() instead, which installs
the same computeBoundsTree / disposeBoundsTree helpers via the SDK's
dynamic import.

the per-detect computeBoundsTree() / disposeBoundsTree() calls stay,
they now resolve to the SDK-installed helpers. computeBoundsTree() is
guarded since enableAcceleratedRaycast() is async (dynamic import),
so an early Detect press before it resolves falls back to the stock
raycaster instead of throwing.

importmap keeps three-mesh-bvh (the SDK dynamic-imports it from the
page's module graph at runtime), bumped to 0.9.10 to match the
version the SDK is built against.
…press race

enableAcceleratedRaycast() is async (dynamic import), so the previous
guard only degraded gracefully on an early press, it still ran the
stock raycaster for that press. store the kickoff promise and await it
at the top of detect() (already async) before building the per-press
bounds tree. normally already resolved since it's fired at init, so
this is a no-op wait; a very early press now waits the import out and
gets the accelerated path too.

the computeBoundsTree guard stays for the genuine failure case: if
three-mesh-bvh is unreachable the promise resolves false, the helper
is never installed, and the build is skipped (stock raycaster).
@salmanmkc
salmanmkc force-pushed the feat/objects-3d-followup branch from de18b7d to f215ec4 Compare June 16, 2026 07:10
@salmanmkc salmanmkc changed the title demos/objects_3d: BVH via SDK helper + draggable control panel + clean detect snapshot objects_3d: use the xb BVH helper instead of patching THREE inline Jun 16, 2026
@salmanmkc
salmanmkc marked this pull request as ready for review June 17, 2026 05:50
@ruofeidu
ruofeidu merged commit 0396f43 into google:main Jun 17, 2026
8 checks passed
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.

2 participants