説明:
次の例では、Script_Test アクション内のインテグレータ インタフェースの使用方法を紹介します。
用途:
Script_Test : ヘルパー アクション内部で使用する必要があります。
効果:
インテグレータを使用する必要があるかどうかを確認できます。インテグレータ パーティクルがないと、パーティクルはゼロ Z プレーン周辺で停止します。インテグレータを使用すると、パーティクルをプレーン レベルで正確に停止できるので、後でパーティクル位置を変更する必要がありません。
次の例のフローでは、パーティクルが発生し、加速されます。Script_Test テストはパーティクルの位置をチェックし、問題がなければ 2 番目のイベントに渡します。ここで、パーティクルは停止します。
例:
--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.useSpeed = true --enable the Speed channel ) --The Init handler is called on initialization. --It is not used in this case. on Init pCont do ( ) on Proceed pCont do ( --Get the End Time end = pCont.GetTimeEnd() as float --Get the interface to the Integrator _int = pCont.GetIntegrator() --Get the current particle count count = pCont.NumParticles() --Get the particle container pCont_curr = pCont.GetParticleContainer() --Initialize Arrays timeToStopInt = #() timeToStopFloat = #() particlesToStop = #{} --Initialize a flag to signal when --there are particles to send to the integrator hasParticlesToIntegrate = false --Go through all particles for i in 1 to count do ( --Set the current particle index pCont.particleIndex = i --Calculate the remaining time to travel timeForTravel = end - (pCont.particleTimeasfloat) -- format "time to travel % = %\n" i timeforTravel --Get the current position and speed of the particle curPos = pCont.particlePosition curSpeed = pCont.particleSpeed --Calculate the time to the XY plane. Because of the minus sign, --when the Z coordinate is negative, the time will be positive timeToPlane = -curPos.z / curSpeed.z -- format "time to plane % = %\n" i timeToPlane --Initialize a flag stopThisParticle = 0 --Get the particle time in frames curParticleTime = pCont.particleTime as time --If the time to plane is positive or zero and shorter --than the time to travel, then the particle has passed --the plane already and has to be stopped! if((timeToPlane >= 0.0)and(timeToPlane <= timeForTravel))do ( --Set the Test status to true pCont.particleTestStatus = true --Set the precise particle time pCont.setParticleTestTimePrecise i pCont.particleTime timeToPlane --Append the particle index to the BitArray of particles --to be stopped append particlesToStop i --Raise the flag to signal there is work for the integrator hasParticlesToIntegrate = true ) --Append the particle time frame and fraction to the two arrays append timeToStopInt curParticleTime append timeToStopFloat timeToPlane ) --If the flag has been set if hasParticlesToIntegrate then ( --If the integrator can be accessed, send the particles to stop --to the Integrator if _int != undefined then _int.proceedASync pCont_curr timeToStopInt timeToStopFloat true particlesToStop ) -- format "time to stop Int= %\n" timeToStopInt -- format "time to stop Float= %\n" timeToStopFloat -- format "part to stop Index= %\n" particlesToStop ) --The Release handler is used to do cleanup work. --Not used in this case. on Release pCont do ( )