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

fix(useRaycaster): set delta on pointer-missed events #853

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AntoninRousset
Copy link

Fixes #852.

Introduces a very small overhead because the delta is computed for every pointerup event.

Copy link

netlify bot commented Oct 12, 2024

Deploy Preview for tresjs-docs ready!

Name Link
🔨 Latest commit a2f1707
🔍 Latest deploy log https://app.netlify.com/sites/tresjs-docs/deploys/670b9b1b3bff200008f6b097
😎 Deploy Preview https://deploy-preview-853--tresjs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@alvarosabu alvarosabu added the p3-minor-bug An edge case that only affects very specific usage (priority) label Oct 13, 2024
@alvarosabu
Copy link
Member

Hi, @andretchen0 is this contemplated in your refactor #844? Should we merge this PR first?

@andretchen0
Copy link
Contributor

andretchen0 commented Oct 14, 2024

@alvarosabu

Hi, @andretchen0 is this contemplated in your refactor #844?

In the event system rewrite, event.delta is recalculated (and usually non-0) for pointerup, contextmenu, dblclick, and click. Otherwise, it's 0. (This is more like R3F than our current main implementation, which keeps the delta value until the next pointerup, iirc. Not sure if that interferes with @AntoninRousset 's use case.)

Here's the code. (It's called distance internally.)

  const distance = (incomingEvent.type === 'click' || incomingEvent.type === 'contextmenu' || incomingEvent.type === 'dblclick' || incomingEvent.type === 'pointerup')
    ? Math.sqrt(((incomingEvent.offsetX - config.pointerDownPosition.x) ** 2) + ((incomingEvent.offsetY - config.pointerDownPosition.y) ** 2))
    : 0

From here

Also in the rewrite, users can supply their own handleIntersections method to TresCanvas (the method is a few hundred lines long, though). Hopefully that will allow users to make their own tweaks for cases like this one in the future.

Fwiw, for the use case under discussion, the new system also implements pointer capture, which makes dragging things around a lot simpler.

Should we merge this PR first?

I don't have a feeling one way or another on this one.

@andretchen0
Copy link
Contributor

@alvarosabu @AntoninRousset

Fwiw, the new event system sets delta on @pointermissed.

Screen.Recording.2024-10-17.at.13.11.31.mov

But, @pointermissed works slightly differently and the current @pointer-missed [sic]:

  • current: @pointer-missed is only fired when all objects are missed
  • new: @pointermissed is fired on an object whenever the object registering a @pointermissed handler is missed. I.e. not only when all objects are missed. This works like R3F.

So, again, I don't have a strong opinion here. We can merge here if it helps someone, but there are changes in the pipeline for the next major version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

The delta of pointer-missed events is always zero
3 participants