Mtor
|
Introduction
Slim Ribbox Scripting I provided a couple of simple
examples of using TCL expressions in a ribbox. This page provides examples of
ribbox scripts that make more extended use of TCL.
[ # calculate one or more values using the TCL expr # procedure ie. # set foo [expr math_function] # # use the TCL return procedure to output one or # more RIB statements ie. # return "RIB_Statement $foo" ] |
Example 1 - setting a surface colorIn this example the slim predefined variable "$pct" is used to set a (grayscale) color based on the sine function. Because the sine function generates values from -1 to 1 the abs() function is used to ensure positive values are assigned to the RIB "Color" statement. [ set 2PI 6.282 set cycles 3.0 set comp [expr abs(sin($pct * $2PI * $cycles))] return "Color $comp $comp $comp" ] Example 2 - setting a randomized rotationIn general when we use a function such as rand() what we require is not just random values but repeatable random values. Without performing steps 1 and 2 we would obtain a visually hopeless result because the rotational axis of each cube, on a frame-by-frame basis, would be "dancing" around in an erratic fashion. |
figure 1 |
Example 3 - using a custom string attribute to access a prebaked ribIn Maya a custom attribute (aka. channel) can be added to an objects transform node via the Modify->Add Attribute... menu item. In this example, a MEL script adds two string attribute to the shape node of a (selected) object. string $obj[] = `listRelatives -s`; addAttr -ln bake -dt "string" $obj[0]; addAttr -ln path -dt "string" $obj[0]; setAttr ($obj[0] + ".bake") -t "string" "teapot.rib"; setAttr ($obj[0] + ".path") -t "string" "G:/archives"; The attribute is added to the shape node rather than the transform node so that the TCL script embedded within in the ribbox is able to (more conveniently) access the attribute using slim's built-in "clientcmd" procedure. [ set bake [clientcmd "getAttr $OBJPATH.bake"] set path [clientcmd "getAttr $OBJPATH.path"] if {$bake != "" && $path != ""} { return "ReadArchive \"$path/$bake\"" } else { return "### WARNING: no prebake info!!" } ]
The advantage of this approach is that the assignment of a pre-baked rib to a
proxy object, say a cuble, can be controlled from the Maya attribute editor.
As a consequence a single ribbox, containing the code shown in listing 4, can
be attached to several proxy objects. Normally, each proxy object must be assigned
its own ribbox that in turn references a specific pre-baked rib.
|
figure 3 |
Example 4 - assigning a TCL expression to a shape nodeThis example was suggested to me by Michal Fratczak. It involves a cunning way of controlling the behavior of a ribbox by assigning short TCL scripts to the shape node of a proxy object. Suppose two custom attributes are added to the shape node of a poly cube ie. string $shape[] = `listRelatives -s`; addAttr -ln tcl -dt "string" $shape[0]; addAttr -ln fval -dv 0.2 -k true $shape[0]; Using the "attribute editor" the following text is entered into the "tcl" attribute, clientcmd "getAttr $OBJPATH.fval" A ribbox containing the following TCL script is attached to the cube, [ set str [clientcmd "getAttr $OBJPATH.tcl"] return [eval $str] ] The result of the eval'uation of the short TCL script contained in the "tcl" attribute will be to insert the following text into the output RIB file. In itself this example does not perform any useful task. However, it does demonstrate the fact that Slim's predefined variables ($OBJPATH for example) can be used in the text of an "external" TCL script that is evaluated somewhat indirectly within the Slim TCL context of a ribbox. #slim ribbox RIBBox_5 0.2 <--- result of "indirect" evaluation |
© 2002-5 Malcolm Kesson. All rights reserved.