Categories
code of the day cotd maya mel

Code of the Day: Flock

Flock 1.0 script by JohnKG: http://www.creativecrash.com/maya/downloads/scripts-plugins/c/flock

Flock 1.0is a MEL script for creating a swarming group of particles around a locator.

Language: MEL
Type: Maya Editor Script
Script Files: 1
Number of lines: 195

Functionality: 6.5
The script offers a few controls (initial size, spacing, speed, range, min/max distance and influence), which gives a few nice options for initial setup. The script particles themselves move similar to flying bugs (apparently it is a derivative of the gnat script), so any more complex flocking (such as that of birds or other animals) is not really what the script is about. The code does give a warning in Maya 2012, which is not that unexpected since it is an older script:

// Warning: -r/runtime should be replaced with -rbd/runtimeBeforeDynamics or -rad/runtimeAfterDynamics. //

Design: 6
The code uses a number of global variables to pass information around, and creates a very long expression for the dynamics. The script also automatically begins playing back the newly created particles, which should really be an option in the UI, as in many cases there will need to be additional tweaks before wanting to play back the animation.

Style: 5
While creating dynamics expression can be complicated, it is probably best if it is does not use 20 variables and is over 2400 characters long in a single one liner. If the dynamics expression is that complicated, it would be worthwhile to build up the expression through intermediate strings to at least add in the debugging. The rest of the code has inconsistent spacing and indentation, and there are a number of places where code is commented out (especially non-working versions of the dynamic expression string).

Documentation: 6.5
The code gives a lot of information in the header about what the script is supposed to do, but the only comments in the code are for commented out functionality.

Reusability: 6
The code base is pretty small, basically an interface to setup a dynamic expression for particles. The UI uses empty text files instead of one of the layouts to setup the position and spacing of the UI, but otherwise would be easy to maintain. There is not a lot of code that could be reused however as it is heavily reliant on the global variables.

Overall: 6.5
If you need a lot of bugs as dynamic particles that move in a flocking movement this is a quick and easy way to set them up. It is apparently similar to the “gnats.mel” script, but with more options.

Until next time,
Michael Hubbard
https://michaelhubbard.ca

Leave a Reply

Your email address will not be published. Required fields are marked *