Blitz3D+ Command Reference

ParticleMesh emitter,mesh

Parameters

emitter - CPU or GPU particle emitter entity

mesh - mesh whose first surface is copied into the emitter

Description

Gives an emitter a 3D shape to draw instead of a flat billboard.

GPU emitters upload one immutable copy of the first surface and instance it from GPU state, without per-particle CPU expansion or per-frame source uploads. Source colours, both UV sets, particle tint/atlas and yaw rotation are preserved. Empty, non-finite or invalid-index surfaces are rejected before replacement. The source surface is limited to 65535 vertices; particle capacity has its separate GPU limit. Use the emitter material; the source brush is not copied. Billboard population limits are not mesh performance promises.

This is what you reach for when the effect is made of objects rather than of light: chunks of debris from a smashed crate, coins bursting out of a chest, leaves in the wind, shell casings, or a swarm of little rocks. The emitter builds them all into one batch, so a few hundred spinning chunks still cost a single draw.

The first surface of the mesh is copied into the emitter - vertices, normals, vertex colours, both texture coordinate sets and triangles - and switching to mesh render mode happens automatically, so you do not need a separate ParticleRenderMode call. Because the data is copied, you can hide or free the source mesh straight afterwards.

Particles are tinted by ParticleColor on top of the mesh's own vertex colours, scaled by ParticleSize, and turned about their up axis by ParticleRotation. The texture still comes from the emitter with EntityTexture, and if ParticleAnimation is active the mesh's texture coordinates are mapped into the current sheet frame.

On CPU emitters keep the mesh small. One particle costs a whole copy of the mesh, and the emitter buffer holds 65535 vertices in total, so a 100 vertex mesh caps the emitter at 655 particles no matter what ParticleMax says. A mesh whose first surface has fewer than three vertices or no triangles is rejected with a runtime error, and only the first surface is used - flatten a multi-surface model before passing it in.

Requires Extended mode.

See also: ParticleRenderMode, ParticleMax, ParticleSize, ParticleRotation, CreateMesh.

Example

; ParticleMesh Example
; --------------------
; Requires Extended mode.

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,2,-6
CameraClsColor camera,8,12,24

; Mesh particles are lit like normal geometry
light=CreateLight()
RotateEntity light,45,-30,0

floor=CreatePlane()
EntityColor floor,30,34,44

; Hidden source meshes - the emitter copies their first surface
cube=CreateCube()
HideEntity cube
cone=CreateCone(6)
HideEntity cone
ball=CreateSphere(4)
HideEntity ball

; A loot geyser tossing spinning 3D pieces in one batched draw
emitter=CreateParticleEmitter(500)
PositionEntity emitter,0,0.5,0
ParticleEmissionRate emitter,60
ParticleLifetime emitter,2,3
ParticleVelocity emitter,0,4,0,1,0.5,1
ParticleGravity emitter,0,-4,0
ParticleColor emitter,255,200,60,1,255,120,40,1
ParticleSize emitter,0.15,0.1,0.3
ParticleRotation emitter,0,360,-180,180

; Start with cube-shaped particles
ParticleMesh emitter,cube
mesh_name$="1 cube"

While Not KeyDown(1)

    ; Keys 1-3 swap the particle mesh
    If KeyHit(2)
        ParticleMesh emitter,cube
        mesh_name$="1 cube"
    EndIf
    If KeyHit(3)
        ParticleMesh emitter,cone
        mesh_name$="2 cone"
    EndIf
    If KeyHit(4)
        ParticleMesh emitter,ball
        mesh_name$="3 sphere"
    EndIf

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    ; UpdateWorld also advances the particle simulation
    UpdateWorld
    RenderWorld

    Text 0,0,"Arrow keys: move camera   1/2/3: particle mesh   Esc: exit"
    Text 0,20,"ParticleMesh source: "+mesh_name$

    Flip

Wend

End

Index