squarefeet / ShaderParticleEngine

A GLSL-heavy particle engine for THREE.js. Originally based on Stemkoski's great particle engine (see README)
http://squarefeet.github.io/ShaderParticleEngine/
MIT License
850 stars 115 forks source link

Only 1st Group Updating #125

Closed stickyfingies closed 6 years ago

stickyfingies commented 6 years ago

Hi Squarefeet! First off: awesome library, been using it for a while and I love it :)

Unfortunately, I have recently encountered an issue where only the first SPE.Group instance created is updated / rendered. I have a Fire function class with this.group and this.emitter set to a new group and emitter, respectively. Whenever this is called, it adds the this object to a global array, where all Fire instances can be updated in my render loop. It works fine with one Fire instance; however, when I try to add more only the first is updated. I know (or at least am quite certain) it is not a problem with the array approach, as I am using this technique for a variety of other implementations and they all work quite nicely.

To specify, by not updating I mean the particles will still appear, and then disappear when their maxAge is reached with new ones replacing them; however, any velocity or acceleration values are not considered; the particles just stay stationary.

Not sure if this a problem with the library itself or my code... Any help is appreciated. Thanks!

THREE.js r87 Chrome v63 Beta Using NPM

stickyfingies commented 6 years ago

Nevermind, it appears it was a problem with my code :) Lesson learned, never jump to conclusions... It appears the problem was that when I was trying to update multiple groups / emitters per frame and calling Clock.getDelta() individually in the loop, then the delta time between the first group update and the second is zero; thus, only the first group updates. By instead creating a local variable time equal to the clock delta in the update function itself, and reusing that variable for each group in the particles loop, then all the particle groups are updated with the same delta, and thus all are updated.