Coder Social home page Coder Social logo

Comments (1)

dusunax avatar dusunax commented on June 11, 2024

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 />

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
    • useThree must be used inside the Canvas
      image
  • Therefore, passing a ref or using a global store was considered

Conclusion: use onPointerUp instead.

  • while considering how to move onPointerDown, I examine onPointerUp as well.
    • It turns out the logic of onPointerUp was just toggling the archball rotate start/end state
  • handles the user's pointer events with onPointerUp instead of onPointerDown
    • executes the operation of onPointerUp in handleModelClick together
  • 👉however, when onPointerUp occurs outside the group, the original onPointerUp logic does not operate same, so onPointerUp need to registered with the <Canvas />
    • since onPointerDown is being used with a hook, onPointerUp's position is moved and replaced for use.

from react-three-fiber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.