You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working with #30, I was wondering if there's a cleaner way to handle raycasting and pointer events. I'm thinking of a two-step approach, raycaster-first and object-first.
Raycaster-first
Sometimes I want to raycast against everything in a crowded scene - in this case, I'd rather write a single raycaster's pointerEnter and pointerLeave functions than those of all the objects in the scene. To accomplish this, we could add a Raycaster component:
This would raycast against everything (raycaster.intersectObjects(scene.children)) and fire appropriate callbacks when pointer interactions start and end. We could also include an optional prop targetObjects if the user wants to specify which objects to target if they don't want all of them.
Object-first
I'm finding the <Renderer mouse-over> and mesh :onHover prop a little confusing - maybe we could do something like this:
Add pointerEnter and pointerLeave props to all Meshes
In a mesh's initialization, if either pointerEnter or pointerLeave are defined, check for this.three.raycaster.
If one is defined, add the mesh to the list of target objects the raycaster can intersect.
If one is not defined, tell this.three to create one (a new method like this.three.initializeRaycaster()), then add the mesh to the list of target objects.
From there, three.raycaster can handle calling events on meshes when the pointer enters or leaves them. This way we don't need any Renderer-level awareness of raycasting and the pointerEnter/pointerLeave events more closely match the Raycast component above (plus they're more clearly named for handling non-mouse inputs).
Happy to add this in the next couple days if it sounds worthwhile - let me know any thoughts @klevron !
The text was updated successfully, but these errors were encountered:
While working with #30, I was wondering if there's a cleaner way to handle raycasting and pointer events. I'm thinking of a two-step approach, raycaster-first and object-first.
Raycaster-first
Sometimes I want to raycast against everything in a crowded scene - in this case, I'd rather write a single raycaster's
pointerEnter
andpointerLeave
functions than those of all the objects in the scene. To accomplish this, we could add aRaycaster
component:This would raycast against everything (
raycaster.intersectObjects(scene.children)
) and fire appropriate callbacks when pointer interactions start and end. We could also include an optional proptargetObjects
if the user wants to specify which objects to target if they don't want all of them.Object-first
I'm finding the
<Renderer mouse-over>
and mesh:onHover
prop a little confusing - maybe we could do something like this:pointerEnter
andpointerLeave
props to all MeshespointerEnter
orpointerLeave
are defined, check forthis.three.raycaster
.this.three
to create one (a new method likethis.three.initializeRaycaster()
), then add the mesh to the list of target objects.From there,
three.raycaster
can handle calling events on meshes when the pointer enters or leaves them. This way we don't need anyRenderer
-level awareness of raycasting and thepointerEnter
/pointerLeave
events more closely match the Raycast component above (plus they're more clearly named for handling non-mouse inputs).Happy to add this in the next couple days if it sounds worthwhile - let me know any thoughts @klevron !
The text was updated successfully, but these errors were encountered: