particleInteger Sample Script

Description:

The following sample script assigns Integer values to the particleInteger channel according to particle speed.

Can Be Used With:

Can be used to choose targets in the Find_Target Test when .Assignment_Type is set to 4 : By Script Integer.

Effect:

When used with a Find_Target operator, the particleInteger channel can be used to specify the target objects by index.

If the speed is below 1 unit per frame, then the particle is assigned to the first target (index=0). If the speed is higher than 10 units per frame then the particle is assigned to the third target (index=2). All other particles are assigned to the second target (index = 1).

Example:

--The ChannelsUsed handler defines the channels

--to be made available to the script.

--For the list of all channels, see

--Interface: MaxscriptParticleContainer

--The parameter pCont passed to the handler

--contains the Particle Container the script is applied to

on ChannelsUsed pCont do

(

--Enable the Time channel:

pCont.useTime = true

--Enable the Speed channel:

pCont.useSpeed = true

--Enable the Integer channel:

pCont.useInteger = true

)

--The Init hander is called on initialization.

--It is not used in this case.

on Init pCont do

(

)

 

--The Proceed handler contains the main script

--applied to the Particles.

--The parameter pCont passed to the handler

--contains the Particle Container the script is applied to:

on Proceed pCont do

--get the number of particles

count = pCont.NumParticles()

 

--define two local variables slowSpeed and fastSpeed

--as 1 resp. 10 units per frame (in NTSC time 160 ticks are 1 frame)

slowSpeed = 1/160.0

fastSpeed = 10/160.0

 

--Loop from 1 to the number of particles:

for i in 1 to count do

(

 

--Set the particle index in the container to the current i value

pCont.particleIndex = i

 

--If the length of the particleSpeed vector is shorter than

--the defined slowSpeed value,

--then set the particleInteger value to 0:

if length(pCont.particleSpeed) < slowSpeed then

pCont.particleInteger = 0

 

--If the particle is faster than the slowSpeed value, test its

--speed against the fastSpeed value. If faster, assign 2, if slower,

--(between slowSpeed and fastSpeed), assign 1 to the

--particleInteger channel:

else

(

if (length(pCont.particleSpeed) > fastSpeed) then

pCont.particleInteger = 2

else

pCont.particleInteger = 1

)

)--end i loop

)--end Proceed

--The Release handler is used to do cleanup work.

--Not used in this case.

on Release pCont do

(

)

See also

Interface: MaxscriptParticleContainer

Find_Target : Helper

Using MAXScript in Script Actions

Particle Flow Sample Scripts