/****************************************************************************** NintendoWare for CTR Maya Plugin File: NW4C_SetCameraFovy.mel Description: set camera fovy Date: 2010/01/26 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. ******************************************************************************/ // UpdateWindow /****************************************************************************** is camera transform ******************************************************************************/ proc int IsCameraTransform(string $node) { string $childs[] = `listRelatives -pa -s $node`; return (size(`ls -typ camera $childs`) > 0); } /****************************************************************************** get selected camera node return node size ******************************************************************************/ proc int GetSelectedCameraNode(string $cams[]) { clear($cams); string $xforms[] = `ls -sl -typ transform`; for ($xform in $xforms) { if (IsCameraTransform($xform)) { $cams[size($cams)] = $xform; } } string $shapes[] = `ls -sl -typ camera`; for ($shape in $shapes) { string $parents[] = `listRelatives -ap -pa -typ transform $shape`; for ($parent in $parents) { $cams[size($cams)] = $parent; } } $cams = stringArrayRemoveDuplicates($cams); return size($cams); } /****************************************************************************** fovy setjob ******************************************************************************/ proc SetJob_Fovy(string $node) { string $cmd = "floatSliderGrp -e -v `camera -q -vfv " + $node + "` nw4cSetCameraFovy_Fovy"; scriptJob -p nw4cSetCameraFovy_Fovy -rp -ac ($node + ".focalLength") $cmd; scriptJob -p nw4cSetCameraFovy_ApertureV -rp -ac ($node + ".verticalFilmAperture") $cmd; } /****************************************************************************** fovy callback ******************************************************************************/ global proc nw4cSetCameraFovy_FovyCB(string $mainNode) { string $cams[]; GetSelectedCameraNode($cams); float $val = `floatSliderGrp -q -v nw4cSetCameraFovy_Fovy`; for ($node in $cams) { camera -e -vfv $val $node; } //SetJob_Fovy($mainNode); } /****************************************************************************** update window ******************************************************************************/ global proc nw4cSetCameraFovy_UpdateWindow() { //----------------------------------------------------------------------------- // get selection string $cams[]; int $enableFlag = (GetSelectedCameraNode($cams) > 0); //----------------------------------------------------------------------------- // set node name string $nodesName; if ($enableFlag) { $nodesName = $cams[0]; int $nodeSize = size($cams); for ($inode = 1; $inode < $nodeSize; ++$inode) { if ($inode == 3) { $nodesName += ", ... (" + $nodeSize + ")"; break; } $nodesName += ", " + $cams[$inode]; } } else { $nodesName = "(None)"; } text -e -l $nodesName nw4cSetCameraFovy_NodeName; //----------------------------------------------------------------------------- // set current attr & change command if ($enableFlag) { string $node = $cams[0]; floatSliderGrp -e -v `camera -q -vfv $node` -cc ("nw4cSetCameraFovy_FovyCB " + $node) nw4cSetCameraFovy_Fovy; SetJob_Fovy($node); } //----------------------------------------------------------------------------- // set enable state control -e -en $enableFlag nw4cSetCameraFovy_Fovy; } /****************************************************************************** main ******************************************************************************/ global proc NW4C_SetCameraFovy() { //----------------------------------------------------------------------------- // create window int $winW = 400; int $winH = 204; if (!`window -exists nw4cSetCameraFovy_Win`) { window -t "NW4C Set Camera Fovy" -wh $winW $winH -mxb 0 -mb 1 nw4cSetCameraFovy_Win; menu -l "Help"; menuItem -l ("Help on " + `window -q -t nw4cSetCameraFovy_Win` + "...") -c "NW4C_ShowHelp \"html/NW4C_SetCameraFovy.html\" \"\""; columnLayout -adj 1 -cat "both" 4 -cal "center" -rs 4; //----------------------------------------------------------------------------- // node name frameLayout -l "Selected Camera" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; columnLayout -adj 1 -cal "center" -rs 8; text -l "" nw4cSetCameraFovy_NodeName; setParent ..; // columnLayout setParent ..; // formLayout //----------------------------------------------------------------------------- // set frameLayout -l "Set" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; columnLayout -adj 1 -rs 8; floatSliderGrp -l "Fovy" -f 1 -pre 4 -cw3 100 60 100 -min 1.0 -max 160.0 -v 30.0 nw4cSetCameraFovy_Fovy; text -l "dummy" -vis 0 nw4cSetCameraFovy_ApertureV; setParent ..; // columnLayout setParent ..; // formLayout //----------------------------------------------------------------------------- // close button string $closeCmd = "deleteUI nw4cSetCameraFovy_Win"; string $form = `formLayout -nd 100`; string $closeBtn = `button -h 26 -l "Close" -c $closeCmd`; formLayout -e -af $closeBtn "top" 0 -af $closeBtn "left" 0 -af $closeBtn "bottom" 0 -af $closeBtn "right" 0 $form; setParent ..; // formLayout setParent ..; // columnLayout setFocus $closeBtn; //----------------------------------------------------------------------------- // set selection change job scriptJob -p nw4cSetCameraFovy_Win -e "SelectionChanged" "nw4cSetCameraFovy_UpdateWindow"; } if (`window -q -w nw4cSetCameraFovy_Win` < $winW) { window -e -w $winW nw4cSetCameraFovy_Win; } if (`window -q -h nw4cSetCameraFovy_Win` < $winH) { window -e -h $winH nw4cSetCameraFovy_Win; } //window -e -wh $winW $winH nw4cSetCameraFovy_Win; //----------------------------------------------------------------------------- // update window nw4cSetCameraFovy_UpdateWindow; //----------------------------------------------------------------------------- // show window showWindow nw4cSetCameraFovy_Win; }