30-04-2018, 08:44 AM
(28-04-2018, 02:05 AM)tooomg Wrote: Hi there!
I'm trying to get a better control of the number of active particles from an ObiEmitter at any time, but it looks like changing the NumParticles in the ObiEmitter resets all the particle physic states (so I guess it's only meant to be initialized once and then left untouched...). Using the speed setting is not a safe enough option for me, as I need to generate an accurate number of particles, that increases over time.
Is there a way to work around this without needing to change how the ObiEmitter itself works? (I was thinking of pre-allocating a max number of particles using NumParticles, and then controlling the emission using a separate variable in ObiEmitter. But I don't like having to work around a lib, as it makes upgrades more complex to deal with )
Maybe that would be a nice feature?
Note: I'm currently on Obi Fluid 3.3 (or maybe 3.2), so maybe that has been fixed in the meantime in Obi Fluid 3.4?
Cheers!
Hi,
ObiEmitter already works by preallocating a fixed amount of particles (NumParticles) and activating particles as they need to be emitted. This ensures zero garbage generation and no allocation overhead.
The ObiEmitter class has two methods: EmitParticle() and KillParticle() specifically designed to allow what you want to do. Note however that when emitting particles manually you need to be extra careful about their spacing, to avoid sudden pressure spikes. Each particle represents a small amount of mass, so if too many particles are spawned at once in the same place, the density (and the pressure) will skyrocket resulting in a sudden burst. That's why "speed" is used to control emission, as it controls both the emission speed and the amount of particles to ensure constant density.