我正在使用下面的代码在Three.js中为粒子系统中的一些粒子设置动画。
for(var i = 0; i < particleSystem.geometry.vertices.length; i++ ){
var pX = Math.sin(i + counter) * 100 + Math.random() * 20,
pY = Math.cos(i + counter) * 100 + Math.random() * 20,
pZ = Math.sin(i + counter) * 100 + Math.random() * 20;
particleSystem.geometry.vertices[i] = new THREE.Vector3(pX, pY, pZ);
}
它通过更改粒子的顶点来工作。它可以很好地更改它们,没有错误,但没有更新。我可以四处走动,所有其他的动画都工作得很好。这是在我的animate()
函数中,如下所示:
function animate(){
for(var i = 0; i < particleSystem.geometry.vertices.length; i++ ){
var pX = Math.sin(i + counter) * 100 + Math.random() * 20,
pY = Math.cos(i + counter) * 100 + Math.random() * 20,
pZ = Math.sin(i + counter) * 100 + Math.random() * 20;
particleSystem.geometry.vertices[i] = new THREE.Vector3(pX, pY, pZ);
}
counter += 1;
requestAnimationFrame(animate); // So it stops when you change window and otherwise repeats
renderer.render(scene,camera); // Render
controls.update(clock.getDelta()); // Update control/camera movement information
}
发布于 2013-10-12 13:56:05
首先,我认为你应该更新顶点,而不是用新的实例替换它们:
particleSystem.geometry.vertices[i].set( pX, pY, pZ );
然后,您可能还必须告诉Three.js顶点已更改:
particleSystem.geometry.verticesNeedUpdate = true;
这些操作应在update()
期间完成
https://stackoverflow.com/questions/19331734
复制