react-three-fiber icon indicating copy to clipboard operation
react-three-fiber copied to clipboard

prepareRaycaster breaks when using <Html /> from drei

Open johnmarinelli opened this issue 4 years ago • 10 comments

see the original problem here - https://github.com/pmndrs/drei/issues/191#issuecomment-766432113

TLDR - when hovering over an <Html/>, the mouse event is triggered on the underlying <div> instead of the <canvas>.

The proposed solution will check the event.target type, and perform the necessary logic based on the type of the element.

johnmarinelli avatar Jan 25 '21 09:01 johnmarinelli

reproduction in v6: https://codesandbox.io/s/r3f-basic-demo-forked-w2mcv?file=/package.json

johnmarinelli avatar Apr 14 '21 07:04 johnmarinelli

the sandbox crashes in some grid component

drcmda avatar Apr 14 '21 11:04 drcmda

got the sandbox from a discord PM, the instructions are:

For some reason it doesn't work on first load, but if you comment out the "cytoscape component" and uncomment again it runs properly There's two cameras, one commented out, and one active. You can see from the front perspective clicks register on the graph properly, while from an angle none of the clicks register where they should

i plan on taking a look tonight

johnmarinelli avatar Apr 15 '21 09:04 johnmarinelli

the original problem was fixed in v6 (proof: https://codesandbox.io/s/drei-html-mouse-bug-forked-fixed-0h8i9?file=/src/App.js), however there is another problem (edited sandbox based off my last comment): https://codesandbox.io/s/bug-964-5io6k?file=/src/App.js

for me, the <Html/> element doesn't show up until I move the camera, and the onClick handler never gets called when the <Html/> element is clicked. am looking into it

update: toggling distanceFactor option determines if <Html/> is visible on first load

johnmarinelli avatar Apr 20 '21 13:04 johnmarinelli

@johnmarinelli I tested toggling distanceFactor in your sandbox and it seems to be visible in Chrome and Safari, but it isn't visible on first load without the distanceFactor in Firefox.

Hope this helps debug the issue.

njm222 avatar Apr 30 '21 08:04 njm222

@njm222 it definitely does, i am primarily using Firefox so that is probably why

johnmarinelli avatar Apr 30 '21 13:04 johnmarinelli

@johnmarinelli does this solve it? https://codesandbox.io/s/gracious-proskuriakova-fuodi?file=/src/App.js

drcmda avatar May 06 '21 12:05 drcmda

@drmcda yes, this version responds to mouse events successfully. was the solution the computeOffsets function or the states.events.connect(fwdRef.current)?

johnmarinelli avatar May 07 '21 08:05 johnmarinelli

mostly computeOffsets. r3f uses offsetxy, but that's reliant on the target. if you hover a div offsetxy starts at relative zero. with a flip to clientxy it should work. both clientxy and offsetxy have their ups and downs, if we pick one, usecases for the other will fail. imo allowing users to compute offsets is an easy way to fix all possible usecases.

drcmda avatar May 07 '21 11:05 drcmda

Should we revisit #965 now that events are done? We can pass layout info into the RN canvas shim so the fix will translate over.

CodyJasonBennett avatar Dec 11 '21 21:12 CodyJasonBennett