Class SimpleParticle

3DS Max Plug-In SDK

Class SimpleParticle

See Also: Class ParticleObject, Marker Types, Class Mesh, Class ParticleSys, Class Interval, Template Class Tab, Class ParamDimension,.

class SimpleParticle : public ParticleObject

Description:

This class provides a base class from which you may derive Particle System plug-ins. This class may be used by particle systems that fit within its form. The form is primarily dictated by the data members maintain by the class. The class maintains an instance of class ParticleSys that describes the particles. It also has a table of force fields and collision objects. The emitter for the particles is represented by a mesh. There is also a parameter block pointer available.

Particle system plug-ins that don't fit this form may derive from a base class without any constraints. See Class ParticleObject for more details.

Data Members:

public:

IParamBlock *pblock;

The parameter block pointer.

ParticleSys parts;

This is a description of the particles themselves (their count, position, velocities, ...).

TimeValue tvalid;

A particle system derived from SimpleParticle is valid at a particular time only (it does not have a validity interval). It is assumed to be always changing. This data member holds the time at which it is valid (when valid is TRUE).

BOOL valid;

This flag indicates if the particle system is valid. If TRUE, tvalid should contain the time it is valid for.

Tab<ForceField*> fields;

The table of force fields affecting the particles.

Tab<CollisionObject*> cobjs;

The table of collision objects affecting the particles.

Mesh mesh;

The mesh object that represents the emitter.

Interval mvalid;

The validity interval for the emitter mesh. If the mesh is invalid BuildEmitter() will be called.

static SimpleParticle *editOb;

The SimpleParticle object that is being edited between BeginEditParams() and EndEditParams().

static IObjParam *ip;

Storage for the interface pointer passed into BeginEditParams(). This pointer is only valid between BeginEditParams() and EndEditParams().

Methods:

Prototype:

SimpleParticle();

Remarks:

Constructor. The pblock is initialized to NULL, the mvalid interval is set to empty, and valid is set to FALSE.

Prototype:

virtual void UpdateParticles(TimeValue t, INode *node)=0;

Remarks:

Implemented by the Plug-In.

This method is called so the particle system can update its state to reflect the current time passed. This may involve generating new particle that are born, eliminating old particles that have expired, computing the impact of collisions or force field effects, and modify the positions and velocities of the particles.

Parameters:

TimeValue t

The particles should be updated to reflect this time.

INode *node

This is the emitter node. Particles system are world space objects so they are not instanced. This means that the particle system can depend on the node's world space position.

Sample Code:

For example code see \MAXSDK\SAMPLES\OBJECTS\RAIN.CPP.

Prototype:

void SetParticlePosition(TimeValue t, int i, Point3 pos);

Remarks:

This method is available in release 3.0 and later only.

Sets the position of the specified particle at the specified time.

Parameters:

TimeValue t

The time at which to set the particle position.

int i

The zero based index of the particle to set.

Point3 pos

The position to set.

Prototype:

void SetParticleVelocity(TimeValue t, int i, Point3 vel);

Remarks:

This method is available in release 3.0 and later only.

Sets the velocity of the specified particle at the specified time (in 3ds max units per tick).

Parameters:

TimeValue t

The time at which to set the particle velocity.

int i

The zero based index of the particle to set.

Point3 vel

The velocity to set.

Prototype:

void SetParticleAge(TimeValue t, int i, TimeValue age);

Remarks:

This method is available in release 3.0 and later only.

Sets the age of the specified particle at the specified time.

Parameters:

TimeValue t

The time at which to set the particle age.

int i

The zero based index of the particle to set.

TimeValue age

The age to set.

Prototype:

virtual void BuildEmitter(TimeValue t, Mesh& amesh)=0;

Remarks:

Implemented by the Plug-In.

This method is called to allow the plug-in to provide a representation of its emitter in the 3D viewports.

Parameters:

TimeValue t

Specifies the time to build the emitter.

Mesh& amesh

Store the built mesh representation here.

Prototype:

virtual Interval GetValidity(TimeValue t)=0;

Remarks:

Implemented by the Plug-In.

This method is called to retrieve the validity time of the particle system emitter.

Parameters:

TimeValue t

The time to compute the validity interval.

Return Value:

The validity interval of the particle system emitter at the specified time.

Prototype:

virtual MarkerType GetMarkerType();

Remarks:

Implemented by the Plug-In.

Returns one of the defined marker types to use when displaying particles.

Return Value:

One of the following values:

See Marker Types.

Default Implementation:

{return POINT_MRKR;}

Prototype:

virtual BOOL OKtoDisplay(TimeValue t);

Remarks:

Implemented by the Plug-In.

This method is called to determine if the particle emitter is okay to display at the specified time. If at certain times it is not okay to display this method should return FALSE. This might occur if a size goes to 0. Normally however it is always okay to display so the default implementation returns TRUE.

Parameters:

TimeValue t

The time to display the emitter.

Return Value:

TRUE if it is okay to display, FALSE otherwise.

Default Implementation:

{return TRUE;}

Prototype:

virtual BOOL EmitterVisible();

Remarks:

Implemented by the Plug-In.

This method is called to determine if the particle emitter is visible in the viewports. If the plug-in provides a UI control to toggle the emitter on and off, this method should return the state of this control.

Return Value:

TRUE if the emitter is visible; otherwise FALSE.

Default Implementation:

{return TRUE;}

Prototype:

virtual void InvalidateUI();

Remarks:

Implemented by the Plug-In.

It is important the user interface controls display values that reflect the current time. This method is called if the user interface parameters needs to be updated because the user moved to a new time.

Example:

If the plug-in uses a parameter map for handling its UI, it may call a method of the parameter map to handle this: pmapParam->Invalidate();

If the plug-in does not use parameter maps, it should call the SetValue() method on each of its controls that display a value, for example the spinner controls. This will cause to the control to update the value displayed. The code below shows how this may be done for a spinner control. Note that ip and pblock are assumed to be initialized interface and parameter block pointers

(IObjParam *ip, IParamBlock *pblock).

float newval;

Interval valid=FOREVER;

TimeValue t=ip->GetTime();

// Get the value from the parameter block at the current time.

pblock->GetValue( PB_ANGLE, t, newval, valid );

// Set the value. Note that the notify argument is passed as FALSE.

// This ensures no messages are sent when the value changes.

angleSpin->SetValue( newval, FALSE );

Prototype:

virtual ParamDimension *GetParameterDim(int pbIndex);

Remarks:

Implemented by the Plug-In.

This method returns the parameter dimension of the parameter whose index is passed.

Parameters:

int pbIndex

The index of the parameter to return the dimension of.

Return Value:

Pointer to a ParamDimension.

Example:

return stdNormalizedDim;

Default Implementation:

The default implementation returns defaultDim.

See Also: ParamDimension

Prototype:

virtual TSTR GetParameterName(int pbIndex);

Remarks:

Implemented by the Plug-In.

This method returns the name of the parameter whose index is passed.

Parameters:

int pbIndex

The index of the parameter to return the name of.

Return Value:

The name of the parameter.

Default Implementation:

The default implementation returns TSTR(_T("Parameter"))