Skip to content

Conversation

@vyrnix9582046173
Copy link
Contributor

@vyrnix9582046173 vyrnix9582046173 commented May 18, 2019

This PR remove mousemove event onPointerMove function in TransformControls. A bug we ran into at exokitxr/exokit#1065 while using TransformControls.

@gkjohnson
Copy link
Collaborator

Can you explain the bug you're running in to? It's not immediately clear looking at your other issue.

@vyrnix9582046173
Copy link
Contributor Author

hopefully this isn't more confusing:

the problem:

the breakdown of solution was:

so simply adding to the dispose in TransformControls.js:
document.removeEventListener( "mousemove", onPointerMove, false );

fixes it

@gkjohnson
Copy link
Collaborator

Okay it sounds like the fundamental issue is that in certain conditions the TransformControls leaves a lingering event on document that also causes a "sticky" behavior with the controls and doesn't get cleaned up even when the controls are disposed, right?

You can reproduce the sticky behavior in Chrome here:

  1. Got to https://threejs.org/examples/?q=transform#misc_controls_transform
  2. Click and hold on a drag handle
  3. Drag outside the iframe and release click
  4. Move mouse back into iframe
  5. Drag controls still move with mouse even though no buttons are pressed.

Interestingly I can't reproduce this when the example is not embedded in an iframe in chrome -- it must have to do with how events are delegated. In Firefox it works as expected in both cases.

I think one solution is to add a "mouseenter" callback to the document that checks if the mouse button is pressed and if it's not then remove the "mousemove" event. That way if the user does click drag out of the window and release the event will get removed when hovering over the window again.

I'm not sure how tightly we want to consider these two issues but that solution may help with your issue, as well.

@looeee
Copy link
Collaborator

looeee commented May 21, 2019

This behaves differently again in Edge - when moving the mouse over the menu while dragging the position of the cube "jumps". So we have different behaviour in Chrome, Firefox and Edge, only Firefox is correct.

@arodic
Copy link
Contributor

arodic commented May 21, 2019

I think this PR should be merged regardless of the sticky behavior which I can fix in a separate PR. I think it is a good practice to dispose all event listeners just in case dispose() happens in the middle of an interaction for whatever reason.

@arodic
Copy link
Contributor

arodic commented May 21, 2019

Interesting... the sticky behavior happens only if OrbitControls are added alongside with TransformControls.

Edit: it appears to be this preventDefault() shomehow blocks the correct behavior. I'm not sure why.

@mrdoob mrdoob added this to the r105 milestone May 22, 2019
@mrdoob mrdoob merged commit 979253e into mrdoob:dev May 22, 2019
@mrdoob
Copy link
Owner

mrdoob commented May 22, 2019

Thanks!

@arodic
Copy link
Contributor

arodic commented May 22, 2019

Hey @WestLangley, I noticed you added this line. Would it be possible to remove it since it causes sticky behavior when releasing drag outside an iframe? The comment says "Prevent the browser from scrolling." Is that intended for touch scroll?

@WestLangley
Copy link
Collaborator

@arodic I'll have to defer to others on this -- there are so many use-cases, it is nearly impossible to please everyone. Maybe @greggman can be of help. #15620.

@gkjohnson
Copy link
Collaborator

It seems like it should be possible to achieve both use cases. I wonder why that line would be causing sticky behavior.

@arodic
Copy link
Contributor

arodic commented May 22, 2019

@gkjohnson I'm not sure why it is but you can clearly see in this fiddle.

With preventDefault() on mousedown, there are no events logged if you click-and-drag outside the iframe. If you disable preventDefault(), both mousemove and mouseup continue tracking outside the iframe.

@arodic
Copy link
Contributor

arodic commented May 22, 2019

My theory is that mousedown event "captures" the pointer so that while you are dragging, mouse events keeps getting dispatched to the original iframe as you drag outside. I you preventDefault(), the capture doesn't happen.

@greggman
Copy link
Contributor

The comment in the OrbitControls is wrong. My bad.

The line itself is old

22182b0

If you remove the line you can probably remove the line after as well.

I did a quick test with it removed and I didn't notice anything but I might have missed what it's for.

Things it might have been for? It might have been for stopping selection a long time ago before user-select: none; existed? Just a guess.

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.

7 participants