最終ステップ更新の例

説明:

次の例では、詳細コメント付きで既定値の Final Step Update スクリプトを示しています。

用途:

既定値の Final Step Update スクリプトとして PF_Source によって使用されます。

効果:

既定のスクリプトでは、パーティクルの速度と方向が修正され、パーティクルは球状のパスを描くようになります。

例:

    --Get the current particle system executing the script
    pf_node_current = particleFlow.scriptRunner()

    --In case the current particle system is a valid node...
    if (pf_node_current != undefined) then(

    --Get the total number of particles
    count = pf_node_current.NumParticles()
    --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.
    --This makes the i-th particle in the container the current one:
    pf_node_current.particleIndex = i

    --Get the age of the particle, multiply by 5 and use as angle
    --to define the particle speed
    --Decreasing the constant 5 will slow down the rotation
    --Increasing the constant will speed up the rotation
    age = 5*pf_node_current.particleAge

    --Calculate a factor variable based on the particle age
    --This variable will define the radius of the bulb and will vary
    --thanks to the sine of the age over time.
    --Change the constant 20 to change the radius.
    factor = 20*(sin(2*age)+1)

    --Finally, calculate and set the particle position
    --using the factor as Radius and the particle index as Angle
    --in the function of the circle. The position of the node has to be
    --added to move the particles to the origin of the Source.
    --Info: In general, a circle can be drawn using an Angle
    --going from 0 to 2*Pi and the following functions for X and Y:
    --X = CenterX+Radius*Cos(Angle)
    --Y = CenterY+Radius*Sin(Angle)
    --In our case, CenterX and CenterY are 0, Radius is set to factor,
    --and Angle is based on the particle index multiplied by 77.
    --The Z position is based on the age.
    pf_node_current.particlePosition = [factor*cos(77*i), factor*sin(77*i), -age] + pf_node_current.pos

    )--end i loop
    )--end if