3DTilesRendererJS icon indicating copy to clipboard operation
3DTilesRendererJS copied to clipboard

EnvironmentControls errors when no scene is provided

Open repalash opened this issue 8 months ago • 1 comments

Description

EnvironmentControls errors on raycast when no scene is provided.

three.module.js:49919 Uncaught TypeError: Cannot read properties of null (reading 'layers')
    at intersectObject (three.module.js:49919:14)
    at Raycaster.intersectObject (three.module.js:49887:3)
    at EnvironmentControls2._raycast (EnvironmentControls.js:1388:28)
    at EnvironmentControls2._getPointBelowCamera (EnvironmentControls.js:1114:20)
    at EnvironmentControls2.update (EnvironmentControls.js:721:73)

Not sure if using the controls without scene is a valid usecase, but I saw that there is fallback plane anyway so it could be useful if someone doesn't want to raycast the whole scene.

Reproduction steps

  1. Create and add EnvironmentControls without passing scene
  2. Click on the model

Code

Simple null check should fix it and use the fallback plane

See - https://github.com/repalash/3DTilesRendererJS/commit/4cb2607539d17f899a3f39ad5375bebe904ca059 I can create a PR if it makes sense to support null scene.

Live example

Haven't created yet.

Screenshots & Tile Set

No response

Library Version

v0.4.9

Three.js Version

r157

repalash avatar May 11 '25 19:05 repalash

Thanks - I think this would be a good thing to support. It looks like we'd just need to adjust the raycast function and the pointerdownCallback function where the cursor icon are added.

gkjohnson avatar May 12 '25 00:05 gkjohnson

Hey I'm finally taking a look at this. I tried adjusting this so "Scene" was assigned to an empty group by default so the controls can be used but the issue is that the "drag" icon (the little circle) can no longer show up or be rendered since it's added to that group, which makes it feel broken. I think I'd prefer to keep Scene required by default and the user can assign an empty group if they'd really like but I'm open to other thoughts.

I saw that there is fallback plane anyway so it could be useful if someone doesn't want to raycast the whole scene.

The "fallbackPlane" is designed for the case where a raycast misses the tile geometry so the user can still manipulate the scene.

gkjohnson avatar Jul 01 '25 00:07 gkjohnson

Lets keep scene as a required object, for now. Users can provide an empty object if they'd really like.

gkjohnson avatar Jul 06 '25 00:07 gkjohnson