tyapo
tyapo

Reputation: 130

TrackballControls change events

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?

Upvotes: 4

Views: 3353

Answers (1)

WestLangley
WestLangley

Reputation: 104763

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

Upvotes: 6

Related Questions