Mel
|
IntroductionThis tutorial presents a simple L-System intended to create a Koch snowflake, figure 1, and similar shapes (figure 2). Despite Mel being somewhat clumsy in regard to the handling of strings the code presented in listing 1 does demonstrate the principles of L-System string re-writing and string interpretation. A more extensive python implementation of a L-System can be found in the tutorial "L system: Code and Testing".
The ScriptsThe mel scripts in listings 1, 2 and 3 should be saved in the "scripts" directory of a Maya project directory. For example, maya/projects/Koch/scripts/koch.mel maya/projects/Koch/scripts/node_utils.mel maya/projects/Koch/scripts/preamble.mel
When the main script, kock.mel, is run it will generate a script named "snowflake.mel"
that when sourced,
rotate 0 0 60.0; curve -d 1 -p 0 0 0 -p 0 1 0; In mel, however, the rotate statement is normally specified AFTER the geometry ie. curve -d 1 -p 0 0 0 -p 0 1 0; rotate 0 0 60.0; otherwise the transformation will not effect the curve! The "node_utils.mel" (listing 2) and "preamble.mel" (listing 3) ensure that transformations and geometries are "parented" to a group node named "$tnode". The parenting enables the characters of a L strings to be interpreted in the classic "transform followed geometry" sequence without the need to rearrange the characters in either the "axiom" or the "rule". This makes it relatively easy to adapt examples of L strings taken from texts that deal with "Algorithmic Botany". Extension to 3D
If the |
|
Listing 1 (koch.mel)
|
Listing 2 (node_utils.mel)
|
Listing 3 (preamble.mel)
|
© 2002- Malcolm Kesson. All rights reserved.