Closed dusunax closed 8 months ago
[!NOTE] I've checked the documentation and resolved the issue myself. so self close Issue & sharing this troubleshooting for anyone who might be facing the same problem.
Category | Content |
---|---|
Cause | Lack of understanding of (1)3D event propagation, (2)the library in use (R3F) |
Solution | Thoroughly read the official documentation & source code (as always, the best solution). react-three-fiber: events, events.ts |
<canvas />
→ <group />
In 3D, because one can occlude another (differently from DOM), it operates differently.
- Bubbling starts from the object closest to the camera.
- Propagates through all objects intersecting with the ray as intersections.
- event.stopPropagation() not only prevents bubbling to ancestors but also to objects behind.
- If a pointerover event is passed - a pointerout event is immediately triggered.
return(
<CanvasWrapper>
<Canvas> // R3F canvas
<LoadingSuspense>
<CanvasContents> // Contains the onPointerDown logic
<CanvasHTMLElements> // HTML elements not in 3D
</LoadingSuspense>
</Canvase>
</CanvasWrapper>
)
onPointerUp
instead.onPointerDown
, I examine onPointerUp
as well.
onPointerUp
was just toggling the archball rotate start/end state
onPointerUp
instead of onPointerDown
onPointerUp
in handleModelClick
togetherthe original onPointerUp logic
does not operate same, so onPointerUp
need to registered with the <Canvas />
onPointerDown
is being used with a hook, onPointerUp's position is moved and replaced for use.
I am having trouble using the onPointerDown event of a
<group/>
and the event.handlers ofuseThree()
together.What I want is
to execute the
1️⃣onModelClick
handler of a group when in "object addition mode," and when not in "object addition mode," I want to execute the function set in the2️⃣onPointerDown
of the useThree state.With my current knowledge of web frontend, it seems like I need to manage event propagation, but once I register a handler in event.handlers, the previously created onModelClick of the group does not get triggered.
In the console or react dev tool, the event target appears as the canvas. I have been working with 3D rendering for less than a year, so debugging is challenging for me🥲
What I did
I added handlers to
onPointerMove
andonPointerDown
of useThree's events.handlers later on. It's for implementing the arcball feature that rotates 3D model, not the existing orbitControl that rotates the camera.👉 Since it needs to rotate even when clicking outside the model, I cannot combine onPointerDown with the .
Solution that I can think of
Solution A
Solution B
I would really appreciate a hint from someone knowledgeable. Thank you in advance. If I solve it myself, I will share the result for beginners like me
currently reading https://docs.pmnd.rs/react-three-fiber/api/events#customizing-the-event-settings, checking out EventManageFactory