Cutter
Manual Slim Template Scripting


return to main index



Introduction

This tutorial explains how Cutter can be used to write scripts, called Slim templates, that implement custom nodes for Pixar's Slim shading editor. Slim is one of a suite of applications that collectively form RenderMan for Maya (RfM). Like many components of the RMS graphics system Slim templates are scripted in the Tool Command Language (TCL). The RMS online documentation provides very detailed information about Slim scripting. They are the primary source of information and guidance for those wishing to understand the inner workings of Slim.

The Slim-savvy facilities introduced in Cutter version 6.1.7 are intended to help artists create their own (simple) custom nodes for Slim.


Clarification about the use of the word "template"

Pixar's Slim templates are documents that implement nodes used by the Slim shading editor. Somewhat confusingly, Cutter also uses the term "template". However, Cutter templates are documents that provide users with snippets of sample code to help them get started in a variety of languages such as python, tcl, rib etc.


Scripting

The following step-by-step tutorial shows how a simple and, it must be said, quite bizarre node can be created using Cutter. The following screen shots show how the node can be used to reorder the "rgb" components of an input color as "rbg", "gbr", "brg" and "bgr".



Figure 1


Step 1 - creating an empty Slim doc

Choose the cutrEmpty.slim document from the Templates->Slim menu - figure 1.



Figure 1


Save the document as SwapComponents.slim. Because this will become an experimental Slim node the document can be saved in any directory.


Step 2 - adding bootstrap Slim code

A right mouse button click will raise a popup menu. Choose Templates->color node - figure 2.




Figure 2


The document will be populated with code, see below, that will act as the starting point for the development of a color node.


Bootstrap Code (SwapComponents.slim)


# menuInfo fundza,NAME_OF_TEMPLATE#0 color node NAME_OF_TEMPLATE /Color node
  
slim 1 extensions cutter {
extensions fundza cutr {
    template color UNTITLED_CLR {
        description {
            Description of the node goes here.
            }
        previewinfo {
            shadingrate 1
            objectsize 1
            objectshape Sphere
            frame 1
            }
        #__custom parameters Begin____________

        #__custom parameters End______________
  
        parameter color result {
            access output
            display hidden
            }
        RSLFunction {
        void cutrUNTITLED_CLR (
            // parameter vars goes here...
            //
            output color result;
            )
        {
        result = color(1,1,1);
        }
    }
}
}}

Step 3 - changing the default names

3.1 Change the first line of text to,

    # menuInfo fundza,SwapComponents#0 color node SwapComponents /Color node

3.2 Change the name of the node to,

    template color SwapComponents {

3.3 Change the name of the RSLFunction to,

    void cutrSwapComponents (

Slim templates are written in the TCL scripting language. White space is very important in TCL. Make sure the space before each "{" curly bracket is never removed - doing so will "break" the node!!


Step 4 - testing the template

Before any significant Slim (ie. TCL) scripting is done, we will next see how a Slim document can be sourced. Use the Slim button on the RenderMan shelf to launch Slim - figure 3.



Figure 3


4.1 Execute the following MEL command in Maya's script window,

    commandPort -n ":2222"

4.2 In Cutter make sure the SwapComponents.slim document is the front window, then use the keyboard shortcut Alt+e, Control+e or Apple+e to "send" the document to Maya. The editor for the node will automatically open - figure 4.



Figure 4



Step 5 - building the interface

5.1 Put the text cursor immediately after the comment,
    #__custom parameters Begin____________
and use the popup menu (right mouse click) to add a color parameter block - figure 5.



Figure 5


5.2 Change the name of the parameter, its label and default value as follows.

    parameter color c {
        label "Input Color"
        description "No description."
        default {0.37 0.65 0.43}
        detail varying
        }

5.3 Add a color variable to the RSLFunction as follows.

    void cutrSwapComponents (
        // parameter vars goes here...
        color c;
        output color result;
        )

Use the keyboard shortcut to send the script to Maya. Because the parameter was defined as "varying" it will be able to connect to other nodes - figure 6.



Figure 6


5.4 A float parameter will next be added to the interface. The parameter will have a dropdown menu that will eventually allow the "rgb" components of a color to be swapped. Choose the float->selector parameter from the menu - figure 7. Make sure the new float parameter block goes immediately after the color parameter block.



Figure 7


Edit the float parameter's name, label, range and default value as shown below.

    #__custom parameters Begin____________
    parameter color c {
        label "Input Color"
        description "No description."
        default {0.37 0.65 0.43}
        detail varying
        }
    parameter float comps {
        label "Reorder Components"
        description "No description."
        subtype selector
        range {rbg 0 gbr 1 brg 2 bgr 3}
        default 0
        provider variable
        }
    #__custom parameters End______________

5.5 Add a corresponding float variable as follows.

    void cutrSwapColors (
        // parameter vars goes here...
        color c;
        float comps;
        output color result;
        )
Step 6 - implementing the RSL code

Edit the body of the RSLFunction as shown below.

    void cutrSwapComponents (
        color c;
        float comps;
        output color result;
        )
    {
    if(comps == 0)
        result = color(c[0],c[2],c[1]);
    else if(comps == 1)
        result = color(c[1],c[2],c[0]);
    else if(comps == 2)
        result = color(c[2],c[0],c[1]);
    else
        result = color(c[2],c[1],c[0]);
    }

Save the file, send it again to Slim. If you wish to make it automatically available for use with every session of Slim follow the instructions in the tutorial RMS: Setup for Mel, Rman, Slim & the Image Tool. The complete code for the SwapComponents node is given below.


SwapComponents.slim


# menuInfo fundza,SwapComponents#0 color node SwapComponents /Color node
  
slim 1 extensions cutter {
extensions fundza cutr {
    template color SwapComponents {
        description {
            Description of the node goes here.
            }
        previewinfo {
            shadingrate 1
            objectsize 1
            objectshape Sphere
            frame 1
            }
        #__custom parameters Begin____________
        parameter color c {
            label "Input Color"
            description "No description."
            default {0.37 0.65 0.43}
            detail varying
            }
        parameter float comps {
            label "Reorder Components"
            description "No description."
            subtype selector
            range {rbg 0 gbr 1 brg 2 bgr 3}
            default 0
            provider variable
            }
        #__custom parameters End______________
        parameter color result {
            access output
            display hidden
            }
        RSLFunction {
        void cutrSwapComponents (
            color c;
            float comps;
            output color result;
            )
        {
        if(comps == 0)
            result = color(c[0],c[2],c[1]);
        else if(comps == 1)
            result = color(c[1],c[2],c[0]);
        else if(comps == 2)
            result = color(c[2],c[0],c[1]);
        else
            result = color(c[2],c[1],c[0]);
        }
    }
}
}}



© 2002- Malcolm Kesson. All rights reserved.