Flying Letters from a Custom Text

Description:

The following example uses a Script Operator to assign a single letter to each particle based on a scene text objects. You can type in any text you want, define the font and change the appearance of the text using modifiers like Extrude and Bevel and let Particle Flow generate a stream of letters showing the text.

Can Be Used With:

The scripts should be used inside a Script_Operator.

pview_flyingletters.gif

Effect:

NOTE:

The source object must be a text object with some meshing modifier on top. Do not collapse the stack to EMesh as the script needs access to the text baseobject's font and text properties!

Sample File:

[3dsmax5]\scenes\particle_flow\maxscript\FlyingLettersFromCustomText.max

Example:

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

(

 

)

See also

Using MAXScript in Script Actions

Particle Flow Sample Scripts