Tuesday, December 13, 2011

Object ID pass

Well, some days back someone asked me for small help to automate the process of generating object ID pass. So I thought lets share it with every one....

so here is a small MEL script for generating object Id pass.

To obtain/setup an object ID pass, please follow these steps:

  • Copy the given script/code to your maya script editor.
  • execute the script.
  • and then execute the following command by supplying the render camera name as an argument
  * for example if you are using "persp" as an render camera then the command will be...

  setUpObjectIdPass("persp")

MEL SCRIPT:

//object ID pass
proc setUpObjectIdPass( string $renderCam )
{
         // get selection list
         string $sel[] = `ls -sl`;
         string $camShapeNode[] = `listRelatives -s -noIntermediate $renderCam`;
         int $id = 1;
         // add miLable attribute
         addAttr -ln "miLabel" -at long -k 1;
         for( $item in $sel )
        {
                 // set object ids
                 setAttr ($item + ".miLabel") $id;
                 $id++;
        }
        // create mentalrayOutputPass and connections
        string $mrOutputPassNode = `createNode mentalrayOutputPass`;
        setAttr ($mrOutputPassNode+".dataType") 11;
        connectAttr -f ($mrOutputPassNode+".message") ($camShapeNode[0]+".mentalRayControls.miOutputShaderList[0]");
}

Hit render and you will get a separate render image of object Id pass as an result.

Cheers....

No comments: