VolumeDocking サンプル スクリプト
 
 
 
 

   

パーティクル フロー クイック ナビゲーション

説明:

次のサンプルは、Laszlo Sebo の VolumeDocking01.max シーンに基づいています。このサンプルでは、パーティクル フロー での次の MAXScript 操作について説明します。

用途:

このスクリプトは自己収容型で、すべてのオブジェクトと パーティクル フロー イベントおよびアクションを迅速に作成できます。

効果:

このスクリプトは、対応するアクションおよびイベントを備えたジオメトリ プリミティブと PF_Source を 2 つずつ作成します。

ジオメトリ オブジェクトは、パーティクルを塗り潰すボリュームとして使用されます。パーティクルの初期位置は、particleVector チャンネルにダンプされます。パーティクルは、Find_Target アクションを使って、一方のボリュームからもう一方のボリュームへの道筋を検出し、旋回して位置を切り替えます。

例:

-----------------
-- シーンの設定 --
-----------------
 
-- シーン アニメーションの範囲を 150 フレームに設定
animationRange = interval 0f 150f
-- Cylinder プリミティブを作成
cyl=cylinder radius:44 height:44 heightsegs:5 sides:18 pos:[-60, -55, 0]
-- Torus プリミティブを作成
tor=torus radius1:55 radius2:20 smooth:2 pos:[135, 120, 0]
-- Vortex スペース ワープを作成
vor=vortex timeOff:33 axialStrength:22 rotationStrength:33 iconSise:40 rotation:(quat -1 0 0 0) pos:[20,35,-5]
 
-- PF_Flow の設定
pf=PF_Source Show_Logo:offShow_Emitter:offQuantity_Viewport:100 isSelected:true
 
-------------------------------------
-- アクション リスト-追加例 --
-------------------------------------
 
-- イベントの自動カプセル化を無効化し、編集を開始:
ParticleFlow.BeginEdit()
a1 = RenderParticles()--Action 1 を定義
pf.AppendAction a1--アクションを PF_Source に追加
ParticleFlow.EndEdit()--編集を終了し、自動カプセル化を有効化
 
x=y=1--2 つの変数を初期化
--パーティクル ビュー内の PF_Source の場所を取得
pf.GetPViewLocation &x &y
 
------------------------
-- 最初のイベントを定義 --
------------------------
ParticleFlow.BeginEdit()--編集開始
-- Event 1 の Birth アクションを作成
ev1_a1 = Birth Emit_Start:0 Emit_Stop:0 Amount:300
 
-- Event 1 の Position Object アクションを作成
ev1_a2 = Position_Object Location:4 Emitter_Objects:#(tor) name:"PositionObjectFirst"
-- Position Object をコメント化
pf.SetComments ev1_a2"The operator defines the destination point inside the target volume"
 
-- Script オペレータの作成
ev1_a3 = Script_Operator()
-- Script オペレータのスクリプト コードを文字列に設定。
-- このコードは位置チャンネルとベクトル チャンネルを有効にし、
-- すべての新規パーティクルの位置情報を
-- ベクトル チャンネルに書き込む。
ev1_a3.proceed_script ="on ChannelsUsed pCont do
(
 pCont.usePosition = true
 pCont.useVector = true
)
on Init pCont do
(\n
)
on Proceed pCont do
(
 count = pCont.NumParticles()
 for i in 1 to count do
 (
 pCont.particleIndex = i
 if (pCont.particleNew) then
 ( pCont.particleVector = pCont.particlePosition)
 )
)
on Release pCont do
(\n
)"
 
-- アクションをコメント化:
pf.SetComments ev1_a3"The script is used to dump particle position to script vector channel"
 
-- Event 1 から Position_Object アクションを複製
-- 複製の結果は
-- 参照変数 dc に格納される
maxOps.cloneNodes ev1_a2 newNodes:&dc
-- 複製 (配列の最初の要素) を取得
ev1_a4 = dc[1]
-- アクション名を設定
ev1_a4.name ="PositionObjectSecond"
-- Cylinder をエミッタに設定
ev1_a4.Emitter_Objects = #(cyl)
 
-- アクションをコメント化:
pf.SetComments ev1_a4"The operator defines the initial position of a particle inside a start volume. The destination position is overwritten but the real value is kept in Script Vector channel"
 
-- パーティクル システムの制御に必要なその他のアクションを作成
ev1_a5 = Speed Direction:3
ev1_a6 = Rotation()
ev1_a7 = ShapeStandard Shape:1
ev1_a8 = DisplayParticles Type:6 Color:(color 255 0 0)
 
-- 空のイベントを作成し、このイベントに、これまでに作成した
-- アクションを追加
ev1 = Event()
ev1.AppendAction ev1_a1
ev1.AppendAction ev1_a2
ev1.AppendAction ev1_a3
ev1.AppendAction ev1_a4
ev1.AppendAction ev1_a5
ev1.AppendAction ev1_a6
ev1.AppendAction ev1_a7
ev1.AppendAction ev1_a8
-- 編集を無効化し、自動イベント カプセル化を有効化
ParticleFlow.EndEdit()
 
-- イベントを初期アクション リストとして PF_Source に追加
-- イベントと PF_Source が接続される
pf.appendInitialActionList ev1
-- イベントをパーティクル ビュー内に配置
ev1.SetPViewLocation x (y+100)
 
-------------------------------------
-- アクション リスト-例の挿入 --
-------------------------------------
 
--編集を再開
ParticleFlow.BeginEdit()
 
ev1_a9 = Spin SpinRate:200 Variation:55--Spin アクションを作成
ev1_a10 = Force Influence:111--フォースを作成
--Vortex をフォース内のスペース ワープに設定
ev1_a10.Force_Space_Warps = #(vor)
 
--Find_Target アクションの作成と設定:
ev1_a11 = Find_Target()
ev1_a11.name ="FindTarget"
ev1_a11.Cruise_Speed_Variation = 1000
ev1_a11.Acceleration_Limit=3000
ev1_a11.Aim_Point_Type = 2
ev1_a11.Icon_Size = 0
 
-- アクションをコメント化:
pf.SetComments ev1_a11"The destination point is defined by script vector. The script vector value was defined by the Script Operator 01 from the Position Object 01"
 
-- 既存のイベントに新しいアクションを挿入
ev1.InsertAction ev1_a9 8
ev1.InsertAction ev1_a10 9
ev1.InsertAction ev1_a11 10
ParticleFlow.EndEdit()
 
-- 2 番目のイベントとそのアクションの作成
ParticleFlow.BeginEdit()
ev2_a1 = Speed Speed:0
ev2 = Event()
ev2_a2 = DisplayParticles Type:6 Color:(color 0 255 0)
ev2.AppendAction ev2_a1
ev2.AppendAction ev2_a2
ParticleFlow.EndEdit()
 
--2 番目のイベントを Find_Target に接続
ev1_a11.setNextActionList ev2 ev1_a11
--再配置
ev2.SetPViewLocation x (y+400)
 
 
-- PF_Source のコピーを作成し、Position_Object オペレータの
-- エミッタ オブジェクトと交換:
 
-- PF_Source と 2 つのエミッタを複製し、
-- 複製を参照変数内に格納
maxOps.CloneNodes #(pf, ev1, ev2) newNodes:&dc
 
-- PF_Source およびエミッタの複製を取得
pfc = dc[1]
ev1c = dc[2]
ev2c = dc[3]
 
-- 現在のパーティクル ビューの位置を取得
x=y=1
pfc.GetPViewLocation &x &y
-- 2 つのイベントを再配置
ev1c.SetPViewLocation x (y+100)
ev2c.SetPViewLocation x (y+400)
 
-- 元の Position_Objects からエミッタ オブジェクトをコピー
if $PositionObjectFirst01 != undefined then (
 $PositionObjectFirst01.Emitter_Objects = ev1_a4.Emitter_Objects
)
if $PositionObjectSecond01 != undefined then (
 $PositionObjectSecond01.Emitter_Objects = ev1_a2.Emitter_Objects
)
 
-- Find_Target テストの出力を 2 番目のイベントの複製に接続
if $FindTarget01 != undefined then (
 $FindTarget01.setNextActionList ev2c $FindTarget01
) 
 
-- [修正]パネルに切り替え
max modify mode
-- パーティクル ビューを開き、実行結果を確認
ParticleFlow.OpenParticleView()
関連事項