Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use offsetX/offsetY to compute mouse position in default raycaster #782

Merged
merged 1 commit into from
Nov 3, 2020
Merged

Use offsetX/offsetY to compute mouse position in default raycaster #782

merged 1 commit into from
Nov 3, 2020

Conversation

axelboc
Copy link
Contributor

@axelboc axelboc commented Nov 3, 2020

Fix #350, including the regression involving a scrollable container on top of the canvas that receives R3F's event handlers - cf. 42569b9.

As discussed, I add the ability for the user to pass a computeOffsets function to compute the correct offsetX and offsetY values to be used in the raycaster based on the scroll position:

const computeOffsets = useCallback((event) => {
  const { offsetX, offsetY } = event.nativeEvent
  return {
    offsetX,
    offsetY: offsetY - state.scrollTop,
  }
}, [])

<Canvas
  // ...
  raycaster={{ computeOffsets }}
/>

@drcmda drcmda merged commit 8ca3856 into pmndrs:master Nov 3, 2020
@axelboc axelboc deleted the compute-offsets branch November 3, 2020 11:52
@drcmda
Copy link
Member

drcmda commented Nov 3, 2020

thanks! seems to work: https://codesandbox.io/s/r3flex-forked-8trbt it's published, too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Events trigger outside of canvas when moved
2 participants