How to get pointer events before objects in the scene? #929
Unanswered
dangrabcad
asked this question in
Q&A
Replies: 1 comment 7 replies
-
this seems to me is best solved with an abstraction of your event. centralize them and make them check for app-state in there. hijacking events in specific order, using planes, etc, that sounds a bit hacky/specific. function useClick() {
const annotate = useStore(state => state.annotate)
return e => {
if (annotate) doThis()
else doThat()
}
}
function Foo() {
return <mesh onClick={useClick()} /> other than that,
but you just get the intersection, not the dom event. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Sometimes in my application you go into a mode, where the pointer does things other than activate objects in the scene; for example, normally when you click on an object it selects it, using an
onClick
handler on the object, but when you're in "annotate mode", clicking anywhere (on an object or not) draws annotations instead of calling the object'sonClick
. I'd like an extraonClick
method that happens before objects in the scene get called, and the same for other pointer events.To collect pointer-on-background events, I've used an invisible skybox that's further away than all the real objects in the scene. I could use a near plane, attached to the camera, to get the preview events, but that seems riskier: it'll go wrong if the near clipping plane goes past it, or if we dolly in enough to bring scene objects past this foreground plane. For those reasons I'd prefer to avoid repeating that strategy.
Another option is capturing DOM pointer events in the capture phase, before they even reach the Canvas and R3F's event system, but I need my event handlers to get the R3F-style event with the intersection and hit object. To achieve that I'd need to replicate the way R3F creates and casts a ray and puts that information into the event, which is not very maintainable.
Do you have any other ideas?
Beta Was this translation helpful? Give feedback.
All reactions