以下代码似乎不适用于版本88及更高版本:
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);
}
目标对象似乎消失了,没有错误。它看起来像dstrot = new THREE.Euler()。copy(camera.rotation)值返回NaN而不是数字。该代码来自之前的帖子:
答案 0 :(得分:0)
没关系,当我用以前的版本传递{x:2,y:2,z:2}时,我的dstlookat运行正常,但最新版本似乎需要定义Vector3值。
解决方案:
var dstlookat = {x:2,y:2,z:2};
为:
dstlookat = new THREE.Vector3(2,2,2);