Scripted Position Test Example

 

   

Particle Flow - Quick Navigation

Description:

The following example uses Script_Test actions to implement scripted position tests with both relative offset and absolute position options.

Can Be Used With:

The two scripts should be used inside the Script_Test : Helper actions.

Effect:

SCRIPT 1

--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
pCont.usePosition = true
)
 
--The Init handler is called on initialization.
--In this case, it is used to define the offset parameters
on Init pCont do
(
--Data paramters definition
struct paramsStruct (cond_less, axis, testpos, offset)
global paramsData = paramsStruct()
 
--true means less than, false means greater then
paramsData_offset.cond_less = true
--Axis option: x=1, y=2, z=3
paramsData_offset.axis = 3
--When set to true, the offset test is relative
--When set to false, the offset test is absolute.
paramsData_offset.offset = true
--Set the offset value to test for
paramsData_offset.testpos = -100
 
-- collects initial pos of each particle for offset test
global pos_init_array =#()
)
 
--In the Proceed handler, the actual testing is performed
 
on Proceed pCont do
(
count = pCont.NumParticles()
 
for i in 1 to count do
(
pCont.particleIndex = i
-- get ID of active particle
id = pCont.getParticleID pCont.particleIndex
if paramsData.cond_less == true then
(
if paramsData.offset == true then
(
-- collect initial pos for new born particle
if pCont.particleNew == true then
append pos_init_array pCont.particlePosition[paramsData.axis]
pos_id = pCont.GetParticlePositionByID id
if pos_id[paramsData.axis] < (pos_init_array[id] + paramsData.testpos) then
 testSatisfied = true
)
else
(
if pCont.particlePosition[paramsData.axis] < paramsData.testpos then
testSatisfied = true
)
)
else
(
if paramsData.offset == true then
(
-- collect initial pos for new born particle
 if pCont.particleNew == true then
append pos_init_array pCont.particlePosition[paramsData.axis]
pos_id = pCont.GetParticlePositionByID id
 if pos_id[paramsData.axis] > (pos_init_array[id] + paramsData.testpos) then
testSatisfied = true
)
else
(
 if pCont.particlePosition[paramsData.axis] > paramsData.testpos then
testSatisfied = true
)
)
if testSatisfied == true then
(
pCont.particleTestStatus = true
pCont.particleTestTime = pCont.particleTime
)
)
)
 
on Release pCont do
(
)

SCRIPT 2

on ChannelsUsed pCont do
(
pCont.useTime = true
pCont.usePosition = true
)
on Init pCont do
(
--Data paramters definition
struct paramsStruct (cond_less, axis, testpos, offset)
global paramsData = paramsStruct()
 
--true means less than, false means greater then
paramsData.cond_less = true
 
--Axis option: x=1, y=2, z=3
paramsData.axis = 3
--When set to false, the offset test is absolute.
--When set to true, the offset test is relative
paramsData.offset = false
--Set the position value to test
paramsData.testpos = -200
 
-- Collects initial pos of each particle for offset test:
global pos_init_array =#()
)
 
--The Proceed handler is identical to the one in the first script.
--Only the test parameters defined in the Init handler alter the
--behavior of the script!
 
on Proceed pCont do
(
count = pCont.NumParticles()
 
for i in 1 to count do
(
pCont.particleIndex = i
-- get ID of active particle
id = pCont.getParticleID pCont.particleIndex
if paramsData.cond_less == true then
(
if paramsData.offset == true then
(
-- collect initial pos for new born particle
if pCont.particleNew == true then
append pos_init_array pCont.particlePosition[paramsData.axis]
pos_id = pCont.GetParticlePositionByID id
if pos_id[paramsData.axis] < (pos_init_array[id] + paramsData.testpos) then
 testSatisfied = true
)
else
(
if pCont.particlePosition[paramsData.axis] < paramsData.testpos then
testSatisfied = true
)
)
else
(
if paramsData.offset == true then
(
-- collect initial pos for new born particle
if pCont.particleNew == true then
append pos_init_array pCont.particlePosition[paramsData.axis]
pos_id = pCont.GetParticlePositionByID id
if pos_id[paramsData.axis] > (pos_init_array[id] + paramsData.testpos) then
testSatisfied = true
)
else
(
if pCont.particlePosition[paramsData.axis] > paramsData.testpos then
testSatisfied = true
)
)
if testSatisfied == true then
(
pCont.particleTestStatus = true
pCont.particleTestTime = pCont.particleTime
)
)
)
 
on Release pCont do
(
)