我正在为一个沿着一条线的所有顶点移动的球创建一个动画。我有这样的代码:
var vertices = mesh.geometry.vertices;
var duration = 100;
// Iterate through each vertex in the line, starting at 1.
for (var i = 1, len = vertices.length; i < len; i++) {
// Set the position of the sphere to the previous vertex.
sphere.position.copy(vertices[i - 1]);
// Create the tween from the current sphere position to the current vertex.
new TWEEN.Tween(sphere.position).to(vertices[i], duration).delay(i * duration).start();
}当球体位于最后一个顶点时,我可以做些什么,使这个字段重新开始动画。
发布于 2015-12-15 18:46:28
我和yavg私下聊了聊,下面的解决方案起作用了:
var vertices = mesh.geometry.vertices;
var duration = 10;
function startToEnd() {
var i = 0;
async.eachSeries(vertices, function(vertice, callback) {
if (i !== 0) {
sphere.position.copy(vertices[i - 1]);
new TWEEN.Tween(sphere.position).to(vertices[i], duration).delay(duration).onComplete(function() {
callback(null);
}).start();
} else {
callback(null);
}
i++;
}, startToEnd);
}
startToEnd();它会从vertix开始一直到最后,然后无穷无尽地重复这个过程。不过,它确实使用了异步库,以便为我实现从一个vertix到另一个vertix的the。
https://stackoverflow.com/questions/34277887
复制相似问题