Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TrackballControls change events

Tags:

three.js

I have a static scene with no animation loop, and am trying to use the change event of TrackballControls to trigger the render function following the pattern in this thread, i.e.:

var controls = new THREE.TrackballControls( camera, renderer.domElement );
controls.addEventListener( 'change', render );
function render() {
    renderer.render( scene, camera );
}

This works well with OrbitControls, but the change events don't fire when I substitute TrackballControls. However, if I add the line:

_this.update();

at the end of mousewheel(), mousemove(), and touchmove() functions in TrackballControls.js, I can get the change events to fire correctly (in my case, anyway). I am not sure if this is the best way to get the change events firing. Is forking a local copy of TrackballControls the best solution for this case, have I overlooked something, or does it make sense to change TrackballControls.js?

like image 855
tyapo Avatar asked Oct 28 '25 10:10

tyapo


1 Answers

TrackballControls was written to require an animation loop in which controls.update() is called.

OrbitControls, on the other hand, can be used in static scenes in which the scene is rendered only when the mouse is moved, like so:

controls.addEventListener( 'change', render );

In either case, the controls are part of the examples -- not the library -- so you are free to hack them to your liking.

What you are proposing is fine if your scene is static and there is no damping required.

EDIT: corrected for three.js r.73

like image 85
WestLangley Avatar answered Oct 30 '25 13:10

WestLangley