Reputation: 168
the following code does not seem to work with revision 88 and beyond:
function moveAndLookAt(dstpos, dstlookat, duration = 500) {
TWEEN.removeAll();
var origpos = new THREE.Vector3().copy(camera.position); // original position
var origrot = new THREE.Euler().copy(camera.rotation); // original rotation
camera.position.set(dstpos.x, dstpos.y, dstpos.z);
camera.lookAt(dstlookat);
var dstrot = new THREE.Euler().copy(camera.rotation)
// reset original position and rotation
camera.position.set(origpos.x, origpos.y, origpos.z);
camera.rotation.set(origrot.x, origrot.y, origrot.z);
// position
new TWEEN.Tween(this.camera.position).to({
x: dstpos.x,
y: dstpos.y,
z: dstpos.z
}, duration).start();;
// rotation (using slerp)
let scope = this;
(function () {
var qa = new THREE.Quaternion().copy(camera.quaternion); // src quaternion
var qb = new THREE.Quaternion().setFromEuler(dstrot); // dst quaternion
var qm = new THREE.Quaternion();
var o = {t: 0};
new TWEEN.Tween(o).to({t: 1}, duration).onUpdate(function () {
THREE.Quaternion.slerp(qa, qb, qm, o.t);
scope.camera.quaternion.set(qm.x, qm.y, qm.z, qm.w);
}).start();
}).call(this);
}
The target object seem to disappear and no errors. It looks like the dstrot = new THREE.Euler().copy(camera.rotation) value is returning NaN instead of numeric numbers. The code was from a previous post:
Tween camera position while rotation with slerp -- THREE.js
Upvotes: 0
Views: 107
Reputation: 168
Nevermind, my dstlookat worked fine when I was passing {x:2,y:2,z:2} with previous versions but the latest version seem to require defined Vector3 values.
Solution:
var dstlookat = {x:2, y: 2, z: 2};
to:
dstlookat = new THREE.Vector3( 2, 2, 2 );
Upvotes: 0