Birth Script Example

Description:

The following example shows the default Birth_Script script with detailed comments.

Can Be Used With:

This script is used as the default script in the Birth_Script action.

pview_birthScript.gif

Effect:

The script generates a nice particle pattern – a helix built by a fiine sine curve. In order to see the effect of the script, you should:

pview_birthScript_viewport.gif

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

(

pCont.useTime = true --enable the Time channel

pCont.useAge = true --enable the Age channel

pCont.usePosition = true --enable the Position channel

pCont.useSpeed = true --enable the Speed channel

)

 

--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 Start Time as float. This converts the time to ticks.

t1 = pCont.getTimeStart() as float

--Get the End Time as float. This converts the time to ticks.

t2 = pCont.getTimeEnd() as float

 

--Clamp negative time values to 0

if (t1 < 0) then (t1 = 0)

 

--If the end time is less than 100 frames

--(100 frames * 160 ticks per frame in 30 fps NTSC)

if (t2 < 100*160) do

(

--then do a loop using the time values divided by 8

--this way a particle will be created every 8 ticks

for i in (t1/8+1) to (t2/8) do

(

--set the variable curTime to the actual time in ticks

curTime = 8*i as float

--give birth to a new particle

pCont.AddParticle()

--get the index of the last particle that was added

pCont.particleIndex = pCont.NumParticles()

--set the current time of the particle in frames

--(160 ticks in one frame at 30 fps NTSC animation)

pCont.particleTime = curTime/160

--Set the age of the particle to 0 – newborn!

pCont.particleAge = 0

--Define a radius variable based on the sine of the current time

sh = 2*sin(5*curTime)

--Define an angle variable based on the current time

ang = 0.2*curTime

--Set the particle position using the above variables

pCont.particlePosition = [sh*sin(ang), sh*cos(ang), 0]

--Define the speed using the same variables and falling down along Z

pCont.particleSpeed = [0.01*sin(ang), 0.01*cos(ang), -0.005]

)

)

)

 

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

--Not used in this case.

on Release pCont do

(

)

See also

Interface: MaxscriptParticleContainer

Birth_Script : Helper

Using MAXScript in Script Actions

Particle Flow Sample Scripts