问题
I'm trying to ease camera rotation to look at a selected object in a graph.
So far, I have
fourd.render_loop.push(() => TWEEN.update());
fourd.intersect_callback = function(vertex){
console.log(vertex);
var camera = fourd._internals.camera;
var start = new THREE.Euler().copy(camera.rotation);
camera.lookAt(vertex.position);
var end = new THREE.Euler().copy(camera.rotation);
camera.rotation.copy(start);
var tween = new TWEEN.Tween(camera.rotation)
.to(end, 600)
.easing(TWEEN.Easing.Quadratic.In)
.start();
};
where render_loop is simply a collection of functions called in the render loop. I don't know what I'm missing, but I'm getting an error:
THREE.Euler: .setFromRotationMatrix() given unsupported order: NaN
回答1:
You can tween the camera's orientation (or rotation), but to do so, it is simplest to tween the camera's quaternion, instead.
var dummy = new THREE.Camera(); // create these once and reuse
var qStart = new THREE.Quaternion();
var qEnd = new THREE.Quaternion();
. . .
// tween
var time = { t: 0 };
new TWEEN.Tween( time )
.to( { t : 1 }, 1000 )
.easing( TWEEN.Easing.Linear.None )
.onStart( function() {
dummy.position.copy( camera.position );
dummy.lookAt( point ); // point is your target Vector3
qStart.copy( camera.quaternion );
qEnd.copy( dummy.quaternion );
} )
.onUpdate( function() {
THREE.Quaternion.slerp( qStart, qEnd, camera.quaternion, time.t );
} )
.onComplete( function() {
camera.quaternion.copy( qEnd ); // so it is exact
} )
.start();
three.js r.88
来源:https://stackoverflow.com/questions/47844030/using-tween-to-animate-a-camera