RfM
|
IntroductionThe tutorial "RfM: OSL RIB Box Hack outlined a method by which a rib archive that contains shading statements can be used to apply a OSL shader to an object via a RIB Box. A major limitation of using a (static) rib archive is that the parameters of the OSL shader cannot be animated. This tutorial demonstrates how a RIB Box and TCL (Tool Command Language) can dynamically generate (shading) rib statements that reference attributes that have been added to the shape node of an object. As a consequence the inputs of an OSL shader can be animated via the shape node attributes. |
WorkflowThis demonstration will use the same OSL shader (RedLeft.osl) that was presented in the first tutorial. It is assumed the reader has set a project directory in Maya and has copied the compiled OSL shader (RedLeft.oso) to that directory. |
Step 1 - Prepare a Rib ArchiveCopy and paste the rib statements in listing 1 into a rib file. Save the file in the Maya project directory that will use the OSL shader. For example, the following rib was saved as RedLeftNetwork.rib. Listing 1 (RedLeftNetwork.rib)
|
Step 2 - Convert the Rib Archive to TCL & MEL ScriptsIn Cutter select all the text of the RedLeftNetwork.rib document and right-mouse click to open the popup menu. Select the "Export as MEL & TCL" menu item - figure 1.
Cutter will create a .tcl and a .mel document. The .tcl document is shown next. The MEL document that will also be created by Cutter can be viewed here. |
Listing 1 (RedLeft.tcl)
|
Step 2.1 - Save and Edit the TCL Script
Save the TCL script as redleft.tcl in the Maya project directory. Change
#source [file join $RMSPROJ FILENAME.tcl] to redleft.tcl, #source [file join $RMSPROJ redleft.tcl] Step 2.2 - Copy and Execute the MEL Script
In Maya select the object that will be shaded by the OSL shader. Select its transform node
then copy ALL the text of the MEL script to Maya's script editor. Make sure the script editor is
using a MEL tab. Execute (run) the script and it will automatically
add the attributes to the object's shape node that will enable the parameters of the OSL
shader to be dynamically adjusted ie. animated.
Step 3 - Assigning a RIBBox in MayaAssign any material to the object to be shaded with the OSL shader. Go to the material Shading Group and add a RIB Box.
Step 3.1 - Using the TCL Code in the RIB Box
Change the "RIB Box Interpolation" to
Render the scene to confirm the external TCL (redleft.tcl) is generating the shading statements.
|
Step 4 - Using the Attibute "Controls"Select the shape node of the object that has been assigned the RIB Box. Adjust the values of the slider and/or colors and re-render. The shading of the object should respond to the new values.
|
© 2002- Malcolm Kesson. All rights reserved.