カスタム文字列によるフライング文字

説明:

次の例では、Script オペレータを使用して、シーンのテキスト オブジェクトに基づいて単一の文字を各パーティクルに割り当てます。ユーザは任意の文字を入力でき、フォントを定義し、Extrude や Bevel などのモディファイヤを使用してテキストの外観を変更します。また、パーティクル フロー によってテキストを示す文字のストリームを生成します。

用途:

このスクリプトは、Script_Operator 内部で使用されます。

効果:

注:

ソース オブジェクトは、何らかのメッシュ モディファイヤが上部にあるテキスト オブジェクトでなくてはなりません。このスクリプトはテキストの基本オブジェクト (baseobject)のフォントおよびテキスト プロパティにアクセスする必要があるので、スタックを EMesh に集約しないでください。

例:

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

    )