0

I'm attempting to create a randomly distributed particle field that exhibits Brownian (random) motion.

Scroll to the bottom of the code to see where the error happens. I'm trying to set the position of a single vertex with position.x.

I'll omit the rest of the code not directly related to rendering the particles in effort to save your time.

//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;

}

1 Answer 1

2
  • verticiesNeedUpdate should be spelled verticesNeedUpdate
  • your while loop is wrongly incrementing the index variable before it is used. So in the last iteration (when index == 999) you try to access particles.vertices[1000] which is not defined
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.