-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pointer EventManager state #515
Comments
Imagine each mesh below is visible on screen and not occluded by any other meshes. <TresCanvas :on-click="() => console.log('Scene')">
<TresGroup :on-click="() => console.log('Group')">
<Sphere :on-click="() => console.log('Sphere')">
<Torus :on-click="() => console.log('Torus')" />
<TorusRing />
</Sphere>
<Box />
</TresGroup>
</TresCanvas> What should be in the console when ...
|
Hi @andretchen0 regarding your example
In the case that you have a group and the children are not occluding, (example you click on the sphere inside of the group) then it will trigger the console for Sphere and then the on for Group In r3f (we don't have stopPropagation yet) If you do |
Hey @alvarosabu ,
Maybe we're talking about different things. I should have included working code. Here's a StackBlitz with the kind of nesting I'm talking about. So, with that kind of setup, assume Box2 doesn't have an event handler, but its parent (Box1) does. <Box> <!-- Box0 -->
<Box :on-click="() => alert('Box1')"> <!-- Box1 -->
<Box /> <!-- Box2 -->
</Box>
</Box> Is Box2 clickable? If so and it's clicked, will Box1's Assuming we're doing events like the DOM does, it seems to me that the answer to both is "yes". I just want to make sure my understanding is correct. |
Note if we follow convention, then we would also log Do we want to let canvas receive all events thought 🤔 Q/A
Torus
Sphere
Group
Sphere
Group
Sphere
Group
Group
Yes if you click Box2, Box1 would receive the event. To add on to this, if you lined up the view so that Box2 was occluding Box1/Box0 then clicked on Box2(with no stopProgation), Box1's event handler would get called twice
|
@garrlker Thanks for the answers and clarifications. That's making sense now. About bubbling events to Maybe relevant: R3F has an event called Maybe relevant to the broader discussion of how to implement events: I haven't looked at the R3F source, but at least in this R3F StackBlitz |
Anytime!
I also think it could be handy, thought I'm not quite sure how I'd use it yet. I think it's better we include it than not
Good catch! We definitely want to include that event
Those events don't fire unless the pointer is moved, by default You can force the ray cast to fire with the mouse's last know coordinates in a useFrame callback, and if a moving object moves into those coordinates those events will be triggered |
Gotcha! Thanks! |
@andretchen0 What you are describing is what was discussed in #426 . I agree with you. The fix should be provided in the scope of this issue. |
Related: #527 |
It's still WIP, but I've pushed up my changes so that you all can start reviewing the code and test out the changes There is a playground example wired up at So far I've implemented Events
FeaturesPrimitives are supported (and possibly anything else in the scene judging by #527 ) ✅
Event Propogation
Event HMR is broken right now so that needs to be fixed before merge as well Besides that, I wasn't able to create this in a store-ish approach. I unhooked the current system so I could work on it free from bias but the @alvarosabu / @Tinoooo I may need a bit of guidance on how you two were wanting the use of said store to look like to try and work this event system into what ya'll were expecting. Changes
|
Description
As a developer using TresJS, I would like to have an Event Management solution with the following features:
Propagation through intersected objects
Raycasting-Based Interaction: Tres should use Three.js's raycasting to determine which objects are interacted with. A ray is cast from the camera through the mouse position into the 3D space, and intersections with objects are calculated.
Simulated Bubbling: When an event occurs, Tres might propagate it through objects based on their spatial arrangement (like from child to parent), but this is based on the raycast hits and not a strict parent-child hierarchy as in the DOM.
Meaning that stop propagation is based on occlusion
If the object is a Group or a model consistent with several meshes, the same concept applies, the closest mesh to the camera stops the propagation
Suggested solution
Current solution uses:
useRaycaster
https://github.com/Tresjs/tres/blob/main/src/composables/useRaycaster/index.tsusePointerEventHandler
https://github.com/Tresjs/tres/tree/main/src/composables/usePointerEventHandlerRegister of events is being done here
https://github.com/Tresjs/tres/blob/main/src/composables/usePointerEventHandler/index.ts#L57-L62
These are then used on the renderer by saving them on the
userData
of the scene objecthttps://github.com/Tresjs/tres/blob/main/src/core/nodeOps.ts#L102
Desired solution
A state/store to manage the events
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: