MtoA Arnold for Maya DOF Focus Assist Tool

Hey! I’m an old school CG artist from the days of CPU rendering and depth pass and zDefocus, and only recently got over the psychological barrier of doing in-camera DOF. My conclusion – it’s liberating. Of course, GPU render engines like RedShift is the real deal for this kind of workflow.

But for now, for those who want to give it shot at using Arnold for in-camera DOF, here’s a little script to quickly set up a focus assist locator which you can position as you wish. Just select the camera and run the script to get a focus assist locator. Hope it helps and let me know if you’ve some ideas to improve tool.

A simple tool to have viewport locator feedback for Arnold’s 3D depth of field. You can exactly direct the camera’s focal point in 3D space. It’s easier for me to see and animate this locator than to try animating “distance from camera” value. Hope you find this useful too. Cheers!

Ronald Fong MtoA Maya Arnold DOF Focus Assist Tool Demo 200px

//Author: Ronald Fong
//Date: 09 June 2018
//Usage: Just select your render camera and run the script. Enjoy!
global proc rf_aiDof() {
    string $cam[] = `ls -sl`;
    if (!objExists($cam[0])) {
        print "Ooops! Please select a camera! \n";
        }
    else {
        string $camShape[] = `listRelatives -s $cam[0]`;
        float $camPos[] = `getAttr ($cam[0] + ".translate")`;
        string $locs = `distanceDimension -sp 1 1 1 -ep $camPos[0] $camPos[1] $camPos[2]`;
        connectAttr -f ($locs + ".distance") ($camShape[0] + ".aiFocusDistance");
        setAttr ($camShape[0] + ".aiEnableDOF") 1;
        setAttr ($camShape[0] + ".aiApertureSize") 1;
        setAttr ($camShape[0] + ".aiApertureBlades") 5;
        string $creation[] = `ls -sl`;
        string $camLoc[] = `listRelatives -parent $creation[0]`;
        parent `listRelatives -parent $creation[0]` $cam[0];
        parent $creation[1] $cam[0];
        select -cl;
        print "Success! Position the focus locator as you please! \n";
    }
}
rf_aiDof();

Quick colors in Maya Ramp

It’s very time-consuming to manually create many ramp entries in Maya’s ramp node, so I wrote a little script.
This simple function can be useful to create a procedural circular brushed metal texture where we want a hundred alternating colors.

//Author: Ronald Fong
//Date: 03 June 2018
global proc rf_zebraRamp(int $count) {
    $ramp = `ls -sl`;
    //Clear existing entries    
    int $entries = `getAttr -size ($ramp[0] + ".colorEntryList")`;
    for ($i=0; $i<$entries; $i++) {
        removeMultiInstance -break true ($ramp[0] + ".colorEntryList[" + $i + "]");
    }
    
    //Set alternate colors
    $currCol = 0; //Initialize current color
    for ($i=1; $i<$count+1; $i++) {
        $div = 1.0 / $count;
        $currDiv = $div * $i;
        $prevCol = `getAttr ($ramp[0] + ".colorEntryList[" + ($i-1) + "].color")`;
        setAttr ($ramp[0] + ".colorEntryList[" + ($i-1) + "].color") -type double3 $prevCol[0] $prevCol[0] $prevCol[0]; //Flush previous color
        if ($prevCol[0] == 0) {
            $currCol = 1;
        }
        else if ($prevCol[0] == 1) {
            $currCol = 0;
        }
        //print ($div + " " + $i + " " + $prevCol[0] + "\n");
        setAttr ($ramp[0] + ".colorEntryList[" + $i + "].color") -type double3 $currCol $currCol $currCol;
        setAttr ($ramp[0] + ".colorEntryList[" + $i + "].position") $currDiv;
    }
}
rf_zebraRamp("10");