GPU Particles

Heaps supports rendering particles on the GPU. This allows for an extremely high amount of particles to be rendered on screen with very little performance impact. Setting up your GPU particles involves first creating a particle system.

  1. //Create a particle system and pass it our 3d scenevar particles = new h3d.parts.GpuParticles(s3d);

From there you add particle groups to the system. Each group is it’s own separate bundle of particles that work independently. A particle system can support multiple groups.

  1. //Create a particle group with a reference to our particle systemvar particleGroup = new h3d.parts.GpuParticles.GpuPartGroup(particles);

When you are ready to see your particle group on screen you just need to add it to the system.

  1. particles.addGroup(particleGroup);

Customizing Particles

API docs for a full list.

  1. //The shape at which the particles will be emitted each ar of type GPUEmitModeparticleGroup.emitMode = Cone;//The angle which the paricles will be emittedparticleGroup.emitAngle = 0.5;//The distance from the initial spawn location of each particleparticleGroup.emitDist = 0;//Fade in and fade out time for each particleparticleGroup.fadeIn = 0.8;particleGroup.fadeOut = 0.8;particleGroup.fadePower = 10;//How much the particles are effective by gravityparticleGroup.gravity = 5;//The initial size of each particleparticleGroup.size = 0.1;//Random size offset of each particleparticleGroup.sizeRand = 0.5;//How fast the particles will rotateparticleGroup.rotSpeed = 10;//The speed of each particleparticleGroup.speed = 2;//Random variation in speed for each particleparticleGroup.speedRand = 0.5;//The lifespan of the particle in secondsparticleGroup.life = 2;//Random variance in lifespanparticleGroup.lifeRand = 0.5;//The number of particles in a group - these all get uploaded to the GPUparticleGroup.nparts = 10000;//You can assign a texture to the particle group//Every particle will have the texture appllied.particleGroup.texture = hxd.Res.hxlogo.toTexture();//Use Texture.fromColor to set the color of each particle.particleGroup.texture = h3d.mat.Texture.fromColor(0xEA8220);

Looping

By default the particle groups will loop. You can disable this with the following

  1. particleGroup.emitLoop = false;

If your particle groups are not set to looping you can listen for a completion event to know when the particle system is done emitting. Note that

  1. particles.onEnd = function(){ //If none of the groups in this particle system are set to looping //this method will fire once the system is done emitting particles}