PDA

View Full Version : birth script problem (re-post)


rafoarc
09-09-2010, 10:49 PM
hello all... I already posted this on the maxscript forum, but I figured that this might be a more appropriate place, so I apologize for the double post.
So, I am having some problem with a birth script in PF. I am trying to generate particles on the vertices of a mesh, and have them generated over time. here is the basic part of the script:

on Proceed pCont do
(

t1 = pCont.getTimeStart() as float
t2 = pCont.getTimeEnd() as float
local theMesh = snapshotAsMesh $Shape01
local theCount = theMesh.numverts

if (t1 < 0) then (t1 = 0)

if (t2 < theCount*160) do
(

for i in (t1/8+1) to (t2/8) do
(
curTime = 8*i as float
pCont.AddParticle()
pCont.particleIndex = pCont.NumParticles()
pCont.particleTime = curTime/160
pCont.particleAge = 0
local theNormal = getNormal theMesh i
if theNormal == [0,0,1] then
(
theMatrix = matrix3 1
)
else
(
local theUpVector = [0,0,1]
local theXVector = normalize (cross theNormal theUpVector)
local theYVector = normalize (cross theNormal theXVector)
theMatrix = matrix3 theXVector theYVector theNormal [0,0,0]
)

theMatrix.row4 = getVert theMesh i
pCont.particleTM = theMatrix
)

delete theMesh

)
)

Now, everything works fine, except that at certain vertices the particles are not generated. More specifically at vertices with index number 512, 1024, 1536, 2048 etc...When I change t1/8+1 and t2/8 into something like t1/6+1 and t2/6 or any other number in the place of the 8, the pattern of empty vertices changes (and I get far more empty ones...)
well... any ideas????
thanks...

HornBerger
09-11-2010, 07:28 PM
here is one source of error in your script:

t2 < theCount*160

you are running the birth script for theCount*160 number of ticks or theCount number of frames! so if i had a mesh with 120 vertices (theCount = number of vertices = 120) the birth script would run up till (120*160 ticks or 120 frames) and the loop inside your script runs 20 iterations per frame (irrespective of the integration step) i.e you would be producing 120*20 = 2400 number of particles at the end of the simulation and you only have the transformation matrices of 120 vertices!

here's how i would do it :

on ChannelsUsed pCont do
(
pCont.useTime = true
pCont.useAge = true
pCont.usePosition = true
pCont.useSpeed = true
pCont.useTM = true
)

on Init pCont do
(

)

on Proceed pCont do
(
fn computeTM nV = (
upV = [0,0,1]
xV = normalize (cross nV upV)
yV = normalize (cross nV xV)
tm = matrix3 xV yV nV [0,0,0]
)

t1 = pCont.getTimeStart() as float
t2 = pCont.getTimeEnd() as float


NOF = pCont.numparticles()
for k = 1 to NOF do
(
at time (((t2 as string) + "t") as time)
(
themesh = snapshotasmesh $plane
)
pCont.particleindex = k
theMatrix = computeTM (getnormal themesh pcont.particleid)
theMatrix.row4 = getVert themesh pcont.particleid
pCont.particleTM = thematrix
delete themesh
)

theMesh = snapshotasmesh $plane
theCount = theMesh.numVerts
vertsPerFrame = 5

if (mod theCount vertsPerFrame) >= 1 then
numberOfFrames = (theCount/vertsPerFrame) + (1)
else
numberOfFrames = (theCount/vertsPerFrame)

if (t1 < 0) then (t1 = 0)

if (t2 < ticksperframe * numberOfFrames) do -- 100 frames
(
if ((mod t2 ticksperframe) == 0.0) do
(
i = (t2/ticksperframe) as integer
at time i
(
theMesh = snapshotasmesh $plane
)

for j = ((i*vertsPerFrame) + 1) to (amin ((i+1)*vertsPerFrame) (theCount)) do
(
pCont.addParticle()
pCont.particleindex =pcont.numparticles()
pCont.particleAge = 0
pCont.particleTime = i
theMatrix = computeTM (getnormal themesh j)
theMatrix.row4 = getVert themesh j
pcont.particleTM = theMatrix
)
delete theMesh
)
)
)

on Release pCont do
(

)

the key variable in the above script is themesh make sure to change this variables before you simulate, either rename your mesh object to plane or change the value of this variable to "$name of your mesh".
Another important variable is vertsperframe a value of 5 means 5 vertices of the mesh would be used to place 5 particles every frame (i.e particles would be produced at rate of 5 per frame)

[attached max 2010 file]
enjoy! cheers! :)

CGTalk Moderation
09-11-2010, 07:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.