Speed Operator in Script Operator Example

 

   

Particle Flow - Quick Navigation

Description:

The following example shows a Script_Operator that creates a Speed operator and uses it to simulate its own functionality. It is possible to create several standard operators in this manner, set their properties in the Init block, and use them all together in succession in the Proceed block.

Can Be Used With:

Should be used inside a Script_Operator.

Effect:

This is basically a scripted wrapped around a Speed Operator. The Script Operator has the same functionality as the encapsulated Speed Operator inside of it. Using this as the starting point, the script could be enhanced to add scripted functionality to the existing operator.

EXAMPLE

--The ChannelsUsed handler defines the channels
--to be made available to the script.
on ChannelsUsed pCont do
(
-- No channels specified because the script doesn't make direct
-- access to particle data
)
 
--The Init handler is called on initialization.
--It is used to get the Speed action or create a new one
--if there is not an existing one
on Init pCont do
(
--Get an existing Speed Action by its unique name.
bb = $Speed74b93a88
 
--If the unique action does not exist, create one and give it
--the unique name. If you are reusing the code in multiple
--Script Operators, change the name to have a unique ID!
if (bb == undefined) then
(
ParticleFlow.BeginEdit()
bb = Speed()
bb.name ="Speed74b93a88"
bb.speed = 100
ParticleFlow.EndEdit()
)
initActions = pCont.getInitActions()
--Call the Init method in the Speed Action and pass
--the Particle container, Particle System object and node
--and the init action objects and nodes from the Scripted Operator.
bb.Init (pCont.getParticleContainer()) (pCont.getParticleSystem()) (pCont.getParticleSystemNode()) (pCont.getInitActions()) (pCont.getInitActionNodes())
)
 
--In the Proceed handler, we can call the .Proceed method
--of the Operator Interface and pass the container,
--particle system object and node, and
--the Init Action objects and nodes
--This means that the external Speed action will proceed whenever
--the Script_Operator does.
on Proceed pCont do
(
t_start = pCont.GetTimeStart() as time
t_end = pCont.GetTimeEnd() as time
bb = $Speed74b93a88
if (bb != undefined) then
(
bb.Proceed (pCont.getParticleContainer()) t_start &t_end (pCont.getParticleSystem()) (pCont.getParticleSystemNode()) bb (pCont.GetIntegrator())
)
pCont.SetTimeEnd t_end
)
 
--In the Release hander of the Script_Operator,
--call the.Release method and pass the container of the
--Script_Operator. 
on Release pCont do
(
bb = $Speed74b93a88
if (bb != undefined) then
bb.Release(pCont.getParticleContainer())
)
 

See Also