説明:
次の例は、Parray パーティクル システムと Mesher Compound オブジェクトを使用してその場でオブジェクト フラグメントを生成するフラグメントのサンプル スクリプトを示しています。
用途:
Birth_Script アクション内で、フラグメント パーティクルを作成するために使用します。
効果:
Init ハンドラ内で、スクリプトは、フラグメントを保持するためのフラグメント ソース オブジェクト、単一の PArray、単一の Mesher Compound、および 2 つの編集可能メッシュを用意します。次に、PArray を Mesher に割り当てます。
Proceed ハンドラで、スクリプトは、パーティクル システムの時間がフレーム 0 で、パーティクルが存在していないことを確認します。この場合、スクリプトは Mesher から PArray のメッシュを取得し、そのメッシュを要素に分解し、新しいパーティクルを発生させ、それらにメッシュとフラグメントの位置を割り当てます。
スクリプトによってフラグメントのあるパーティクルが作成されたら、それらは通常どおり パーティクル フロー のオペレータで制御できます。
例:
--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.useAge = true--enable the Age channel pCont.usePosition = true--enable the Position channel pCont.useSpeed = true--enable the Speed channel pCont.useShape = true--enable the Shape channel ) --The Init handler is called on initialization. --This is where preparation works can be performed. --The parameter pCont passed to the handler --contains the Particle Container the script is applied to on Init pCont do ( -- Create a geometry primitive to break into fragments. global bb = $Teapot_69e13b6c--a unique name -- Create a PArray particle system to create the fragments. global a = $PArray_36ce15a4--a unique name -- Create a Mesher Compound object to turn PArray into mesh. global mshr = $Mesher_23951616--a unique name -- Create a mesh to hold the total mesh. global totalMesh = $EMesh_5990501d--a unique name -- Create a mesh to hold separate fragments. global fragmentMesh = $EMesh_1589735c-- a unique name --Disable screen redraw to speed up execution withredrawoff( -- If the source object does not exist in the scene... if (bb == undefined) then ( -- create a Teapot for fragmentation, give it a unique name bb = Teapot radius:20 smooth:on segs:6 body:on handle:on spout:on lid:on mapCoords:off bb.name ="Teapot_69e13b6c" hide bb-- hide the teapot ) -- If the PArray object does not exist in the scene... if (a == undefined) then ( -- Create and setup a PArray a = PArray() a.name ="PArray_36ce15a4" a.speed = 0 a.emitter = b ba.particleType = 2 a.viewtype = 2 hide a ) -- If the Mesher object does not exist in the scene... if (mshr == undefined) then ( -- Create a Mesher Compound Object -- The Mesher gets mesh data out of the PArray mshr = mesher() mshr.name ="Mesher_23951616" mshr.pick = a-- Assign the Parray to the Mesher select mshr modPanel.addModToSelection (Edit_Mesh ()) ui:on clearSelection() hide mshr ) -- If the total Emesh object does not exist in the scene... if(totalMesh == undefined)then( -- Create a new editable meshes with unique name totalMesh = editable_mesh() totalMesh.name ="EMesh_5990501d" hide totalMesh ) -- If the fragments Emesh object does not exist in the scene... if(fragmentMesh == undefined)then( -- to create editable meshes our of Mesher fragmentMesh = editable_mesh() fragmentMesh.name ="EMesh_1589735c" hide fragmentMesh ) ) ) --The Proceed handler contains the particle creating script --The parameter pCont passed to the handler --contains the Particle Container the script is applied to: on Proceed pCont do( -- Get the time range t1 = pCont.getTimeStart() as float t2 = pCont.getTimeEnd() as float -- Only if the current time is at moment 0... if((t1 <= 0) and (t2 >= 0))then( -- Initialize a counter i = 0 -- If there are still no particles in the system if(pCont.NumParticles() <= 0)then ( print("should be making fragments") -- You can modify the fragmentation parameters here: a.Fragment_Thickness = 1 a.fragmentmethod = 1 a.fragChunkMinimum = 202 -- Get the complete mesh from the mesher totalMesh.mesh = mshr.mesh -- Create a bitarray with all faces set print("assigning particles") -- Repeat while there are still faces in the mesh while totalMesh.numfaces != 0 do ( -- Get the mesh element the first face belongs to el = meshop.getelementsusingface totalMesh #{1} -- Detach the faces of the element tMesh = meshop.detachFaces totalMesh el delete:true asMesh:true -- Set the mesh of the fragment Emesh to the element fragmentMesh.mesh = tMesh -- Update the fragment Emesh update fragmentMesh -- Get the center of the fragment mesh meshCenter = fragmentMesh.center -- The original particle position is the center of the fragment particlePos = fragmentMesh.center -- Adjust vertex location to center around the chunk pivot for j in 1 to fragmentMesh.verts.count do ( curVert = getVert fragmentMesh.mesh j curVert = curVert - meshCenter setVert fragmentMesh.mesh j curVert ) -- Move the pivot of the fragment to the original center -- of the fragment fragmentMesh.pivot = meshCenter -- Give birth to a new particle pCont.AddParticle() -- Increase the counter i += 1 -- Set the current particle index to the counter pCont.particleIndex = i -- Set particle time and age to 0 (newborn particle!) pCont.particleTime = 0 pCont.particleAge = 0 -- Set the particle’s position to the original fragment position pCont.particlePosition = particlePos -- Reset the speed to 0 pCont.particleSpeed = [0,0,0] -- Set the shape of the particle to the mesh of the fragment pCont.particleShape = fragmentMesh.mesh ) print("assigned particles "+ (pCont.NumParticles() as string)) ) ) ) --The Release handler is used to do cleanup work. --Not used in this case. on Release pCont do ( )