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