Particles In Code: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(expanded)
(more expansion)
Line 7: Line 7:
<source lang=cpp>PrecacheParticleSystem( "your_particle_effect_name" );</source>
<source lang=cpp>PrecacheParticleSystem( "your_particle_effect_name" );</source>


== Creating ==
== Server ==


=== Serverside ===
=== Dispatching ===


Particles are dispatched as [[events]]. The functions are shared, so there's no need to <code>#ifdef</code> calls out on the client.
Particles are dispatched as [[Temporary Entity|temp ents]]. The dispatch functions are shared, so there's no need to <code>#ifdef</code> calls out on the client.


<source lang=cpp>
<source lang=cpp>
Line 17: Line 17:


// Create at world co-ords
// Create at world co-ords
void DispatchParticleEffect( "my_particle", vecOrigin, angAngles, pOwnerEntity )
DispatchParticleEffect( "my_particle", vecOrigin, angAngles, pOwnerEntity )
 
// Create at model attachment
// Create at model attachment
void DispatchParticleEffect( "my_particle", ParticleAttachment_t, pOwnerEntity, iAttachmentPoint, bResetAllParticlesOnEntity  )</source>
DispatchParticleEffect( "my_particle", ParticleAttachment_t, pOwner, iAttachment, bResetAllParticlesOnEntity  )</source>
 
See also <code>[[#ParticleAttachment_t|ParticleAttachment_t]]</code>, below.


{{bug|Valve's code for dispatching a particle on a model [[attachment]] is broken. [[SDK Known Issues List Fixed#Server Dispatching an Attached Particle Effect|Get the fix here.]]}}
{{bug|Valve's code for dispatching a particle on a model [[attachment]] is broken. [[SDK Known Issues List Fixed#Server Dispatching an Attached Particle Effect|Get the fix here.]]}}


Values of <code>ParticleAttachment_t</code> are:
=== Destroying ===


; <code>PATTACH_ABSORIGIN</code>
; <code>StopParticleEffects( CBaseEntity* )</code>
; <code>PATTACH_ABSORIGIN_FOLLOW</code>
: Stops all effects on the given entity.
: Spawn at (and optionally follow) the entity's [[origin]].
; <code>PATTACH_POINT</code>
; <code>PATTACH_POINT_FOLLOW</code>
: Spawn at (and optionally follow) an [[attachment]] point on the entity's model.
; <code>PATTACH_CUSTOMORIGIN</code>
: Spawn at a given origin.
; <code>PATTACH_WORLDORIGIN</code>
: Don't associate with an entity at all. Use with caution - could easily cause memory leaks.


=== Client ===
== Client ==


Each particle system is a [[temporary entity]]: only the client can interact with it once it has been dispatched. In addition, it isn't possible to specify [[Control Point (particles)|control points]] on the server at all.
=== Creating ===


Each active system is a <code>[[CNewParticleEffect]]</code> object that can be created and accessed through an entity's <code>[[ParticleProp()]]</code> accessor.
Particle systems are automatically created on the client when a dispatch event is received, or can be created manually. Each system is a <code>[[CNewParticleEffect]]</code> object managed through the owning entity's <code>[[ParticleProp()]]</code> accessor:


<source lang=cpp>
<source lang=cpp>
#include "particles_new.h"
#include "particles_new.h"


// To create a new systen:
// Create a new system
CNewParticleEffect* pEffect = ParticleProp()->Create( "my_particles", PATTACH_ABSORIGIN );
CNewParticleEffect* pEffect = ParticleProp()->Create( "my_particles", PATTACH_ABSORIGIN );


// Or if the system already exists:
// System already exists
CNewParticleEffect* pEffect = ParticleProp()->FindEffect( "my_particles" );
CNewParticleEffect* pEffect = ParticleProp()->FindEffect( "my_particles" );
pEffect->SetControlPoint( 1, vecSomeVector );
</source>
</source>


Alternatively, you can hook into particle creation:
Alternatively, you can hook into particle creation events:


<source lang=cpp>void C_MyEntity::OnNewParticleEffect( const char* pszParticleName, CNewParticleEffect* pNewParticleEffect )
<source lang=cpp>void C_MyEntity::OnNewParticleEffect( const char* pszParticleName, CNewParticleEffect* pNewParticleEffect )
Line 61: Line 54:
}</source>
}</source>


== Destroying ==
=== Control points ===


You can stop particle systems with:
It is not possible to set the value of [[Control Point (particles)|control points]] from the server. On the client, you can with these <code>CNewParticleEffect</code> functions:
 
; <code>SetControlPoint()</code>
: An arbitary [[Vector]].
; <code>SetControlPointEntity()</code>
: Follow the given entity's [[origin]].
; <code>SetControlPointOrientation()</code>
; <code>SetControlPointRightVector()</code>
; <code>SetControlPointForwardVector()</code>
; <code>SetControlPointUpVector()</code>
: Set orientation with a [[QAngle]] or series of Vectors.
 
=== Destroying ===


; <code>StopParticleEffects( CBaseEntity* )</code>
; <code>StopParticleEffects( CBaseEntity* )</code>
: Stops all effects on the given entity
: Stops all effects on the given entity.
; <code>ParticleProp()->StopParticlesInvolving( CBaseEntity* )</code>
; <code>ParticleProp()->StopParticlesInvolving( CBaseEntity* )</code>
: Stops all effects with a control point attached to the given entity.
: Stops all effects with a control point attached to the given entity. {{todo|Global or only on current entity?}}
; <code>ParticleProp()->StopParticlesNamed( const char* )</code>
; <code>ParticleProp()->StopParticlesNamed( const char* )</code>
: Stops all effects with the given system name. {{todo|Global or only on current entity?}}
: Stops all effects with the given system name. {{todo|Global or only on current entity?}}
; <code>[[CNewParticleEffect]]<nowiki>::</nowiki>StopEmission( bool bInfiniteOnly, bool bRemoveAllParticles, bool bWakeOnStop)</code>
; <code>CNewParticleEffect<nowiki>::</nowiki>StopEmission( bool bInfiniteOnly, bool bRemoveAllParticles, bool bWakeOnStop)</code>
: Stops the current particle system, without removing it. {{todo|Meaning of first and third arguments.}}
: Stops the current particle system, without removing it. {{todo|Meaning of first and third arguments.}}
== ParticleAttachment_t ==
One of these values is passed when dispatching or creating an effect:
; <code>PATTACH_ABSORIGIN</code>
; <code>PATTACH_ABSORIGIN_FOLLOW</code>
: Spawn at (and optionally follow) the entity's [[origin]].
; <code>PATTACH_POINT</code>
; <code>PATTACH_POINT_FOLLOW</code>
: Spawn at (and optionally follow) an [[attachment]] point on the entity's model.
; <code>PATTACH_CUSTOMORIGIN</code>
: Spawn at a given origin.
; <code>PATTACH_WORLDORIGIN</code>
: Don't associate with an entity at all. Use with caution - could easily cause memory leaks.


[[Category: Particle System]]
[[Category: Particle System]]

Revision as of 13:28, 26 October 2009

Precaching

Particle systems must be precached before they can be used. This is done by listing the PCF containing them in particles_manifest.txt, then making this call:

PrecacheParticleSystem( "your_particle_effect_name" );

Server

Dispatching

Particles are dispatched as temp ents. The dispatch functions are shared, so there's no need to #ifdef calls out on the client.

#include "particle_parse.h"

// Create at world co-ords
DispatchParticleEffect( "my_particle", vecOrigin, angAngles, pOwnerEntity )

// Create at model attachment
DispatchParticleEffect( "my_particle", ParticleAttachment_t, pOwner, iAttachment, bResetAllParticlesOnEntity  )

See also ParticleAttachment_t, below.

Icon-Bug.pngBug:Valve's code for dispatching a particle on a model attachment is broken. Get the fix here.  [todo tested in ?]

Destroying

StopParticleEffects( CBaseEntity* )
Stops all effects on the given entity.

Client

Creating

Particle systems are automatically created on the client when a dispatch event is received, or can be created manually. Each system is a CNewParticleEffect object managed through the owning entity's ParticleProp() accessor:

#include "particles_new.h"

// Create a new system
CNewParticleEffect* pEffect = ParticleProp()->Create( "my_particles", PATTACH_ABSORIGIN );

// System already exists
CNewParticleEffect* pEffect = ParticleProp()->FindEffect( "my_particles" );

Alternatively, you can hook into particle creation events:

void C_MyEntity::OnNewParticleEffect( const char* pszParticleName, CNewParticleEffect* pNewParticleEffect )
{
	// ...
}

Control points

It is not possible to set the value of control points from the server. On the client, you can with these CNewParticleEffect functions:

SetControlPoint()
An arbitary Vector.
SetControlPointEntity()
Follow the given entity's origin.
SetControlPointOrientation()
SetControlPointRightVector()
SetControlPointForwardVector()
SetControlPointUpVector()
Set orientation with a QAngle or series of Vectors.

Destroying

StopParticleEffects( CBaseEntity* )
Stops all effects on the given entity.
ParticleProp()->StopParticlesInvolving( CBaseEntity* )
Stops all effects with a control point attached to the given entity.
Todo: Global or only on current entity?
ParticleProp()->StopParticlesNamed( const char* )
Stops all effects with the given system name.
Todo: Global or only on current entity?
CNewParticleEffect::StopEmission( bool bInfiniteOnly, bool bRemoveAllParticles, bool bWakeOnStop)
Stops the current particle system, without removing it.
Todo: Meaning of first and third arguments.

ParticleAttachment_t

One of these values is passed when dispatching or creating an effect:

PATTACH_ABSORIGIN
PATTACH_ABSORIGIN_FOLLOW
Spawn at (and optionally follow) the entity's origin.
PATTACH_POINT
PATTACH_POINT_FOLLOW
Spawn at (and optionally follow) an attachment point on the entity's model.
PATTACH_CUSTOMORIGIN
Spawn at a given origin.
PATTACH_WORLDORIGIN
Don't associate with an entity at all. Use with caution - could easily cause memory leaks.