如何在 Three.js 中沿直线移动相机?

How to move camera along a straight line in Three.js?

我刚刚开始使用 Three.js 和一般的图形编程。我要做的就是将相机从一个位置平稳地过渡到另一个位置。

我发现的一个解决方案使用了 PathControls.js,此后已被删除。

这个函数应该会有帮助。需要 tween.js,您可以在 three.js

的 examples/js/libs 文件夹中找到它
function setupCameraPositionTween( source, target, duration, delay, easing )
{
    var l_delay = ( delay !== undefined ) ? delay : 0;
    var l_easing = ( easing !== undefined ) ? easing : TWEEN.Easing.Linear.None;

    new TWEEN.Tween( source )
        .to( target, duration )
        .delay( l_delay )
        .easing( l_easing )
        .onUpdate ( function()
            {
                // copy incoming position into camera position
                camera.position.copy( source );
            })
        .start();
}