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.

TrackballControls are not mouse event to rAF ratio independent.

See original GitHub issue
Description of the problem

The TrackballControls seem to be designed that they take input from mouseMove and use it in update which is expected be called from requestAnimationFrame? They seem to expect there to be a 1x1 relationship, one mouseMove followed by 1 rAF. But if there are more mousemove events per rAF then they stop working correctly (run really slow)

Here’s a repo. Not sure this happens on all machines or OSes or browser. I’m in Chrome 80 on Windows 10. I also have the Oculus Rift software installed (no idea what that does to my system)

https://jsfiddle.net/greggman/qz7jug2v/

Here’s what I see.

With the devtools closed

trackballcontrols-with-devtools-closed

With the devtools open

trackballcontrols-with-dev-tools-open

Adding some code I found with the devtools closed there is 1 mouse event per rAF but open I saw as many as 16 events per rAF

Adding calls to _this.update() in mousemove, touchmove, and wheel seems to fix it since then each event is handled individually?

https://jsfiddle.net/greggman/k8fotepb/

Note I didn’t test touchmove but I’m guessing it can’t hurt?

Three.js version
  • Dev
  • r115
Browser
  • All of them
  • Chrome
  • [?] Firefox
  • [?] Internet Explorer
OS
  • All of them
  • Windows
  • [?] macOS
  • [?] Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

0reactions
greggmancommented, Apr 13, 2020

Oh yea, forgot about that 😅

Still I can do this

setInterval(() => {
  requestAnimationFrame(render);
}, 2000);

and I don’t think I’m only supposed to get mouseevents once every 2 seconds 😜

Which reminds me, another issue with TrackballControls is that the change event only gets issued if you call update. Is that by design? The OrbitControls make it relative easy to make a “render on demand” app. Just render on change events, no loop needed. As it is the TrackballControls you have to call update in your own loop and then you’ll get change events but that means you’re always running a loop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TrackballControls are not mouse event to rAF ratio independent. -
TrackballControls are not mouse event to rAF ratio independent. ... They seem to expect there to be a 1x1 relationship, one mouseMove followed...
Read more >
three.js mousedown not working when trackball controls ...
Trackball works well in my three.js program along with onMouseClick and onMouseUp event listeners. I enable Trackball using the ...
Read more >
TrackballControls – three.js docs
The HTMLDOMElement used to listen for mouse / touch events. This must be passed in the constructor; changing it here will not set...
Read more >
Untitled
Pm&r board review course 2014, Xerox docucentre 2056 driver, No ships, Ucla extension refund ... 92626 sales tax rate, Thrombocytopenia gingival bleeding, ...
Read more >
Full text of "Computer Gaming World Issue 171"
688 ATTACK SUB (not by Dani) was the only other EA game to use the code developed for ... which uses trackball controls,...
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