説明:
次の例では、Script オペレータを使用して、シーンのテキスト オブジェクトに基づいて単一の文字を各パーティクルに割り当てます。ユーザは任意の文字を入力でき、フォントを定義し、Extrude や Bevel などのモディファイヤを使用してテキストの外観を変更します。また、パーティクル フロー によってテキストを示す文字のストリームを生成します。
用途:
このスクリプトは、Script_Operator 内部で使用されます。
効果:
この例は、インスタンス化されたソースとして一意のシーン テキスト オブジェクト (上に任意のモディファイヤ付き) を使用します。
スクリプトによってソース テキストのコピーが作成され、元のテキストがそのテキストの中の単一の文字によって置き換えられます。つまり、ユーザが自由に外観を作成(たとえば、カスタムの Bevel をソースに追加するなど) でき、パーティクル システムはこれらの設定を継承します。
Source の[フォント]の[テキスト]を変更し、時間を取り消して戻したら、パーティクル システムは自動的に更新されます。
シーンから削除された文字が検出され、パーティクル システムがそれらを再生成して元に戻します。
ソース オブジェクトが削除された場合、押し出しモディファイヤの新しい既定値のテキストが、「Enter Text Here」という文字列を使用してシーン内に作成され、レンダリング可能フラグが false に設定されます。つまり、このテキスト オブジェクトを使用して最初から作成し、フォント、テキスト、スタックを編集して希望どおりの外観にすることができるのです。
ソース オブジェクトは、何らかのメッシュ モディファイヤが上部にあるテキスト オブジェクトでなくてはなりません。このスクリプトはテキストの基本オブジェクト (baseobject)のフォントおよびテキスト プロパティにアクセスする必要があるので、スタックを EMesh に集約しないでください。
外観を変更したら、新しい外観を表示するために Cache オペレータをすべて無効にする必要があります。
テキストが既定値よりも長い場合、Birth オペレータのタイミングを変更して多くのパーティクルを取得することができます。
他の任意の PFlow オペレータを使用してパーティクルに影響を与えることができます。Script では、パーティクルのシェイプのみが確認されます。
スクリプトを使用した複数のパーティクル システムが必要な場合、スクリプト全体を通して固有の名前を変更してそれぞれを分離します。
例:
--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.useShape = true --enable changes to the shape ) --The Init handler is called on initialization. --In this case, it is used to define the string, font name --and create the text objects for every letter on Init pCont do ( --Define a global variable to store the array of letter objects --Use different unique ID if reusing the code --multiple times in the same scene global pflow_letter_array17b02b680 local text_source = $PFlowText17b02b680 --If the unique source is missing... if not isValidNode text_source do ( --Create new text source object text_source = text text:"Enter Text Here" --Give it the unique name - use a different ID --throughout the script if you need to use multiple --scripts in the same scene text_source.name ="PFlowText17b02b680" --Add an extrude modifier to the text object addmodifier text_source (extrude amount:10) --make the source invisible to the renderer text_source.renderable = false ) --If the array has been initialized before... if pflow_letter_array17b02b680 != undefined do ( txtpos = 0 --Go through all elements of the array for i in pflow_letter_array17b02b680 do ( txtpos += 1 --If any of the array nodes is invalid (deleted), --or the font does not match the source's font name, --or a letter does not match the letter in the source text, --reset the whole array so it can be reinitialized if not (isValidNode i) or i.font != text_source.font or i.text != (substring text_source.text txtpos 1) do pflow_letter_array = undefined ) ) --If the array is newly created or reset (see above) if pflow_letter_array17b02b680 == undefined do ( --Initialize to empty array pflow_letter_array17b02b680 = #() --Get the string to display by the particle system from the --source text object in the scene. You can edit the --text's source to display any text you want! --Moving the time slider will update all letters! local str = text_source.text --Delete all possibly existing letter objects by name delete $PFlow_Letter_17b02b680_* --Loop from 1 to the number of letters in the string for i = 1 to str.count do ( --Create a copy of the source object with --the i-th letter from the string letter = copy text_source letter.text = (substring str i 1) --Give the object a unique name letter.name = (uniquename"PFlow_Letter_17b02b680_") --Set the font to the font of the source letter.font = text_source.font --Append the new text object to the array append pflow_letter_array17b02b680 letter --Hide the text object hide letter ) ) ) --In the Proceed handler, we will assign the letters to the --available particles on Proceed pCont do ( --Get the current particle count count = pCont.numParticles() --Get the number of text objects in the global array maxcount = pflow_letter_array17b02b680.count --Create an empty mesh empty_mesh = triMesh() --Repeat for all particles for i = 1 to count do ( --Set the current particle index pCont.particleIndex = i --If the particle index is less than the number of letters if i <= maxcount then ( --If the node is not deleted, set the particle shape --to the mesh of the i-th text object if isValidNode pflow_letter_array17b02b680[i] do pCont.particleShape = pflow_letter_array17b02b680[i].mesh ) else ( --If there is no letter for this particle, --set the shape to an empty mesh pCont.particleShape = empty_mesh ) ) ) --The Release handler is used to do cleanup work. --Not used in this case. on Release pCont do ( )