particleInteger サンプル スクリプト

説明:

次のサンプル スクリプトは、パーティクル速度に従って particleInteger チャネルに整数値を割り当てます。

用途:

.Assignment_Type4: [By Script Integer]に設定されているとき、Find_Target テスト内でターゲットを選択するために使用できます。

効果:

Find_Target オペレータと使用すると、particleIntegerチャネルで、インデックスからターゲット オブジェクトを指定できます。

フレームごとの速度が 1 単位より小さい場合、パーティクルは最初のターゲット(インデックス 0) に割り当てられます。フレームごとの速度が 10 単位より大きい場合、パーティクルは 3 番目のターゲット(インデックス 2)に割り当てられます。その他のすべてのパーティクルは 2 番目のターゲット (インデックス 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
    (
    --Enable the Time channel:
    pCont.useTime = true
    --Enable the Speed channel:
    pCont.useSpeed = true
    --Enable the Integer channel:
    pCont.useInteger = true
    )
    --The Init handler 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 number of particles
    count = pCont.NumParticles()

    --define two local variables slowSpeed and fastSpeed
    --as 1 resp. 10 units per frame (in NTSC time 160 ticks are 1 frame)
    slowSpeed = 1/160.0
    fastSpeed = 10/160.0

    --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
    pCont.particleIndex = i

    --If the length of the particleSpeed vector is shorter than
    --the defined slowSpeed value,
    --then set the particleInteger value to 0:
    if length(pCont.particleSpeed) < slowSpeed then
    pCont.particleInteger = 0

    --If the particle is faster than the slowSpeed value, test its
    --speed against the fastSpeed value. If faster, assign 2, if slower,
    --(between slowSpeed and fastSpeed), assign 1 to the
    --particleInteger channel:
    else
    (
    if (length(pCont.particleSpeed) > fastSpeed) then
    pCont.particleInteger = 2
    else
    pCont.particleInteger = 1
    )
    )--end i loop
    )--end Proceed
    --The Release handler is used to do cleanup work.
    --Not used in this case.
    on Release pCont do
    (
    )