Comments (1)
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 |
Registering the onPointerDown event
- without replacing the event in useThree❌, attaching an onPointerDown event to the canvas⭕️ does not affect the group's onPointerDown event trigger
- and the event propagates in the order of
<canvas />
→<group />
- and the event propagates in the order of
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.
Problem no.2
- currently, my component is wrapped in the following wrapper format
return(
<CanvasWrapper>
<Canvas> // R3F canvas
<LoadingSuspense>
<CanvasContents> // Contains the onPointerDown logic
<CanvasHTMLElements> // HTML elements not in 3D
</LoadingSuspense>
</Canvase>
</CanvasWrapper>
)
- however, to move onPointerDown to canvas, the useThree hook must be used outside the Canvas
- Therefore, passing a ref or using a global store was considered
Conclusion: use onPointerUp
instead.
- while considering how to move
onPointerDown
, I examineonPointerUp
as well.- It turns out the logic of
onPointerUp
was just toggling thearchball rotate start/end state
- It turns out the logic of
- handles the user's pointer events with
onPointerUp
instead ofonPointerDown
- executes the operation of
onPointerUp
inhandleModelClick
together
- executes the operation of
- 👉however, when onPointerUp occurs outside the group,
the original onPointerUp logic
does not operate same, soonPointerUp
need to registered with the<Canvas />
- since
onPointerDown
is being used with a hook, onPointerUp's position is moved and replaced for use.
- since
from react-three-fiber.
Related Issues (20)
- Help: TypeError in is.equ HOT 4
- Primitive with children mounting / unmounting + documentation HOT 4
- This sandbox doesn't work HOT 1
- Canvas eventHandler: onWebGLContextLost, onWebGLContextRestored HOT 2
- Cannot catch error HOT 1
- Is it possible to use react-three-fiber with React-Native CLI application? HOT 1
- Types: Removed classes from three.js are still available at R3F HOT 3
- Rendering `<Context.Consumer.Provider>` is not supported HOT 1
- R3F & StereoCamera
- Breaking changes in React experimental branch HOT 1
- Cannot read properties of undefined (reading 'boundingSphere') HOT 1
- Forced landscape HOT 1
- load gltb file show error `Uncaught Invalid typed array length: 64548` HOT 1
- Updating from 8.15.19 to 8.16.1 causes 'demand' frameloop issues with @react-spring/three HOT 2
- Rendering issue HOT 1
- How to draw 2D views in 3D Canvas with ReactNative? HOT 1
- R3F raycast hits wrong object HOT 1
- MapControls with OrthograhicCamera respond to maxDistance not maxZoom, minZoom HOT 1
- It's not possible to preventDefault on onPointerDown HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-three-fiber.