Dark Side of the Sun

Wednesday, November 25, 2009

In Defense of Proceduralism

When we have to do something in CG animation/VFX nowadays, be it modeling, animation or many other tasks, we are faced with two main ways to go about it:
  1. Manual
  2. Procedural
To explain the differences, I will use an example. Suppose that the goal to achieve is to place 10 trees on a hilly landscape:
  1. If we do a copy of a tree, then manually place it at some point of the landscape, making sure that it is in the right vertical position (not above or below the landscape's surface), then make another copy, place it, and so on until all 10 trees have been placed, that would be a manual approach.
  2. If we create a script which automatically creates the 10 copies, and places them at random points of the landscape, making sure they are correctly placed on the surface, that´s a fully procedural solution.
A middle ground would be to manually make the 10 copies (to modify them, for example, and make them different from each other) and then use a script to place them on random points of the surface. We can easily think about many more combinations and degrees of proceduralism in between.

Despite the title of this post, I have to say that some tasks are more suited to a manual approach, while others would be impossible to do without a high degree of procedurality. In my actual specialty as FX TD, proceduralism rules my world! Just think particles... the fully manual way to animate particles would be to hand-keyframe every one of the 1,000,000 raindrops falling in your shot. That would be insane! And what if the client/supervisor/director asks for a change, and wants the rain to be angled sideways, instead of fall vertically... if you work 100% manually, you will shoot yourself before you get that shot approved! Of course, that never happens...

This brings me to state the two main advantages of procedural methods:
  1. Reproducibility
  2. Ease and Speed of adaptation to new contexts or changing client's requests.
To go back to our landscape & trees example: if the modelers change the landscape, and you had placed your trees manually, you need to move every one of them up or down so they are again on the surface, or even move them around so they are not placed in brand new weird spots of the landscape... whereas, if your aproach was procedural, you would simply run the script again on the new landscape, and it would be solved. Faster and less tedious (some of us humans don´t like to repeat the same task over and over, whereas computers just love to do that!)

To illustrate this, I will use another example. A real and specific one this time. Hopefully, this one will also throw some light as to why in some occasions the approach to take is not too clear, and how to spot the signs that will lead you to the right use of procedurality, in those cases:

Less than a week ago, I uploaded the Autumn Leaves MEL script to my website. As I have stated before, it is based on a technique I developed to animate/simulate leaves in the movie Planet 51. It all started with having to simulate a few leaves, still on the ground, being swept away by a broom. So I devised the proxies + wrap to high-res nCloth sim technique that makes the core of Autumn Leaves. But I first tested it manually, making copies of the lowres and highres, grouping them, moving them about, then combining the low-res, setting nCloth sim, then applying wrap deformers, etc... until I had 4 or 5 leaves that moved the way I wanted and simmed fast enough. Then, I could have made the same with 10 or 20 more leaves, manually. That wouldn't have taken too long. But in the end, I wrote the script (which would be the prototype for Autumn Leaves), even though that took longer than setting the simulation for all the leaves in that shot manually. Why? 2 reasons:

  1. There were a couple more shots with leaves to do, where the same technique could be used (reproducibility). Making a script for only one shot is often not optimal. But once you have a procedural rig/script, making more shots with it can be extremely fast. So the more shots (or even different jobs!) you use a technique/element in, the more useful it will be to go procedural.
  2. A red alarm light switched on in my brain: What if the directors want any changes later? What if they want a different proportion in the different types of leaves, or just want more of them, or... a thousand changes like that could be asked for. My approach to optimize and combine all low-poly leaves into one single model and nCloth sim would severely complicate them... but if I did it procedurally, any change would be a piece of cake, and very fast to make.
And once again, proceduralism saved the day! The leaves models I was given were judged to be too small, and I was asked to make them much larger. It only took a few minutes to scale the base models up, run the script, run a new sim... change done. Just with that, and the speed at which I did the other leaf shots, the time I spent writing the script payed itself tenfold!

Got any good stories / examples about using procedural workflows? When did proceduralism save your day? When did you cry and wish you hadn't collapsed those stacks / deleted that history? When did you regret not taking the time to write a proper script, and then wasted 5 times more time doing modifications or doing the same thing over and over in other shots / jobs?

Friday, November 20, 2009

Autumn Leaves v1.0 (MEL script)

The first version of Autumn Leaves is now available for download from the scripts section of my website. It's the first MEL script to find its way there.

Autumn Leaves automatically creates an optimized setup to simulate dozens of flying / falling tree leaves, with proper collisions, deformations, dynamics and aerodynamics. You only need to have high-res and low-res models of your leaves (you can combine several different models), and a NURBS surface to place the leaves on. After applying the script, you cand add more stuff to the simulation, like fields, or collisions with animated objects and characters.

Here's a very simple example video:

Autumn Leaves (Maya MEL script) example from Mayec Rancel on Vimeo.

This script is an evolution of a technique I developed to do leaves simulations in the film Planet 51 (which, by coincidence, comes out in US cinemas today!). It creates a relatively fast low-res single nCloth simulation, and transfers its animation to the high-res leaves through the use of wrap deformers.

I have many ideas of how to take this tool further, and make it more powerful / flexible. So if you use it and have any ideas for improvements, let me know. Same thing, of course, if you find any bugs (they are always there, creeping about somewhere...).

Here is the release info (which you can find in the .txt file that comes with the script download):

Autumn Leaves v.1.0

AUTHOR: Mayec Rancel


Tested in Maya Versions: 2009 x64


This script prepares a scene for a realistic simulation of falling tree-leaves.
You can also make them blow in the wind, or collide with the ground or other objects, etc.

The simulation itself is done with nCloth. The idea is to have one or several leaf models,
and their corresponding low-res models (sub-divided and shaped planes, basically). This script
1. Scatter as many copies as you want of those leaves, on the NURBS surface of your choice
(with random rotations), avoiding intersections.
2. Combine all the low-res models into a single object (named "simLeaves_Lo") , which will be
simulated with nCloth.
3. Apply wrap deformers to the high-res leaves, so they will have the movement and deformations of the
simulated low-res leaves.
4. Set basic parameters of the nCloth simulation, although you will have to tweak those depending
on the scale of your scene/leaves and desired behaviour.


For the script to work, you need to have in your scene:
- A high-res model for each of you different leaf variations, named "leaf#_Hi"
(e.g.: leaf1_Hi, leaf2_Hi and leaf3_Hi.)
- As many corresponding low-res models, properly aligned and with the same number
as their corresponding high-res leaf. Their names should be "leaf#_Lo".
(e.g.: leaf1_Lo, leaf2_Lo, leaf3_Lo). These models are to be simulated
with nCloth. For instructions on how to optimize them for this use, read
the Maya documentation on nCloth, or take a look at the Autumn Leaves example scene.
- A NURBS surface, where all your leaf copies will be placed.
When you execute the script, you just have to confirm (or modify) the number of different
leaf models you want to use, input the name of your Placement Surface object, and enter
the number of copies you want of each leaf variation.

Execute the script. And after all the calculations and setup, your scene should be ready to play
and sim. By default, script hides low-res leaves and leaves high-res leaves visible. If you hide the
high-res and show the low-res instead, your simulation will go faster (for display reasons). You can
cache it, and then bring back on the high-res leaves for playblasting/rendering.

You will probably want to tweak the parameters of the nCloth object, to adapt to your scene
scale and/or desired behaviour. The default settings are suposed to work pretty well with a real scale
(leaves aproximately 10cm large). The script sets the following parameters to these values:

Space Scale: 0.05
Use Plane: true
SubSteps: 12
Collision Iterations: 16
Start Frame: 1
Thickness: 0.3
Lift: 0.6
Drag: 0.6
Mass: 5
Bend Resistance: 5

So if things look weird for your specific scale, these could be the first parameters to adjust: Space Scale,
Thickness, Lift, Drag, Mass and Bend Resistance.

After running the script, you can add fields or collisions to the nCloth sim.


With this script you will find a test scene, called "autumnLeaves_testScene.ma". It´s an example of how to
set your scene before using Autumn Leaves. Just open it, and launch the AutumnLeaves MEL script. Leave
everything at default, and set up the number of copies (around 20 is a good value), then run, and you should
see the pretty leaves flying around.

The leaf models in this scene were modeled and kindly donated by Bego Gonzalez. Feel free to use them for your
animations, as long as proper credit is given to her (and to me, if you use the script ;).


- more precise check for intersections.
- more scatter options:
- scatter leaves on an object's surface (make it work for Poly)
- scatter leaves in an object's volume
- scatter leaves at particles
- option to have other names for leaf models.