Script Test 内の Age Test の例

説明:

次の例では、Script Test の Proceed ハンドラから Age Test の Proceed メソッドへのアクセスを示します。

用途:

Script_Test: ヘルパー内部で使用し、Age_Test: ヘルパーにアクセスする必要があります。

効果:

Init ハンドラにおいて Script_Test テストは、一意の Age Test アクションを作成するか、それが作成済みの場合は既存の Age Test アクションにアクセスします。次に、Age Test の Proceed メソッドを呼び出し、テスト結果を取得します。さらに、Age Test をまだ通過していないパーティクルのみを取り出し、球状ボリュームと照合します。ボリューム内部に落下しているパーティクルも、Script Test を通過します。

テストで True の返されたパーティクルは 2 番目のイベントに渡され、そこで停止します。最終結果は、すべてのパーティクルが古すぎるために停止するか、球状ボリュームに入ってしまっているために停止するかのどちらかです。

サンプル シーンでは、スクリプトによってテストされる球状ボリュームは、半径 20 の天球体で表されています。パーティクルは、球のサーフェスに残っているか、サーフェスの通過後、エージが球の範囲を超えたために停止しているかのどちらかです。

例:

    --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
    (
    )