Lsystem
RenderMan Procedural Primitive


return to main index



Introduction

This tutorial presents a tcl script that implements a procedural primitive - otherwise known as a RenderMan helper application. An introduction to procedural primitives can be found at Helper App Basics and Helper App - TCL Script The script listed below uses LMan.tcl to generate graphics at render time. Before using the script the first two lines of LManProcedural.tcl must be edited.


LManProcedural.tcl


set ROOT     PATH_TO_YOUR_LCODE_DIRECTORY
set LSCRIPTS PATH_TO_YOUR_LSCRIPTS_DIRECTORY
  
source $ROOT/LScriptReader.tcl
source $ROOT/LGenerator.tcl
source $ROOT/LMan.tcl
  
fconfigure stdout -translation binary
  
while { [gets stdin buffer] != -1 } {
    # The first data item is "pixel coverage"
    # Currently this script ignores its value.
    # set numPixels [lindex $buffer 0]
  
    # Second data item is the name of a Lscript
    set name [lindex $buffer 1]
    
    readScript $LSCRIPTS/$name script
  
    # Data read from the script file can be overridden 
    # by new values passed to the helper.
    for {set n 1} {$n < [llength $buffer]} {incr n} {
        set param  [lindex $buffer $n]
        incr n
        set value  [lindex $buffer $n]
        set script($param) $value    
        }
    
    # The empty string forces LMan.tcl to use stdout
    # instead of writing a file
    render [generate script] script ""
    
    # Tell the renderer we've finished producing
    # rib statements.
    puts "\377" 
    flush stdout
    }


Testing

If TCL is installed on the host computer, LManProcedural.tcl can be used with Maya (plus Pixar's mtor plugin) or with Houdini. It is useful, however, before committing time and effort to either of these applications to test the script directly with a RIB file. A typical test RIB is shown below. If the reader uses OSX or Linux the call to tclsh should be changed to,

    /usr/bin/tclsh

procedural_tester.rib


Display "untitled" "framebuffer" "rgb"
Format 400 400 1
Projection "perspective" "fov" 40
ShadingRate 1
  
LightSource "distantlight" 1 "intensity" 1.5 
                             "from" [0 0 0] 
                             "to" [0 0 1]
Translate  0 -10 30
Rotate 0 1 0 0
Rotate 0   0 1 0
Scale 1 1 -1
WorldBegin
   TransformBegin
      Scale 0.3 0.3 0.3
      Procedural "RunProgram" 
      ["tclsh PATH_TO_YOUR_LCODE_DIRECTORY/LManProcedural.tcl" 
                "PATH_TO_YOUR_LSCRIPTS_DIRECTORY/script.dat \
                        angle 23"] 
      [-100 100 -100 100 -100 100]
   TransformEnd
WorldEnd
  

Because the "tree-like" shape generated by this Lsystem grows taller with additional iterations it has been necessary to apply a scaling factor and to use large bounding box values.




© 2002- Malcolm Kesson. All rights reserved.