RenderMan
Post Processing Curve Widths


return to main index



Introduction

Prior to 2007 Pixar's high-end production software for Maya was RenderMan Artist Tools (RAT). While it enabled Maya curves to become renderable objects it only allowed a constant width to be assigned to a curve. The RenderMan Specification, however, allows curves to be defined with varying widths and colors. In fact any user-defined attribute can be bound to the curve. With the introduction in 2007 of Pixar's RenderMan Studio (RMS) it became possible to assign, from within the Maya interface, a "base width" and a "tip width" to a curve. Curves generated by RMS smoothly interpolate the width of the curve. Curve widths cannot be assigned on a segment by segment basis. Refer to the tutorial "RenderMan: Maya Curves to Rman Curves" for an explanation of how to blend colors along the length of a curve.



Figure 1
Before post-processing


Figure 2
After post_-processing


Although RMS does not enable more than two widths to be assigned to a curve there are times when it is useful to be able to render curves whose segments have differing multiple widths and/or differing normals. This and another tutorial propose two "work-arounds". The first technique, and the subject of this tutorial, uses a script to post-process the rib file(s) generated by RMS. The second technique is outlined in "RenderMan: Post Processing Curve Normals" and relies on hiding data in the name that Maya assigns to a curve. A script is also used to post-process the rib files but instead of assigning arbitary attribute values to a curve it extracts numeric data from the name of each curve that it applies as additional attributes to the curve.


Adding Arbitary Widths

This tutorial describes the simpliest of the post-processing techniques. In listing 1 a sequence of differing but fixed widths are added to a curve. The values could be semi-randon values. The technique is relatively simple because the values do not depend on any information derived from the Maya scene. Instead the additional values depent solely on the values the Tcl script "decides" to add to a curve or curves. Post processing a sequence of rib files consists of,

  1. copying the contents of each rib file, and
  2. adding and/or deleting data during the copy process

Listing 1


# This script assumes the Curves in the rib files have 8 cv's
proc addCurveWidths { inpath outpath } {
    set in [open $inpath r]
  
    # base the name of the output rib on the 
    # name of the input rib prefixed with "copy_"
    set inname [file tail $inpath]
    set outname "/copy_"
    append outname $inname
  
    append outpath $outname
    set out [open $outpath w]
    
    # a flag to indicate a Curves
    # statement has been found
    set flag 0
    
    while { [eof $in] != 1 } {
        # read a line of text
        gets $in line
    
        # get the first item from the list of words on a line
        set firstword [lindex $line 0]
    
        # we've found a Curves statement...
        if { $firstword == "Curves" } {
            set flag 1
            }
        # look for AttributeEnd
        if { $flag == 1 && $firstword == "AttributeEnd" } {
            # insert some arbitary width values
            puts $out " \"width\" \[0.4 0.1 0.05 0.01 0.01 0.1\]" 
            set flag 0
            }
        puts $out $line
        }
    close $in
    close $out
    }
  
proc processribs { src_dir  dest_dir } {
    set contents [glob -nocomplain -directory $src_dir *.rib]
    foreach item $contents {
        puts "Processing rib file called $item"
        addCurveWidths $item $dest_dir
        }
    }
# Edit this for your rib files
set srcDir PATH_TO_YOUR_SOURCE_RIB_DIR
set dstDir PATH_TO_YOUR_OUTPUT_RIB_DIR
processribs $srcDir $dstDir

Any general purpose scripting/programming language can be used to post-process rib files. Listing 1 provides an example written in Tcl. The script processes the rib files located in a "target" or "source" directory. The script assumes the post-processed rib's are to be saved in a "destination" directory. Before continuing you may wish to review the tutorial "Tcl: File Filtering".

The script assumes,

  • the original Maya curves ALL have 4 cv's, as a consequence
  • each RenderMan Curves statement in the rib files produced by RMS has 8 cv's.

Because the Curves statements in the rib files consist of 8 cv's each curve will have 6 segments and as such we will be able to add 6 widths. Refer to the tutorial that deals with curve segments for more details.

Before using this script decide what width values you wish to use and edit the script appropriately. Other than that the only other edit you will need to make is to change the paths leading to the input and output directories on the last lines of the script.

For example, figure 1 shows that the "source" rib's are located in the default mtor "rib" directory while the "destination" directory is called "out_ribs". To run the script save it as "addCurveWidths.tcl". Then "cd" to the directory in which it is saved and enter this command,

    tclsh addCurveWidths.tcl

The time taken to produce the copies will obviously depend on the number of rib's and their size. Rib files 1MB in size will each take about 2.5 seconds to process. Once the copies have been produced they can be batch rendered.




© 2002- Malcolm Kesson. All rights reserved.