added pointer events to HTMLMesh - #24259
jrjdavidson wants to merge 6 commits into
Conversation
|
I think we can probably just replace I don't remember why I didn't just use pointer events... |
|
I think it’s important to trigger them all because they’re being dispatched
artificially(I.e. not by an actual mouse). Mouse events won’t trigger if we
only have pointers there.. might be wrong!
…On Tue, 21 Jun 2022 at 16:00, mrdoob ***@***.***> wrote:
I think we can probably just replace mousemove with pointermove and so on?
I don't remember why I didn't just use pointermove...
—
Reply to this email directly, view it on GitHub
<#24259 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALFBMN45OIOYNSYTSUQTBMDVQE437ANCNFSM5ZKUB67A>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Pointer Events are triggered by mouses, fingers and pencils 🤔 Do you mind replacing them for now and see if it still works for you? |
Correct, but in this case we are triggering the pointer event with a line of code, and not a mouse, finger or pencil. Any DOM Element that has a mouse event only (and not a pointer event) will not be triggered when selected in VR if we only fire pointer event in the code. This might actually be the behaviour we want? Do we want mouse event to be triggered as well in VR, or only pointer events? Intuitively I think I would the latter makes sense - Pointer Events are triggered by mouses, fingers, pencils, and VR selections?
Will do, it'll work for my case but I believe that it will ignore the cases where only mouse events are attached to DOM elements. |
Clean up.
More clean up.
| const events = { | ||
| 'move': 'mousemove', | ||
| 'move': 'pointermove', | ||
| 'select': 'click', |
There was a problem hiding this comment.
Maybe like so?
'select': 'pointerdown',There was a problem hiding this comment.
I think pointerup is more in line with the select event.
There was a problem hiding this comment.
Ok that was wrong, according to this , you are right, it should be at the start.
However, I've run into a strange issue where the event gets fired twice, but only sometimes. I've narrowed it down to the select event triggering the callback a second time.
jrjdavidson
left a comment
There was a problem hiding this comment.
Removed click and changed select XR events to correspond to pointerup DOM events
| const events = { | ||
| 'move': 'mousemove', | ||
| 'move': 'pointermove', | ||
| 'select': 'click', |
There was a problem hiding this comment.
I think pointerup is more in line with the select event.
|
That's for updating the PR. Seems like with pointer events we lose desktop events... Before: https://threejs.org/examples/webxr_vr_sandbox.html Screen.Recording.2022-06-28.at.3.48.18.PM.movAfter: https://raw.githack.com/jrjdavidson/three.js/pointerEvents/examples/webxr_vr_sandbox.html Screen.Recording.2022-06-28.at.3.48.45.PM.mov |
|
And it also seems to not work on mobile devices (and the current version before this PR works with clicking but not moving)... |
|
Ah... I remember now... The problem is that @georgealways any plans on moving from mouse/touch events to pointer events? |
|
I did not know they brought that API back! I'll definitely look into it—I'm sure it would make the lib a bit smaller to consolidate mouse/touch listeners. My 2 cents: it does seem a little odd that HTMLMesh wouldn't trigger listeners unless they're specifically bound to pointer events. |
|
HTMLMesh now produces pointer events and they do not trigger mouse events listeners. |
|
So at quick glance, moving lil-gui to pointerevents would be non-trivial. There's a fair amount of listeners that have subtle differences between mouse and touch. For example, if the user is on touch and the GUI has a scrollbar, a slider will wait for a few moves before it actually decides to slide. If the movement is mostly vertical, it assumes the user is trying to scroll. It looks like there's a |
Exactly. This is how controls like three.js/examples/jsm/controls/OrbitControls.js Lines 823 to 837 in a605e57 |
One benefit of Pointer events is that it has sub pixel precision. Probably not that important for lil-gui though. We transitioned all controls from mouse/touch events to point events last year. It was a bit bumpy at first but we hadn't heard of anyone having issues with it for a while. |
|
gotcha gotcha So I took a pass at moving the logic for the sliders to There's two main blockers though:
So overall I think I'd like to move to pointer events, but not before 2 gets figured out. Appreciate any insight! edit: lil-gui aside, I still agree w @jrjdavidson—feels a bit weird to me that HTMLMesh will no longer work with mouse events after this change. |
When I remember correctly you can fix this by specifying the CSS |
|
Thanks @Mugen87—so you're right, that fixes the pull-to-refresh gesture, but it breaks scrolls that start on a slider. Seems kinda insignificant, but it's a pretty common scenario on a phone. Right now I'm happy with the way lil-gui deals with ambiguity between touch-scrolling and sliding. I want to use pointer events, but it's actually turning out to be pretty tough to get it working the same way. I've tried a lot: That said—even if we do get it working perfectly, I really think Hope that doesn't sound like I'm making excuses 😅, I really would like to get pointer events working. |
Agree.
I think in general they are also very widely used and are the way forward. |
I tend to vote for a PointerEvents only solution. The idea is to guide users into the right direction. "Forcing" them into future-proof concepts (in this context hardware agnostic pointer input) is better than support and tolerate "outdated" approaches. Even if that means users have to migrate their code towards pointer events if they want to use |
Do it 👍 |
|
@jrjdavidson Are you still available for updating the PR? I think a pure pointer-events solution for |
|
Hey @Mugen87 , I did maintain a fork of threejs with a slightly modified version of this PR for awhile to use in a little experiment that we ran here. I vaguely remember that having both pointer and mouse events fire caused subtle bugs where events occurred twice and I wasn't able to debug it at the app level, and ended up just remove mouse events from HTMLMesh. On a different note- again, this is a while ago, but I remember HTMLMesh feeling like a bit of a hack, surely there is a better way to render HTML pages in XR mode by now? |
That is unfortunate to hear and makes me less confident to adapt a combined support for mouse and pointer events.
I'm not sure. Event the native layers demo uses New idea: How about we add a new ctor parameter "eventType" that allows to define what type of events |
|
Ok I've been thinking about this, and again this is a while ago and I might be making it up, but I think the issue I was seeing was that the two events were called separately, instead of as one native browser ui event which fires mouse and pointer events. This means that you weren't able to use of event functions such as It might be possible to intercept/modify |
How would this look like? I fear that such logic could end up in a more complex The ctor parameter idea would be easy to implement. And mouse events should be safe default for most apps. If you know the component you are going to use with |
|
Hey again, I think the correct design decision is to keep improving HTMLMesh so it emulates an actual HMTL page. The whole thing is a shim that allows HTML to be displayed in XR (and very impressive shim I must say, I actually learned quite a bit by studying it!). We already have examples in this PR of how we don't have full control of the code that we use in HTMLMesh, such as lilgui above, and it being hard knowing what listeners are used in said code. I think it is important to keep striving to match HTML/js behaviour in and out of XR and we have a chance to do that here. I guess we could add a flag that keeps the old behaviour to keep it safe for current users. |
That sounds like a good compromise. If no issues are reported overt time, we can remove the fallback at a later point. |

Related issue: #None
Description
Added pointer events to the HTMLMesh