Class ParticleObject

3DS Max Plug-In SDK

Class ParticleObject

See Also: Class GeomObject, Class ForceField, Class CollisionObject, Class ShadeContext.

class ParticleObject : public GeomObject

Description:

This is the base class for creating particle system plug-ins.

Many particle systems may be derived from class SimpleParticle instead of this class. See Class SimpleParticle for more details.

Note: This class is derived from GeomObject and still has GEOMOBJECT_CLASS_ID as its super class. To determine if an object is a ParticleObject, call:

Animatable::GetInterface() with the ID I_PARTICLEOBJ or use the macro:

GetParticleInterface(anim) where anim is the object in question. This will return a ParticleObject* or NULL. See Class Animatable .

Note: See the method Animatable::GetProperty() for details on choosing the method used to evaluate the particle system during motion blur rendering. See Class Animatable .

Methods:

Prototype:

virtual void ApplyForceField(ForceField *ff)=0;

Remarks:

Implemented by the Plug-In.

This method is called to add the force field object passed to the list of force field objects operating on this particle system.

Parameters:

ForceField *ff

Points to an instance of a ForceField object.

Sample Code:

void SimpleParticle::ApplyForceField(ForceField *ff) {

fields.Append(1,&ff);

}

Prototype:

virtual BOOL ApplyCollisionObject(CollisionObject *co)=0;

Remarks:

Implemented by the Plug-In.

This method is called to add the collision object passed to the list of collision objects operating on this particle system.

Parameters:

CollisionObject *co

Points to an instance of a collision object.

Return Value:

If a particle does not support this method it should return FALSE; otherwise return TRUE.

Sample Code:

BOOL SimpleParticle::ApplyCollisionObject(CollisionObject *co) {

cobjs.Append(1,&co);

return TRUE;

}

Prototype:

int IsDeformable();

Remarks:

Implemented by the System.

This method returns TRUE to indicate it is deformable. A particle object is deformable, but does not let itself be deformed using the usual GetPoint() / SetPoint() methods. Instead a space warp must apply a force field to deform the particle system.

Prototype:

BOOL CanCacheObject();

Remarks:

Implemented by the System.

This method returns FALSE to indicate the object cannot be cached. Particle objects don't perform a shallow copy and therefore cannot be cached.

Prototype:

virtual BOOL NormalAlignVector(TimeValue t,Point3 &pt, Point3 &norm);

Remarks:

This method is available in release 2.0 and later only.

Implemented by the System.

This method is inherited from Class Object. This is a default implementation provided for particle systems.

Parameters:

TimeValue t

The time to compute the normal align vector.

Point3 &pt

The point of intersection.

Point3 &norm

The normal at the point of intersection.

Return Value:

TRUE if this method is implemented to return the normal align vector; otherwise FALSE.

Default Implementation:

{pt=Point3(0,0,0);norm=Point3(0,0,-1);return TRUE;}

Prototype:

virtual Point3 ParticlePosition(TimeValue t,int i);

Remarks:

Implemented by the Plug-In.

This method is available in release 2.0 and later only.

Returns the position of the specified particle in world space at the time passed.

The Particle Age texture map and the Particle Motion Blur texture map use this method.

Parameters:

TimeValue t

The time to return the particle position.

int i

The index of the particle.

Note: When a texture map calls these methods, the particle index i is passed to the texmap in the data member ShadeContext::mtlNum. The particle systems encode the index of the particle associated with the face of the particle mesh being shaded into the mtlNum. For instance, once the particle system generates a mesh to be rendered, every face of the mesh corresponds to a particle. This isn't a one-to-one correspondance because there are more faces than particles (if the particles are represented as tetrahedrons there are four faces per particle). When a texture map or material that is shading a mesh generated by a particle system wants to know which particle the face is associated with it gets this info out of the ShadeContext::mtlNum.

For example, here is a fragment of the code from the Particle Age texture map where it evaluates the color of the point being shaded:

AColor PartAgeTex::EvalColor(ShadeContext& sc)

 {

 ...

 // Evaluate...

 Object *ob = sc.GetEvalObject();

 if (ob && ob->IsParticleSystem()) {

  ParticleObject *obj = (ParticleObject*)ob;

  TimeValue t = sc.CurTime();

  TimeValue age = obj->ParticleAge(t,sc.mtlNum);

  TimeValue life = obj->ParticleLife(t,sc.mtlNum);

  ...etc.

 

Default Implementation:

{return Point3(0,0,0);}

Prototype:

virtual Point3 ParticleVelocity(TimeValue t,int i);

Remarks:

This method is available in release 2.0 and later only.

Implemented by the Plug-In.

Returns the velocity of the specified particle at the time passed (in 3ds max units per tick). This is specified as a vector. The Particle Age texture map and the Particle Motion Blur texture map use this method.

Parameters:

TimeValue t

The time to return the particle velocity.

int i

The index of the particle.

Default Implementation:

{return Point3(0,0,0);};

Prototype:

virtual float ParticleSize(TimeValue t,int i);

Remarks:

This method is available in release 2.0 and later only.

Implemented by the Plug-In.

Returns the world space size of the specified particle in at the time passed.

The Particle Age texture map and the Particle Motion Blur texture map use this method.

Parameters:

TimeValue t

The time to return the particle size.

int i

The index of the particle.

Default Implementation:

{return 0.0f;};

Prototype:

virtual int ParticleCenter(TimeValue t,int i);

Remarks:

This method is available in release 2.0 and later only.

Implemented by the Plug-In.

Returns a value indicating where the particle geometry (mesh) lies in relation to the particle position.

This is used by Particle Motion Blur for example. It gets the point in world space of the point it is shading, the size of the particle from ParticleSize(), and the position of the mesh from ParticleCenter(). Given this information, it can know where the point is, and it makes the head and the tail more transparent.

Parameters:

TimeValue t

The time to return the particle center.

int i

The index of the particle.

Return Value:

One of the following:

PARTCENTER_HEAD

The particle geometry lies behind the particle position.

PARTCENTER_CENTER

The particle geometry is centered around particle position.

PARTCENTER_TAIL

The particle geometry lies in front of the particle position.

Default Implementation:

{return PARTCENTER_CENTER;}

Prototype:

virtual TimeValue ParticleAge(TimeValue t, int i);

Remarks:

Implemented by the Plug-In.

This method is available in release 2.0 and later only.

Returns the age of the specified particle -- the length of time it has been 'alive'.

The Particle Age texture map and the Particle Motion Blur texture map use this method.

Parameters:

TimeValue t

Specifies the time to compute the particle age.

int i

The index of the particle.

Default Implementation:

{return -1;}

Prototype:

virtual TimeValue ParticleLife(TimeValue t, int i);

Remarks:

This method is available in release 2.0 and later only.

Implemented by the Plug-In.

Returns the life of the particle -- the length of time the particle will be 'alive'.

The Particle Age texture map and the Particle Motion Blur texture map use this method.

Parameters:

TimeValue t

Specifies the time to compute the particle life span.

int i

The index of the particle.

Default Implementation:

{return -1;}

Prototype:

virtual BOOL HasConstantTopology();

Remarks:

This method is available in release 2.0 and later only.

Implemented by the Plug-In.

If a particle system has a fixed number of particles of fixed topology, then it can return TRUE for this method, and the renderer will then compute the image motion blur velocities based on the vertex motions, giving motion blur for rotating particles etc. If the particle system is topology-varying it should return FALSE.

Default Implementation:

{return FALSE;}