How to add and remove particles in a ParticleSystem?!
See original GitHub issueI’m writing a little game including some bullets and explosion. So I think using ParticleSystem is a good idea.
The problem is : adding and removing particles from the ParticleSystem are very often. In every frame , I need to compute each particle’s position and change them in the ParticleSystem Sometimes,when new bullet come or old bullet die,I also need to add or remove vertex in geometry in ParticleSystem.
Now my way to solve this problem is so stupid,it already make my FPS lower when I shoot bullet All I want is to find a fine way to make it optimistic !
My way is here if there is bullets in the scene every frame I update it like this
// First. remove the PS from scene
scene.remove( this.particles );
// Then. new a geometry and compute each bullet vertices's position,for they are flying!
this.geometry= new THREE.Geometry();
for(....)
// to do some compute,then add vertices to geometry
this.geometry.vertices.push( new THREE.Vertex( this.bullets[i].position ) );
// Then. new the ParticleSystem with the geometry
this.particles = new THREE.ParticleSystem( this.geometry, this.material );
// Finally. add it back to scene
scene.add( this.particles );
OK,it got no problem when I run it,but it’s really slow I think there is no need to do the ‘remove’,‘new’,or ‘add’ every time I just need to change the position of vertices and add or remove vertex There must be some ‘clever’ way
and I know
geometry.__dirtyVertices = true;
geometry.__dirtyElements = true;
maybe it can solve this problem? But when I add vertex it shows nothing added when I remove vertex the chrome totally stopped I must do something wrong
So,what is the right clever way? Thank you
Issue Analytics
- State:
- Created 11 years ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
That has nothing to do with the this issue. Better open a new issue with your new question.
Ok.I will try
Another question,how to do Collision-Detection using threejs? Maybe my words are not clear,do you know what I mean? For example,there are two helicopters in my game,if they get a collision they are supposed to explode So,how to detect if objects(in the scene) got Collision with other objects?
Thank you