Pages

Thursday, December 25, 2008

Fast Randomise (Jiggle) with Maxscript

by Jamie T. Bentley
Thursday 17th Jan 2008



In this tutorial, with a basic shape, we're going to jiggle a hundred or so objects in under 30 seconds. This will utilise a very small piece of Max script which you can utilise to do any sort of randomisation you require.

Randomly changing orientation will not be covered, as it requires more than a single line (and thus, isn't "Fast").


Step 1 - Select the objects to Jiggle
I've made a ground plane and a rock object. I've instanced the rock object 99 times so there are 100 rocks. What we're going to do is offset them within a tolerance on the X and Y axis, then scale them randomly as well. The application of this can be anything, asteroids, leaves, rain drops, whatever floats your boat.

If you don't have any rocks, make some teapots or sphere's.



Step 2 - Using Scripting
In the bottom left of Max (by default) is where you can quickly enter Maxscript commands. Now, simply putting in a move command will obviously move the selection in a uniform manner.

We're going to move each object individually by performing the same task 100 times (well, as many times as you have objects).

The syntax of what I want to do is quite simple.
for i in selection do move i [x,y,z]

for i in selection --- Run this loop as many times as there are objects in my selection
do move i --- move object i
[x,y,z] --- The affected coordinates

random 30.0 0 --- this is the random function.
Its syntax is "Random "

So, I'm going to jiggle the rocks 25 units on the X and Y axis with the following...

for i in selection do move i [random 25 0, random 25 0, 0]

This moves the objects up to 25 on the X and Y axis. Z has been left as 0.

Now we'll do the same thing for scale... Since I have used rocks, my pivot is at ground level, not in the centre. Also, I am only scaling on the Z axis to flatten my rocks out.

for i in selection do scale i [1,1,random 1.1 0.1]

So there we have it. A simple and quick way to jiggle scale and movement of objects.

Underneath is the same thing but cloned and done again, and again.

No comments:

Post a Comment

Thanks for your comment