Lsystem
|
Introduction
This tutorial provides a starting point for coding an Lsystem using the TCL
scripting language. The Lsystem can output either a rib stream for rendering
with a RenderMan complient renderer or a mel script that can be sourced by
Maya - either directly using Maya's script window, or indirectly using mel's commandPort procedure.
|
Figure 1 - output via rib |
Figure 2 - output via mel |
System Architecture
The TCL and other scripts that implement the Lsystem are shown in figure 3.
LControl.tcl, as its name suggests, is the script that coordinates the
operation of the scripts that comprise the Lsystem. LControl.tcl uses
LScriptReader.tcl to parse the input data file from
which it builds a database of parameter values that are stored in a tcl array.
The database is passed to LGenerator.tcl where, after a process of
string rewriting, a long sequence of
characters, an Lstring, is returned to LControl. During the string rewriting
phase, an Lsystem
(at least as far as the one currently under
discussion is concerned) makes no judgements about what graphics will be
eventually displayed.
|
Scripts - String Generation
Three scripts take care of reading a Lscript and generating a
Lstring. render [generate script] script "temp" #puts "[generate script]"
Assuming you have the three scripts in the directory specified by the source
proc on the first line of code of LControl.tcl and the directory also has a copy
of default.dat (see the top of this page) you should be able to run LControl.tcl
either from the command line or from within Cutter - figure 4.
Figure 4 Scripts - String InterpretationThe characters in an Lstring are (usually) interpreted as commands that create 3D objects. Although the next set of TCL scripts generate output for two very different graphics environments, they share one guiding principle and that is of growth. In general, when an object has been "put" into a scene the current coordinate system is translated to the "top" of the object. This ensures the next object will appear to extend or grow from the end of the previous shape. |
Three scripts take care of interpreting a Lscript and generating a
graphic using Maya or RenderMan. Graphical Output - MayaA Lstring interpreted by LMel.tcl produces a mel script named "temp.mel". Using Maya's script window "temp.mel" can be sourced in the normal way ie. source "FULL_PATH/temp.mel; Alternatively, if LControl.tcl is calling on the services of LMayaPort.tcl (refer to the last 3 lines of LControl.tcl) it is possible to run the entire Lsystem from Maya's script window ie. commandPort -n ":2222"; // run this only once
then, // windows
or // linux/osx
Where Graphical Output - Rib
A RenderMan rib stream can be generated in two ways, |
Additional Mel Resources
For mel output, the script LMelProcs.mel should be copied into your Lsystem
working directory. This script is source'd by temp.mel. It contains a few
procs that manage the way shapes are parented to each other. In particular,
this script implements a push & popable stack that enables branching
structures to be created by the Lsystem.
|
axiom "G" generations 4 rule G "6{>zG}{<zG}6G" rule 6 "66" angle 17 scale 0.9 statement 6 {\$tnode = addShapeTo(\$tnode, \"cylinder -hr 4 -ax 0 1 0 -r 0.05;\", 0.1, 0.1);} # OR #statement 6 {\$tnode = addShapeTo(\$tnode, \"torus -hr 0.5 -ax 0 0 1 -r 0.09;\", 0.1, 0.1);} a "tree" will be made from cylinders or torii - figure 5 and 6. |
Figure 5 |
Figure 6 |
Extending the LSystemHere are some suggestions for extending the Lsystem. Shapes 0 "Disk" 1 "Cone" <<-- done 2 "Cylinder" 3 "Sphere" 4 "Curve" <<-- done 5 "Polygon" 6 "Torus" Transformations > "Positive rotation" <<-- done < "Negative rotation" <<-- done R "Reverse direction" <<-- done @ "Reverse the rotation" s "Scale x, y and z" <<-- done S "Scale will be inverted"<<-- done + "Moves will be positive"<<-- done - "Moves will be negative"<<-- done T "Turn 180.0 1 0 0" Attributes % "Reverse Attribute" O "Opacity +/- value" r "Red +/- value" g "Green +/- value" b "Blue +/- value" In addition to extending the list of characters that control object creation, placement and coloration, it is also worth including some special control characters that effect the way that LGenerator performs string rewriting. For example, the following characters are already implemented but others could be added. ~ apply the rule randomly <<-- done * apply the rule ONLY on the last rewrite <<-- done ! do NOT apply the rule on the final rewriting <<-- done The tilde rule modification character enables the same rule to have several substitutions ie. "~a" "xxy2" "~a" "xyyy2" The tilde character, in the example shown above, says, "sometimes use "xxy2" and sometimes use "xyyy2". The decision is made on a random basis. |
© 2002- Malcolm Kesson. All rights reserved.