The Time node in MASH is really useful for creating looping or offset animations inherited from an input model. Check out this tutorial for more on that.
The problem is that the Time node is only available when MASH is creating an output mesh via the Repro node (this is MASH’s default mode). This mode can be impractical if you want to create thousands high polygon objects all with looping input animations. So, how do you do this if you’re using the Instancer with MASH?
If you’ve only got one model, the answer is simple, id cycling.
The Id node in MASH can do id cycling which is really useful for looping animations where each frame of the animation is a separate model on the Instancer (you set this up by creating an Animation Snapshot of your model). This is an age old technique that will be familiar to anyone who’s used the Particle Instancer with Maya’s nParticles.
However, what if you’ve got multiple models with different loop lengths (like different models of people cheering in a crowd). The answer here, ladies and gentleman, as with everything else so far on this blog, is the Python node which you would use instead of the Id node. The script is pretty short, take a look:
#three animations on the instancer, here are their start ids and end ids
#the animations do not have to be the same length
animationStarts = [0, 30, 60]
animationEnds = [29, 59, 89]
#initialise the MASH network data
md = openMASH.MASHData(thisNode)
#this is how to get the frame number
frame = md.getFrame()
#and this gets the number of objects in the network
count = md.count()
#change the id based on the frame number
for i in range(count):
#which animation shall we use
whichAnim = random.randint(0,len(animationStarts)-1)
#how long is this animation
animationLength = animationEnds[whichAnim]-animationStarts[whichAnim]
#create a random start point for the animation
startpoint = random.randint(0,animationLength)
#which frame in this sequence are we
frameInSequence = (startpoint+frame)%animationLength
#offset to the correct animation sequence
md.outId[i] = frameInSequence+animationStarts[whichAnim]
#tell MASH to write the network data