Simulating A Flock With MEL

zj, Apr 2003

Definitions:

"Flock" is a group of objects that exhibit the general class of polarized (aligned), non-colliding, aggregate motion.

"Boid" is an abbreviation of "birdoid", as his rules applied equally to simulated flocking birds, and schooling fish.

Here is an animation of a flock of more than 600 members.

Introduction

Simulating the complex motions of a flock in computer animation may be always a greate challenge. Maya's built-in dynamic engine offers a solution: Particle Instance. However the most important feature of a flock, non-colliding between each individual flockmember, has not been taken into account. I think we can rely on more traditional technique of keyframe to define each flockmember's path, taking full advantage of some MEL of course.

There are more than 13,000 keys set by my script flocksimulator.mel in no more than 5 minutes.

Advantages

The path of every flockmember will be totally under control. You can modify, hide and delete any undesirable "particle" by hand.

Feel free to playback the animation and your disk space will not be stuffed with particle caches.

Background

There is a great webpage by Craig Reynolds describing the model of Boid behavior, providing much inspiration and resources.

 

The flock is made up of a large number of very silly animals. They can do nothing but seeking food, fleeing predator, staying close to nearby flockmates and avoiding run into each other. They can see the environment around them and think with their mind to deside where to go in the next second as if they were real life.

How To Use It

All the boids and the seek/flee objects can be any kind of Maya objects as long as you can translate and rotate it. Here we use polygon cones and cubes for a faster interactive display. Make sure all of them are in the same coordinate system, and "world" will be mostly used.

What should be done first is to give an initial state to the flock. All the members of the flock are created and placed by another MEL script named flockmaker. Of course you can modify the flock by hand. A set is created at the same time for easy pickup.

Click "pick up" button will select the set of "boid".

Click "Discard" button to cut all key when the set is selected.

Select object(s) to seek or flee and add their name to the field. Clicking the button when nothing is selected will clear the field.

When the set is selected, click "Start Calculation", you will see the motion of the flock after the calculation is done. Since the simulator only key the translation of selected objects, you will need another script named faceforward to correct their orientations.

Future Works

Up to now, the flock is made up of very simple-minded animals. In the future, they will show more intelligence such as avoiding bumping into things and target prediction. When a real flow field is supported, you can paint a map to control it. I will constantly update the webpage and share any improvement here.