1/****************************************************************************** 2 NintendoWare for CTR Maya Plugin 3 4 File: NW4C_SetCameraFovy.mel 5 Description: set camera fovy 6 Date: 2010/01/26 7 Author: Takashi Endo 8 9 Copyright (C)2009-2010 Nintendo Co., Ltd. / HAL Laboratory, Inc. All rights reserved. 10******************************************************************************/ 11 12// UpdateWindow 13 14/****************************************************************************** 15 is camera transform 16******************************************************************************/ 17proc int IsCameraTransform(string $node) 18{ 19 string $childs[] = `listRelatives -pa -s $node`; 20 return (size(`ls -typ camera $childs`) > 0); 21} 22 23/****************************************************************************** 24 get selected camera node 25 26 return node size 27******************************************************************************/ 28proc int GetSelectedCameraNode(string $cams[]) 29{ 30 clear($cams); 31 32 string $xforms[] = `ls -sl -typ transform`; 33 for ($xform in $xforms) 34 { 35 if (IsCameraTransform($xform)) 36 { 37 $cams[size($cams)] = $xform; 38 } 39 } 40 41 string $shapes[] = `ls -sl -typ camera`; 42 for ($shape in $shapes) 43 { 44 string $parents[] = `listRelatives -ap -pa -typ transform $shape`; 45 for ($parent in $parents) 46 { 47 $cams[size($cams)] = $parent; 48 } 49 } 50 51 $cams = stringArrayRemoveDuplicates($cams); 52 53 return size($cams); 54} 55 56/****************************************************************************** 57 fovy setjob 58******************************************************************************/ 59proc SetJob_Fovy(string $node) 60{ 61 string $cmd = "floatSliderGrp -e -v `camera -q -vfv " + $node + 62 "` nw4cSetCameraFovy_Fovy"; 63 64 scriptJob -p nw4cSetCameraFovy_Fovy -rp -ac ($node + ".focalLength") $cmd; 65 scriptJob -p nw4cSetCameraFovy_ApertureV -rp -ac ($node + ".verticalFilmAperture") $cmd; 66} 67 68/****************************************************************************** 69 fovy callback 70******************************************************************************/ 71global proc nw4cSetCameraFovy_FovyCB(string $mainNode) 72{ 73 string $cams[]; 74 GetSelectedCameraNode($cams); 75 76 float $val = `floatSliderGrp -q -v nw4cSetCameraFovy_Fovy`; 77 for ($node in $cams) 78 { 79 camera -e -vfv $val $node; 80 } 81 82 //SetJob_Fovy($mainNode); 83} 84 85/****************************************************************************** 86 update window 87******************************************************************************/ 88global proc nw4cSetCameraFovy_UpdateWindow() 89{ 90 //----------------------------------------------------------------------------- 91 // get selection 92 string $cams[]; 93 int $enableFlag = (GetSelectedCameraNode($cams) > 0); 94 95 //----------------------------------------------------------------------------- 96 // set node name 97 string $nodesName; 98 if ($enableFlag) 99 { 100 $nodesName = $cams[0]; 101 int $nodeSize = size($cams); 102 for ($inode = 1; $inode < $nodeSize; ++$inode) 103 { 104 if ($inode == 3) 105 { 106 $nodesName += ", ... (" + $nodeSize + ")"; 107 break; 108 } 109 $nodesName += ", " + $cams[$inode]; 110 } 111 } 112 else 113 { 114 $nodesName = "(None)"; 115 } 116 text -e -l $nodesName nw4cSetCameraFovy_NodeName; 117 118 //----------------------------------------------------------------------------- 119 // set current attr & change command 120 if ($enableFlag) 121 { 122 string $node = $cams[0]; 123 124 floatSliderGrp -e -v `camera -q -vfv $node` 125 -cc ("nw4cSetCameraFovy_FovyCB " + $node) 126 nw4cSetCameraFovy_Fovy; 127 128 SetJob_Fovy($node); 129 } 130 131 //----------------------------------------------------------------------------- 132 // set enable state 133 control -e -en $enableFlag nw4cSetCameraFovy_Fovy; 134} 135 136/****************************************************************************** 137 main 138******************************************************************************/ 139global proc NW4C_SetCameraFovy() 140{ 141 //----------------------------------------------------------------------------- 142 // create window 143 int $winW = 400; 144 int $winH = 204; 145 if (!`window -exists nw4cSetCameraFovy_Win`) 146 { 147 window -t "NW4C Set Camera Fovy" -wh $winW $winH -mxb 0 -mb 1 148 nw4cSetCameraFovy_Win; 149 menu -l "Help"; 150 menuItem -l ("Help on " + `window -q -t nw4cSetCameraFovy_Win` + "...") 151 -c "NW4C_ShowHelp \"html/NW4C_SetCameraFovy.html\" \"\""; 152 153 columnLayout -adj 1 -cat "both" 4 -cal "center" -rs 4; 154 155 //----------------------------------------------------------------------------- 156 // node name 157 frameLayout -l "Selected Camera" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; 158 columnLayout -adj 1 -cal "center" -rs 8; 159 160 text -l "" nw4cSetCameraFovy_NodeName; 161 162 setParent ..; // columnLayout 163 setParent ..; // formLayout 164 165 //----------------------------------------------------------------------------- 166 // set 167 frameLayout -l "Set" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; 168 columnLayout -adj 1 -rs 8; 169 170 floatSliderGrp -l "Fovy" -f 1 -pre 4 -cw3 100 60 100 171 -min 1.0 -max 160.0 -v 30.0 172 nw4cSetCameraFovy_Fovy; 173 174 text -l "dummy" -vis 0 175 nw4cSetCameraFovy_ApertureV; 176 177 setParent ..; // columnLayout 178 setParent ..; // formLayout 179 180 //----------------------------------------------------------------------------- 181 // close button 182 string $closeCmd = "deleteUI nw4cSetCameraFovy_Win"; 183 string $form = `formLayout -nd 100`; 184 string $closeBtn = `button -h 26 -l "Close" -c $closeCmd`; 185 formLayout -e 186 -af $closeBtn "top" 0 187 -af $closeBtn "left" 0 188 -af $closeBtn "bottom" 0 189 -af $closeBtn "right" 0 190 $form; 191 setParent ..; // formLayout 192 193 setParent ..; // columnLayout 194 195 setFocus $closeBtn; 196 197 //----------------------------------------------------------------------------- 198 // set selection change job 199 scriptJob -p nw4cSetCameraFovy_Win 200 -e "SelectionChanged" "nw4cSetCameraFovy_UpdateWindow"; 201 } 202 if (`window -q -w nw4cSetCameraFovy_Win` < $winW) 203 { 204 window -e -w $winW nw4cSetCameraFovy_Win; 205 } 206 if (`window -q -h nw4cSetCameraFovy_Win` < $winH) 207 { 208 window -e -h $winH nw4cSetCameraFovy_Win; 209 } 210 //window -e -wh $winW $winH nw4cSetCameraFovy_Win; 211 212 //----------------------------------------------------------------------------- 213 // update window 214 nw4cSetCameraFovy_UpdateWindow; 215 216 //----------------------------------------------------------------------------- 217 // show window 218 showWindow nw4cSetCameraFovy_Win; 219} 220