1/******************************************************************************
2	NintendoWare for CTR Maya Plugin
3
4	File:         NW4C_ExpDialog.mel
5	Description:  create export dialog
6	Date:         2010/10/07
7	Author:       Takashi Endo
8
9	Copyright (C)2009-2010 Nintendo Co., Ltd. / HAL Laboratory, Inc. All rights reserved.
10******************************************************************************/
11
12// NW4C_ExpDirect
13// OpenOptionWindow CreateSettingMenu
14// SetOptionVariable SetOptionControl UpdateOptionVariableT ResetOptionVariable
15// ExportCB DoExportCmd CheckOptionValue
16// SetConsistentCallback
17// SaveSettingToScene LoadSettingFromScene DeleteUselessSettingNode
18// SaveSettingToFile LoadSettingFromFile GetOptionStringFromC3es
19// SearchAnim
20
21/******************************************************************************
22	variables
23******************************************************************************/
24global int $nw4cExpDialog_SettingLatestVer = 10;
25global string $nw4cExpDialog_c3esLatestVer = "1.2.0";
26global int $nw4cExpDialog_LoadSettingJob = -1;
27
28/******************************************************************************
29	load plugin
30******************************************************************************/
31proc LoadPlugin()
32{
33	if (!`pluginInfo -q -l "NW4C_Export.mll"`)
34	{
35		loadPlugin("NW4C_Export.mll");
36	}
37}
38
39/******************************************************************************
40	show error & stop
41******************************************************************************/
42proc ShowError(string $msg)
43{
44	if (!`about -batch`)
45	{
46		trace ("Error: " + $msg + "\n");
47	}
48	error $msg;
49}
50
51/******************************************************************************
52	use custom ui
53******************************************************************************/
54proc int UseCustomUI()
55{
56	// �J�X�^�� UI �̎g�p�ݒ���‹��ϐ� NW4C_MAYA_CUSTOM_UI ����擾����B
57	// �‹��ϐ��̐ݒ�l�� "0" �̎��̓J�X�^�� UI ���g�p�����A"1" �̎��̓J�X�^�� UI ���g�p����B
58	// �‹��ϐ�����`����Ă��Ȃ��ꍇ�� "0" ���ݒ肳��Ă���Ƃ݂Ȃ��B
59	string $val = `getenv "NW4C_MAYA_CUSTOM_UI"`;
60	if ($val == "")
61	{
62		$val = "0";
63	}
64	return int($val);
65}
66
67/******************************************************************************
68	find string in array
69******************************************************************************/
70proc int FindStringInArray(string $array[], string $value)
71{
72	int $size = size($array);
73	int $idx;
74	for ($idx = 0; $idx < $size; ++$idx)
75	{
76		if ($array[$idx] == $value)
77		{
78			return $idx;
79		}
80	}
81	return -1;
82}
83
84/******************************************************************************
85	does save load scene setting
86******************************************************************************/
87proc int DoesSaveLoadSceneSetting()
88{
89	if (!`optionVar -ex nw4cExpDialog_SaveLoadSceneSetting`)
90	{
91		return 1; // default
92	}
93	//trace ("save load scene setting: " + `optionVar -q nw4cExpDialog_SaveLoadSceneSetting` + "\n");
94	return `optionVar -q nw4cExpDialog_SaveLoadSceneSetting`;
95}
96
97/******************************************************************************
98	load setting from option string
99******************************************************************************/
100proc LoadSettingFromOptionString(int $version, string $opts)
101{
102	print ("load NW4C export settings from scene (ver "
103		+ ($version / 10) + "." + ($version % 10) + ")\n");
104
105	//-----------------------------------------------------------------------------
106	// set option variable
107	optionVar -sv nw4cExport_Options $opts;
108
109	//-----------------------------------------------------------------------------
110	// refresh option box
111	if (`scrollLayout -ex nw4cExpDialog_ScrollLayout`)
112	{
113		if (`columnLayout -ex nw4cExpDialog_MainColumn`)
114		{
115			NW4C_ExpDialog;
116		}
117	}
118}
119
120/******************************************************************************
121	load setting from scene (called when scene is opened)
122******************************************************************************/
123global proc nw4cExpDialog_LoadSettingFromScene()
124{
125	global int $nw4cExpDialog_SettingVer;
126	global string $nw4cExpDialog_SettingExportOptions;
127
128	//-----------------------------------------------------------------------------
129	// check save / load scene setting is enabled
130	if (!DoesSaveLoadSceneSetting())
131	{
132		return;
133	}
134
135	//-----------------------------------------------------------------------------
136	// evaluate setting node
137	string $node = "nw4cExpDialog_Setting1";
138	if (!`objExists $node`)
139	{
140		return;
141	}
142	if (nodeType($node) != "script")
143	{
144		return;
145	}
146	string $cmd = `getAttr ($node + ".b")`;
147	if (!size($cmd))
148	{
149		return;
150	}
151	eval($cmd);
152	int $version = $nw4cExpDialog_SettingVer;
153	string $opts = $nw4cExpDialog_SettingExportOptions;
154
155	//-----------------------------------------------------------------------------
156	// load setting
157	if (size($opts))
158	{
159		LoadSettingFromOptionString($version, $opts);
160	}
161}
162
163/******************************************************************************
164	setting node function (called from script node) (do nothing now)
165******************************************************************************/
166global proc nw4cExpDialog_SettingNodeFunc()
167{
168
169}
170
171/******************************************************************************
172	set consistent callback
173******************************************************************************/
174global proc nw4cExpDialog_SetConsistentCallback()
175{
176	// set load setting job at scene opened
177	global int $nw4cExpDialog_LoadSettingJob = -1;
178	$nw4cExpDialog_LoadSettingJob = `scriptJob -e "SceneOpened"
179		"if (`exists nw4cExpDialog_LoadSettingFromScene`) nw4cExpDialog_LoadSettingFromScene;"`;
180}
181
182/******************************************************************************
183	delete useless setting node
184******************************************************************************/
185proc DeleteUselessSettingNode()
186{
187	string $nodes[] = `ls -typ script`;
188	string $node;
189	for ($node in $nodes)
190	{
191		if (gmatch($node, "*_nw4cExpDialog_Setting*") ||
192			gmatch($node, "*:nw4cExpDialog_Setting*"))
193		{
194			if (`referenceQuery -inr $node`) // if referenced
195			{
196				print ("disable settings: " + $node + "\n");
197				if (`getAttr -l ($node + ".st")`)
198				{
199					print "(locked)\n";
200				}
201				else
202				{
203					catch(`setAttr ($node + ".st") 0`); // Demand
204				}
205			}
206			else
207			{
208				print ("delete settings: " + $node + "\n");
209				catch(`delete $node`);
210			}
211		}
212	}
213}
214
215/******************************************************************************
216	get setting node command
217******************************************************************************/
218proc string GetSettingNodeCommand()
219{
220	string $cmd = "";
221
222	//-----------------------------------------------------------------------------
223	// setting version
224	global int $nw4cExpDialog_SettingLatestVer;
225	$cmd += "global int $nw4cExpDialog_SettingVer = " + $nw4cExpDialog_SettingLatestVer + ";\n";
226
227	//-----------------------------------------------------------------------------
228	// export options
229	$cmd += "global string $nw4cExpDialog_SettingExportOptions = \""
230		+ `optionVar -q nw4cExport_Options` + "\";\n";
231
232	//-----------------------------------------------------------------------------
233	// setting node function
234	$cmd += "if (`exists nw4cExpDialog_SettingNodeFunc`) "
235		+ "nw4cExpDialog_SettingNodeFunc();\n";
236
237	return $cmd;
238}
239
240/******************************************************************************
241	save setting to scene
242******************************************************************************/
243proc SaveSettingToScene(int $checkSceneSettingFlag)
244{
245	//return; // never save (debug)
246
247	//-----------------------------------------------------------------------------
248	// check save / load flag
249	if ($checkSceneSettingFlag && !DoesSaveLoadSceneSetting())
250	{
251		return;
252	}
253
254	//-----------------------------------------------------------------------------
255	// delete useless setting node
256	DeleteUselessSettingNode();
257
258	//-----------------------------------------------------------------------------
259	// create setting node
260	string $node = "nw4cExpDialog_Setting1";
261	if (!`objExists $node`)
262	{
263		string $selBak[] = `ls -sl`;
264		createNode script -n $node;
265		select $selBak;
266	}
267
268	//-----------------------------------------------------------------------------
269	// set setting node command & attr
270	if (`getAttr -l ($node + ".b")`)
271	{
272		print "NW4C export settings node is locked\n";
273		return;
274	}
275
276	string $cmd = GetSettingNodeCommand();
277	catch(`setAttr ($node + ".b") -type "string" $cmd`);
278	catch(`setAttr ($node + ".st") 1`); // Open/Close
279}
280
281/******************************************************************************
282	save setting file folder
283******************************************************************************/
284proc SaveSettingFileFolder(string $filePath)
285{
286	string $settingFolder = substitute("[^/]*$", $filePath, "");
287	optionVar -sv nw4cExpDialog_SettingFileFolder $settingFolder;
288}
289
290/******************************************************************************
291	set setting file folder to currnet
292******************************************************************************/
293proc SetSettingFileFolderToCurrent()
294{
295	string $settingFolder = "";
296	if (`optionVar -ex nw4cExpDialog_SettingFileFolder`)
297	{
298		$settingFolder = `optionVar -q nw4cExpDialog_SettingFileFolder`;
299	}
300	if (size($settingFolder) > 0 && `filetest -d $settingFolder`)
301	{
302		workspace -dir $settingFolder;
303	}
304}
305
306/******************************************************************************
307	get float string for setting file
308******************************************************************************/
309proc string GetFloatStringForSettingFile(float $val)
310{
311	string $str = $val;
312	if (match("\\.", $str) == "")
313	{
314		$str += ".0";
315	}
316	return $str;
317}
318
319/******************************************************************************
320	save setting to file (do)
321******************************************************************************/
322global proc nw4cExpDialog_SaveSettingToFileDo(string $filePath)
323{
324	global string $nw4cExpDialog_c3esLatestVer;
325
326	string $boolNames[2] = { "false", "true" };
327
328	//-----------------------------------------------------------------------------
329	// add extension
330	if (match("\\.c3es$", $filePath) == "")
331	{
332		$filePath += ".c3es";
333	}
334
335	//-----------------------------------------------------------------------------
336	// update option variable
337	nw4cExpDialog_UpdateOptionVariable(0); // no save setting to scene
338
339	//-----------------------------------------------------------------------------
340	// get generator version
341	string $generatorVersion = "?";
342	if (`pluginInfo -q -l "NW4C_Export.mll"`)
343	{
344		$generatorVersion = eval("NW4C_ExportInfoCmd -p");
345	}
346
347	//-----------------------------------------------------------------------------
348	// get date & time
349	if (size(match("^//", `pwd`)) != 0)
350	{
351		// if the current folder is on network drive
352		// change it on local drive for getting date & time properly
353		string $localFolder = getenv("TEMP");
354		if (size($localFolder) > 0 && `filetest -d $localFolder`)
355		{
356			chdir($localFolder);
357			//trace ("change cur folder to " + $localFolder);
358		}
359	}
360
361	string $date = `system "echo %DATE%"`;
362	$date = match("[0-9/]+", $date);
363	$date = substituteAllString($date, "/", "-");
364	string $time = `system "echo %TIME%"`;
365	$time = match("[0-9:]+", $time);
366
367	//-----------------------------------------------------------------------------
368	// parse export options
369	//-----------------------------------------------------------------------------
370
371	//-----------------------------------------------------------------------------
372	// init
373	string $processMode = "Single";
374	string $exportTarget = "All";
375	string $outputFileName = "";
376	string $outputMode = "File";
377	string $outputFolder = "";
378	int $mergeCmdl = 0;
379	string $mergeCmdlPath = "";
380	//int $mergeCmdlAuto = 1;
381
382	float $magnify = 1.0;
383	string $frameRange = "All";
384	int $startFrame = 1;
385	int $endFrame = 100;
386	//string $texMatrixMode = "Maya";
387	int $removeNamespace = 0;
388
389	int $outputCmdl = 1;
390	int $outputCtex = 1;
391	int $outputCmdla = 0;
392	int $outputCskla = 0;
393	int $outputCmata = 0;
394	int $outputCmcla = 0;
395	int $outputCmtpa = 0;
396	int $outputCmtsa = 0;
397	int $outputCcam = 0;
398	int $outputClgt = 0;
399	int $outputCenv = 0;
400
401	string $compressNode = "None";
402	//int $combinePolygon = 0;
403	int $compressMaterial = 0;
404	int $optimizePrimitive = 1;
405	int $convertToModel = 1;
406	//int $delUselessVtxData = 0;
407
408	string $quantizePos = "Float";
409	string $quantizeNrm = "Float";
410	string $quantizeTex = "Float";
411	int $frameFormat = 0;
412	int $scaleQuantizeQuality = 9;
413	int $rotateQuantizeQuality = 9;
414	int $translateQuantizeQuality = 9;
415
416	string $adjustSkinning = "None";
417	string $meshVisibilityMode = "BindByIndex";
418	int $nonUniformScale = 0;
419	int $maxReservedUniformRegisters = 0;
420
421	int $bakeAllAnim = 1;
422	float $framePrecision = 1.0;
423	int $loopAnim = 0;
424//	int $keepAtLeastOneKey = 0;
425
426	float $toleranceScale     = 0.1;
427	float $toleranceRotate    = 0.1;
428	float $toleranceTranslate = 0.01;
429	float $toleranceTexScale     = 0.1;
430	float $toleranceTexRotate    = 0.1;
431	float $toleranceTexTranslate = 0.01;
432	float $toleranceColor = 0.001;
433
434	//-----------------------------------------------------------------------------
435	// get option var
436	string $optStr = "";
437	if (`optionVar -ex nw4cExport_Options`)
438	{
439		$optStr = `optionVar -q nw4cExport_Options`;
440	}
441
442	//-----------------------------------------------------------------------------
443	// parse option var
444	string $opts[], $words[];
445	tokenize($optStr, ";", $opts);
446	int $optSize = size($opts);
447	int $iopt;
448	for ($iopt = 0; $iopt < $optSize; ++$iopt)
449	{
450		tokenize($opts[$iopt], "=", $words);
451		string $tag = $words[0];
452		string $val = $words[1];
453		int $boolVal = ($val == "true" || $val == "On" || $val == "1");
454
455		//-----------------------------------------------------------------------------
456		// output
457		if ($tag == "ProcessMode")
458		{
459			$processMode = $val;
460		}
461		else if ($tag == "ExportTarget")
462		{
463			$exportTarget = $val;
464		}
465		else if ($tag == "OutputFileName")
466		{
467			$outputFileName = $val;
468		}
469		else if ($tag == "OutputMode")
470		{
471			$outputMode = $val;
472		}
473		else if ($tag == "OutputFolder")
474		{
475			$outputFolder = $val;
476		}
477		else if ($tag == "MergeCmdl")
478		{
479			$mergeCmdl = $boolVal;
480		}
481		else if ($tag == "MergeCmdlPath")
482		{
483			$mergeCmdlPath = $val;
484		}
485		//else if ($tag == "MergeCmdlAuto")
486		//{
487		//	$mergeCmdlAuto = $boolVal;
488		//}
489
490		//-----------------------------------------------------------------------------
491		// general
492		else if ($tag == "Magnify")
493		{
494			$magnify = $val;
495		}
496		else if ($tag == "FrameRange")
497		{
498			$frameRange = $val;
499		}
500		else if ($tag == "StartFrame")
501		{
502			$startFrame = $val;
503		}
504		else if ($tag == "EndFrame")
505		{
506			$endFrame = $val;
507		}
508		//else if ($tag == "TexMatrixMode")
509		//{
510		//	$texMatrixMode = $val;
511		//}
512		else if ($tag == "RemoveNamespace")
513		{
514			$removeNamespace = $boolVal;
515		}
516
517		//-----------------------------------------------------------------------------
518		// file selection
519		else if ($tag == "OutputCmdl")
520		{
521			$outputCmdl = $boolVal;
522		}
523		else if ($tag == "OutputCtex")
524		{
525			$outputCtex = $boolVal;
526		}
527		else if ($tag == "OutputCmdla")
528		{
529			$outputCmdla = $boolVal;
530		}
531		else if ($tag == "OutputCskla")
532		{
533			$outputCskla = $boolVal;
534		}
535		else if ($tag == "OutputCmata")
536		{
537			$outputCmata = $boolVal;
538		}
539		else if ($tag == "OutputCmcla")
540		{
541			$outputCmcla = $boolVal;
542		}
543		else if ($tag == "OutputCmtpa")
544		{
545			$outputCmtpa = $boolVal;
546		}
547		else if ($tag == "OutputCmtsa")
548		{
549			$outputCmtsa = $boolVal;
550		}
551		else if ($tag == "OutputCcam")
552		{
553			$outputCcam = $boolVal;
554		}
555		else if ($tag == "OutputClgt")
556		{
557			$outputClgt = $boolVal;
558		}
559		else if ($tag == "OutputCenv")
560		{
561			$outputCenv = $boolVal;
562		}
563
564		//-----------------------------------------------------------------------------
565		// optimization
566		else if ($tag == "CompressNode")
567		{
568			$compressNode = $val;
569		}
570		//else if ($tag == "CombinePolygon")
571		//{
572		//	$combinePolygon = $boolVal;
573		//}
574		else if ($tag == "CompressMaterial")
575		{
576			$compressMaterial = $boolVal;
577		}
578		else if ($tag == "OptimizePrimitive")
579		{
580			$optimizePrimitive = $boolVal;
581		}
582		else if ($tag == "ConvertToModel")
583		{
584			$convertToModel = $boolVal;
585		}
586
587		//else if ($tag == "DelUselessVtxData")
588		//{
589		//	$delUselessVtxData = $boolVal;
590		//}
591
592		//-----------------------------------------------------------------------------
593		// quantization
594		else if ($tag == "QuantizePos")
595		{
596			$quantizePos = $val;
597		}
598		else if ($tag == "QuantizeNrm")
599		{
600			$quantizeNrm = $val;
601		}
602		else if ($tag == "QuantizeTex")
603		{
604			$quantizeTex = $val;
605		}
606		else if ($tag == "FrameFormat")
607		{
608			$frameFormat = $boolVal;
609		}
610		else if ($tag == "ScaleQuantizeQuality")
611		{
612			$scaleQuantizeQuality = $val;
613		}
614		else if ($tag == "RotateQuantizeQuality")
615		{
616			$rotateQuantizeQuality = $val;
617		}
618		else if ($tag == "TranslateQuantizeQuality")
619		{
620			$translateQuantizeQuality = $val;
621		}
622
623		//-----------------------------------------------------------------------------
624		// model
625		else if ($tag == "AdjustSkinning")
626		{
627			$adjustSkinning = $val;
628		}
629		else if ($tag == "MeshVisibilityMode")
630		{
631			$meshVisibilityMode = $val;
632		}
633		else if ($tag == "NonUniformScale")
634		{
635			$nonUniformScale = $boolVal;
636		}
637		else if ($tag == "MaxReservedUniformRegisters")
638		{
639			$maxReservedUniformRegisters = $val;
640		}
641
642		//-----------------------------------------------------------------------------
643		// animation
644		else if ($tag == "BakeAllAnim")
645		{
646			$bakeAllAnim = $boolVal;
647		}
648		else if ($tag == "FramePrecision")
649		{
650			if ($val == "2")
651			{
652				$framePrecision = 0.5;
653			}
654			else if ($val == "5")
655			{
656				$framePrecision = 0.2;
657			}
658			else if ($val == "10")
659			{
660				$framePrecision = 0.1;
661			}
662		}
663		else if ($tag == "LoopAnim")
664		{
665			$loopAnim = $boolVal;
666		}
667//		else if ($tag == "KeepAtLeastOneKey")
668//		{
669//			$keepAtLeastOneKey = $boolVal;
670//		}
671
672		//-----------------------------------------------------------------------------
673		// tolerance
674		else if ($tag == "ToleranceScale")
675		{
676			$toleranceScale = $val;
677		}
678		else if ($tag == "ToleranceRotate")
679		{
680			$toleranceRotate = $val;
681		}
682		else if ($tag == "ToleranceTranslate")
683		{
684			$toleranceTranslate = $val;
685		}
686		else if ($tag == "ToleranceTexScale")
687		{
688			$toleranceTexScale = $val;
689		}
690		else if ($tag == "ToleranceTexRotate")
691		{
692			$toleranceTexRotate = $val;
693		}
694		else if ($tag == "ToleranceTexTranslate")
695		{
696			$toleranceTexTranslate = $val;
697		}
698		else if ($tag == "ToleranceColor")
699		{
700			$toleranceColor = $val;
701		}
702	}
703
704	//-----------------------------------------------------------------------------
705	// open file
706	int $fid = fopen($filePath, "w");
707	if ($fid == 0)
708	{
709		ShowError("Can't open file: " + $filePath);
710	}
711
712	//-----------------------------------------------------------------------------
713	// header
714	fprint($fid, "# NW4C_Export settings\r\n");
715	fprint($fid, "SettingsVersion=\"" + $nw4cExpDialog_c3esLatestVer + "\"\r\n");
716	fprint($fid, "GeneratorName=\"Maya " + `about -v` + " NW4C_Export\"\r\n");
717	fprint($fid, "GeneratorVersion=\"" + $generatorVersion + "\"\r\n");
718	fprint($fid, "Date=\"" + $date + "T" + $time + "\"\r\n");
719	fprint($fid, "\r\n");
720
721	//-----------------------------------------------------------------------------
722	// output options
723	fprint($fid, "# Output Options\r\n");
724	fprint($fid, "ProcessMode=\"" + $processMode + "\"\r\n");
725	fprint($fid, "ExportTarget=\"" + $exportTarget + "\"\r\n");
726	fprint($fid, "OutputFileName=\"" + $outputFileName + "\"\r\n");
727	fprint($fid, "OutputMode=\"" + $outputMode + "\"\r\n");
728	fprint($fid, "OutputFolder=\"" + $outputFolder + "\"\r\n");
729	fprint($fid, "MergeCmdl=\"" + $boolNames[$mergeCmdl] + "\"\r\n");
730	fprint($fid, "MergeCmdlPath=\"" + $mergeCmdlPath + "\"\r\n");
731	//fprint($fid, "MergeCmdlAuto=\"" + $boolNames[$mergeCmdlAuto] + "\"\r\n");
732	fprint($fid, "\r\n");
733
734	//-----------------------------------------------------------------------------
735	// general options
736	fprint($fid, "# General Options\r\n");
737	fprint($fid, "Magnify=\"" + GetFloatStringForSettingFile($magnify) + "\"\r\n");
738	fprint($fid, "FrameRange=\"" + $frameRange + "\"\r\n");
739	fprint($fid, "StartFrame=\"" + $startFrame + "\"\r\n");
740	fprint($fid, "EndFrame=\"" + $endFrame + "\"\r\n");
741	//fprint($fid, "TexMatrixMode=\"" + $texMatrixMode + "\"\r\n");
742	fprint($fid, "RemoveNamespace=\"" + $boolNames[$removeNamespace] + "\"\r\n");
743	fprint($fid, "\r\n");
744
745	//-----------------------------------------------------------------------------
746	// output file selection
747	fprint($fid, "# Output File Selection\r\n");
748	fprint($fid, "OutputCmdl=\"" + $boolNames[$outputCmdl] + "\"\r\n");
749	fprint($fid, "OutputCtex=\"" + $boolNames[$outputCtex] + "\"\r\n");
750	fprint($fid, "OutputCmdla=\"" + $boolNames[$outputCmdla] + "\"\r\n");
751	fprint($fid, "OutputCskla=\"" + $boolNames[$outputCskla] + "\"\r\n");
752	fprint($fid, "OutputCmata=\"" + $boolNames[$outputCmata] + "\"\r\n");
753	fprint($fid, "OutputCmcla=\"" + $boolNames[$outputCmcla] + "\"\r\n");
754	fprint($fid, "OutputCmtpa=\"" + $boolNames[$outputCmtpa] + "\"\r\n");
755	fprint($fid, "OutputCmtsa=\"" + $boolNames[$outputCmtsa] + "\"\r\n");
756	fprint($fid, "OutputCcam=\"" + $boolNames[$outputCcam] + "\"\r\n");
757	fprint($fid, "OutputClgt=\"" + $boolNames[$outputClgt] + "\"\r\n");
758	fprint($fid, "OutputCenv=\"" + $boolNames[$outputCenv] + "\"\r\n");
759	fprint($fid, "\r\n");
760
761	//-----------------------------------------------------------------------------
762	// optimization options
763	fprint($fid, "# Optimization Options\r\n");
764	fprint($fid, "CompressNode=\"" + $compressNode + "\"\r\n");
765	//fprint($fid, "CombinePolygon=\"" + $boolNames[$combinePolygon] + "\"\r\n");
766	fprint($fid, "CompressMaterial=\"" + $boolNames[$compressMaterial] + "\"\r\n");
767	fprint($fid, "OptimizePrimitive=\"" + $boolNames[$optimizePrimitive] + "\"\r\n");
768	fprint($fid, "ConvertToModel=\"" + $boolNames[$convertToModel] + "\"\r\n");
769	//fprint($fid, "DelUselessVtxData=\"" + $boolNames[$delUselessVtxData] + "\"\r\n");
770	fprint($fid, "\r\n");
771
772	//-----------------------------------------------------------------------------
773	// quantization options
774	fprint($fid, "# Quantization Options\r\n");
775	fprint($fid, "QuantizePos=\"" + $quantizePos + "\"\r\n");
776	fprint($fid, "QuantizeNrm=\"" + $quantizeNrm + "\"\r\n");
777	fprint($fid, "QuantizeTex=\"" + $quantizeTex + "\"\r\n");
778	fprint($fid, "\r\n");
779
780	//-----------------------------------------------------------------------------
781	// model options
782	fprint($fid, "# Model Options\r\n");
783	fprint($fid, "AdjustSkinning=\"" + $adjustSkinning + "\"\r\n");
784	fprint($fid, "MeshVisibilityMode=\"" + $meshVisibilityMode + "\"\r\n");
785	fprint($fid, "NonUniformScale=\"" + $boolNames[$nonUniformScale] + "\"\r\n");
786	fprint($fid, "MaxReservedUniformRegisters=\"" + $maxReservedUniformRegisters + "\"\r\n");
787
788
789	fprint($fid, "\r\n");
790
791	//-----------------------------------------------------------------------------
792	// animation options
793	fprint($fid, "# Animation Options\r\n");
794	fprint($fid, "BakeAllAnim=\"" + $boolNames[$bakeAllAnim] + "\"\r\n");
795	fprint($fid, "FramePrecision=\"" + GetFloatStringForSettingFile($framePrecision) + "\"\r\n");
796	fprint($fid, "LoopAnim=\"" + $boolNames[$loopAnim] + "\"\r\n");
797	fprint($fid, "FrameFormat=\"" + $boolNames[$frameFormat] + "\"\r\n");
798//	fprint($fid, "KeepAtLeastOneKey=\"" + $boolNames[$keepAtLeastOneKey] + "\"\r\n");
799	fprint($fid, "ScaleQuantizeQuality=\"" + $scaleQuantizeQuality + "\"\r\n");
800	fprint($fid, "RotateQuantizeQuality=\"" + $rotateQuantizeQuality + "\"\r\n");
801	fprint($fid, "TranslateQuantizeQuality=\"" + $translateQuantizeQuality + "\"\r\n");
802	fprint($fid, "\r\n");
803
804	//-----------------------------------------------------------------------------
805	// tolerance options
806	fprint($fid, "# Tolerance Options\r\n");
807	fprint($fid, "ToleranceScale=\"" + GetFloatStringForSettingFile($toleranceScale) + "\"\r\n");
808	fprint($fid, "ToleranceRotate=\"" + GetFloatStringForSettingFile($toleranceRotate) + "\"\r\n");
809	fprint($fid, "ToleranceTranslate=\"" + GetFloatStringForSettingFile($toleranceTranslate) + "\"\r\n");
810	fprint($fid, "ToleranceTexScale=\"" + GetFloatStringForSettingFile($toleranceTexScale) + "\"\r\n");
811	fprint($fid, "ToleranceTexRotate=\"" + GetFloatStringForSettingFile($toleranceTexRotate) + "\"\r\n");
812	fprint($fid, "ToleranceTexTranslate=\"" + GetFloatStringForSettingFile($toleranceTexTranslate) + "\"\r\n");
813	fprint($fid, "ToleranceColor=\"" + GetFloatStringForSettingFile($toleranceColor) + "\"\r\n");
814	fprint($fid, "\r\n");
815
816	//-----------------------------------------------------------------------------
817	// close file
818	fclose($fid);
819
820	//-----------------------------------------------------------------------------
821	// end
822	print ("Saved to " + $filePath + "\n");
823}
824
825/******************************************************************************
826	save setting to file (file command)
827******************************************************************************/
828global proc nw4cExpDialog_SaveSettingToFileFC(string $filePath, string $fileType)
829{
830	//-----------------------------------------------------------------------------
831	// save setting file folder
832	SaveSettingFileFolder($filePath);
833
834	//-----------------------------------------------------------------------------
835	// do
836	nw4cExpDialog_SaveSettingToFileDo($filePath);
837}
838
839/******************************************************************************
840	save setting to file (main)
841******************************************************************************/
842global proc nw4cExpDialog_SaveSettingToFile()
843{
844	//-----------------------------------------------------------------------------
845	// set setting file folder to currnet
846	SetSettingFileFolderToCurrent();
847
848	//-----------------------------------------------------------------------------
849	// open file dialog
850	fileBrowserDialog -m 1 -an "Save" -in "c3es"
851		-ft "Best Guess"
852		-fc "nw4cExpDialog_SaveSettingToFileFC";
853}
854
855/******************************************************************************
856	get option string from c3es
857******************************************************************************/
858global proc string nw4cExpDialog_GetOptionStringFromC3es(string $filePath)
859{
860	global string $nw4cExpDialog_c3esLatestVer;
861
862	string $boolNames[2] = { "false", "true" };
863
864	//-----------------------------------------------------------------------------
865	// init
866	string $settingsVersion = "";
867
868	string $processMode = "Single";
869	string $exportTarget = "All";
870	string $outputFileName = "";
871	string $outputMode = "File";
872	string $outputFolder = "";
873	int $mergeCmdl = 0;
874	string $mergeCmdlPath = "";
875	//int $mergeCmdlAuto = 1;
876
877	float $magnify = 1.0;
878	string $frameRange = "All";
879	int $startFrame = 1;
880	int $endFrame = 100;
881	//string $texMatrixMode = "Maya";
882	int $removeNamespace = 0;
883
884	int $outputCmdl = 1;
885	int $outputCtex = 1;
886	int $outputCmdla = 0;
887	int $outputCskla = 0;
888	int $outputCmata = 0;
889	int $outputCmcla = 0;
890	int $outputCmtpa = 0;
891	int $outputCmtsa = 0;
892	int $outputCcam = 0;
893	int $outputClgt = 0;
894	int $outputCenv = 0;
895
896	string $compressNode = "None";
897	//int $combinePolygon = 0;
898	int $compressMaterial = 0;
899	int $optimizePrimitive = 1;
900	int $convertToModel = 1;
901	//int $delUselessVtxData = 0;
902
903	string $quantizePos = "Float";
904	string $quantizeNrm = "Float";
905	string $quantizeTex = "Float";
906	int $frameFormat = 0;
907	int $scaleQuantizeQuality = 9;
908	int $rotateQuantizeQuality = 9;
909	int $translateQuantizeQuality = 9;
910
911	string $adjustSkinning = "None";
912	string $meshVisibilityMode = "IndexMode";
913	int $nonUniformScale = 0;
914	int $maxReservedUniformRegisters = 0;
915
916	int $bakeAllAnim = 1;
917	int $framePrecision = 1;
918	int $loopAnim = 0;
919//	int $keepAtLeastOneKey = 0;
920
921	float $toleranceScale     = 0.1;
922	float $toleranceRotate    = 0.1;
923	float $toleranceTranslate = 0.01;
924	float $toleranceTexScale     = 0.1;
925	float $toleranceTexRotate    = 0.1;
926	float $toleranceTexTranslate = 0.01;
927	float $toleranceColor = 0.001;
928
929	//-----------------------------------------------------------------------------
930	// open file
931	int $fid = fopen($filePath, "r");
932	if ($fid == 0)
933	{
934		ShowError("Can't open file: " + $filePath);
935	}
936
937	//-----------------------------------------------------------------------------
938	// check header
939	string $line = fgetline($fid);
940	if (size(match("^# NW4C_Export settings", $line)) == 0)
941	{
942		fclose($fid);
943		ShowError("c3es file is wrong: " + $filePath);
944	}
945
946	//-----------------------------------------------------------------------------
947	// parse
948	string $words[];
949	while (!feof($fid))
950	{
951		string $line = fgetline($fid);
952		$line = substitute("\r*\n$", $line, ""); // cut [CR+LF] or [LF]
953		// skip empty line & comment line
954		if (size($line) == 0 || substring($line, 1, 1) == "#")
955		{
956			continue;
957		}
958
959		tokenize($line, "=", $words);
960		if (size($words) < 2)
961		{
962			continue;
963		}
964		string $tag = $words[0];
965		string $val = $words[1];
966		$val = substitute("^\"", $val, ""); // cut first double quote
967		$val = substitute("\".*$", $val, ""); // cut last double quote
968		int $boolVal = ($val == "true" || $val == "On" || $val == "1");
969		//print ($tag + ": " + $val + "\n");
970
971		//-----------------------------------------------------------------------------
972		// header
973		if ($tag == "SettingsVersion")
974		{
975			$settingsVersion = $val;
976			//if ($settingsVersion != $nw4cExpDialog_c3esLatestVer)
977			//{
978			//	fclose($fid);
979			//	ShowError("c3es file version is wrong: " + $settingsVersion);
980			//}
981		}
982
983		//-----------------------------------------------------------------------------
984		// output
985		else if ($tag == "ProcessMode")
986		{
987			$processMode = $val;
988		}
989		else if ($tag == "ExportTarget")
990		{
991			$exportTarget = $val;
992		}
993		else if ($tag == "OutputFileName")
994		{
995			$outputFileName = $val;
996		}
997		else if ($tag == "OutputMode")
998		{
999			$outputMode = $val;
1000		}
1001		else if ($tag == "OutputFolder")
1002		{
1003			$outputFolder = NW4C_GetUnixFilePath($val);
1004		}
1005		else if ($tag == "MergeCmdl")
1006		{
1007			$mergeCmdl = $boolVal;
1008		}
1009		else if ($tag == "MergeCmdlPath")
1010		{
1011			$mergeCmdlPath = NW4C_GetUnixFilePath($val);
1012		}
1013		//else if ($tag == "MergeCmdlAuto")
1014		//{
1015		//	$mergeCmdlAuto = $boolVal;
1016		//}
1017
1018		//-----------------------------------------------------------------------------
1019		// general
1020		else if ($tag == "Magnify")
1021		{
1022			$magnify = $val;
1023		}
1024		else if ($tag == "FrameRange")
1025		{
1026			$frameRange = $val;
1027		}
1028		else if ($tag == "StartFrame")
1029		{
1030			$startFrame = $val;
1031		}
1032		else if ($tag == "EndFrame")
1033		{
1034			$endFrame = $val;
1035		}
1036		//else if ($tag == "TexMatrixMode")
1037		//{
1038		//	$texMatrixMode = $val;
1039		//}
1040		else if ($tag == "RemoveNamespace")
1041		{
1042			$removeNamespace = $boolVal;
1043		}
1044
1045		//-----------------------------------------------------------------------------
1046		// file selection
1047		else if ($tag == "OutputCmdl")
1048		{
1049			$outputCmdl = $boolVal;
1050		}
1051		else if ($tag == "OutputCtex")
1052		{
1053			$outputCtex = $boolVal;
1054		}
1055		else if ($tag == "OutputCmdla")
1056		{
1057			$outputCmdla = $boolVal;
1058		}
1059		else if ($tag == "OutputCskla")
1060		{
1061			$outputCskla = $boolVal;
1062		}
1063		else if ($tag == "OutputCmata")
1064		{
1065			$outputCmata = $boolVal;
1066		}
1067		else if ($tag == "OutputCmcla")
1068		{
1069			$outputCmcla = $boolVal;
1070		}
1071		else if ($tag == "OutputCmtpa")
1072		{
1073			$outputCmtpa = $boolVal;
1074		}
1075		else if ($tag == "OutputCmtsa")
1076		{
1077			$outputCmtsa = $boolVal;
1078		}
1079		else if ($tag == "OutputCcam")
1080		{
1081			$outputCcam = $boolVal;
1082		}
1083		else if ($tag == "OutputClgt")
1084		{
1085			$outputClgt = $boolVal;
1086		}
1087		else if ($tag == "OutputCenv")
1088		{
1089			$outputCenv = $boolVal;
1090		}
1091
1092		//-----------------------------------------------------------------------------
1093		// optimization
1094		else if ($tag == "CompressNode")
1095		{
1096			$compressNode = $val;
1097		}
1098		//else if ($tag == "CombinePolygon")
1099		//{
1100		//	$combinePolygon = $boolVal;
1101		//}
1102		else if ($tag == "CompressMaterial")
1103		{
1104			$compressMaterial = $boolVal;
1105		}
1106		else if ($tag == "OptimizePrimitive")
1107		{
1108			$optimizePrimitive = $boolVal;
1109		}
1110		else if ($tag == "ConvertToModel")
1111		{
1112			$convertToModel = $boolVal;
1113		}
1114		//else if ($tag == "DelUselessVtxData")
1115		//{
1116		//	$delUselessVtxData = $boolVal;
1117		//}
1118
1119		//-----------------------------------------------------------------------------
1120		// quantization
1121		else if ($tag == "QuantizePos")
1122		{
1123			$quantizePos = $val;
1124		}
1125		else if ($tag == "QuantizeNrm")
1126		{
1127			$quantizeNrm = $val;
1128		}
1129		else if ($tag == "QuantizeTex")
1130		{
1131			$quantizeTex = $val;
1132		}
1133		else if ($tag == "FrameFormat")
1134		{
1135			$frameFormat = $boolVal;
1136		}
1137		else if ($tag == "ScaleQuantizeQuality")
1138		{
1139			$scaleQuantizeQuality = $val;
1140		}
1141		else if ($tag == "RotateQuantizeQuality")
1142		{
1143			$rotateQuantizeQuality = $val;
1144		}
1145		else if ($tag == "TranslateQuantizeQuality")
1146		{
1147			$translateQuantizeQuality = $val;
1148		}
1149
1150		//-----------------------------------------------------------------------------
1151		// model
1152		else if ($tag == "AdjustSkinning")
1153		{
1154			$adjustSkinning = $val;
1155		}
1156		else if ($tag == "MeshVisibilityMode")
1157		{
1158			$meshVisibilityMode = $val;
1159		}
1160		else if ($tag == "NonUniformScale")
1161		{
1162			$nonUniformScale = $boolVal;
1163		}
1164		else if ($tag == "MaxReservedUniformRegisters")
1165		{
1166			$maxReservedUniformRegisters = $val;
1167		}
1168
1169		//-----------------------------------------------------------------------------
1170		// anim
1171		else if ($tag == "BakeAllAnim")
1172		{
1173			$bakeAllAnim = $boolVal;
1174		}
1175		else if ($tag == "FramePrecision")
1176		{
1177			float $floatVal = $val;
1178			if ($floatVal == 0.5)
1179			{
1180				$framePrecision = 2;
1181			}
1182			else if ($floatVal == 0.2)
1183			{
1184				$framePrecision = 5;
1185			}
1186			else if ($floatVal == 0.1)
1187			{
1188				$framePrecision = 10;
1189			}
1190		}
1191		else if ($tag == "LoopAnim")
1192		{
1193			$loopAnim = $boolVal;
1194		}
1195//		else if ($tag == "KeepAtLeastOneKey")
1196//		{
1197//			$keepAtLeastOneKey = $boolVal;
1198//		}
1199
1200		//-----------------------------------------------------------------------------
1201		// tolerance
1202		else if ($tag == "ToleranceScale")
1203		{
1204			$toleranceScale = $val;
1205		}
1206		else if ($tag == "ToleranceRotate")
1207		{
1208			$toleranceRotate = $val;
1209		}
1210		else if ($tag == "ToleranceTranslate")
1211		{
1212			$toleranceTranslate = $val;
1213		}
1214		else if ($tag == "ToleranceTexScale")
1215		{
1216			$toleranceTexScale = $val;
1217		}
1218		else if ($tag == "ToleranceTexRotate")
1219		{
1220			$toleranceTexRotate = $val;
1221		}
1222		else if ($tag == "ToleranceTexTranslate")
1223		{
1224			$toleranceTexTranslate = $val;
1225		}
1226		else if ($tag == "ToleranceColor")
1227		{
1228			$toleranceColor = $val;
1229		}
1230	}
1231
1232	//-----------------------------------------------------------------------------
1233	// close file
1234	fclose($fid);
1235
1236	//-----------------------------------------------------------------------------
1237	// set option var
1238	string $optStr = "";
1239
1240	$optStr += "ProcessMode=" + $processMode + ";";
1241	$optStr += "ExportTarget=" + $exportTarget + ";";
1242	$optStr += "OutputFileName=" + $outputFileName + ";";
1243	$optStr += "OutputMode=" + $outputMode + ";";
1244	$optStr += "OutputFolder=" + $outputFolder + ";";
1245	$optStr += "MergeCmdl=" + $boolNames[$mergeCmdl] + ";";
1246	$optStr += "MergeCmdlPath=" + $mergeCmdlPath + ";";
1247	//$optStr += "MergeCmdlAuto=" + $boolNames[$mergeCmdlAuto] + ";";
1248
1249	$optStr += "Magnify=" + $magnify + ";";
1250	$optStr += "FrameRange=" + $frameRange + ";";
1251	$optStr += "StartFrame=" + $startFrame + ";";
1252	$optStr += "EndFrame=" + $endFrame + ";";
1253	//$optStr += "TexMatrixMode=" + $texMatrixMode + ";";
1254	$optStr += "RemoveNamespace=" + $boolNames[$removeNamespace] + ";";
1255
1256	$optStr += "OutputCmdl=" + $boolNames[$outputCmdl] + ";";
1257	$optStr += "OutputCtex=" + $boolNames[$outputCtex] + ";";
1258	$optStr += "OutputCmdla=" + $boolNames[$outputCmdla] + ";";
1259	$optStr += "OutputCskla=" + $boolNames[$outputCskla] + ";";
1260	$optStr += "OutputCmata=" + $boolNames[$outputCmata] + ";";
1261	$optStr += "OutputCmcla=" + $boolNames[$outputCmcla] + ";";
1262	$optStr += "OutputCmtpa=" + $boolNames[$outputCmtpa] + ";";
1263	$optStr += "OutputCmtsa=" + $boolNames[$outputCmtsa] + ";";
1264	$optStr += "OutputCcam=" + $boolNames[$outputCcam] + ";";
1265	$optStr += "OutputClgt=" + $boolNames[$outputClgt] + ";";
1266	$optStr += "OutputCenv=" + $boolNames[$outputCenv] + ";";
1267
1268	$optStr += "CompressNode=" + $compressNode + ";";
1269	//$optStr += "CombinePolygon=" + $boolNames[$combinePolygon] + ";";
1270	$optStr += "CompressMaterial=" + $boolNames[$compressMaterial] + ";";
1271	$optStr += "OptimizePrimitive=" + $boolNames[$optimizePrimitive] + ";";
1272	$optStr += "ConvertToModel=" + $boolNames[$convertToModel] + ";";
1273	//$optStr += "DelUselessVtxData=" + $boolNames[$delUselessVtxData] + ";";
1274
1275	$optStr += "QuantizePos=" + $quantizePos + ";";
1276	$optStr += "QuantizeNrm=" + $quantizeNrm + ";";
1277	$optStr += "QuantizeTex=" + $quantizeTex + ";";
1278	$optStr += "FrameFormat=" + $boolNames[$frameFormat] + ";";
1279	$optStr += "ScaleQuantizeQuality=" + $scaleQuantizeQuality + ";";
1280	$optStr += "RotateQuantizeQuality=" + $rotateQuantizeQuality + ";";
1281	$optStr += "TranslateQuantizeQuality=" + $translateQuantizeQuality + ";";
1282
1283	$optStr += "AdjustSkinning=" + $adjustSkinning + ";";
1284	$optStr += "MeshVisibilityMode=" + $meshVisibilityMode + ";";
1285	$optStr += "NonUniformScale=" + $boolNames[$nonUniformScale] + ";";
1286	$optStr += "MaxReservedUniformRegisters=" + $maxReservedUniformRegisters + ";";
1287
1288	$optStr += "BakeAllAnim=" + $boolNames[$bakeAllAnim] + ";";
1289	$optStr += "FramePrecision=" + $framePrecision + ";";
1290	$optStr += "LoopAnim=" + $boolNames[$loopAnim] + ";";
1291//	$optStr += "KeepAtLeastOneKey=" + $boolNames[$keepAtLeastOneKey] + ";";
1292
1293
1294	$optStr += "ToleranceScale=" + $toleranceScale + ";";
1295	$optStr += "ToleranceRotate=" + $toleranceRotate + ";";
1296	$optStr += "ToleranceTranslate=" + $toleranceTranslate + ";";
1297	$optStr += "ToleranceTexScale=" + $toleranceTexScale + ";";
1298	$optStr += "ToleranceTexRotate=" + $toleranceTexRotate + ";";
1299	$optStr += "ToleranceTexTranslate=" + $toleranceTexTranslate + ";";
1300	$optStr += "ToleranceColor=" + $toleranceColor + ";";
1301
1302	return $optStr;
1303}
1304
1305/******************************************************************************
1306	load setting from file (do)
1307******************************************************************************/
1308global proc nw4cExpDialog_LoadSettingFromFileDo(string $filePath)
1309{
1310	//-----------------------------------------------------------------------------
1311	// get option string from c3es
1312	$optStr = nw4cExpDialog_GetOptionStringFromC3es($filePath);
1313	optionVar -sv nw4cExport_Options $optStr;
1314
1315	//-----------------------------------------------------------------------------
1316	// update setting node
1317	SaveSettingToScene(1);
1318
1319	//-----------------------------------------------------------------------------
1320	// refresh option box
1321	if (`scrollLayout -ex nw4cExpDialog_ScrollLayout`)
1322	{
1323		if (`columnLayout -ex nw4cExpDialog_MainColumn`)
1324		{
1325			NW4C_ExpDialog;
1326		}
1327	}
1328
1329	//-----------------------------------------------------------------------------
1330	// end
1331	print ("Loaded from " + $filePath + "\n");
1332}
1333
1334/******************************************************************************
1335	load setting from file (file command)
1336******************************************************************************/
1337global proc nw4cExpDialog_LoadSettingFromFileFC(string $filePath, string $fileType)
1338{
1339	//-----------------------------------------------------------------------------
1340	// save setting file folder
1341	SaveSettingFileFolder($filePath);
1342
1343	//-----------------------------------------------------------------------------
1344	// do
1345	nw4cExpDialog_LoadSettingFromFileDo($filePath);
1346}
1347
1348/******************************************************************************
1349	load setting from file (main)
1350******************************************************************************/
1351global proc nw4cExpDialog_LoadSettingFromFile()
1352{
1353	//-----------------------------------------------------------------------------
1354	// set setting file folder to currnet
1355	//SetSettingFileFolderToCurrent();
1356
1357	//-----------------------------------------------------------------------------
1358	// open file dialog
1359	//fileBrowserDialog -m 0 -an "Load" -in "c3es"
1360	//	  -fc "nw4cExpDialog_LoadSettingFromFileFC";
1361
1362	string $dirMask = "*.c3es"; // fileDialog can use mask
1363	string $settingFolder = "";
1364	if (`optionVar -ex nw4cExpDialog_SettingFileFolder`)
1365	{
1366		$settingFolder = `optionVar -q nw4cExpDialog_SettingFileFolder`;
1367	}
1368	if (size($settingFolder) > 0 && `filetest -d $settingFolder`)
1369	{
1370		$dirMask = $settingFolder + $dirMask;
1371	}
1372	//trace ("dirMask: " + $dirMask);
1373
1374	string $filePath = `fileDialog -dm $dirMask`;
1375	if (size($filePath) > 0)
1376	{
1377		nw4cExpDialog_LoadSettingFromFileFC($filePath, "");
1378	}
1379}
1380
1381/******************************************************************************
1382	process mode callback
1383******************************************************************************/
1384global proc nw4cExpDialog_ProcessModeCB()
1385{
1386	if (!`control -q -vis nw4cExpDialog_ProcessMode`)
1387	{
1388		return;
1389	}
1390	int $animRangeFlag = (`radioButtonGrp -q -sl nw4cExpDialog_ProcessMode` == 2);
1391	int $cmata = `checkBoxGrp -q -v1 nw4cExpDialog_CmataFileOut`;
1392	int $cmcla = 0;
1393	int $cmtpa = 0;
1394	int $cmtsa = 0;
1395	int $ccam = `checkBoxGrp -q -v1 nw4cExpDialog_CcamFileOut`;
1396	int $clgt = `checkBoxGrp -q -v1 nw4cExpDialog_ClgtFileOut`;
1397	int $cenv = `checkBoxGrp -q -v1 nw4cExpDialog_CenvFileOut`;
1398	int $fileNameFlag;
1399
1400	if (`UseCustomUI` == 1)
1401	{
1402		$cmcla = `checkBoxGrp -q -v1 nw4cExpDialog_CmclaFileOut`;
1403		$cmtpa = `checkBoxGrp -q -v1 nw4cExpDialog_CmtpaFileOut`;
1404		$cmtsa = `checkBoxGrp -q -v1 nw4cExpDialog_CmtsaFileOut`;
1405	}
1406
1407	$fileNameFlag =
1408		(!$animRangeFlag || $cmata || $cmcla || $cmtpa || $cmtsa || $ccam || $clgt || $cenv);
1409
1410	control -e -en $fileNameFlag nw4cExpDialog_OutFileName;
1411	control -e -en $fileNameFlag nw4cExpDialog_SceneToOutFileName;
1412	control -e -en $fileNameFlag nw4cExpDialog_NodeToOutFileName;
1413	control -e -en ($animRangeFlag==0) nw4cExpDialog_UseCreativeStudio;
1414
1415	if ($animRangeFlag)
1416	{
1417		radioButtonGrp -e -sl 1 nw4cExpDialog_OutInterFile;
1418		radioButtonGrp -e -sl 0 nw4cExpDialog_UseCreativeStudio;
1419		nw4cExpDialog_OutInterFileCB();
1420	}
1421
1422	string $selectionStr = (!$animRangeFlag) ?
1423		"Selection  ( Below )" : "Selection  ( Tree )";
1424	radioButtonGrp -e -l2 $selectionStr	nw4cExpDialog_ExportTarget;
1425}
1426
1427/******************************************************************************
1428	out inter file callback
1429******************************************************************************/
1430global proc nw4cExpDialog_OutInterFileCB()
1431{
1432	int $outInterFile = (`radioButtonGrp -q -sl nw4cExpDialog_OutInterFile` == 1);
1433	control -e -en $outInterFile nw4cExpDialog_OutFolder;
1434	control -e -en $outInterFile nw4cExpDialog_OutFolderBrowser;
1435
1436	int $useCs = !$outInterFile;
1437	int $cmdl = `checkBoxGrp -q -v1 nw4cExpDialog_CmdlFileOut`;
1438	int $mergeCmdl = `checkBoxGrp -q -v1 nw4cExpDialog_MergeCmdlFlag`;
1439	int $cmdlPathEnable = $cmdl && $mergeCmdl;
1440	control -e -en $cmdl nw4cExpDialog_MergeCmdlFlag;
1441	control -e -en $cmdlPathEnable nw4cExpDialog_MergeCmdlPath;
1442	control -e -en $cmdlPathEnable nw4cExpDialog_MergeCmdlBrowser;
1443	//control -e -en ($cmdlPathEnable && $useCs) nw4cExpDialog_MergeCmdlAuto;
1444}
1445
1446/******************************************************************************
1447	set node name to file name
1448******************************************************************************/
1449global proc nw4cExpDialog_SetNodeNameToFileName()
1450{
1451	// get selection
1452	// ��ŊK�w�̐[�����ׂ�̂� -l ���K�v
1453	string $xforms[] = `ls -l -sl -typ transform`;
1454	if (size($xforms) == 0)
1455	{
1456		$xforms = `ls -l -v -typ transform`;
1457	}
1458	if (size($xforms) == 0)
1459	{
1460		error "No transform node";
1461	}
1462
1463	// find top level node
1464	string $name, $buf[];
1465	int $depthMin = 10000;
1466	for ($xform in $xforms)
1467	{
1468		int $depth = tokenize($xform, "|", $buf);
1469		if ($depth < $depthMin)
1470		{
1471			$name = $xform;
1472			$depthMin = $depth;
1473		}
1474	}
1475
1476	// set name
1477	$name = substitute(".*|", $name, ""); // to short path
1478	textFieldGrp -e -tx $name nw4cExpDialog_OutFileName;
1479}
1480
1481/******************************************************************************
1482	out folder browser callback
1483******************************************************************************/
1484global proc nw4cExpDialog_OutFolderBrowserFC(string $filePath, string $fileType)
1485{
1486	textFieldGrp -e -tx $filePath nw4cExpDialog_OutFolder;
1487}
1488
1489global proc nw4cExpDialog_OutFolderBrowserCB()
1490{
1491	NW4C_SetCurDirFromFile(`textFieldGrp -q -tx nw4cExpDialog_OutFolder`);
1492
1493	eval("NW4C_FileDialog -m 4 -an \"Select\" -in \"Output Folder\" " +
1494		"-fc \"nw4cExpDialog_OutFolderBrowserFC\"");
1495	//fileBrowserDialog -m 4 -an "Select" -in "Output Folder"
1496	//	  -fc "nw4cExpDialog_OutFolderBrowserFC";
1497}
1498
1499/******************************************************************************
1500	merge cmdl browser callback
1501******************************************************************************/
1502global proc nw4cExpDialog_MergeCmdlBrowserCB()
1503{
1504	string $curPath = `textField -q -tx nw4cExpDialog_MergeCmdlPath`;
1505	if (size($curPath) > 0)
1506	{
1507		$curPath = dirname($curPath);
1508		$curPath = (`filetest -d $curPath`) ? ($curPath + "/") : "";
1509	}
1510	string $newPath = `fileDialog -dm ($curPath + "*.cmdl")`;
1511	if (size($newPath) > 0)
1512	{
1513 		textField -e -tx $newPath nw4cExpDialog_MergeCmdlPath;
1514 	}
1515}
1516
1517/******************************************************************************
1518	magnify callback
1519******************************************************************************/
1520global proc nw4cExpDialog_MagnifyCB()
1521{
1522	float $magnify = `floatFieldGrp -q -v1 nw4cExpDialog_Magnify`;
1523	if ($magnify < 0.001)
1524	{
1525		floatFieldGrp -e -v1 0.001 nw4cExpDialog_Magnify;
1526	}
1527	else if ($magnify > 1000.0)
1528	{
1529		floatFieldGrp -e -v1 1000.0 nw4cExpDialog_Magnify;
1530	}
1531}
1532
1533/******************************************************************************
1534	frame range callback
1535******************************************************************************/
1536global proc nw4cExpDialog_FrameRangeCB()
1537{
1538	int $frameRange = `radioButtonGrp -q -sl nw4cExpDialog_FrameRange` - 1;
1539	int $enableFlag = ($frameRange == 2);
1540	control -e -en $enableFlag nw4cExpDialog_StartFrame;
1541	control -e -en $enableFlag nw4cExpDialog_EndFrame;
1542}
1543
1544/******************************************************************************
1545	frame start end callback
1546******************************************************************************/
1547global proc nw4cExpDialog_FrameStartEndCB()
1548{
1549	int $start = `intField -q -v nw4cExpDialog_StartFrame`;
1550	int $end   = `intField -q -v nw4cExpDialog_EndFrame`;
1551	if ($start > $end)
1552	{
1553		intField -e -v $end nw4cExpDialog_StartFrame;
1554		intField -e -v $start nw4cExpDialog_EndFrame;
1555	}
1556}
1557
1558/******************************************************************************
1559	compress node callback
1560******************************************************************************/
1561global proc nw4cExpDialog_CompressNodeCB()
1562{
1563	int $compressNode = `optionMenuGrp -q -sl nw4cExpDialog_CompressNode` - 1;
1564
1565	//control -e -en ($compressNode != 0)
1566	//	nw4cExpDialog_CombinePolygon;
1567}
1568
1569/******************************************************************************
1570	max reserved uniform registers callback
1571******************************************************************************/
1572global proc nw4cExpDialog_MaxReservedUniformRegistersCB()
1573{
1574	int $val = `intFieldGrp -q -v1 nw4cExpDialog_MaxReservedUniformRegisters`;
1575	if ($val < 0 || $val > 57)
1576	{
1577		if ($val < 0 ) $val = 0;
1578		if ($val > 57 ) $val = 57;
1579		intFieldGrp -e -v1 $val nw4cExpDialog_MaxReservedUniformRegisters;
1580	}
1581}
1582
1583/******************************************************************************
1584	model file callback
1585******************************************************************************/
1586global proc nw4cExpDialog_ModelCB()
1587{
1588	int $cmdl = `checkBoxGrp -q -v1 nw4cExpDialog_CmdlFileOut`;
1589	int $cmdla = `checkBoxGrp -q -v1 nw4cExpDialog_CmdlaFileOut`;
1590
1591	int $visAnim = ($cmdl || $cmdla);
1592
1593	control -e -en $cmdl nw4cExpDialog_OptimizePrimitive;
1594	//control -e -en $cmdl nw4cExpDialog_DelUselessVtxData;
1595
1596	control -e -en $cmdl nw4cExpDialog_QuantPos;
1597	control -e -en $cmdl nw4cExpDialog_QuantNrm;
1598	control -e -en $cmdl nw4cExpDialog_QuantTex;
1599
1600	control -e -en $cmdl nw4cExpDialog_AdjustSkinning;
1601	control -e -en $visAnim nw4cExpDialog_MeshVisibilityMode;
1602	control -e -en $cmdl nw4cExpDialog_NonUniformScale;
1603	control -e -en $cmdl nw4cExpDialog_MaxReservedUniformRegisters;
1604
1605
1606	nw4cExpDialog_OutInterFileCB(); // update merge cmdl file
1607}
1608
1609/******************************************************************************
1610	anim file callback
1611******************************************************************************/
1612global proc nw4cExpDialog_AnimCB()
1613{
1614	//-----------------------------------------------------------------------------
1615	// get out file
1616	int $cmdl = `checkBoxGrp -q -v1 nw4cExpDialog_CmdlFileOut`;
1617	int $cmdla = `checkBoxGrp -q -v1 nw4cExpDialog_CmdlaFileOut`;
1618	int $cskla = `checkBoxGrp -q -v1 nw4cExpDialog_CsklaFileOut`;
1619	int $ccam = `checkBoxGrp -q -v1 nw4cExpDialog_CcamFileOut`;
1620	int $clgt = `checkBoxGrp -q -v1 nw4cExpDialog_ClgtFileOut`;
1621	int $cmata = `checkBoxGrp -q -v1 nw4cExpDialog_CmataFileOut`;
1622	int $cmcla = 0;
1623	int $cmtpa = 0;
1624	int $cmtsa = 0;
1625	int $anyAnim;
1626	int $visAnim;
1627
1628	if (`UseCustomUI` == 1)
1629	{
1630		$cmcla = `checkBoxGrp -q -v1 nw4cExpDialog_CmclaFileOut`;
1631		$cmtpa = `checkBoxGrp -q -v1 nw4cExpDialog_CmtpaFileOut`;
1632		$cmtsa = `checkBoxGrp -q -v1 nw4cExpDialog_CmtsaFileOut`;
1633	}
1634
1635	$anyAnim = ($cmdla || $cskla || $cmata || $cmcla || $cmtpa || $cmtsa || $ccam || $clgt);
1636	$visAnim = ($cmdl || $cmdla);
1637
1638	//-----------------------------------------------------------------------------
1639	// get frame format
1640	int $frameFmt = `checkBoxGrp -q -v1 nw4cExpDialog_FrameFormat`;
1641
1642	//-----------------------------------------------------------------------------
1643	// process mode callback (enable/disable out file name)
1644	nw4cExpDialog_ProcessModeCB();
1645
1646	//-----------------------------------------------------------------------------
1647	// quantization options
1648	control -e -en $cskla nw4cExpDialog_FrameFormat;
1649	control -e -en ($cskla && !$frameFmt) nw4cExpDialog_ScaleQuantizeQuality;
1650	control -e -en ($cskla && !$frameFmt) nw4cExpDialog_RotateQuantizeQuality;
1651	control -e -en ($cskla && !$frameFmt) nw4cExpDialog_TranslateQuantizeQuality;
1652
1653	//-----------------------------------------------------------------------------
1654	// model options
1655	control -e -en $visAnim nw4cExpDialog_MeshVisibilityMode;
1656
1657	//-----------------------------------------------------------------------------
1658	// animation options
1659	control -e -en $anyAnim nw4cExpDialog_BakeAll;
1660	control -e -en $anyAnim nw4cExpDialog_FramePrecision;
1661	control -e -en $anyAnim nw4cExpDialog_LoopAnim;
1662//	control -e -en $cskla   nw4cExpDialog_KeepAtLeastOneKey;
1663
1664	//-----------------------------------------------------------------------------
1665	// tolerance options
1666	int $nodeTolFlagRT = $cskla || $ccam || $clgt;
1667	int $nodeTolFlagS = $cskla;
1668	control -e -en $nodeTolFlagRT nw4cExpDialog_TolT;
1669	control -e -en $nodeTolFlagRT nw4cExpDialog_TolR;
1670	control -e -en $nodeTolFlagS nw4cExpDialog_TolS;
1671
1672	int $texTolFlagSRT = $cmata || $cmtsa;
1673	control -e -en $texTolFlagSRT nw4cExpDialog_TolTexT;
1674	control -e -en $texTolFlagSRT nw4cExpDialog_TolTexR;
1675	control -e -en $texTolFlagSRT nw4cExpDialog_TolTexS;
1676
1677	int $colorTolFlag = $cmata || $cmcla || $clgt;
1678	control -e -en $colorTolFlag nw4cExpDialog_TolC;
1679}
1680
1681/******************************************************************************
1682	tolerance srt callback
1683******************************************************************************/
1684global proc nw4cExpDialog_ToleranceSRTCB(string $field)
1685{
1686	float $val = eval("floatFieldGrp -q -v1 " + $field);
1687	if ($val < 0.0)
1688	{
1689		eval("floatFieldGrp -e -v1 0.0 " + $field);
1690	}
1691}
1692
1693/******************************************************************************
1694	tolerance color callback
1695******************************************************************************/
1696global proc nw4cExpDialog_ToleranceColorCB(string $field)
1697{
1698	float $val = eval("floatFieldGrp -q -v1 " + $field);
1699	if ($val < 0.0)
1700	{
1701		eval("floatFieldGrp -e -v1 0.0 " + $field);
1702	}
1703}
1704
1705/******************************************************************************
1706	update all control state
1707******************************************************************************/
1708proc nw4cExpDialog_UpdateAllControlState()
1709{
1710	nw4cExpDialog_ProcessModeCB();
1711	nw4cExpDialog_OutInterFileCB();
1712
1713	nw4cExpDialog_MagnifyCB();
1714	nw4cExpDialog_FrameRangeCB();
1715	nw4cExpDialog_FrameStartEndCB();
1716
1717	nw4cExpDialog_CompressNodeCB();
1718
1719	nw4cExpDialog_ModelCB();
1720	nw4cExpDialog_AnimCB();
1721
1722	nw4cExpDialog_ToleranceSRTCB("nw4cExpDialog_TolT");
1723	nw4cExpDialog_ToleranceSRTCB("nw4cExpDialog_TolR");
1724	nw4cExpDialog_ToleranceSRTCB("nw4cExpDialog_TolS");
1725
1726	nw4cExpDialog_ToleranceSRTCB("nw4cExpDialog_TolTexT");
1727	nw4cExpDialog_ToleranceSRTCB("nw4cExpDialog_TolTexR");
1728	nw4cExpDialog_ToleranceSRTCB("nw4cExpDialog_TolTexS");
1729
1730	nw4cExpDialog_ToleranceColorCB("nw4cExpDialog_TolC");
1731}
1732
1733/******************************************************************************
1734	set option variable
1735******************************************************************************/
1736proc SetOptionVariable(int $resetFlag)
1737{
1738	if ($resetFlag || !`optionVar -ex nw4cExport_Options`)
1739	{
1740		string $optStr =
1741			"ProcessMode=Single;" +
1742			"ExportTarget=All;" +
1743			"OutputFileName=" + `file -q -namespace` + ";" +
1744			"OutputMode=File;" +
1745			"OutputFolder=" + `workspace -q -rd` + ";" +
1746			"MergeCmdl=false;" +
1747			"MergeCmdlPath=" + "" + ";" +
1748			//"MergeCmdlAuto=true;" +
1749
1750			"Magnify=1.0;" +
1751			"FrameRange=All;" +
1752			"StartFrame=1;" +
1753			"EndFrame=100;" +
1754			//"TexMatrixMode=Maya;" +
1755			"RemoveNamespace=false;" +
1756
1757			"OutputCmdl=true;" +
1758			"OutputCtex=true;" +
1759			"OutputCmdla=false;" +
1760			"OutputCskla=false;" +
1761			"OutputCmata=false;" +
1762			"OutputCmcla=false;" +
1763			"OutputCmtpa=false;" +
1764			"OutputCmtsa=false;" +
1765			"OutputCcam=false;" +
1766			"OutputClgt=false;" +
1767			"OutputCenv=false;" +
1768
1769			"CompressNode=None;" +
1770			//"CombinePolygon=true;" +
1771			"CompressMaterial=false;" +
1772			"OptimizePrimitive=true;" +
1773			"ConvertToModel=true;" +
1774			//"DelUselessVtxData=false;" +
1775
1776			"QuantizePos=Float;" +
1777			"QuantizeNrm=Float;" +
1778			"QuantizeTex=Float;" +
1779			"FrameFormat=false;" +
1780			"ScaleQuantizeQuality=9;" +
1781			"RotateQuantizeQuality=9;" +
1782			"TranslateQuantizeQuality=9;" +
1783
1784			"AdjustSkinning=None;" +
1785			"MeshVisibilityMode=BindByIndex;" +
1786			"NonUniformScale=false;" +
1787			"MaxReservedUniformRegisters=0;" +
1788
1789			"BakeAllAnim=true;" +
1790			"FramePrecision=1;" +
1791			"LoopAnim=false;" +
1792//			"KeepAtLeastOneKey=false;" +
1793
1794			"ToleranceScale=0.1;" +
1795			"ToleranceRotate=0.1;" +
1796			"ToleranceTranslate=0.01;" +
1797			"ToleranceTexScale=0.1;" +
1798			"ToleranceTexRotate=0.1;" +
1799			"ToleranceTexTranslate=0.01;" +
1800			"ToleranceColor=0.001;" +
1801
1802			"";
1803		optionVar -sv nw4cExport_Options $optStr;
1804	}
1805}
1806
1807/******************************************************************************
1808	set option control
1809******************************************************************************/
1810proc SetOptionControl()
1811{
1812	int $useCustomUI = UseCustomUI();
1813
1814	if (`optionVar -ex nw4cExport_Options`)
1815	{
1816		string $optStr = `optionVar -q nw4cExport_Options`;
1817		if (size($optStr) > 0)
1818		{
1819			string $optList[];
1820			tokenize($optStr, ";", $optList);
1821			int $iopt;
1822			for ($iopt = 0; $iopt < size($optList); ++$iopt)
1823			{
1824				string $words[];
1825				tokenize($optList[$iopt], "=", $words);
1826				int	$intVal;
1827				float $floatVal;
1828				int $boolVal = ($words[1] == "true" || $words[1] == "On" || $words[1] == "1");
1829
1830				//-----------------------------------------------------------------------------
1831				// output
1832				if ($words[0] == "ProcessMode")
1833				{
1834					$intVal = ($words[1] == "AnimationRange");
1835					radioButtonGrp -e -sl ($intVal + 1) nw4cExpDialog_ProcessMode;
1836				}
1837				else if ($words[0] == "ExportTarget")
1838				{
1839					$intVal = ($words[1] == "Selection");
1840					radioButtonGrp -e -sl ($intVal + 1) nw4cExpDialog_ExportTarget;
1841				}
1842				else if ($words[0] == "OutputFileName")
1843				{
1844					textFieldGrp -e -tx $words[1] nw4cExpDialog_OutFileName;
1845				}
1846				else if ($words[0] == "OutputMode")
1847				{
1848					if ($words[1] == "CreativeStudio")
1849					{
1850						radioButtonGrp -e -sl 1 nw4cExpDialog_UseCreativeStudio;
1851					}
1852					else
1853					{
1854						radioButtonGrp -e -sl 1 nw4cExpDialog_OutInterFile;
1855					}
1856				}
1857				else if ($words[0] == "OutputFolder")
1858				{
1859					textFieldGrp -e -tx $words[1] nw4cExpDialog_OutFolder;
1860				}
1861				else if ($words[0] == "MergeCmdl")
1862				{
1863					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_MergeCmdlFlag;
1864				}
1865				else if ($words[0] == "MergeCmdlPath")
1866				{
1867					textField -e -tx $words[1] nw4cExpDialog_MergeCmdlPath;
1868				}
1869				//else if ($words[0] == "MergeCmdlAuto")
1870				//{
1871				//	checkBoxGrp -e -v1 $boolVal nw4cExpDialog_MergeCmdlAuto;
1872				//}
1873
1874				//-----------------------------------------------------------------------------
1875				// general
1876				else if ($words[0] == "Magnify")
1877				{
1878					$floatVal = $words[1];
1879					floatFieldGrp -e -v1 $floatVal nw4cExpDialog_Magnify;
1880				}
1881				else if ($words[0] == "FrameRange")
1882				{
1883					int $sel = 1; // All
1884					if ($words[1] == "Playback")
1885					{
1886						$sel = 2;
1887					}
1888					else if ($words[1] == "Range")
1889					{
1890						$sel = 3;
1891					}
1892					radioButtonGrp -e -sl $sel nw4cExpDialog_FrameRange;
1893				}
1894				else if ($words[0] == "StartFrame")
1895				{
1896					$intVal = $words[1];
1897					intField -e -v $intVal nw4cExpDialog_StartFrame;
1898				}
1899				else if ($words[0] == "EndFrame")
1900				{
1901					$intVal = $words[1];
1902					intField -e -v $intVal nw4cExpDialog_EndFrame;
1903				}
1904				//else if ($words[0] == "TexMatrixMode")
1905				//{
1906				//	int $sel = 1; // maya
1907				//	if ($words[1] == "3dsmax")
1908				//	{
1909				//		$sel = 2;
1910				//	}
1911				//	optionMenuGrp -e -sl $sel nw4cExpDialog_TexMatrixMode;
1912				//}
1913				else if ($words[0] == "RemoveNamespace")
1914				{
1915					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_RemoveNamespace;
1916				}
1917
1918				//-----------------------------------------------------------------------------
1919				// file select
1920				else if ($words[0] == "OutputCmdl")
1921				{
1922					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CmdlFileOut;
1923				}
1924				else if ($words[0] == "OutputCtex")
1925				{
1926					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CtexFileOut;
1927				}
1928				else if ($words[0] == "OutputCmdla")
1929				{
1930					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CmdlaFileOut;
1931				}
1932				else if ($words[0] == "OutputCskla")
1933				{
1934					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CsklaFileOut;
1935				}
1936				else if ($words[0] == "OutputCmata")
1937				{
1938					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CmataFileOut;
1939				}
1940				else if ($words[0] == "OutputCmcla")
1941				{
1942					if ($useCustomUI == 1)
1943					{
1944						checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CmclaFileOut;
1945					}
1946				}
1947				else if ($words[0] == "OutputCmtpa")
1948				{
1949					if ($useCustomUI == 1)
1950					{
1951						checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CmtpaFileOut;
1952					}
1953				}
1954				else if ($words[0] == "OutputCmtsa")
1955				{
1956					if ($useCustomUI == 1)
1957					{
1958						checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CmtsaFileOut;
1959					}
1960				}
1961				else if ($words[0] == "OutputCcam")
1962				{
1963					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CcamFileOut;
1964				}
1965				else if ($words[0] == "OutputClgt")
1966				{
1967					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_ClgtFileOut;
1968				}
1969				else if ($words[0] == "OutputCenv")
1970				{
1971					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_CenvFileOut;
1972				}
1973
1974				//-----------------------------------------------------------------------------
1975				// optimization
1976				else if ($words[0] == "CompressNode")
1977				{
1978					int $sel = 1; // None
1979					if ($words[1] == "Cull")
1980					{
1981						$sel = 2;
1982					}
1983					else if ($words[1] == "CullUninfluential")
1984					{
1985						$sel = 3;
1986					}
1987					else if ($words[1] == "UniteCompressible")
1988					{
1989						$sel = 4;
1990					}
1991					else if ($words[1] == "UniteAll")
1992					{
1993						$sel = 5;
1994					}
1995					optionMenuGrp -e -sl $sel nw4cExpDialog_CompressNode;
1996				}
1997				//else if ($words[0] == "CombinePolygon")
1998				//{
1999				//	checkBox -e -v $boolVal nw4cExpDialog_CombinePolygon;
2000				//}
2001				else if ($words[0] == "CompressMaterial")
2002				{
2003					optionMenuGrp -e -sl ($boolVal + 1) nw4cExpDialog_CompressMaterial;
2004				}
2005				else if ($words[0] == "OptimizePrimitive")
2006				{
2007					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_OptimizePrimitive;
2008				}
2009				else if ($words[0] == "ConvertToModel")
2010				{
2011					int $val = ($boolVal == 0) ? 1 : 0;
2012					checkBoxGrp -e -v1 $val nw4cExpDialog_DisableSkiModelSimplification;
2013				}
2014				//else if ($words[0] == "DelUselessVtxData")
2015				//{
2016				//	checkBoxGrp -e -v1 $boolVal nw4cExpDialog_DelUselessVtxData;
2017				//}
2018
2019				//-----------------------------------------------------------------------------
2020				// quantization
2021				else if ($words[0] == "QuantizePos")
2022				{
2023					int $sel = 1; // Float
2024					if ($words[1] == "Float")
2025					{
2026						$sel = 1;
2027					}
2028					else if ($words[1] == "Short")
2029					{
2030						$sel = 2;
2031					}
2032					else if ($words[1] == "Byte")
2033					{
2034						$sel = 3;
2035					}
2036					optionMenuGrp -e -sl $sel nw4cExpDialog_QuantPos;
2037				}
2038				else if ($words[0] == "QuantizeNrm")
2039				{
2040					int $sel = 1; // Float
2041					if ($words[1] == "Float")
2042					{
2043						$sel = 1;
2044					}
2045					else if ($words[1] == "Short")
2046					{
2047						$sel = 2;
2048					}
2049					else if ($words[1] == "Byte")
2050					{
2051						$sel = 3;
2052					}
2053					optionMenuGrp -e -sl $sel nw4cExpDialog_QuantNrm;
2054				}
2055				else if ($words[0] == "QuantizeTex")
2056				{
2057					int $sel = 1; // Float
2058					if ($words[1] == "Float")
2059					{
2060						$sel = 1;
2061					}
2062					else if ($words[1] == "Short")
2063					{
2064						$sel = 2;
2065					}
2066					else if ($words[1] == "Byte")
2067					{
2068						$sel = 3;
2069					}
2070					optionMenuGrp -e -sl $sel nw4cExpDialog_QuantTex;
2071				}
2072				else if ($words[0] == "FrameFormat")
2073				{
2074					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_FrameFormat;
2075				}
2076				else if ($words[0] == "ScaleQuantizeQuality")
2077				{
2078					$intVal = $words[1];
2079					intSliderGrp -e -v $intVal nw4cExpDialog_ScaleQuantizeQuality;
2080				}
2081				else if ($words[0] == "RotateQuantizeQuality")
2082				{
2083					$intVal = $words[1];
2084					intSliderGrp -e -v $intVal nw4cExpDialog_RotateQuantizeQuality;
2085				}
2086				else if ($words[0] == "TranslateQuantizeQuality")
2087				{
2088					$intVal = $words[1];
2089					intSliderGrp -e -v $intVal nw4cExpDialog_TranslateQuantizeQuality;
2090				}
2091				//-----------------------------------------------------------------------------
2092				// model
2093				else if ($words[0] == "AdjustSkinning")
2094				{
2095					int $sel = 1; // None
2096					if ($words[1] == "None")
2097					{
2098						$sel = 1;
2099					}
2100					else if ($words[1] == "RigidSkinning")
2101					{
2102						$sel = 2;
2103					}
2104					optionMenuGrp -e -sl $sel nw4cExpDialog_AdjustSkinning;
2105				}
2106				else if ($words[0] == "MeshVisibilityMode")
2107				{
2108					int $sel = 1; // BindByIndex
2109					if ($words[1] == "BindByIndex")
2110					{
2111						$sel = 1;
2112					}
2113					else if ($words[1] == "BindByName")
2114					{
2115						$sel = 2;
2116					}
2117					optionMenuGrp -e -sl $sel nw4cExpDialog_MeshVisibilityMode;
2118				}
2119				else if ($words[0] == "NonUniformScale")
2120				{
2121					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_NonUniformScale;
2122				}
2123				else if ($words[0] == "MaxReservedUniformRegisters")
2124				{
2125					$intVal = $words[1];
2126					intFieldGrp -e -v1 $intVal nw4cExpDialog_MaxReservedUniformRegisters;
2127				}
2128
2129				//-----------------------------------------------------------------------------
2130				// anim
2131				else if ($words[0] == "BakeAllAnim")
2132				{
2133					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_BakeAll;
2134				}
2135				else if ($words[0] == "FramePrecision")
2136				{
2137					$intVal = $words[1];
2138					int $sel = 1;				// 1.0
2139					if ($intVal == "2")			// 0.5
2140					{
2141						$sel = 2;
2142					}
2143					else if ($intVal == "5")	// 0.2
2144					{
2145						$sel = 3;
2146					}
2147					else if ($intVal == "10")	// 0.1
2148					{
2149						$sel = 4;
2150					}
2151					optionMenuGrp -e -sl $sel nw4cExpDialog_FramePrecision;
2152				}
2153				else if ($words[0] == "LoopAnim")
2154				{
2155					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_LoopAnim;
2156				}
2157//				else if ($words[0] == "KeepAtLeastOneKey")
2158//				{
2159//					checkBoxGrp -e -v1 $boolVal nw4cExpDialog_KeepAtLeastOneKey;
2160//				}
2161
2162				//-----------------------------------------------------------------------------
2163				// tolerance
2164				else if ($words[0] == "ToleranceScale")
2165				{
2166					$floatVal = $words[1];
2167					floatFieldGrp -e -v1 $floatVal nw4cExpDialog_TolS;
2168				}
2169				else if ($words[0] == "ToleranceRotate")
2170				{
2171					$floatVal = $words[1];
2172					floatFieldGrp -e -v1 $floatVal nw4cExpDialog_TolR;
2173				}
2174				else if ($words[0] == "ToleranceTranslate")
2175				{
2176					$floatVal = $words[1];
2177					floatFieldGrp -e -v1 $floatVal nw4cExpDialog_TolT;
2178				}
2179				else if ($words[0] == "ToleranceTexScale")
2180				{
2181					$floatVal = $words[1];
2182					floatFieldGrp -e -v1 $floatVal nw4cExpDialog_TolTexS;
2183				}
2184				else if ($words[0] == "ToleranceTexRotate")
2185				{
2186					$floatVal = $words[1];
2187					floatFieldGrp -e -v1 $floatVal nw4cExpDialog_TolTexR;
2188				}
2189				else if ($words[0] == "ToleranceTexTranslate")
2190				{
2191					$floatVal = $words[1];
2192					floatFieldGrp -e -v1 $floatVal nw4cExpDialog_TolTexT;
2193				}
2194				else if ($words[0] == "ToleranceColor")
2195				{
2196					$floatVal = $words[1];
2197					floatFieldGrp -e -v1 $floatVal nw4cExpDialog_TolC;
2198				}
2199			}
2200		}
2201	}
2202
2203	//-----------------------------------------------------------------------------
2204	// update control state
2205	nw4cExpDialog_UpdateAllControlState();
2206}
2207
2208/******************************************************************************
2209	check option value
2210******************************************************************************/
2211proc CheckOptionValue()
2212{
2213	int $animRangeFlag = (`radioButtonGrp -q -sl nw4cExpDialog_ProcessMode` == 2);
2214
2215	//int $cscaFlag = `checkBoxGrp -q -v1 nw4cExpDialog_CscaFileOut`;
2216	int $cscaFlag = 0;
2217
2218	if (!$animRangeFlag || $cscaFlag)
2219	{
2220		string $outputFileName = `textFieldGrp -q -tx nw4cExpDialog_OutFileName`;
2221		if (size($outputFileName) == 0)
2222		{
2223			ShowError("Output File Name is wrong");
2224		}
2225		if (size(match("[=;:/*?<>|\"]", $outputFileName)) > 0 ||
2226			NW4C_GetUnixFilePath($outputFileName) != $outputFileName) // check "\"
2227		{
2228			ShowError("Output File Name is wrong (please don't use [=] [;] [:] [/] [\\] [*] [?] [<] [>] [|] [double quote])");
2229		}
2230	}
2231
2232	int $useCs = (`radioButtonGrp -q -sl nw4cExpDialog_UseCreativeStudio` == 1);
2233	if (!$useCs)
2234	{
2235		string $outputFolder = `textFieldGrp -q -tx nw4cExpDialog_OutFolder`;
2236		if (size($outputFolder) == 0)
2237		{
2238			ShowError("Output Folder is wrong");
2239		}
2240		if (size(match("[=;*?<>|\"]", $outputFolder)) > 0)
2241		{
2242			ShowError("Output Folder is wrong (please don't use [=] [;] [*] [?] [<] [>] [|] [double quote])");
2243		}
2244	}
2245
2246	int $mergeCmdl = `checkBoxGrp -q -v1 nw4cExpDialog_MergeCmdlFlag`;
2247	if ($mergeCmdl)
2248	{
2249		string $mergeCmdlPath = `textField -q -tx nw4cExpDialog_MergeCmdlPath`;
2250		if (size($mergeCmdlPath) == 0)
2251		{
2252			ShowError("Path of cmdl file to merge is wrong");
2253		}
2254		if (size(match("[=;*?<>|\"]", $mergeCmdlPath)) > 0)
2255		{
2256			ShowError("Path of cmdl file to merge is wrong (please don't use [=] [;] [*] [?] [<] [>] [|] [double quote])");
2257		}
2258	}
2259}
2260
2261/******************************************************************************
2262	update option variable (UpdateOptionVariableT)
2263******************************************************************************/
2264global proc nw4cExpDialog_UpdateOptionVariable(int $saveSettingToScene)
2265{
2266	int $intVal;
2267	float $floatVal;
2268	string $optStr = "", $path;
2269
2270	string $boolNames[2] = { "false", "true" };
2271
2272	//-----------------------------------------------------------------------------
2273	// output
2274	$intVal = `radioButtonGrp -q -sl nw4cExpDialog_ProcessMode` - 1;
2275	string $processModeNames[] = { "Single", "AnimationRange" };
2276	$optStr += "ProcessMode=" + $processModeNames[$intVal] + ";";
2277
2278	$intVal = `radioButtonGrp -q -sl nw4cExpDialog_ExportTarget` - 1;
2279	string $exportTargetNames[] = { "All", "Selection" };
2280	$optStr += "ExportTarget=" + $exportTargetNames[$intVal] + ";";
2281
2282	$optStr += "OutputFileName=" + `textFieldGrp -q -tx nw4cExpDialog_OutFileName` + ";";
2283
2284	$intVal = (`radioButtonGrp -q -sl nw4cExpDialog_UseCreativeStudio` == 1);
2285	string $outputTargetNames[] = { "File", "CreativeStudio" };
2286	$optStr += "OutputMode=" + $outputTargetNames[$intVal] + ";";
2287
2288	$path = `textFieldGrp -q -tx nw4cExpDialog_OutFolder`;
2289	$optStr += "OutputFolder=" + NW4C_GetUnixFilePath($path) + ";";
2290
2291	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_MergeCmdlFlag`;
2292	$optStr += "MergeCmdl=" + $boolNames[$intVal] + ";";
2293	$path = `textField -q -tx nw4cExpDialog_MergeCmdlPath`;
2294	$optStr += "MergeCmdlPath=" + NW4C_GetUnixFilePath($path) + ";";
2295//	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_MergeCmdlAuto`;
2296//	$optStr += "MergeCmdlAuto=" + $boolNames[$intVal] + ";";
2297
2298	//-----------------------------------------------------------------------------
2299	// general
2300	$floatVal = `floatFieldGrp -q -v1 nw4cExpDialog_Magnify`;
2301	$optStr += "Magnify=" + $floatVal + ";";
2302
2303	$intVal = `radioButtonGrp -q -sl nw4cExpDialog_FrameRange` - 1;
2304	string $frameRangeNames[] = { "All", "Playback", "Range" };
2305	$optStr += "FrameRange=" + $frameRangeNames[$intVal] + ";";
2306
2307	$intVal = `intField -q -v nw4cExpDialog_StartFrame`;
2308	$optStr += "StartFrame=" + $intVal + ";";
2309
2310	$intVal = `intField -q -v nw4cExpDialog_EndFrame`;
2311	$optStr += "EndFrame=" + $intVal + ";";
2312
2313//	$intVal = `optionMenuGrp -q -sl nw4cExpDialog_TexMatrixMode` - 1;
2314//	string $texMatrixModeNames[] = { "Maya", "3dsMax" };
2315//	$optStr += "TexMatrixMode=" + $texMatrixModeNames[$intVal] + ";";
2316
2317	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_RemoveNamespace`;
2318	$optStr += "RemoveNamespace=" + $boolNames[$intVal] + ";";
2319
2320	//-----------------------------------------------------------------------------
2321	// file selection
2322	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CmdlFileOut`;
2323	$optStr += "OutputCmdl=" + $boolNames[$intVal] + ";";
2324
2325	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CtexFileOut`;
2326	$optStr += "OutputCtex=" + $boolNames[$intVal] + ";";
2327
2328	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CmdlaFileOut`;
2329	$optStr += "OutputCmdla=" + $boolNames[$intVal] + ";";
2330
2331	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CsklaFileOut`;
2332	$optStr += "OutputCskla=" + $boolNames[$intVal] + ";";
2333
2334	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CmataFileOut`;
2335	$optStr += "OutputCmata=" + $boolNames[$intVal] + ";";
2336
2337	if (`UseCustomUI` == 1)
2338	{
2339		$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CmclaFileOut`;
2340		$optStr += "OutputCmcla=" + $boolNames[$intVal] + ";";
2341
2342		$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CmtpaFileOut`;
2343		$optStr += "OutputCmtpa=" + $boolNames[$intVal] + ";";
2344
2345		$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CmtsaFileOut`;
2346		$optStr += "OutputCmtsa=" + $boolNames[$intVal] + ";";
2347	}
2348	else
2349	{
2350		// CustomUI ���g�p���Ȃ����� cmcla, cmtpa, cmtsa ���o�͂��Ȃ��悤�ɂ���B
2351		$optStr += "OutputCmcla=" + $boolNames[0] + ";";
2352		$optStr += "OutputCmtpa=" + $boolNames[0] + ";";
2353		$optStr += "OutputCmtsa=" + $boolNames[0] + ";";
2354	}
2355
2356	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CcamFileOut`;
2357	$optStr += "OutputCcam=" + $boolNames[$intVal] + ";";
2358
2359	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_ClgtFileOut`;
2360	$optStr += "OutputClgt=" + $boolNames[$intVal] + ";";
2361
2362	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_CenvFileOut`;
2363	$optStr += "OutputCenv=" + $boolNames[$intVal] + ";";
2364
2365	//-----------------------------------------------------------------------------
2366	// optimization
2367	$intVal = `optionMenuGrp -q -sl nw4cExpDialog_CompressNode` - 1;
2368	string $compressNodeNames[] = {
2369		"None", "Cull", "CullUninfluential", "UniteCompressible", "UniteAll" };
2370	$optStr += "CompressNode=" + $compressNodeNames[$intVal] + ";";
2371
2372//	$intVal = `checkBox -q -v nw4cExpDialog_CombinePolygon`;
2373//	$optStr += "CombinePolygon=" + $boolNames[$intVal] + ";";
2374
2375	$intVal = `optionMenuGrp -q -sl nw4cExpDialog_CompressMaterial` - 1;
2376	$optStr += "CompressMaterial=" + $boolNames[$intVal] + ";";
2377
2378	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_OptimizePrimitive`;
2379	$optStr += "OptimizePrimitive=" + $boolNames[$intVal] + ";";
2380
2381	$intVal = (`checkBoxGrp -q -v1 nw4cExpDialog_DisableSkiModelSimplification` == 0) ? 1 : 0;
2382	$optStr += "ConvertToModel=" + $boolNames[$intVal] + ";";
2383
2384//	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_DelUselessVtxData`;
2385//	$optStr += "DelUselessVtxData=" + $boolNames[$intVal] + ";";
2386
2387	//-----------------------------------------------------------------------------
2388	// quantization
2389	$intVal = `optionMenuGrp -q -sl nw4cExpDialog_QuantPos` - 1;
2390	string $quantPosNames[] = { "Float", "Short", "Byte", "Auto" };
2391	$optStr += "QuantizePos=" + $quantPosNames[$intVal] + ";";
2392
2393	$intVal = `optionMenuGrp -q -sl nw4cExpDialog_QuantNrm` - 1;
2394	string $quantNrmNames[] = { "Float", "Short", "Byte", "Auto" };
2395	$optStr += "QuantizeNrm=" + $quantNrmNames[$intVal] + ";";
2396
2397	$intVal = `optionMenuGrp -q -sl nw4cExpDialog_QuantTex` - 1;
2398	string $quantTexNames[] = { "Float", "Short", "Byte", "Auto" };
2399	$optStr += "QuantizeTex=" + $quantTexNames[$intVal] + ";";
2400
2401	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_FrameFormat`;
2402	$optStr += "FrameFormat=" + $boolNames[$intVal] + ";";
2403
2404	$intVal = `intSliderGrp -q -v nw4cExpDialog_ScaleQuantizeQuality`;
2405	$optStr += "ScaleQuantizeQuality=" + $intVal + ";";
2406
2407	$intVal = `intSliderGrp -q -v nw4cExpDialog_RotateQuantizeQuality`;
2408	$optStr += "RotateQuantizeQuality=" + $intVal + ";";
2409
2410	$intVal = `intSliderGrp -q -v nw4cExpDialog_TranslateQuantizeQuality`;
2411	$optStr += "TranslateQuantizeQuality=" + $intVal + ";";
2412
2413	//-----------------------------------------------------------------------------
2414	// model
2415	$intVal = `optionMenuGrp -q -sl nw4cExpDialog_AdjustSkinning` - 1;
2416	string $adjustSkinningNames[] = {
2417		"None", "RigidSkinning" };
2418	$optStr += "AdjustSkinning=" + $adjustSkinningNames[$intVal] + ";";
2419	$intVal = `optionMenuGrp -q -sl nw4cExpDialog_MeshVisibilityMode` - 1;
2420	string $meshVisibilityModeNames[] = {
2421		"BindByIndex", "BindByName" };
2422	$optStr += "MeshVisibilityMode=" + $meshVisibilityModeNames[$intVal] + ";";
2423
2424	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_NonUniformScale`;
2425	$optStr += "NonUniformScale=" + $boolNames[$intVal] + ";";
2426	$intVal = `intFieldGrp -q -v1 nw4cExpDialog_MaxReservedUniformRegisters`;
2427	$optStr += "MaxReservedUniformRegisters=" + $intVal + ";";
2428
2429	//-----------------------------------------------------------------------------
2430	// animation
2431	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_BakeAll`;
2432	$optStr += "BakeAllAnim=" + $boolNames[$intVal] + ";";
2433
2434	$intVal = `optionMenuGrp -q -sl nw4cExpDialog_FramePrecision`;
2435	int $framePrecision = 1;
2436	if ($intVal == 2)		// 0.5
2437	{
2438		$framePrecision = 2;
2439	}
2440	else if ($intVal == 3)	// 0.2
2441	{
2442		$framePrecision = 5;
2443	}
2444	else if ($intVal == 4)	// 0.1
2445	{
2446		$framePrecision = 10;
2447	}
2448	$optStr += "FramePrecision=" + $framePrecision + ";";
2449
2450	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_LoopAnim`;
2451	$optStr += "LoopAnim=" + $boolNames[$intVal] + ";";
2452
2453//	$intVal = `checkBoxGrp -q -v1 nw4cExpDialog_KeepAtLeastOneKey`;
2454//	$optStr += "KeepAtLeastOneKey=" + $boolNames[$intVal] + ";";
2455
2456	//-----------------------------------------------------------------------------
2457	// tolerance
2458	$floatVal = `floatFieldGrp -q -v1 nw4cExpDialog_TolS`;
2459	$optStr += "ToleranceScale=" + $floatVal + ";";
2460
2461	$floatVal = `floatFieldGrp -q -v1 nw4cExpDialog_TolR`;
2462	$optStr += "ToleranceRotate=" + $floatVal + ";";
2463
2464	$floatVal = `floatFieldGrp -q -v1 nw4cExpDialog_TolT`;
2465	$optStr += "ToleranceTranslate=" + $floatVal + ";";
2466
2467	$floatVal = `floatFieldGrp -q -v1 nw4cExpDialog_TolTexT`;
2468	$optStr += "ToleranceTexTranslate=" + $floatVal + ";";
2469
2470	$floatVal = `floatFieldGrp -q -v1 nw4cExpDialog_TolTexR`;
2471	$optStr += "ToleranceTexRotate=" + $floatVal + ";";
2472
2473	$floatVal = `floatFieldGrp -q -v1 nw4cExpDialog_TolTexS`;
2474	$optStr += "ToleranceTexScale=" + $floatVal + ";";
2475
2476	$floatVal = `floatFieldGrp -q -v1 nw4cExpDialog_TolC`;
2477	$optStr += "ToleranceColor=" + $floatVal + ";";
2478
2479	//-----------------------------------------------------------------------------
2480	// set option var
2481	optionVar -sv nw4cExport_Options $optStr;
2482
2483	//-----------------------------------------------------------------------------
2484	// save setting to scene
2485	if ($saveSettingToScene)
2486	{
2487		SaveSettingToScene(1);
2488	}
2489}
2490
2491/******************************************************************************
2492	reset option variable
2493******************************************************************************/
2494global proc nw4cExpDialog_ResetOptionVariable()
2495{
2496	//-----------------------------------------------------------------------------
2497	// reset export dialog options
2498	SetOptionVariable(1);
2499	SetOptionControl();
2500
2501	//-----------------------------------------------------------------------------
2502	// save setting to scene
2503	SaveSettingToScene(1);
2504}
2505
2506/******************************************************************************
2507	do export command
2508******************************************************************************/
2509proc DoExportCmd(int $forceOverwrite)
2510{
2511	//-----------------------------------------------------------------------------
2512	// load plugin
2513	LoadPlugin();
2514
2515	//-----------------------------------------------------------------------------
2516	// get options
2517	string $optStr = "";
2518	if (`optionVar -ex nw4cExport_Options`)
2519	{
2520		$optStr = `optionVar -q nw4cExport_Options`;
2521	}
2522
2523	//-----------------------------------------------------------------------------
2524	// export
2525	string $cmd = "NW4C_ExportCmd ";
2526	if ($forceOverwrite)
2527	{
2528		$cmd += "-f ";
2529	}
2530	$cmd += "-op \"" + $optStr + "\"";
2531	//trace ("cmd: " + $cmd);
2532	if (catch(eval($cmd)))
2533	{
2534		//error "NW4C_Export Failed";
2535	}
2536}
2537
2538/******************************************************************************
2539	export callback
2540******************************************************************************/
2541global proc nw4cExpDialog_ExportCB()
2542{
2543	CheckOptionValue();
2544	nw4cExpDialog_UpdateOptionVariable(1);
2545	DoExportCmd(0);
2546}
2547
2548/******************************************************************************
2549	save settings callback
2550******************************************************************************/
2551global proc nw4cExpDialog_SaveSettingsCB()
2552{
2553	CheckOptionValue();
2554	nw4cExpDialog_UpdateOptionVariable(1);
2555}
2556
2557/******************************************************************************
2558	setting menu command (post menu command)
2559******************************************************************************/
2560global proc nw4cExpDialog_SettingMenuCmd()
2561{
2562	int $sceneSettingFlag = DoesSaveLoadSceneSetting();
2563	int $settingNodeFlag = `objExists nw4cExpDialog_Setting1`;
2564	menuItem -e -cb $sceneSettingFlag nw4cExpDialog_SaveLoadSceneSettingMenu;
2565	menuItem -e -en $settingNodeFlag nw4cExpDialog_DeleteSceneSettingMenu;
2566}
2567
2568/******************************************************************************
2569	save load scene setting menu command
2570******************************************************************************/
2571global proc nw4cExpDialog_SaveLoadSceneSettingMenuCmd()
2572{
2573	int $sceneSettingFlag = DoesSaveLoadSceneSetting();
2574	$sceneSettingFlag = !$sceneSettingFlag;
2575	optionVar -iv nw4cExpDialog_SaveLoadSceneSetting $sceneSettingFlag;
2576	menuItem -e -cb $sceneSettingFlag nw4cExpDialog_SaveLoadSceneSettingMenu;
2577}
2578
2579/******************************************************************************
2580	delete scene setting menu command
2581******************************************************************************/
2582global proc nw4cExpDialog_DeleteSceneSettingMenuCmd()
2583{
2584	DeleteUselessSettingNode();
2585
2586	string $node = "nw4cExpDialog_Setting1";
2587	if (`referenceQuery -inr $node`)
2588	{
2589		print "NW4C export settings node is referenced\n";
2590	}
2591	else
2592	{
2593		catch(`delete $node`);
2594	}
2595}
2596
2597/******************************************************************************
2598	create setting menu
2599******************************************************************************/
2600proc CreateSettingMenu(string $parent)
2601{
2602	//-----------------------------------------------------------------------------
2603	// get option box
2604	global string $gOptionBox;
2605	if (!`window -ex $gOptionBox`)
2606	{
2607		return;
2608	}
2609
2610	//-----------------------------------------------------------------------------
2611	// delete previous menu
2612	if (`menu -q -ex nw4cExpDialog_SettingMenu`)
2613	{
2614		deleteUI nw4cExpDialog_SettingMenu;
2615	}
2616
2617	//-----------------------------------------------------------------------------
2618	// create menu
2619	int $sceneSettingFlag = DoesSaveLoadSceneSetting();
2620	menu -l "NW4C Settings" -p $gOptionBox
2621		-pmc "nw4cExpDialog_SettingMenuCmd"
2622		nw4cExpDialog_SettingMenu;
2623
2624		menuItem -l "Save / Load Scene Settings" -cb $sceneSettingFlag
2625			-ann "Save settings to scene when exporting & Load settings from scene when opening scene"
2626			-c "nw4cExpDialog_SaveLoadSceneSettingMenuCmd"
2627			nw4cExpDialog_SaveLoadSceneSettingMenu;
2628		menuItem -l "Delete Scene Settings"
2629			-ann "Delete script node for settings"
2630			-c "nw4cExpDialog_DeleteSceneSettingMenuCmd"
2631			nw4cExpDialog_DeleteSceneSettingMenu;
2632
2633		menuItem -d 1;
2634
2635		menuItem -l "Load Settings from c3es File"
2636			-ann "Load settings from \".c3es\" file"
2637			-c "nw4cExpDialog_LoadSettingFromFile"
2638			nw4cExpDialog_LoadSettingFromFileMenu;
2639		menuItem -l "Save Settings to c3es File"
2640			-ann "Save settings to \".c3es\" file"
2641			-c "nw4cExpDialog_SaveSettingToFile"
2642			nw4cExpDialog_SaveSettingToMenu;
2643
2644	//-----------------------------------------------------------------------------
2645	// set script job to delete menu
2646	scriptJob -p $gOptionBox -uid nw4cExpDialog_ScrollLayout
2647		"if (!`scrollLayout -ex nw4cExpDialog_ScrollLayout`) { deleteUI nw4cExpDialog_SettingMenu; }";
2648}
2649
2650/******************************************************************************
2651	is no compress node
2652******************************************************************************/
2653proc int IsNoCompressNode(string $node)
2654{
2655	return (`attributeQuery -n $node -ex "nw4cNoCompressNode"`) ?
2656		`getAttr ($node + ".nw4cNoCompressNode")` : 0;
2657}
2658
2659/******************************************************************************
2660	is scene anim object
2661******************************************************************************/
2662proc int IsSceneAnimObject(string $node)
2663{
2664	string $type = nodeType($node);
2665	string $childs[] = `listRelatives -pa -s $node`;
2666	if (size(`ls -cameras -lights -typ environmentFog $childs`) > 0 ||
2667		$type == "lookAt")
2668	{
2669		return true;
2670	}
2671	return false;
2672}
2673
2674/******************************************************************************
2675	is constraint node
2676******************************************************************************/
2677proc int IsConstraintNode(string $node)
2678{
2679	return (size(`ls -typ constraint $node`) != 0);
2680}
2681
2682/******************************************************************************
2683	is needless locator or group
2684******************************************************************************/
2685proc int IsNeedlessLocatorOrGroup(string $node)
2686{
2687	if (nodeType($node) == "transform")
2688	{
2689		string $childs[] = `listRelatives -pa -ni $node`;
2690		if (size($childs) == 0) // empty group
2691		{
2692			return true;
2693		}
2694		else if (size($childs) == 1)
2695		{
2696			string $childType = nodeType($childs[0]);
2697			if ($childType == "locator") // locator without child
2698			{
2699				return true;
2700			}
2701		}
2702	}
2703	return false;
2704}
2705
2706/******************************************************************************
2707	is blend shape target
2708******************************************************************************/
2709proc int IsBlendShapeTarget(string $node)
2710{
2711	string $shapes[] = `listRelatives -pa -ni -s $node`;
2712	if (size($shapes) && nodeType($shapes[0]) == "mesh")
2713	{
2714		string $cons[] = `listConnections -s 0 -d 1 ($shapes[0] + ".worldMesh")`;
2715		if (size($cons) && nodeType($cons[0]) == "blendShape")
2716		{
2717			return true;
2718		}
2719	}
2720	return false;
2721}
2722
2723/******************************************************************************
2724	is animation range control node
2725******************************************************************************/
2726proc int IsAnimRangeControlNode(string $node)
2727{
2728	return `attributeQuery -n $node -ex "nw4c_AnimRangeEnable"`;
2729}
2730
2731/******************************************************************************
2732	is effective node
2733******************************************************************************/
2734proc int IsEffectiveNode(string $node)
2735{
2736	if (IsNoCompressNode($node))
2737	{
2738		return true;
2739	}
2740
2741	string $type = nodeType($node);
2742	if ($type == "ikHandle" ||
2743		$type == "ikEffector" ||
2744		IsConstraintNode($node) ||
2745		IsNeedlessLocatorOrGroup($node) ||
2746		IsBlendShapeTarget($node) ||
2747		IsAnimRangeControlNode($node))
2748	{
2749		return false;
2750	}
2751
2752	if (`getAttr ($node + ".template")`)
2753	{
2754		return false;
2755	}
2756	if (`getAttr ($node + ".overrideEnabled")`)
2757	{
2758		if (!`getAttr ($node + ".overrideVisibility")` ||
2759			!`getAttr ($node + ".overrideShading")` ||
2760			`getAttr ($node + ".overrideDisplayType")` == 1) // Template
2761		{
2762			return false;
2763		}
2764	}
2765
2766	return true;
2767}
2768
2769/******************************************************************************
2770	remove no output child (both argments must be long path)
2771******************************************************************************/
2772proc RemoveNoOutputChild(string $xforms[], string $noOutputs[])
2773{
2774	string $dsts[];
2775	for ($xform in $xforms)
2776	{
2777		int $enable = true;
2778		for ($noOutput in $noOutputs)
2779		{
2780			if (gmatch($xform, $noOutput + "|*"))
2781			{
2782				$enable = false;
2783				//print ("remove by parent: " + $xform + " (" + $noOutput + ")\n");
2784			}
2785		}
2786		if ($enable)
2787		{
2788			$dsts[size($dsts)] = $xform;
2789		}
2790	}
2791	$xforms = $dsts;
2792}
2793
2794/******************************************************************************
2795	get animation range target nodes
2796******************************************************************************/
2797proc GetAnimRangeTargetNodes(string $xforms[])
2798{
2799	string $roots[];
2800	string $sels[] = `ls -l -sl -typ transform`;
2801	for ($sel in $sels)
2802	{
2803		string $root = match("|[^|]+", $sel);
2804		$roots[size($roots)] = $root;
2805	}
2806	$xforms = `ls -l -dag -typ transform $roots`;
2807}
2808
2809/******************************************************************************
2810	get node parent list
2811******************************************************************************/
2812proc GetNodeParentList(string $list[], string $node)
2813{
2814	clear($list);
2815	while (1)
2816	{
2817		$list[size($list)] = $node;
2818		string $parents[] = `listRelatives -pa -p $node`;
2819		if (!size($parents))
2820		{
2821			break;
2822		}
2823		$node = $parents[0];
2824	}
2825}
2826
2827/******************************************************************************
2828	is attr animated
2829******************************************************************************/
2830proc int IsAttrAnimated(string $plug)
2831{
2832	string $ins[] = `listConnections -s 1 -d 0 $plug`;
2833	if (size($ins))
2834	{
2835		string $hists[] = `listHistory $ins[0]`;
2836		if (size(`ls -typ animCurve -typ expression $hists`))
2837		{
2838			return true;
2839		}
2840	}
2841	return false;
2842}
2843
2844/******************************************************************************
2845	is xform node animated
2846******************************************************************************/
2847proc int IsXformNodeAnimated(string $xform, int $depth)
2848{
2849	string $attrs[] = { "tx", "ty", "tz", "rx", "ry", "rz", "sx", "sy", "sz" };
2850	string $compAttrs[] = { "t", "r", "s" };
2851
2852	//-----------------------------------------------------------------------------
2853	// check search depth
2854	//print ("ixna: " + $xform + ", " + $depth + "\n");
2855	if ($depth >= 3)
2856	{
2857		return false;
2858	}
2859
2860	//-----------------------------------------------------------------------------
2861	// child attr
2862	string $checkedCons[];
2863	for ($attr in $attrs)
2864	{
2865		string $plug = $xform + "." + $attr;
2866		string $ins[] = `listConnections -s 1 -d 0 $plug`;
2867		if (size($ins))
2868		{
2869			string $inNode = $ins[0];
2870			string $inType = nodeType($inNode);
2871			string $hists[];
2872			if (gmatch($inType, "animBlendNode*"))
2873				$hists = `listHistory $inNode`;
2874			else
2875				$hists = `listHistory $plug`;
2876
2877			//-----------------------------------------------------------------------------
2878			// curve & expression & rigid body
2879			if (size(`ls -typ animCurve -typ expression -typ rigidBody $hists`))
2880			{
2881				return true;
2882			}
2883
2884			//-----------------------------------------------------------------------------
2885			// xform attr connection (node1.attr -> node2.attr)
2886			if ($inNode != $xform &&
2887				size(`ls -et transform -et joint $inNode`))
2888			{
2889				if (IsXformNodeAnimated($inNode, $depth + 1))
2890				{
2891					return true;
2892				}
2893			}
2894
2895			//-----------------------------------------------------------------------------
2896			// constraint
2897			string $cons[] = `ls -typ constraint $hists`;
2898			if (size($cons))
2899			{
2900				//return true;
2901				string $con = $cons[0];
2902				if (FindStringInArray($checkedCons, $con) == -1)
2903				{
2904					string $targets[] =
2905						`listConnections -s 1 -d  0 -type transform ($con + ".tg")`;
2906					$targets = stringArrayRemoveDuplicates($targets);
2907					//print "tar:\n"; print $targets;
2908					for ($target in $targets)
2909					{
2910						if ($target != $xform && $target != $con)
2911						{
2912							string $list[];
2913							GetNodeParentList($list, $target);
2914							for ($n in $list)
2915							{
2916								if (IsXformNodeAnimated($n, $depth + 1))
2917								{
2918									return true;
2919								}
2920							}
2921						}
2922					}
2923					$checkedCons[size($checkedCons)] = $con;
2924				}
2925			}
2926		}
2927	}
2928
2929	//-----------------------------------------------------------------------------
2930	// compound attr
2931	for ($attr in $compAttrs)
2932	{
2933		string $plug = $xform + "." + $attr;
2934		string $ins[] = `listConnections -s 1 -d 0 $plug`;
2935		if (size($ins))
2936		{
2937			string $inNode = $ins[0];
2938			//-----------------------------------------------------------------------------
2939			// xform (curve -> node1.t -> node2.t)
2940			if (size(`ls -et transform -et joint $inNode`) &&
2941				$inNode != $xform)
2942			{
2943				if (IsXformNodeAnimated($inNode, $depth + 1))
2944				{
2945					return true;
2946				}
2947			}
2948		}
2949	}
2950
2951	return false;
2952}
2953
2954/******************************************************************************
2955	is pole vector animated
2956******************************************************************************/
2957proc int IsPoleVectorAnimated(string $ik)
2958{
2959	string $attrs[] = { "pvx", "pvy", "pvz" };
2960
2961	string $checkedCons[];
2962	for ($attr in $attrs)
2963	{
2964		string $plug = $ik + "." + $attr;
2965		string $ins[] = `listConnections -s 1 -d 0 $plug`;
2966		if (size($ins))
2967		{
2968			string $inNode = $ins[0];
2969			//string $hists[] = `listHistory $inNode`;
2970			string $hists[] = `listHistory $plug`;
2971
2972			if (size(`ls -typ animCurve -typ expression $hists`))
2973			{
2974				return true;
2975			}
2976
2977			if (nodeType($inNode) == "poleVectorConstraint")
2978			{
2979				string $con = $inNode;
2980				if (FindStringInArray($checkedCons, $con) == -1)
2981				{
2982					string $targets[] =
2983						`listConnections -s 1 -d  0 -type transform ($con + ".tg")`;
2984					$targets = stringArrayRemoveDuplicates($targets);
2985					//print "pole tar:\n"; print $targets;
2986					for ($target in $targets)
2987					{
2988						if ($target != $ik && $target != $con)
2989						{
2990							string $list[];
2991							GetNodeParentList($list, $target);
2992							for ($n in $list)
2993							{
2994								if (IsXformNodeAnimated($n, 0))
2995								{
2996									return true;
2997								}
2998							}
2999						}
3000					}
3001					$checkedCons[size($checkedCons)] = $con;
3002				}
3003			}
3004		}
3005	}
3006
3007	return false;
3008}
3009
3010/******************************************************************************
3011	does ik controlled xform exist
3012******************************************************************************/
3013proc int DoesIkControlledXformExist(string $xforms[], string $ik)
3014{
3015	string $sjs[] = `listConnections -s 1 -d 0 ($ik + ".startJoint")`;
3016	string $efs[] = `listConnections -s 1 -d 0 ($ik + ".endEffector")`;
3017	if (size($sjs) && size($efs))
3018	{
3019		string $node = $efs[0];
3020		while ($node != $sjs[0])
3021		{
3022			string $parents[] = `listRelatives -pa -p $node`;
3023			if (!size($parents))
3024			{
3025				break;
3026			}
3027			$node = $parents[0];
3028			if (FindStringInArray($xforms, $node) != -1)
3029			{
3030				return true;
3031			}
3032		}
3033	}
3034	return false;
3035}
3036
3037/******************************************************************************
3038	does chara exist
3039******************************************************************************/
3040proc int DoesCharaAnimExist(string $xforms[])
3041{
3042	//-----------------------------------------------------------------------------
3043	// check size
3044	if (!size($xforms))
3045	{
3046		return false;
3047	}
3048
3049	//-----------------------------------------------------------------------------
3050	// check curve / expression / constraint / rigid body
3051	for ($xform in $xforms)
3052	{
3053		if (IsXformNodeAnimated($xform, 0))
3054		{
3055			return true;
3056		}
3057	}
3058
3059	//-----------------------------------------------------------------------------
3060	// check IK
3061	string $iks[] = `ls -typ ikHandle`;
3062	for ($ik in $iks)
3063	{
3064		if (DoesIkControlledXformExist($xforms, $ik))
3065		{
3066			if (IsXformNodeAnimated($ik, 0) ||
3067				IsPoleVectorAnimated($ik))
3068			{
3069				return true;
3070			}
3071		}
3072	}
3073
3074	return false;
3075}
3076
3077/******************************************************************************
3078	does vis anim exist
3079******************************************************************************/
3080proc int DoesVisAnimExist(string $xforms[], string $meshs[])
3081{
3082	for ($xform in $xforms)
3083	{
3084		if (IsAttrAnimated($xform + ".v"))
3085		{
3086			return true;
3087		}
3088	}
3089
3090	for ($mesh in $meshs)
3091	{
3092		if (IsAttrAnimated($mesh + ".v"))
3093		{
3094			return true;
3095		}
3096	}
3097
3098	return false;
3099}
3100
3101/******************************************************************************
3102	get first file node
3103******************************************************************************/
3104proc string GetFirstFileNode(string $plug)
3105{
3106	string $ins[] = `listConnections -s 1 -d 0 $plug`;
3107	if (size($ins))
3108	{
3109		string $file = $ins[0];
3110		if (nodeType($file) == "layeredTexture")
3111		{
3112			$ins = `listConnections -s 1 -d 0 -type file ($file + ".cs")`;
3113			if (!size($ins))
3114			{
3115				return "";
3116			}
3117			$file = $ins[0];
3118		}
3119		if (nodeType($file) == "file")
3120		{
3121			return $file;
3122		}
3123	}
3124	return "";
3125}
3126
3127/******************************************************************************
3128	does color anim exist
3129******************************************************************************/
3130proc int DoesColorAnimExist(string $mats[])
3131{
3132	string $attrs[] = { "cr", "cg", "cb", "itr", "acr", "acg", "acb", "sr", "sg", "sb" };
3133	string $colorGains[] = { "cgr", "cgg", "cgb" };
3134
3135	for ($mat in $mats)
3136	{
3137		//-----------------------------------------------------------------------------
3138		// direct anim
3139		for ($attr in $attrs)
3140		{
3141			if (!`attributeQuery -n $mat -ex $attr`)
3142			{
3143				break;
3144			}
3145			if (IsAttrAnimated($mat + "." + $attr))
3146			{
3147				return true;
3148			}
3149		}
3150
3151		//-----------------------------------------------------------------------------
3152		// color gain anim
3153		string $file = GetFirstFileNode($mat + ".c");
3154		if (size($file))
3155		{
3156			for ($attr in $colorGains)
3157			{
3158				if (IsAttrAnimated($file + "." + $attr))
3159				{
3160					return true;
3161				}
3162			}
3163		}
3164
3165		//-----------------------------------------------------------------------------
3166		// alpha gain anim
3167		string $file = GetFirstFileNode($mat + ".it");
3168		if (size($file))
3169		{
3170			if (IsAttrAnimated($file + ".ag"))
3171			{
3172				return true;
3173			}
3174		}
3175	}
3176
3177	return false;
3178}
3179
3180/******************************************************************************
3181	does tex pat anim exist
3182******************************************************************************/
3183proc int DoesTexPatAnimExist(string $files[])
3184{
3185	for ($file in $files)
3186	{
3187		if (`getAttr ($file + ".ufe")`)
3188		{
3189			if (IsAttrAnimated($file + ".fe"))
3190			{
3191				return true;
3192			}
3193			//string $ins[] = `listConnections -s 1 -d 0 ($file + ".fe")`;
3194			//if (size($ins))
3195			//{
3196			//	string $hists[] = `listHistory $ins[0]`;
3197			//	if (size(`ls -typ animCurve $hists`)) // curve only
3198			//	{
3199			//		return true;
3200			//	}
3201			//}
3202		}
3203	}
3204
3205	return false;
3206}
3207
3208/******************************************************************************
3209	does tex srt anim exist
3210******************************************************************************/
3211proc int DoesTexSrtAnimExist(string $files[])
3212{
3213	string $attrs[] = { "tfu", "tfv", "rf", "reu", "rev" };
3214
3215	for ($file in $files)
3216	{
3217		string $ins[] = `listConnections -s 1 -d 0 -type place2dTexture ($file + ".uv")`;
3218		if (size($ins))
3219		{
3220			string $place = $ins[0];
3221			for ($attr in $attrs)
3222			{
3223				if (IsAttrAnimated($place + "." + $attr))
3224				{
3225					return true;
3226				}
3227			}
3228		}
3229	}
3230
3231	return false;
3232}
3233
3234/******************************************************************************
3235	does shape anim exist
3236******************************************************************************/
3237proc int DoesShapeAnimExist(string $meshs[])
3238{
3239	if (!size(`ls -typ blendShape`)) // check blend shape exists in scene first
3240	{
3241		return false;
3242	}
3243
3244	for ($mesh in $meshs)
3245	{
3246		string $ins[] = `listConnections -s 1 -d 0 ($mesh + ".i")`;
3247		if (size($ins))
3248		{
3249			string $hists[] = `listHistory $ins[0]`;
3250			string $bss[] = `ls -typ blendShape $hists`;
3251			for ($bs in $bss)
3252			{
3253				if (`getAttr ($bs + ".nds")` == 0)
3254				{
3255					return true;
3256				}
3257			}
3258		}
3259	}
3260
3261	return false;
3262}
3263
3264/******************************************************************************
3265	get file node for attr
3266******************************************************************************/
3267proc GetFileNodeForAttr(string $files[], string $plug)
3268{
3269	string $ins[] = `listConnections -s 1 -d 0 $plug`;
3270	if (size($ins))
3271	{
3272		string $hists[] = `listHistory $ins[0]`;
3273		string $fins[] = `ls -typ file $hists`;
3274		for ($file in $fins)
3275		{
3276			if (FindStringInArray($files, $file) == -1)
3277			{
3278				$files[size($files)] = $file; // append
3279			}
3280		}
3281	}
3282}
3283
3284/******************************************************************************
3285	search anim
3286******************************************************************************/
3287global proc nw4cExpDialog_SearchAnim()
3288{
3289	//-----------------------------------------------------------------------------
3290	// get mode
3291	int $animRangeFlag = (`radioButtonGrp -q -sl nw4cExpDialog_ProcessMode` == 2);
3292
3293	int $selFlag = (`radioButtonGrp -q -sl nw4cExpDialog_ExportTarget` == 2);
3294
3295	//-----------------------------------------------------------------------------
3296	// begin wait cursor
3297	//waitCursor -st 1;
3298
3299	//-----------------------------------------------------------------------------
3300	// get target transform
3301	string $tarXforms[];
3302	if (!$selFlag)		// all
3303	{
3304		$tarXforms = `ls -l -typ transform`;
3305	}
3306	else if (!$animRangeFlag)	// sel (below)
3307	{
3308		$tarXforms = `ls -l -sl -dag -typ transform`;
3309	}
3310	else				// sel (tree)
3311	{
3312		GetAnimRangeTargetNodes($tarXforms);
3313	}
3314
3315	//-----------------------------------------------------------------------------
3316	// get effective transform
3317	string $xforms[];
3318	string $noOutputs[];
3319	for ($xform in $tarXforms)
3320	{
3321		if (!IsSceneAnimObject($xform))
3322		{
3323			if (IsEffectiveNode($xform))
3324			{
3325				$xforms[size($xforms)] = $xform;
3326			}
3327			else
3328			{
3329				$noOutputs[size($noOutputs)] = $xform;
3330			}
3331		}
3332	}
3333	RemoveNoOutputChild($xforms, $noOutputs);
3334
3335	//print "-- xforms --\n"; print $xforms;
3336	if (size($xforms) == 0)
3337	{
3338		if (!$selFlag)
3339		{
3340			warning "No effective node";
3341		}
3342		else
3343		{
3344			warning "Effective node is not selected";
3345		}
3346	}
3347
3348	//-----------------------------------------------------------------------------
3349	// get mesh
3350	string $meshs[];
3351	for ($xform in $xforms)
3352	{
3353		string $shapes[] = `listRelatives -pa -ni -s $xform`;
3354		if (size($shapes) && nodeType($shapes[0]) == "mesh" &&
3355			!`getAttr ($shapes[0] + ".template")`)
3356		{
3357			$meshs[size($meshs)] = $shapes[0];
3358		}
3359	}
3360
3361	//-----------------------------------------------------------------------------
3362	// get material & file
3363	string $mats[];
3364	string $files[];
3365	for ($mesh in $meshs)
3366	{
3367		string $sgs[] = `listSets -t 1 -o $mesh`;
3368		for ($sg in $sgs)
3369		{
3370			string $ins[] = `listConnections -s 1 -d 0 -type lambert ($sg + ".ss")`;
3371			if (size($ins))
3372			{
3373				string $mat = $ins[0];
3374				if (FindStringInArray($mats, $mat) == -1)
3375				{
3376					$mats[size($mats)] = $mat;
3377					GetFileNodeForAttr($files, $mat + ".c");
3378					GetFileNodeForAttr($files, $mat + ".n"); // for nrm map
3379				}
3380			}
3381		}
3382	}
3383
3384	//-----------------------------------------------------------------------------
3385	// search & check
3386	//checkBoxGrp -e -v1 (DoesCharaAnimExist($xforms)) nw4cExpDialog_CsklaFileOut;
3387	//checkBoxGrp -e -v1 (DoesVisAnimExist($xforms, $meshs)) nw4cExpDialog_CviaFileOut;
3388	//checkBoxGrp -e -v1 (DoesColorAnimExist($mats)) nw4cExpDialog_CclaFileOut;
3389	//checkBoxGrp -e -v1 (DoesTexPatAnimExist($files)) nw4cExpDialog_CtpaFileOut;
3390	//checkBoxGrp -e -v1 (DoesTexSrtAnimExist($files)) nw4cExpDialog_CtsaFileOut;
3391	//checkBoxGrp -e -v1 (DoesShapeAnimExist($meshs)) nw4cExpDialog_CshaFileOut;
3392
3393	//-----------------------------------------------------------------------------
3394	// update control
3395	nw4cExpDialog_AnimCB();
3396
3397	//-----------------------------------------------------------------------------
3398	// end wait cursor
3399	//waitCursor -st 0;
3400}
3401
3402/******************************************************************************
3403	open option window
3404
3405		return 1 if success, 0 otherwise
3406******************************************************************************/
3407proc int OpenOptionWindow()
3408{
3409	int $adjustSpace = 20; // Don't zero it !
3410	int $useCustomUI = UseCustomUI();
3411	int $afterMaya2011Adjust = 0;
3412	if (getApplicationVersionAsFloat() >= 2011)
3413		$afterMaya2011Adjust = 1;
3414
3415	//-----------------------------------------------------------------------------
3416	// init option variable
3417	SetOptionVariable(0);
3418
3419	//-----------------------------------------------------------------------------
3420	// get option box
3421	string $optionBox = getOptionBox();
3422	if (size($optionBox) == 0)
3423	{
3424		return 0;
3425	}
3426	setParent $optionBox;
3427
3428	setOptionBoxTitle("NW4C Export Options");
3429
3430	//-----------------------------------------------------------------------------
3431	// create control
3432	//-----------------------------------------------------------------------------
3433
3434	//-----------------------------------------------------------------------------
3435	// begin
3436	setUITemplate -pst DefaultTemplate;
3437	waitCursor -st 1;
3438
3439	//-----------------------------------------------------------------------------
3440	// create layout
3441	scrollLayout -childResizable 1 -minChildWidth 508 nw4cExpDialog_ScrollLayout;
3442		// horizontal scroll bar is appear if layout width < minChildWidth
3443	string $parent = `columnLayout -adj 1 -cat "both" 5 -co "both" 5
3444		nw4cExpDialog_MainColumn`;
3445	$parent = substitute(".*|", $parent, ""); // to short name
3446	setParent $parent;
3447
3448	//-----------------------------------------------------------------------------
3449	// output options
3450	frameLayout -l "Output Options" -cll 1 -cl 0 -bv 1 -bs "etchedIn";
3451		string $outForm = `formLayout -nd 100`;
3452			radioButtonGrp -l "Process Mode" -vis 1 -nrb 2 -cw 1 (103+$adjustSpace) -cw 2 95
3453				-la2 "Single" "Animation Range" -sl 1
3454				-cc "nw4cExpDialog_ProcessModeCB"
3455				nw4cExpDialog_ProcessMode;
3456			string $sep1 = `separator -vis 1 -st "in" -h 3`;
3457
3458			radioButtonGrp -l "Export Target" -nrb 2 -cw 1 (103+$adjustSpace) -cw 2 95
3459				-la2 "All" "Selection" -sl 1
3460				nw4cExpDialog_ExportTarget;
3461
3462			textFieldGrp -l "Output File Name" -cw2 (103+$adjustSpace) 160
3463				nw4cExpDialog_OutFileName;
3464			button -l "Scene" -w 50
3465				-c "textFieldGrp -e -tx `file -q -ns` nw4cExpDialog_OutFileName"
3466				nw4cExpDialog_SceneToOutFileName;
3467			button -l "Node" -w 50 -c "nw4cExpDialog_SetNodeNameToFileName"
3468				nw4cExpDialog_NodeToOutFileName;
3469
3470			//-----------------------------------------------------------------------------
3471			// out intermediate file
3472			string $sep2 = `separator -st "in" -h 3`;
3473			radioButtonGrp -l "" -nrb 1 -cw 1 (0+$adjustSpace) -cw 2 200
3474				-l1 "Output 3D Intermediate Files" -sl 1
3475				-cc "nw4cExpDialog_OutInterFileCB"
3476				nw4cExpDialog_OutInterFile;
3477
3478			textFieldGrp -l "Output Folder" -cw2 (104+$adjustSpace) 290 -adj 2 -rat 1 "both" 2
3479				nw4cExpDialog_OutFolder;
3480			symbolButton -i "navButtonBrowse.xpm" -w 25 -h 22
3481				-c "nw4cExpDialog_OutFolderBrowserCB"
3482				nw4cExpDialog_OutFolderBrowser;
3483
3484			//-----------------------------------------------------------------------------
3485			// use CreativeStudio
3486			radioButtonGrp -l "" -nrb 1 -cw 1 (0+$adjustSpace) -cw 2 200
3487				-l1 "Use CreativeStudio"
3488				-scl nw4cExpDialog_OutInterFile
3489				-cc "nw4cExpDialog_OutInterFileCB"
3490				nw4cExpDialog_UseCreativeStudio;
3491
3492			//-----------------------------------------------------------------------------
3493			// merge cmdl file
3494			string $sep3 = `separator -st "in" -h 3`;
3495			checkBoxGrp -l "" -ncb 1 -cw 1 (0+$adjustSpace) -cw 2 103
3496				-l1 "Merge cmdl File" -v1 0
3497				-cc "nw4cExpDialog_OutInterFileCB"
3498				nw4cExpDialog_MergeCmdlFlag;
3499			textField -w 290
3500				nw4cExpDialog_MergeCmdlPath;
3501			symbolButton -i "navButtonBrowse.xpm" -w 25 -h 22
3502				-c "nw4cExpDialog_MergeCmdlBrowserCB"
3503				nw4cExpDialog_MergeCmdlBrowser;
3504
3505			//checkBoxGrp -l "" -ncb 1 -cw 1 28 -cw 2 50
3506			//	-l1 "Auto" -v1 1
3507			//	nw4cExpDialog_MergeCmdlAuto;
3508
3509			formLayout -e
3510				-af nw4cExpDialog_ProcessMode "left" 0
3511				-af nw4cExpDialog_ProcessMode "top" 4
3512				-an nw4cExpDialog_ProcessMode "right"
3513				-an nw4cExpDialog_ProcessMode "bottom"
3514				-af $sep1 "left" 0
3515				-ac $sep1 "top" 4 nw4cExpDialog_ProcessMode
3516				-af $sep1 "right" 0
3517				-an $sep1 "bottom"
3518
3519				-af nw4cExpDialog_ExportTarget "left" 0
3520				-ac nw4cExpDialog_ExportTarget "top" 4 $sep1
3521				-an nw4cExpDialog_ExportTarget "right"
3522				-an nw4cExpDialog_ExportTarget "bottom"
3523
3524				-af nw4cExpDialog_OutFileName "left" 0
3525				-ac nw4cExpDialog_OutFileName "top" 4 nw4cExpDialog_ExportTarget
3526				-an nw4cExpDialog_OutFileName "right"
3527				-an nw4cExpDialog_OutFileName "bottom"
3528				-ac nw4cExpDialog_SceneToOutFileName "left" 5 nw4cExpDialog_OutFileName
3529				-ac nw4cExpDialog_SceneToOutFileName "top" 4 nw4cExpDialog_ExportTarget
3530				-an nw4cExpDialog_SceneToOutFileName "right"
3531				-an nw4cExpDialog_SceneToOutFileName "bottom"
3532				-ac nw4cExpDialog_NodeToOutFileName "left" 5 nw4cExpDialog_SceneToOutFileName
3533				-ac nw4cExpDialog_NodeToOutFileName "top" 4 nw4cExpDialog_ExportTarget
3534				-an nw4cExpDialog_NodeToOutFileName "right"
3535				-an nw4cExpDialog_NodeToOutFileName "bottom"
3536				-af $sep2 "left" 0
3537				-ac $sep2 "top" 4 nw4cExpDialog_OutFileName
3538				-af $sep2 "right" 0
3539				-an $sep2 "bottom"
3540
3541				-af nw4cExpDialog_OutInterFile "left" 0
3542				-ac nw4cExpDialog_OutInterFile "top" 4 $sep2
3543				-an nw4cExpDialog_OutInterFile "right"
3544				-an nw4cExpDialog_OutInterFile "bottom"
3545
3546				-af nw4cExpDialog_OutFolder "left" 0
3547				-ac nw4cExpDialog_OutFolder "top" 4 nw4cExpDialog_OutInterFile
3548				-ac nw4cExpDialog_OutFolder "right" 5 nw4cExpDialog_OutFolderBrowser
3549				-an nw4cExpDialog_OutFolder "bottom"
3550				-an nw4cExpDialog_OutFolderBrowser "left"
3551				-ac nw4cExpDialog_OutFolderBrowser "top" 4 nw4cExpDialog_OutInterFile
3552				-af nw4cExpDialog_OutFolderBrowser "right" 46
3553				-an nw4cExpDialog_OutFolderBrowser "bottom"
3554
3555				-af nw4cExpDialog_UseCreativeStudio "left" 0
3556				-ac nw4cExpDialog_UseCreativeStudio "top" 4 nw4cExpDialog_OutFolder
3557				-an nw4cExpDialog_UseCreativeStudio "right"
3558				-an nw4cExpDialog_UseCreativeStudio "bottom"
3559				-af $sep3 "left" 0
3560				-ac $sep3 "top" 4 nw4cExpDialog_UseCreativeStudio
3561				-af $sep3 "right" 0
3562				-an $sep3 "bottom"
3563
3564				-af nw4cExpDialog_MergeCmdlFlag "left" 0
3565				-ac nw4cExpDialog_MergeCmdlFlag "top" (4+3) $sep3
3566				-an nw4cExpDialog_MergeCmdlFlag "right"
3567				-an nw4cExpDialog_MergeCmdlFlag "bottom"
3568				-ac nw4cExpDialog_MergeCmdlPath "left" 2 nw4cExpDialog_MergeCmdlFlag
3569				-ac nw4cExpDialog_MergeCmdlPath "top" 4 $sep3
3570				-ac nw4cExpDialog_MergeCmdlPath "right" 5 nw4cExpDialog_MergeCmdlBrowser
3571				-af nw4cExpDialog_MergeCmdlPath "bottom" 4
3572				-an nw4cExpDialog_MergeCmdlBrowser "left"
3573				-ac nw4cExpDialog_MergeCmdlBrowser "top" 4 $sep3
3574				-af nw4cExpDialog_MergeCmdlBrowser "right" 46
3575				-an nw4cExpDialog_MergeCmdlBrowser "bottom"
3576
3577				//-af nw4cExpDialog_MergeCmdlAuto "left" 0
3578				//-ac nw4cExpDialog_MergeCmdlAuto "top" 4 nw4cExpDialog_MergeCmdlPath
3579				//-an nw4cExpDialog_MergeCmdlAuto "right"
3580				//-af nw4cExpDialog_MergeCmdlAuto "bottom" 4
3581			$outForm;
3582		setParent ..; // formLayout
3583	setParent ..; // frameLayout
3584
3585	//-----------------------------------------------------------------------------
3586	// general
3587	frameLayout -l "General Options" -cll 1 -cl 0 -bv 1 -bs "etchedIn";
3588		columnLayout -adj 1 -rs 4;
3589		rowColumnLayout -nc 2 -cw 1 (215 + $adjustSpace) -cw 2 190;
3590			floatFieldGrp -l "Magnify" -nf 1 -cw 1 (140 + $adjustSpace) -cw 2 60
3591				-v1 1.0 -pre 4
3592				-cc "nw4cExpDialog_MagnifyCB"
3593				nw4cExpDialog_Magnify;
3594			text -l ""; // dummy
3595			//optionMenuGrp -l "Texture Matrix" -cw 1 120 -rat 1 "both" 4
3596			//	nw4cExpDialog_TexMatrixMode;
3597			//	menuItem -l "Maya";
3598			//	menuItem -l "3dsmax";
3599		setParent ..; // rowColumnLayout
3600		rowColumnLayout -nc 4 -cw 1 (325 + $adjustSpace + $afterMaya2011Adjust * 25) -cw 2 50 -cw 3 5 -cw 4 50;
3601			radioButtonGrp -l "Start / End Frame" -nrb 3
3602				-cw4 160 50 80 65
3603				-rat 2 "both" 0
3604				-rat 3 "both" 0
3605				-rat 4 "both" 0
3606				-la3 "All" "Playback" "Range" -sl 1
3607				-cc "nw4cExpDialog_FrameRangeCB"
3608				nw4cExpDialog_FrameRange;
3609			intField -v 1
3610				-cc "nw4cExpDialog_FrameStartEndCB"
3611				nw4cExpDialog_StartFrame;
3612			text -l ""; // dummy
3613			intField -v 100
3614				-cc "nw4cExpDialog_FrameStartEndCB"
3615				nw4cExpDialog_EndFrame;
3616		setParent ..; // rowColumnLayout
3617		checkBoxGrp -l "" -ncb 1 -cw 1 (140+$adjustSpace) -cw 2 120
3618			-l1 "Remove Namespace" -v1 0
3619			nw4cExpDialog_RemoveNamespace;
3620		setParent ..; // columnLayout
3621	setParent ..; // frameLayout
3622
3623	//-----------------------------------------------------------------------------
3624	// file selection
3625	frameLayout -l "Output File Selection" -cll 1 -cl 0 -bv 1 -bs "etchedIn";
3626		string $form = `formLayout`;
3627			checkBoxGrp -l "Model Data" -ncb 1 -l1 "[.cmdl]" -v1 1
3628				-cw 1 140 -cw 2 60
3629				-cc1 "nw4cExpDialog_ModelCB" nw4cExpDialog_CmdlFileOut;
3630			checkBoxGrp -l "Texture Data" -ncb 1 -l1 "[.ctex]" -v1 1
3631				-cw 1 140 -cw 2 60
3632				nw4cExpDialog_CtexFileOut;
3633			checkBoxGrp -l "Model Animation Data" -ncb 1 -l1 "[.cmdla]" -v1 0
3634				-cw 1 140 -cw 2 60
3635				-cc "nw4cExpDialog_AnimCB" nw4cExpDialog_CmdlaFileOut;
3636			checkBoxGrp -l "Skeletal Animation Data" -ncb 1 -l1 "[.cskla]" -v1 0
3637				-cw 1 140 -cw 2 60
3638				-cc "nw4cExpDialog_AnimCB" nw4cExpDialog_CsklaFileOut;
3639			checkBoxGrp -l "Material Animation Data" -ncb 1 -l1 "[.cmata]" -v1 0
3640				-cw 1 (140) -cw 2 60
3641				-cc "nw4cExpDialog_AnimCB" nw4cExpDialog_CmataFileOut;
3642			if ($useCustomUI == 1)
3643			{
3644				// �J�X�^�� UI ���g�p����ꍇ�̓}�e���A���A�j���[�V������v�f�i�J���[�A
3645				// �e�N�X�`���p�^�[���A�e�N�X�`��SRT�j���ɏo�͐ݒ���s���B
3646				checkBoxGrp -l "Material Color Animation Data" -ncb 1 -l1 "[.cmcla]" -v1 0
3647					-cw 1 (170 + $afterMaya2011Adjust * 20)  -cw 2 60
3648					-cc "nw4cExpDialog_AnimCB" nw4cExpDialog_CmclaFileOut;
3649				checkBoxGrp -l "Texture Pattern Animation Data" -ncb 1 -l1 "[.cmtpa]" -v1 0
3650					-cw 1 (170 + $afterMaya2011Adjust * 20) -cw 2 60
3651					-cc "nw4cExpDialog_AnimCB" nw4cExpDialog_CmtpaFileOut;
3652				checkBoxGrp -l "Texture SRT Animation Data" -ncb 1 -l1 "[.cmtsa]" -v1 0
3653					-cw 1 (170 + $afterMaya2011Adjust * 20) -cw 2 60
3654					-cc "nw4cExpDialog_AnimCB" nw4cExpDialog_CmtsaFileOut;
3655			}
3656			checkBoxGrp -l "Camera Data" -ncb 1 -l1 "[.ccam]" -v1 0
3657				-cw 1 140 -cw 2 60
3658				-cc "nw4cExpDialog_AnimCB" nw4cExpDialog_CcamFileOut;
3659			checkBoxGrp -l "Light Data" -ncb 1 -l1 "[.clgt]" -v1 0
3660				-cw 1 140 -cw 2 60
3661				-cc "nw4cExpDialog_AnimCB" nw4cExpDialog_ClgtFileOut;
3662			checkBoxGrp -l "Environment Data" -ncb 1 -l1 "[.cenv]" -v1 0
3663				-cw 1 (140) -cw 2 60
3664				-cc "nw4cExpDialog_ProcessModeCB" nw4cExpDialog_CenvFileOut;
3665			button -l "Search Animation" -w 104
3666				-c "nw4cExpDialog_SearchAnim"
3667				nw4cExpDialog_SearchAnimBtn;
3668		setParent ..; // formLayout
3669		if ($useCustomUI == 1)
3670		{
3671			// �}�e���A���A�j���[�V�����������ďo�͂���J�X�^�� UI ���g�p����ꍇ��
3672			// �o�̓t�@�C���ݒ�̔z�u���s���B
3673			formLayout -e
3674				-af nw4cExpDialog_CmdlFileOut "left" $adjustSpace
3675				-af nw4cExpDialog_CmdlFileOut "top" 4
3676				-an nw4cExpDialog_CmdlFileOut "right"
3677				-an nw4cExpDialog_CmdlFileOut "bottom"
3678
3679				-af nw4cExpDialog_CtexFileOut "left" $adjustSpace
3680				-ac nw4cExpDialog_CtexFileOut "top" 4 nw4cExpDialog_CmdlFileOut
3681				-an nw4cExpDialog_CtexFileOut "right"
3682				-an nw4cExpDialog_CtexFileOut "bottom"
3683
3684				-af nw4cExpDialog_CmdlaFileOut "left" $adjustSpace
3685				-ac nw4cExpDialog_CmdlaFileOut "top" 4 nw4cExpDialog_CtexFileOut
3686				-an nw4cExpDialog_CmdlaFileOut "right"
3687				-an nw4cExpDialog_CmdlaFileOut "bottom"
3688
3689				-af nw4cExpDialog_CsklaFileOut "left" $adjustSpace
3690				-ac nw4cExpDialog_CsklaFileOut "top" 4 nw4cExpDialog_CmdlaFileOut
3691				-an nw4cExpDialog_CsklaFileOut "right"
3692				-an nw4cExpDialog_CsklaFileOut "bottom"
3693
3694				-af nw4cExpDialog_CcamFileOut "left" $adjustSpace
3695				-ac nw4cExpDialog_CcamFileOut "top" 4 nw4cExpDialog_CsklaFileOut
3696				-an nw4cExpDialog_CcamFileOut "right"
3697				-an nw4cExpDialog_CcamFileOut "bottom"
3698
3699				-af nw4cExpDialog_ClgtFileOut "left" $adjustSpace
3700				-ac nw4cExpDialog_ClgtFileOut "top" 4 nw4cExpDialog_CcamFileOut
3701				-an nw4cExpDialog_ClgtFileOut "right"
3702				-an nw4cExpDialog_ClgtFileOut "bottom"
3703
3704				-af nw4cExpDialog_CmataFileOut "left" (270 + $adjustSpace + $afterMaya2011Adjust * 20)
3705				-af nw4cExpDialog_CmataFileOut "top" 4
3706				-an nw4cExpDialog_CmataFileOut "right"
3707				-an nw4cExpDialog_CmataFileOut "bottom"
3708
3709				-af nw4cExpDialog_CmclaFileOut "left" (240 + $adjustSpace + $afterMaya2011Adjust * 0)
3710				-ac nw4cExpDialog_CmclaFileOut "top" 4 nw4cExpDialog_CmataFileOut
3711				-an nw4cExpDialog_CmclaFileOut "right"
3712				-an nw4cExpDialog_CmclaFileOut "bottom"
3713
3714				-af nw4cExpDialog_CmtpaFileOut "left" (240 + $adjustSpace + $afterMaya2011Adjust * 0)
3715				-ac nw4cExpDialog_CmtpaFileOut "top" 4 nw4cExpDialog_CmclaFileOut
3716				-an nw4cExpDialog_CmtpaFileOut "right"
3717				-an nw4cExpDialog_CmtpaFileOut "bottom"
3718
3719				-af nw4cExpDialog_CmtsaFileOut "left" (240 + $adjustSpace + $afterMaya2011Adjust * 0)
3720				-ac nw4cExpDialog_CmtsaFileOut "top" 4 nw4cExpDialog_CmtpaFileOut
3721				-an nw4cExpDialog_CmtsaFileOut "right"
3722				-an nw4cExpDialog_CmtsaFileOut "bottom"
3723
3724				-af nw4cExpDialog_CenvFileOut "left" (270 + $adjustSpace + $afterMaya2011Adjust * 20)
3725				-ac nw4cExpDialog_CenvFileOut "top" 4 nw4cExpDialog_CmtsaFileOut
3726				-an nw4cExpDialog_CenvFileOut "right"
3727				-an nw4cExpDialog_CenvFileOut "bottom"
3728
3729				-ac nw4cExpDialog_SearchAnimBtn "left" 32 nw4cExpDialog_CenvFileOut
3730				-af nw4cExpDialog_SearchAnimBtn "top" 4
3731				-an nw4cExpDialog_SearchAnimBtn "right"
3732				-an nw4cExpDialog_SearchAnimBtn "bottom"
3733				$form;
3734		}
3735		else
3736		{
3737			// �J�X�^�� UI ���g�p�����Ƀ}�e���A���A�j���[�V������ .cmata �t�@�C���ɂ܂Ƃ߂ďo�͂���
3738			// �ꍇ�̏o�̓t�@�C���ݒ�̔z�u���s���B
3739			formLayout -e
3740				-af nw4cExpDialog_CmdlFileOut "left" $adjustSpace
3741				-af nw4cExpDialog_CmdlFileOut "top" 4
3742				-an nw4cExpDialog_CmdlFileOut "right"
3743				-an nw4cExpDialog_CmdlFileOut "bottom"
3744
3745				-af nw4cExpDialog_CtexFileOut "left" $adjustSpace
3746				-ac nw4cExpDialog_CtexFileOut "top" 4 nw4cExpDialog_CmdlFileOut
3747				-an nw4cExpDialog_CtexFileOut "right"
3748				-an nw4cExpDialog_CtexFileOut "bottom"
3749
3750				-af nw4cExpDialog_CmdlaFileOut "left" $adjustSpace
3751				-ac nw4cExpDialog_CmdlaFileOut "top" 4 nw4cExpDialog_CtexFileOut
3752				-an nw4cExpDialog_CmdlaFileOut "right"
3753				-an nw4cExpDialog_CmdlaFileOut "bottom"
3754
3755				-af nw4cExpDialog_CsklaFileOut "left" ($adjustSpace)
3756				-ac nw4cExpDialog_CsklaFileOut "top" 4 nw4cExpDialog_CmdlaFileOut
3757				-an nw4cExpDialog_CsklaFileOut "right"
3758				-an nw4cExpDialog_CsklaFileOut "bottom"
3759
3760				-af nw4cExpDialog_CmataFileOut "left" (220 + $adjustSpace + $afterMaya2011Adjust * 20)
3761				-af nw4cExpDialog_CmataFileOut "top" 4
3762				-an nw4cExpDialog_CmataFileOut "right"
3763				-an nw4cExpDialog_CmataFileOut "bottom"
3764
3765				-af nw4cExpDialog_CcamFileOut "left" (220 + $adjustSpace + $afterMaya2011Adjust * 20)
3766				-ac nw4cExpDialog_CcamFileOut "top" 4 nw4cExpDialog_CmataFileOut
3767				-an nw4cExpDialog_CcamFileOut "right"
3768				-an nw4cExpDialog_CcamFileOut "bottom"
3769
3770				-af nw4cExpDialog_ClgtFileOut "left" (220 + $adjustSpace + $afterMaya2011Adjust * 20)
3771				-ac nw4cExpDialog_ClgtFileOut "top" 4 nw4cExpDialog_CcamFileOut
3772				-an nw4cExpDialog_ClgtFileOut "right"
3773				-an nw4cExpDialog_ClgtFileOut "bottom"
3774
3775				-af nw4cExpDialog_CenvFileOut "left" (220 + $adjustSpace + $afterMaya2011Adjust * 20)
3776				-ac nw4cExpDialog_CenvFileOut "top" 4 nw4cExpDialog_ClgtFileOut
3777				-an nw4cExpDialog_CenvFileOut "right"
3778				-af nw4cExpDialog_CenvFileOut "bottom" 4
3779
3780				-ac nw4cExpDialog_SearchAnimBtn "left" 32 nw4cExpDialog_CenvFileOut
3781				-af nw4cExpDialog_SearchAnimBtn "top" 4
3782				-an nw4cExpDialog_SearchAnimBtn "right"
3783				-an nw4cExpDialog_SearchAnimBtn "bottom"
3784				$form;
3785		}
3786	setParent ..; // frameLayout
3787	control -e -vis 0 nw4cExpDialog_SearchAnimBtn; // (debug)
3788
3789	//-----------------------------------------------------------------------------
3790	// optimization
3791	frameLayout -l "Optimization Options" -cll 1 -cl 0 -bv 1 -bs "etchedIn";
3792		columnLayout -adj 1 -rs 4;
3793
3794		optionMenuGrp -l "Compress Node" -cw 1 120
3795			-rat 1 "both" 4 -cw 1 (140 + $adjustSpace) -cw 2 150
3796			-cc "nw4cExpDialog_CompressNodeCB"
3797			nw4cExpDialog_CompressNode;
3798			menuItem -l "None";
3799			menuItem -l "Cull Useless Node";
3800			menuItem -l "Cull Uninfluential Node";
3801			menuItem -l "Unite Compressible Node";
3802			menuItem -l "Unite All Node";
3803			//menuItem -l "Merge Useless Node";
3804
3805		optionMenuGrp -l "Compress Material" -cw 1 110
3806			-rat 1 "both" 4 -cw 1 (140 + $adjustSpace) -cw 2 150
3807			nw4cExpDialog_CompressMaterial;
3808			menuItem -l "None";
3809			menuItem -l "Compress Same Material";
3810			//checkBox -l "Combine Polygon" -v 0
3811			//	nw4cExpDialog_CombinePolygon;
3812		rowColumnLayout -nc 2 -cw 1 (250 + $adjustSpace + $afterMaya2011Adjust * 30) -cw 2 300;
3813			checkBoxGrp -l "" -ncb 1 -cw 1 (140 + $adjustSpace) -cw 2 120
3814				-l1 "Optimize Primitive" -v1 1
3815				nw4cExpDialog_OptimizePrimitive;
3816
3817			checkBoxGrp -l "" -ncb 1 -cw 1 (34 - $afterMaya2011Adjust * 20) -cw 2 220
3818				-l1 "Disable SkeletalModel-Simplification" -v1 0
3819				nw4cExpDialog_DisableSkiModelSimplification;
3820		setParent ..; // rowColumnLayout
3821
3822		//checkBoxGrp -l "" -ncb 1 -cw 1 100 -cw 2 160
3823		//	-l1 "Delete Useless Vertex Data" -v1 0
3824		//	nw4cExpDialog_DelUselessVtxData;
3825
3826		setParent ..; // columnLayout
3827	setParent ..; // frameLayout
3828
3829	//-----------------------------------------------------------------------------
3830	// quantization
3831	frameLayout -l "Quantization Options" -cll 1 -cl 0 -bv 1 -bs "etchedIn";
3832		columnLayout -adj 1 -rs 4;
3833		rowColumnLayout -nc 3 -cw 1 (200+$adjustSpace + $afterMaya2011Adjust * 10)
3834			-cw 2 (164 + $afterMaya2011Adjust * 10) -cw 3 (164 + $afterMaya2011Adjust * 10);
3835			optionMenuGrp -l "Position" -cw 1 (140 + $adjustSpace)
3836				nw4cExpDialog_QuantPos;
3837				menuItem -l "Float";
3838				menuItem -l "Short";
3839				menuItem -l "Byte";
3840			optionMenuGrp -l "Normal" -cw 1 92
3841				nw4cExpDialog_QuantNrm;
3842				menuItem -l "Float";
3843				menuItem -l "Short";
3844				menuItem -l "Byte";
3845			optionMenuGrp -l "Tex Coord" -cw 1 78
3846				nw4cExpDialog_QuantTex;
3847				menuItem -l "Float";
3848				menuItem -l "Short";
3849				menuItem -l "Byte";
3850		setParent ..; // rowColumnLayout
3851		setParent ..; // columnLayout
3852	setParent ..; // frameLayout
3853
3854	//-----------------------------------------------------------------------------
3855	// model
3856	frameLayout -l "Model Options" -cll 1 -cl 0 -bv 1 -bs "etchedIn";
3857		columnLayout -adj 1 -rs 4;
3858			rowColumnLayout -nc 2 -cw 1 (282+$adjustSpace + $afterMaya2011Adjust * 25) -cw 2 270;
3859				optionMenuGrp -l "Adjust Skinning" -cw 1 (140 + $adjustSpace)
3860					-rat 1 "both" 4
3861					nw4cExpDialog_AdjustSkinning;
3862					menuItem -l "None If Possible";
3863					menuItem -l "Rigid Skinning";
3864
3865				optionMenuGrp -l "Mesh Visibility Mode" -cw 1 120
3866					-rat 1 "both" 4
3867					nw4cExpDialog_MeshVisibilityMode;
3868					menuItem -l "Bind By Index";
3869					menuItem -l "Bind By Name";
3870			setParent ..; // rowColumnLayout
3871
3872			rowColumnLayout -nc 2 -cw 1 (285+$adjustSpace + $afterMaya2011Adjust * 29) -cw 2 240;
3873				checkBoxGrp -l "" -ncb 1 -cw 1 (140 + $adjustSpace)
3874					-l1 "Non-Uniform Scale" -v1 0
3875					nw4cExpDialog_NonUniformScale;
3876
3877				intFieldGrp -nf 1 -l "Max Reserved Uniform Registers" -cw2 180 45
3878					-v1 0 -cc "nw4cExpDialog_MaxReservedUniformRegistersCB"
3879					nw4cExpDialog_MaxReservedUniformRegisters;
3880			setParent ..; // rowColumnLayout
3881		setParent ..; // columnLayout
3882	setParent ..; // frameLayout
3883
3884	//-----------------------------------------------------------------------------
3885	// anim
3886	frameLayout -l "Animation Options" -cll 1 -cl 0 -bv 1 -bs "etchedIn";
3887		columnLayout -adj 1 -rs 4;
3888		rowColumnLayout -nc 3 -cw 1 (283+$adjustSpace + $afterMaya2011Adjust * 21) -cw 2 160 -cw 3 100;
3889			checkBoxGrp -l "" -ncb 1 -cw 1 (140+$adjustSpace)
3890				-l1 "Bake All Animation" -v1 1
3891				nw4cExpDialog_BakeAll;
3892			optionMenuGrp -l "Frame Precision" -cw 1 100
3893				nw4cExpDialog_FramePrecision;
3894				menuItem -l "1.0";
3895				menuItem -l "0.5";
3896				menuItem -l "0.2";
3897				menuItem -l "0.1";
3898			checkBoxGrp -l "" -ncb 1 -cw 1 44 -cw 2 100
3899				-l1 "Loop" -v1 0
3900				nw4cExpDialog_LoopAnim;
3901		setParent ..; // rowColumnLayout
3902		rowColumnLayout -nc 2 -cw 1 (270+$adjustSpace) -cw 2 200;
3903			checkBoxGrp -l "" -ncb 1 -cw 1 (140+$adjustSpace) -cw 2 120
3904				-l1 "Frame Format" -v1 0
3905				-cc "nw4cExpDialog_AnimCB"
3906				nw4cExpDialog_FrameFormat;
3907			text -l ""; // dummy
3908//			checkBoxGrp -l "" -ncb 1 -cw 1 1
3909//				-l1 "Keep At Least One Key" -v1 0
3910//				nw4cExpDialog_KeepAtLeastOneKey;
3911		setParent ..; // rowColumnLayout
3912
3913		intSliderGrp -l "Scale Quantize Quality"
3914			-cw 1 (140+$adjustSpace) -cw 2 45 -cw 3 300
3915			-min 0 -max 9 -v 9 -adj 0
3916			nw4cExpDialog_ScaleQuantizeQuality;
3917
3918		intSliderGrp -l "Rotate Quantize Quality"
3919			-cw 1 (140+$adjustSpace) -cw 2 45 -cw 3 300
3920			-min 0 -max 9 -v 9 -adj 0
3921			nw4cExpDialog_RotateQuantizeQuality;
3922
3923		intSliderGrp -l "Translate Quantize Quality"
3924			-cw 1 (140+$adjustSpace) -cw 2 45 -cw 3 300
3925			-min 0 -max 9 -v 9 -adj 0
3926			nw4cExpDialog_TranslateQuantizeQuality;
3927
3928		setParent ..; // columnLayout
3929	setParent ..; // frameLayout
3930
3931	//-----------------------------------------------------------------------------
3932	// tolerance
3933	frameLayout -l "Tolerance Options" -cll 1 -cl 0 -bv 1 -bs "etchedIn";
3934		columnLayout -adj 1 -rs 4;
3935		string $form = `formLayout -h 75`;
3936			// create control in tab order
3937			floatFieldGrp -nf 1 -l "Node Translate" -cw2 140 45
3938				-pre 4 -v1 0.01
3939				-cc "nw4cExpDialog_ToleranceSRTCB \"nw4cExpDialog_TolT\""
3940				nw4cExpDialog_TolT;
3941			floatFieldGrp -nf 1 -l "Node Rotate" -cw2 140 45
3942				-pre 4 -v1 0.1
3943				-cc "nw4cExpDialog_ToleranceSRTCB \"nw4cExpDialog_TolR\""
3944				nw4cExpDialog_TolR;
3945			floatFieldGrp -nf 1 -l "Node Scale" -cw2 140 45
3946				-pre 4 -v1 0.1
3947				-cc "nw4cExpDialog_ToleranceSRTCB \"nw4cExpDialog_TolS\""
3948				nw4cExpDialog_TolS;
3949
3950			floatFieldGrp -nf 1 -l "Texture Translate" -cw2 100 45
3951				-pre 4 -v1 0.01
3952				-cc "nw4cExpDialog_ToleranceSRTCB \"nw4cExpDialog_TolTexT\""
3953				nw4cExpDialog_TolTexT;
3954			floatFieldGrp -nf 1 -l "Texture Rotate" -cw2 100 45
3955				-pre 4 -v1 0.1
3956				-cc "nw4cExpDialog_ToleranceSRTCB \"nw4cExpDialog_TolTexR\""
3957				nw4cExpDialog_TolTexR;
3958			floatFieldGrp -nf 1 -l "Texture Scale" -cw2 100 45
3959				-pre 4 -v1 0.1
3960				-cc "nw4cExpDialog_ToleranceSRTCB \"nw4cExpDialog_TolTexS\""
3961				nw4cExpDialog_TolTexS;
3962
3963			floatFieldGrp -nf 1 -l "Color" -cw2 60 45
3964				-pre 4 -v1 0.001
3965				-cc "nw4cExpDialog_ToleranceColorCB \"nw4cExpDialog_TolC\""
3966				nw4cExpDialog_TolC;
3967		setParent ..; // formLayout
3968		// layout control
3969		formLayout -e -w 440
3970			-af nw4cExpDialog_TolT "left" (0+$adjustSpace)
3971			-af nw4cExpDialog_TolT "top" 0
3972			-an nw4cExpDialog_TolT "right"
3973			-an nw4cExpDialog_TolT "bottom"
3974
3975			-af nw4cExpDialog_TolR "left" (0+$adjustSpace)
3976			-af nw4cExpDialog_TolR "top" 25
3977			-an nw4cExpDialog_TolR "right"
3978			-an nw4cExpDialog_TolR "bottom"
3979
3980			-af nw4cExpDialog_TolS "left" (0+$adjustSpace)
3981			-af nw4cExpDialog_TolS "top" 50
3982			-an nw4cExpDialog_TolS "right"
3983			-an nw4cExpDialog_TolS "bottom"
3984
3985			-af nw4cExpDialog_TolTexT "left" (210+$adjustSpace)
3986			-af nw4cExpDialog_TolTexT "top" 0
3987			-an nw4cExpDialog_TolTexT "right"
3988			-an nw4cExpDialog_TolTexT "bottom"
3989
3990			-af nw4cExpDialog_TolTexR "left" (210+$adjustSpace)
3991			-af nw4cExpDialog_TolTexR "top" 25
3992			-an nw4cExpDialog_TolTexR "right"
3993			-an nw4cExpDialog_TolTexR "bottom"
3994
3995			-af nw4cExpDialog_TolTexS "left" (210+$adjustSpace)
3996			-af nw4cExpDialog_TolTexS "top" 50
3997			-an nw4cExpDialog_TolTexS "right"
3998			-an nw4cExpDialog_TolTexS "bottom"
3999
4000			-af nw4cExpDialog_TolC "left" (420+$adjustSpace)
4001			-af nw4cExpDialog_TolC "top" 0
4002			-an nw4cExpDialog_TolC "right"
4003			-an nw4cExpDialog_TolC "bottom"
4004			$form;
4005		setParent ..; // columnLayout
4006	setParent ..; // frameLayout
4007
4008	//-----------------------------------------------------------------------------
4009	// close layout
4010	setParent ..;	// columnLayout
4011	setParent ..;	// scrollLayout
4012
4013	//-----------------------------------------------------------------------------
4014	// setting menu
4015	CreateSettingMenu($parent);
4016
4017	//-----------------------------------------------------------------------------
4018	// end
4019	waitCursor -st 0;
4020	setUITemplate -ppt;
4021
4022	//-----------------------------------------------------------------------------
4023	// set help tag to save window size
4024	setOptionBoxHelpTag("nw4cExpDialog");
4025
4026	//-----------------------------------------------------------------------------
4027	// set button & menu command
4028	string $applyBtn = getOptionBoxApplyBtn();
4029	button -e -l "Export" -c "nw4cExpDialog_ExportCB" $applyBtn;
4030
4031	string $saveBtn = getOptionBoxSaveBtn();
4032	button -e -c "nw4cExpDialog_SaveSettingsCB" $saveBtn;
4033
4034	string $resetBtn = getOptionBoxResetBtn();
4035	button -e -c "nw4cExpDialog_ResetOptionVariable" $resetBtn;
4036
4037	string $helpMenu = getOptionBoxHelpItem();
4038	menuItem -e -l "Help on NW4C Export..."
4039		-c "NW4C_ShowHelp \"html/export.html\" \"\"" $helpMenu;
4040
4041	//-----------------------------------------------------------------------------
4042	// set option cotrol
4043	SetOptionControl();
4044
4045	//-----------------------------------------------------------------------------
4046	// show option box
4047	setFocus(getOptionBoxApplyAndCloseBtn());
4048	showOptionBox();
4049
4050	return 1;
4051}
4052
4053/******************************************************************************
4054	main
4055******************************************************************************/
4056global proc NW4C_ExpDialog()
4057{
4058	//-----------------------------------------------------------------------------
4059	// load plugin
4060	LoadPlugin();
4061
4062	//-----------------------------------------------------------------------------
4063	// open option window
4064	OpenOptionWindow();
4065}
4066
4067/******************************************************************************
4068	export direct
4069******************************************************************************/
4070global proc NW4C_ExpDirect()
4071{
4072	//-----------------------------------------------------------------------------
4073	// load plugin
4074	LoadPlugin();
4075
4076	//-----------------------------------------------------------------------------
4077	// init option variable
4078	SetOptionVariable(0);
4079
4080	//-----------------------------------------------------------------------------
4081	// export
4082	DoExportCmd(0);
4083}
4084
4085/******************************************************************************
4086	export direct force (no overwrite check)
4087******************************************************************************/
4088global proc NW4C_ExpDirectForce()
4089{
4090	//-----------------------------------------------------------------------------
4091	// load plugin
4092	LoadPlugin();
4093
4094	//-----------------------------------------------------------------------------
4095	// init option variable
4096	SetOptionVariable(0);
4097
4098	//-----------------------------------------------------------------------------
4099	// export
4100	DoExportCmd(1);
4101}
4102