Chunks birth script : how to create chunks every nth frame


#1

This is my first attempt at scripting particles so please excuse my confusion.

How do I adapt the chunk script (below) so that instead of creating all the particles at frame 0 (t<0), the particles are birthed every nth frame.

I assume I need to change the “if t < 0 do” to something like “for t=0 to numChunks by x” where x is the number of frames I want between each particle being birthed. Or am I, as I suspect, barking up the wrong tree? :slight_smile:


 on ChannelsUsed pCont do
 (
 	pCont.useTime = true --enable the Time channel
 	pCont.useAge = true
 	pCont.useTM = true
 	pCont.useShape = true
 )
 
 on Init pCont do
 (
 	global ChunksArray = $parts* as array
 )
 
 on Proceed pCont do
 (
 	t = pCont.getTimeStart() as float
 
 	if t < 0 do
 	(
 		NumChunks = ChunksArray.count
 
 		for i = 1 to NumChunks do
 		(
 			pCont.AddParticle()
 			pCont.particleIndex = pCont.NumParticles()
 			pCont.particleAge = 0
 			pCont.particleTM = ChunksArray[i].transform
 			pCont.particleShape = ChunksArray[i].mesh
 		)
 	)
 )
 
 on Release pCont do
 (
 
 )
 
 

#2

Ok, managed to suss it out.


 on ChannelsUsed pCont do
(
	pCont.useTime = true --enable the Time channel
	pCont.useAge = true
	pCont.useTM = true
	pCont.useShape = true
)

on Init pCont do
(
	global ChunksArray = $parts* as array
)

on Proceed pCont do
(
	t = pCont.getTimeStart() as float

   if t > 0 do
	(
		NumChunks = ChunksArray.count
		tt = ((t/160)+1) 
		pCont.AddParticle()	
		pCont.particleIndex = pCont.NumParticles()
		pCont.particleAge = 0
		pCont.particleTM = ChunksArray[tt].transform
		pCont.particleShape = ChunksArray[tt].mesh
		--pCont.particleOrientation = [0,0,0]
		pCont.particleOrientation += [90,0,0]
   )

)

on Release pCont do
(

)

#3

Thanks for posting the code.

Much appreciated.


#4

Be warned… my code is crap. I think it causes the script to crash when you run out of chunks to create particles from… ie when you scrub the timeline past the birth of the last particle. It works, but not very cleanly.


#5

That’s fairly common and I wouldn’t worry about if it’s a one use deal. If you’re going to do alot of this you’ll want to bake the particle animation. Then you can scrub to your heart’s content.


#6

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.