-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Description
I'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