camera switcher script

Autodesk Maya (Plugin developed by JimStar)

Moderator: JimStar

Post Reply
Wenneker
Licensed Customer
Posts: 111
Joined: Mon Jun 02, 2014 4:12 pm

Since only one camera is send to the GPU you need to re-render if you want to see through a different camera. I've created a little script to make checking different camera's a bit faster. It works by rendering (IPR) the persp camera and matching it to another camera. It is not a complete match of all attributes just the ones I use most often but others can easily be added.

There is no interface so I suggest you drag the script to a shelve and execute it from there.
Just render the persp camera and run the script with the camera you want to look through selected.

Code: Select all

//Getting all cameras in the scene
$cameras = `listCameras -p`;
//getting the selected object
$selected = `ls -sl`;
//setting the default camera
$camera = "persp";

//check if only a single object is selected
if (`size($selected)` != 1){
    print ("Please select only one object");
}else{
   //check if selected is a (perspective) camera
   for ($i=0;$i<size($cameras);$i++){
        if ($cameras[$i] == $selected[0]){
            $camera = $cameras[$i];
        }
    }
    print ("Matching persp camera to: " + $camera + "\n");
}

//Getting the worldSpace position and rotation
$translation = (`xform -ws -q -translation $camera`);
$rotation = (`xform -ws -q -rotation $camera`);

//Splitting position array to individual attr
$tx = $translation[0];
$ty = $translation[1];
$tz = $translation[2];

//Splitting rotation array to individual attr
$rx = $rotation[0];
$ry = $rotation[1];
$rz = $rotation[2];

//Getting some common camera attr
$fL = `getAttr ($camera + ".focalLength")`;
$ha = `getAttr ($camera + ".horizontalFilmAperture")`;
$va = `getAttr ($camera + ".verticalFilmAperture")`;
$fr = `getAttr ($camera + ".filmRollValue")`;
$hfo = `getAttr ($camera + ".horizontalFilmOffset")`;
$vfo = `getAttr ($camera + ".verticalFilmOffset")`;
$ff = `getAttr ($camera + ".filmFit")`;

//getting Octane camera attr
$oa = `getAttr ($camera + ".octAperture")`;
$ofd = `getAttr ($camera + ".octFocalDepth")`;
$oaf = `getAttr ($camera + ".octAutoFocus")`;
$oe = `getAttr ($camera + ".octExposure")`;
$og = `getAttr ($camera + ".octGamma")`;
$or = `getAttr ($camera + ".octResponse")`;
$opp = `getAttr ($camera + ".octCamPPenabled")`;
$oppb = `getAttr ($camera + ".octCamPPbloomPower")`;
$oppgp = `getAttr ($camera + ".octCamPPglarePower")`;
$oppgr = `getAttr ($camera + ".octCamPPglareRayCnt")`;
$oppga = `getAttr ($camera + ".octCamPPglareAngle")`;
$oppgb = `getAttr ($camera + ".octCamPPglareBlur")`;
$oppsi = `getAttr ($camera + ".octCamPPspInt")`;
$oppss = `getAttr ($camera + ".octCamPPspSh")`;

//checking if octCamPPglareBlur is below the minimum value of 0.001
if($oppgb < 0.001){
     $oppgb = 0.0011;  
}

//Setting the persp position
setAttr "persp.translateX" $tx;
setAttr "persp.translateY" $ty;
setAttr "persp.translateZ" $tz;

//Setting the persp rotation
setAttr "persp.rotateX" $rx;
setAttr "persp.rotateY" $ry;
setAttr "persp.rotateZ" $rz;

//Setting some common camera attr
setAttr "persp.focalLength" $fL;
setAttr "persp.horizontalFilmAperture" $ha;
setAttr "persp.verticalFilmAperture" $va;
setAttr "persp.filmRollValue" $fr;
setAttr "persp.horizontalFilmOffset" $hfo;
setAttr "persp.verticalFilmOffset" $vfo;
setAttr "persp.filmFit" $ff;

//Setting octane camera attr
setAttr "persp.octAperture" $oa;
setAttr "persp.octFocalDepth" $ofd;
setAttr "persp.octAutoFocus" $oaf;
setAttr "persp.octExposure" $oe;
setAttr "persp.octGamma" $og;
setAttr "persp.octResponse" $or;
setAttr "persp.octCamPPenabled" $opp;
setAttr "persp.octCamPPbloomPower" $oppb;
setAttr "persp.octCamPPglarePower" $oppgp;
setAttr "persp.octCamPPglareRayCnt" $oppgr;
setAttr "persp.octCamPPglareAngle" $oppga;
setAttr "persp.octCamPPglareBlur" $oppgb;
setAttr "persp.octCamPPspInt" $oppsi;
setAttr "persp.octCamPPspSh" $oppss;
Win 7 x64 | i7-4930 | 64gb | 4x gtx 780Ti 3gb
Post Reply

Return to “Autodesk Maya”