question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drag + Trackball controls

See original GitHub issue

Describe the bug

Hi there!

While setting up a scene with both Trackball and Drag controls active I noticed it has stopped working since version 0.120.0.

I’ve created an example here which demonstrates the issue: https://codepen.io/vasturiano/pen/GRqazYq

As you can see, no drag pointer events are triggered if Trackball controls is enabled on the element.

After diving in a bit, I believe the change was introduced in this particular commit: https://github.com/mrdoob/three.js/commit/f86fcc092aa8459e7b78b3244e02df923f2d4753

The core of the issue is that this pointerdown preventDefault call has a different behavior than when it was applied to the prior mousedown events. As documented here:

If the pointerdown event isn’t canceled through a call to preventDefault(), most user agents will fire a mousedown event, so that sites not using pointer events will work.

So, this preventDefault call is essentially stopping the mousedown events from being triggered in the DragControls (because that module is still using mouse events, not pointer events).

Perhaps the solution is as simple as removing the preventDefault statement, since I think that is a no-op for mousedown events, so it would be in line with the previous behavior.

Or migrate DragControls to use pointer events, that would in theory also solve it.

Btw, I believe OrbitControls has the same effect, since it had a similar change applied.

Just for comparison, here’s a fork of the same example but importing v0.119.1 of TrackballControls instead. You’ll notice that both work simultaneously and can coexist reasonably well. For a seamless experience TrackballControls is disabled dynamically during a drag, so the interactions don’t interfere with each other.

To Reproduce

  1. Go to https://codepen.io/vasturiano/pen/GRqazYq
  2. Try to drag one of the nodes (it won’t work)
  3. Disable Trackball
  4. Drag successful

Code

Relevant portion of the code:

// trackball controls
const tbControls = new THREE.TrackballControls(camera, renderer.domElement);

// drag controls
const dragControls = new THREE.DragControls(objs, camera, renderer.domElement);
dragControls.addEventListener('dragstart', () => tbControls.enabled = false); // Disable trackball controls while dragging
dragControls.addEventListener('dragend', () => tbControls.enabled = true); // Re-enable trackball controls

Live example

Not-working (TrackballControls latest version): https://codepen.io/vasturiano/pen/GRqazYq

Working (v0.119.1): https://codepen.io/vasturiano/pen/oNLRVjj

Expected behavior

Like in versions <0.120.0, be able to have both Drag and Trackball controls active simultaneously.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
pfarnachcommented, May 25, 2021

Looking at my sandbox again, it seems like whatever the issue was was fixed in 0.127.0. 0.128.0 works but 0.126.1 is broken.

2reactions
Mugen87commented, Nov 21, 2020

I’ve made a PR that introduces Pointer Events in DragControls so it’s easier to see the changes and verify them. The PR indeed fixes your codepen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ThreeJS Trackball & Drag controls working 0.119.1
1. // dat.gui controls ; 2. const settings = { Trackball: true, Drag: true }; ; 3. const gui = new dat.GUI(); ;...
Read more >
Three.js trackball controls drag event not working in UIkit modal
The UIkit modal is not catching the drag events. Your problem is that the TrackballControls calculates the domElement 's size while the ...
Read more >
advice: trackball for drag and drop? - Reddit
I've never used a trackball. ... Use a 3rd party tool to change your mouse speed (X-Button Mouse Control is my personal favorite....
Read more >
How to Use a Trackball Mouse More Efficiently
In this guide, we're going to show you how to use a trackball with more efficiency and control, and why it could be...
Read more >
Adding Trackball Controls to a Three.js Scene with Sprites
To zoom, use the mouse wheel (or two fingers trackpad swipe up/down on Macs) · To pan (move the viewport), right-click and drag...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found