Sin*_*ity 1 javascript three.js tween.js
我正在尝试使用 Tween.js 库转换 Three.js 多维数据集。
通过创建两个补间对象,我可以来回移动立方体:
var start_position = { x : 0.0 , y: 0.0 };
var target = { x : 3.0, y: 0.0 };
var tween_to = new TWEEN.Tween(start_position)
.to(target, 2000);
var start_position2 = { x : 3.0 , y: 0.0 };
var target2 = { x : 0.0, y: 0.0 };
var tween_fro = new TWEEN.Tween(start_position2)
.to(target2, 1000);
tween_to.onUpdate(onUpdate);
tween_fro.onUpdate(onUpdate);
function onUpdate()
{
cube.position.x = this.x;
cube.position.y = this.y;
};
tween_to.chain(tween_fro);
tween_to.start();
Run Code Online (Sandbox Code Playgroud)
然后在我的动画循环中我有:
TWEEN.update();
Run Code Online (Sandbox Code Playgroud)
这很好用。但是,如果我通过引用第二个补间中的第一个补间来完成循环,例如:
tween_to.chain(tween_fro);
tween_fro.chain(tween_to);
Run Code Online (Sandbox Code Playgroud)
动画在极端之间跳跃,没有任何插值,它只是出现在每个位置(第一个循环完成后)。
我认为我以某种方式滥用了该库,但按照在线指南,我看不出此方法与官方 Tween.js 示例有何不同。
您可以使用以下模式链接补间:
function onUpdate() {
cube.position.x = position.x;
cube.position.y = position.y;
};
var position = { x : 0.0 , y: 0.0 };
var tween_to = new TWEEN.Tween( position )
.to( { x : 10.0, y: 0.0 }, 2000 )
.onUpdate( onUpdate );
var tween_fro = new TWEEN.Tween( position )
.to( { x : 0.0, y: 0.0 }, 1000 )
.onUpdate( onUpdate );
tween_to.chain( tween_fro );
tween_fro.chain( tween_to );
tween_to.start();
...
TWEEN.update();
Run Code Online (Sandbox Code Playgroud)
或者,更简单地说,像这样:
var tween_to = new TWEEN.Tween( cube.position )
.to( { x : 10.0, y: 0.0 }, 2000 );
var tween_fro = new TWEEN.Tween( cube.position )
.to( { x : 0.0, y: 0.0 }, 1000 );
tween_to.chain( tween_fro );
tween_fro.chain( tween_to );
tween_to.start();
...
TWEEN.update();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3972 次 |
| 最近记录: |