Age Test in Script Test Example
Description:
The following example shows the access to the Proceed methods of an Age Test from
the Proceed hander of a Script Test.
Can Be Used With:
Should be used inside a Script_Test : Helper to access an Age_Test : Helper
Effect:
In the Init hander, the Script_Test creates a unqiue Age Test action or accesses an
existing one if already created before. It then calls the Proceed methods of the Age
Test to acquire its test results. Then it takes only the particles that have not passed
the Age Test and checks them against a spherical volume. Those that fall inside the
volume pass the Script Test, too.
The particles that tested True are passed to a second Event which stops them. The
final result is that all particles either stop because they are too old, or stop because
they have entered the spherical volume.
In the sample scene, a Sphere with radius 20 represents the spherical volume tested
by the script. The particles either rest on the surface of the sphere, or have passed
it and have stopped because of their age outside the sphere.
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.usePosition = true --enable the Position channel
pCont.useAge = true --enable the Age channel
)
--The Init handler is called on initialization.
--In this case, it is used to create the Age Test if it does not
--exist yet, or get the existing one.
on Init pCont do
(
global ageT
--If the unique object does not exist yet
if $ageTest77777 == undefined then
(
--Disable automatic event encapsulation
particleFlow.BeginEdit()
--Create a new Age Test
ageT = Age_Test()
--Give it a unique name! If you are reusing the code
--multiple times, change the number to have a unique ID
ageT.name ="ageTest77777"
--Disable editing mode, enable auto-encapsulation
particleFlow.EndEdit()
--Set the Age Test value to 1600 ticks, no variation
ageT.Test_Value = 1600
ageT.Variation = 0
)
else
ageT = $ageTest77777--if the object exists, get it
)--end init handler
--In the Proceed handler, the Script Test calls the Proceed methods
--of the Age Test to acquire its results and then checks the
--the particles that have not passed the Age Test against
--a spherical volume
on Proceed pCont do
(
--Get the current number of particles
count = pCont.NumParticles()
--Get the exact start and end time
t_start = pCont.GetTimeStart() as time
t_end = pCont.GetTimeEnd() as time
t_start_frac = (pCont.GetTimeStart() as float) - (t_start as integer)
t_end_frac = (pCont.GetTimeEnd() as float) - (t_end as integer)
--Initialize a BitArray to store results
testResult = #{}
--Initialize an Array to store test times
testTime = #()
--Call the ProceedStep1 method of the Age Test
ageT.proceedStep1 (pCont.GetParticleContainer()) (pCont.GetParticleSystem()) (pCont.getParticleSystemNode()) (pCont.getActionNode()) (pCont.getIntegrator())
--Call the ProceedStep2 method of the Age Test
--The results will be returned in the by-reference variables
ageT.proceedStep2 t_start t_start_frac &t_end &t_end_frac &testResult &testTime
--If the particle system is not undefined
if pCont.GetParticleSystem() != undefined then
(
--Go through all particles
for i in 1 to count do
(
--If the i-th particle passed the Age Test
if (testResult[i]) then
(
--Set the current particle index
pCont.particleIndex = i
--Set the particle’s test status to true
pCont.particleTestStatus = true
--Set the particle’s Test time to the one returned by the
--Age Test
pCont.setParticleTestTimePrecise i t_start testTime[i]
)
else
(
--Set the current particle index
pCont.particleIndex = i
--Any particles inside a sphere with radius 20
--satisfy the test
if length(pCont.particlePosition) < 20 then
(
--Tell the particle it passed the test
pCont.particleTestStatus = true
--And set the test time to the current particle time
pCont.particleTestTime = pCont.particleTime
)
)
)
)
)
on Release pCont do
(
)
|