我正在尝试创建一个呈现布朗(随机)运动的随机分布的粒子场。
滚动到代码底部以查看错误发生的位置。我正在尝试使用position.x设置单个顶点的位置。
我将省略与渲染粒子无关的其余代码,以节省您的时间。
//Using WebGL renderer...
var particle, particles = [], particle_system, material, p_x, p_y, p_z;
particles = new THREE.Geometry();
material = new THREE.ParticleBasicMaterial({color: 0xffffff, size: 1});
for(var count = 0; count < 1000; count++){
p_x = Math.random() * 1000 - 500;
p_y = Math.random() * 1000 - 500;
p_z = Math.random() * 1000 - 500;
particle = new THREE.Vector3(p_x, p_y, p_z);
particles.vertices.push(particle);
}
particle_system = new THREE.ParticleSystem(particles, material);
scene.add(particle_system);
particle_system.geometry.dynamic = true;
//All of the code bellow will go into the render loop.
var index = 0;
while(index < 1000){
index++;
particle_system.geometry.verticiesNeedUpdate = true;
//THESE 3 LINES BELLOW CAUSE THE ERROR
particles.vertices[index].position.x += Math.random() * 1000 - 500;
particles.vertices[index].position.y += Math.random() * 1000 - 500;
particles.vertices[index].position.z += Math.random() * 1000 - 500;
}
答案 0 :(得分:2)
verticiesNeedUpdate
应拼写为verticesNeedUpdate
index
变量。所以在最后一次迭代中(当index == 999
时),您尝试访问未定义的particles.vertices[1000]