source: OGRE/trunk/ogrenew/Tools/MayaExport/mel/exporter/OgreExporter.mel @ 657

Revision 657, 32.2 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1global proc UpdateGUI()
2{
3        // mesh controls
4        string $xml_val = `checkBox -query -v meshExportXML`;
5       
6        if($xml_val == "1")
7        {
8                checkBox -edit -en true meshBoneAssign;
9                checkBox -edit -en true meshNormals;
10                checkBox -edit -en true meshDiffuseColor;
11                checkBox -edit -en true meshTexCoords;
12                checkBox -edit -en true meshSub;
13                checkBox -edit -en true meshBinary;
14        }
15        else
16        {
17                checkBox -edit -en false meshBoneAssign;
18                checkBox -edit -en false meshNormals;
19                checkBox -edit -en false meshDiffuseColor;
20                checkBox -edit -en false meshTexCoords;
21                checkBox -edit -en false meshSub;
22                checkBox -edit -en false meshBinary;
23        }
24       
25        // material controls
26        //string $mat_val = `checkBox -query -v materialExport`;
27       
28        //if($mat_val == "1")
29        //{
30        //      text -edit -en true materialLbl;
31        //      textField -edit -en true materialTxt;
32        //}
33        //else
34        //{
35        //      text -edit -en false materialLbl;
36        //      textField -edit -en false materialTxt;
37        //}
38       
39        // animation controls
40        string $anim_val = `checkBox -query -v animExport`;
41       
42        if($anim_val == "1")
43        {
44                checkBox -edit -en true animBinary;
45                checkBox -edit -en true animAnims;
46        }
47        else
48        {
49                checkBox -edit -en false animBinary;
50                checkBox -edit -en false animAnims;
51        }
52       
53        string $anim_in_val = `checkBox -query -v animAnims`;
54        string $anim_val = `checkBox -query -en animAnims`;
55       
56        if($anim_val == "1" && $anim_in_val == "1")
57        {
58                text -edit -en true animDefsLbl;
59                textScrollList -edit -en true animDefLst;
60       
61                text -edit -en true animAddLbl;
62                text -edit -en true animNameLbl;
63                textField -edit -en true animNameTxt;
64                text -edit -en true animStart;
65                textField -edit -en true animStartTxt;
66                text -edit -en true animEnd;
67                textField -edit -en true animEndTxt;
68                text -edit -en true animSkip;
69                textField -edit -en true animSkipTxt;
70                button -edit -en true animBttn;
71        }
72        else
73        {
74                text -edit -en false animDefsLbl;
75                textScrollList -edit -en false animDefLst;
76       
77                text -edit -en false animAddLbl;
78                text -edit -en false animNameLbl;
79                textField -edit -en false animNameTxt;
80                text -edit -en false animStart;
81                textField -edit -en false animStartTxt;
82                text -edit -en false animEnd;
83                textField -edit -en false animEndTxt;
84                text -edit -en false animSkip;
85                textField -edit -en false animSkipTxt;
86                button -edit -en false animBttn;
87        }
88}
89
90global proc AddAnim()
91{
92        string $name = `textField -query -text animNameTxt`;
93       
94        if($name != "")
95        {
96                int $num_items = `textScrollList -query -numberOfItems animDefLst`;
97               
98                int $i;
99                for($i = 0; $i < $num_items; $i++)
100                {
101                        int $s = $i + 1;
102                        textScrollList -edit -sii $s animDefLst;
103                        string $anims[] = `textScrollList -query -si animDefLst`;
104                        string $buffer[];
105                        tokenize $anims[$i] "\" " $buffer;
106                        int $compare = `strcmp $name $buffer[0]`;
107                        if($compare == 0)
108                        {
109                                textScrollList -edit -da animDefLst;
110                                textScrollList -edit -da animDefLst;
111                                error -sl false "Animation name has to be unique";
112                        }
113                }
114               
115                string $step_val = `textField -query -text animSkipTxt`;
116                string $start_val = `textField -query -text animStartTxt`;
117                string $end_val = `textField -query -text animEndTxt`;
118               
119                if($step_val == "")
120                        error -sl false "Step value cannot be Zero";
121                       
122                string $new_anim = "\"" + $name + " " + $start_val + " " + $end_val + " " + $step_val + "\"";
123                textScrollList -edit -append $new_anim -da animDefLst;
124               
125                textField -edit -text "" animNameTxt;
126                textField -edit -text "1" animSkipTxt;
127                textField -edit -text "0" animStartTxt;
128                textField -edit -text "0" animEndTxt;
129               
130                button -edit -en false animRBttn;       
131                textScrollList -edit -da animDefLst;   
132        }
133        else
134                error -sl false "No Name for the animation specified"; 
135}
136
137global proc PreRemoveAnim()
138{
139        string $obj[] = `textScrollList -query -si animDefLst`;
140       
141        if($obj[0] != "")
142                button -edit -en true animRBttn;
143        else
144                button -edit -en true animRBttn;
145}
146
147global proc RemoveAnim()
148{
149        string $obj[] = `textScrollList -query -si animDefLst`;
150        textScrollList -edit -ri $obj[0] animDefLst;
151        button -edit -en false animRBttn;       
152        textScrollList -edit -da animDefLst;
153}
154
155global proc GetOutputDir()
156{
157        string $directory = `OgreGetFolder`;
158        $directory = fromNativePath($directory);
159        $directory += "/";
160        textField -edit -text $directory exportOutputTxt;
161}
162
163global proc WriteSettings()
164{
165        // Export parameters
166        fileInfo "Ogre_OutputDir" `textField -query -fileName exportOutputTxt`;
167        fileInfo "Ogre_OutputFile" `textField -query -fileName exportXMLTxt`;
168        fileInfo "Ogre_ExportOption" `radioButton -query -sl exportEverything`;
169       
170        // Advanced options
171        fileInfo "Ogre_TexCoords" `radioButton -query -sl normUVs`;
172        //fileInfo "Ogre_Triangulate" `checkBox -query -v advTriangulate`;
173               
174        // Animation
175        fileInfo "Ogre_Skeleton" `checkBox -query -v animExport`;
176        fileInfo "Ogre_SkeletonBin" `checkBox -query -v animBinary`;
177        fileInfo "Ogre_IncludeAnims" `checkBox -query -v animAnims`;
178       
179        int $num_items = `textScrollList -query -numberOfItems animDefLst`;
180        string $animations;     
181        int $i;
182        for($i = 0; $i < $num_items; $i++)
183        {
184                int $s = $i + 1;
185                textScrollList -edit -sii $s animDefLst;
186                string $anims[] = `textScrollList -query -si animDefLst`;
187                string $buffer[];
188                int $numTokens = `tokenize $anims[0] "\"" $buffer`;
189                $animations += $buffer[0] + ".";                       
190        }
191        fileInfo "Ogre_Animations" $animations;
192       
193        // Material
194        fileInfo "Ogre_Material" `checkBox -query -v materialExport`;
195       
196        // Mesh
197        fileInfo "Ogre_Mesh" `checkBox -query -v meshExportXML`;
198        fileInfo "Ogre_Bone" `checkBox -query -v meshBoneAssign`;
199        fileInfo "Ogre_Normals" `checkBox -query -v meshNormals`;
200        fileInfo "Ogre_Colors" `checkBox -query -v meshDiffuseColor`;
201        fileInfo "Ogre_UVS" `checkBox -query -v meshTexCoords`;
202        fileInfo "Ogre_SubMesh" `checkBox -query -v meshBinary`;
203        fileInfo "Ogre_MeshBin" `checkBox -query -v meshSub`;           
204}
205
206global proc ReadSettings()
207{
208        // Export parameters
209       
210        string $value[] = `fileInfo -q "Ogre_OutputDir"`;
211        if($value[0] != "")
212                textField -edit -text $value[0] exportOutputTxt;
213       
214        $value = `fileInfo -q "Ogre_OutputFile"`;
215        if($value[0] != "")
216                textField -edit -text $value[0] exportXMLTxt;
217       
218        $value = `fileInfo -q "Ogre_ExportOption"`;
219       
220        if($value[0] != "")
221        {
222                if($value[0] == 1)
223                        radioButton -edit -sl exportEverything;
224                else
225                        radioButton -edit -sl exportSelected;
226        }
227               
228        // Advanced options
229       
230        $value = `fileInfo -q "Ogre_TexCoords"`;
231       
232        if($value[0] != "")
233        {
234                if($value[0] == 1)
235                        radioButton -edit -sl normUVs;
236                else
237                        radioButton -edit -sl mayaUVs;
238        }
239               
240        //$value = `fileInfo -q "Ogre_Triangulate"`;
241       
242        //if($value[0] != "")
243        //{
244        //      if($value[0] == 1)
245        //              checkBox -edit -v true advTriangulate;
246        //      else
247        //              checkBox -edit -v false advTriangulate;
248        //}
249                       
250        // Animation
251        $value = `fileInfo -q "Ogre_Skeleton"`;
252       
253        if($value[0] != "")
254        {
255                if($value[0] == 1)
256                        checkBox -edit -v true animExport;
257                else
258                        checkBox -edit -v false animExport;
259        }
260               
261        $value = `fileInfo -q "Ogre_SkeletonBin"`;
262       
263        if($value[0] != "")
264        {
265                if($value[0] == 1)
266                        checkBox -edit -v true animBinary;
267                else
268                        checkBox -edit -v false animBinary;
269        }               
270       
271        $value = `fileInfo -q "Ogre_IncludeAnims"`;
272        if($value[0] != "")
273        {
274                if($value[0] == 1)
275                        checkBox -edit -v true animAnims;
276                else
277                        checkBox -edit -v false animAnims;
278        }
279               
280        $value = `fileInfo -q "Ogre_Animations"`;
281       
282        if($value[0] != "")
283        {
284                string $buffer[];
285                int $numTokens = `tokenize $value[0] "." $buffer`;     
286                int $i;
287                for($i = 0; $i < $numTokens; $i++)
288                {
289                        string $entry = "\"" + $buffer[$i] + "\"";
290                        textScrollList -edit -append $entry animDefLst;                 
291                }
292        }
293               
294        // Material
295        $value = `fileInfo -q "Ogre_Material"`;
296        if($value[0] != "")
297        {
298                if($value[0] == 1)
299                        checkBox -edit -v true materialExport;
300                else
301                        checkBox -edit -v false materialExport;
302        }
303       
304        // Mesh
305        $value = `fileInfo -q "Ogre_Mesh"`;
306        if($value[0] != "")
307        {
308                if($value[0] == 1)
309                        checkBox -edit -v true meshExportXML;
310                else
311                        checkBox -edit -v false meshExportXML;
312        }
313       
314        $value = `fileInfo -q "Ogre_Bone"`;
315        if($value[0] != "")
316        {
317                if($value[0] == 1)
318                        checkBox -edit -v true meshBoneAssign;
319                else
320                        checkBox -edit -v false meshBoneAssign;
321        }
322       
323        $value = `fileInfo -q "Ogre_Normals"`;
324        if($value[0] != "")
325        {
326                if($value[0] == 1)
327                        checkBox -edit -v true meshNormals;
328                else
329                        checkBox -edit -v false meshNormals;
330        }
331       
332        $value = `fileInfo -q "Ogre_Colors"`;
333        if($value[0] != "")
334        {
335                if($value[0] == 1)
336                        checkBox -edit -v true meshDiffuseColor;
337                else
338                        checkBox -edit -v false meshDiffuseColor;
339        }
340               
341        $value = `fileInfo -q "Ogre_UVS"`;
342        if($value[0] != "")
343        {
344                if($value[0] == 1)
345                        checkBox -edit -v true meshTexCoords;
346                else
347                        checkBox -edit -v false meshTexCoords;
348        }
349       
350        $value = `fileInfo -q "Ogre_SubMesh"`;
351        if($value[0] != "")
352        {
353                if($value[0] == 1)
354                        checkBox -edit -v true meshBinary;
355                else
356                        checkBox -edit -v false meshBinary;
357        }
358       
359        $value = `fileInfo -q "Ogre_MeshBin"`;
360        if($value[0] != "")
361        {
362                if($value[0] == 1)
363                        checkBox -edit -v true meshSub;
364                else
365                        checkBox -edit -v false meshSub;
366        }
367       
368        UpdateGUI();
369}
370
371global proc Export()
372{
373        // flags to pass
374        // -msh (whether to export mesh or not) - done
375        // -bin (whether to export mesh to binary or not) - done
376        // -bsk (whether to export skeletion to binary or not) - done
377        // -sn  (whether to include submesh name or not) - done
378        // -mat (whether to export material or not) - done
379        // -skl (whether to export skeleton or not) - done
380        // -nrm (whether to export normals or not) - done
381        // -uv  (whether to export uvs or not) - done
382        // -col (whether to export colors or not) - done
383        // -vba (whether to export vertex bone assignments) - done
384        // -fuv (whether to flip uvs or not) - done
385        // -n (name of exported file) - done
386        // -dir (directory to export to) - done
387        // -ani (animations to export, can be many of these) - done
388       
389        // write out settings to scene file
390        WriteSettings();
391       
392        // check to see if we need to triangulate
393        //string $triangulate = `checkBox -query -v advTriangulate`;
394       
395        //if($triangulate == "1")
396        //      polyTriangulate;
397       
398        // start command
399        string $command = "OgreExport";
400       
401        // get the output file directory
402        string $dir_text = `textField -query -text exportOutputTxt`;
403       
404        if($dir_text != "")
405        {
406                $dir_text = fromNativePath($dir_text);
407                $command += " -dir \"" + $dir_text + "\"";
408        }
409        else
410                error -sl false "No Output Directory specified under Export Options";
411       
412        // get the output file name
413        string $file_text = `textField -query -text exportXMLTxt`;
414       
415        if($file_text != "")
416                $command += " -n \"" + $file_text + "\"";
417        else
418                error -sl false "No XML Filename specified under Export Options";
419       
420        // see whether or not to export mesh out       
421        string $mesh_bool = `checkBox -query -v meshExportXML`;
422       
423        // see whether or not to export materials
424        string $mat_bool = `checkBox -query -v materialExport`;
425       
426        if($mesh_bool == 1)
427        {       
428                $command += " -msh " + $mesh_bool;
429               
430                $command += " -mat " + $mat_bool;
431       
432                // see whether or not to export skeleton
433                string $skel_bool = `checkBox -query -v animExport`;
434       
435                $command += " -skl " + $skel_bool;
436       
437                // see whether or not to export normals
438                string $norm_bool = `checkBox -query -v meshNormals`;
439       
440                $command += " -nrm " + $norm_bool;
441       
442                // see whether or not to export uvs
443                string $uv_bool = `checkBox -query -v meshTexCoords`;
444       
445                $command += " -uvs " + $uv_bool;
446       
447                // see whether or not to flip uvs
448                string $uv_flip_bool = `radioButton -query -sl normUVs`;
449       
450                $command += " -fuv " + $uv_flip_bool;
451       
452                // see whether or not to export color
453                string $diff_color_bool = `checkBox -query -v meshDiffuseColor`;
454       
455                $command += " -col " + $diff_color_bool;
456       
457                // see whether or not to export bone assignments
458                string $bone_bool = `checkBox -query -v meshBoneAssign`;
459       
460                $command += " -vba " + $bone_bool;
461       
462                // see whether or not to export submeshes
463                string $subMeshes = `checkBox -query -v meshSub`;
464       
465                $command += " -sn " + $subMeshes;
466        }
467       
468        // see whether to export animation stuff
469        string $anim_exp = `checkBox -q -v animExport`;
470       
471        if($anim_exp == 1)
472        {
473                // see whether or not to include animations
474                string $anim_check = `checkBox -query -v animAnims`;
475               
476                if($anim_check == 1)
477                {
478                        // check for animations to export
479                        string $valid = `textScrollList -query -en animDefLst`;
480                       
481                        string $animations = "\"";
482                        if($valid == "1")
483                        {
484                                int $num_items = `textScrollList -query -numberOfItems animDefLst`;
485               
486                                int $i;
487                                for($i = 0; $i < $num_items; $i++)
488                                {
489                                        int $s = $i + 1;
490                                        textScrollList -edit -sii $s animDefLst;
491                                        string $anims[] = `textScrollList -query -si animDefLst`;
492                                        string $buffer[];
493                                        int $numTokens = `tokenize $anims[0] "\"" $buffer`;
494                                        $animations += $buffer[0] + " ";                       
495                                }
496                        }
497                        $animations += "\"";
498                        $command += " -ani " + $animations;
499                }
500        }
501       
502        // call and end command
503        evalEcho($command);
504       
505        string $file_path = `file -q -loc OgreExporter.mel`;
506        string $buffer[];
507        int $numTokens = `tokenize $file_path "//" $buffer`;
508        int $i;
509        $file_path = "";
510        for($i = 0; $i < $numTokens-2; $i++)
511        {
512                $file_path += $buffer[$i] + "/";               
513        }
514       
515        $file_path = fromNativePath($file_path);
516        $file_path = $file_path + "temp/";
517               
518        // see whether or not to export to binary
519        string $binary = `checkBox -query -v meshBinary`;
520       
521        if($mesh_bool && $binary)
522        {
523                //$command += " -bin " + $binary;
524                system("start " + $file_path + "OgreXMLConverter.exe " + "\"" + $dir_text + $file_text + ".mesh.xml\"");
525        }
526       
527        // see whether or not to export skeletion to binary
528        string $skl_binary = `checkBox -query -v animBinary`;
529       
530        if($anim_exp && $skl_binary)
531        {       
532                //$command += " -bsk " + $skl_binary;
533                system("start " + $file_path + "OgreXMLConverter.exe " + "\"" + $dir_text + $file_text + ".skeleton.xml\"");
534        }
535       
536        // call the material upgrader
537        if($mat_bool == 1)
538        {
539                system("start " + $file_path + "OgreMaterialUpgrade.exe " + "\"" + $dir_text + $file_text + ".material\"");
540        }
541               
542        //if($triangulate == "1")
543        //{
544                //undo;
545                //undo;
546        //}
547       
548        textScrollList -edit -da animDefLst;
549}
550
551global proc Preview()
552{
553        // write out settings to scene file
554        WriteSettings();
555       
556        // check to see if we need to triangulate
557        //string $triangulate = `checkBox -query -v advTriangulate`;
558       
559        //if($triangulate == "1")
560        //      polyTriangulate;
561       
562        // start command
563        string $command = "OgreExport";
564       
565        // get the output file directory
566        string $file_path = `file -q -loc OgreExporter.mel`;
567        string $buffer[];
568        int $numTokens = `tokenize $file_path "//" $buffer`;
569        int $i;
570        $file_path = "";
571        for($i = 0; $i < $numTokens-2; $i++)
572        {
573                $file_path += $buffer[$i] + "/";               
574        }
575        string $dir_text = $file_path;
576       
577        if($dir_text != "")
578        {
579                $dir_text = fromNativePath($dir_text);
580                $dir_text = $dir_text + "temp/";
581                $command += " -dir \"" + $dir_text + "\"";
582        }
583        else
584                error -sl false "No Output Directory specified under Export Options";
585               
586        // get the output file name
587        string $file_text = "default";
588               
589        if($file_text != "")
590                $command += " -n \"" + $file_text + "\"";
591        else
592                error -sl false "No XML Filename specified under Export Options";
593       
594        // see whether or not to export mesh out       
595        string $mesh_bool = `checkBox -query -v meshExportXML`;
596       
597        // see whether or not to export materials
598        string $mat_bool = `checkBox -query -v materialExport`;
599       
600        if($mesh_bool == 1)
601        {       
602                $command += " -msh " + $mesh_bool;
603               
604                $command += " -mat " + $mat_bool;
605       
606                // see whether or not to export skeleton
607                string $skel_bool = `checkBox -query -v animExport`;
608       
609                $command += " -skl " + $skel_bool;
610       
611                // see whether or not to export normals
612                string $norm_bool = `checkBox -query -v meshNormals`;
613       
614                $command += " -nrm " + $norm_bool;
615       
616                // see whether or not to export uvs
617                string $uv_bool = `checkBox -query -v meshTexCoords`;
618       
619                $command += " -uvs " + $uv_bool;
620       
621                // see whether or not to flip uvs
622                string $uv_flip_bool = `radioButton -query -sl normUVs`;
623       
624                $command += " -fuv " + $uv_flip_bool;
625       
626                // see whether or not to export color
627                string $diff_color_bool = `checkBox -query -v meshDiffuseColor`;
628       
629                $command += " -col " + $diff_color_bool;
630       
631                // see whether or not to export bone assignments
632                string $bone_bool = `checkBox -query -v meshBoneAssign`;
633       
634                $command += " -vba " + $bone_bool;
635       
636                // see whether or not to export submeshes
637                string $subMeshes = `checkBox -query -v meshSub`;
638       
639                $command += " -sn " + $subMeshes;
640        }
641       
642        // see whether to export animation stuff
643        string $anim_exp = `checkBox -q -v animExport`;
644       
645        if($anim_exp == 1)
646        {
647                // see whether or not to include animations
648                string $anim_check = `checkBox -query -v animAnims`;
649               
650                if($anim_check == 1)
651                {
652                        // check for animations to export
653                        string $valid = `textScrollList -query -en animDefLst`;
654                       
655                        string $animations = "\"";
656                        if($valid == "1")
657                        {
658                                int $num_items = `textScrollList -query -numberOfItems animDefLst`;
659               
660                                int $i;
661                                for($i = 0; $i < $num_items; $i++)
662                                {
663                                        int $s = $i + 1;
664                                        textScrollList -edit -sii $s animDefLst;
665                                        string $anims[] = `textScrollList -query -si animDefLst`;
666                                        string $buffer[];
667                                        int $numTokens = `tokenize $anims[0] "\"" $buffer`;
668                                        $animations += $buffer[0] + " ";                       
669                                }
670                        }
671                        $animations += "\"";
672                        $command += " -ani " + $animations;
673                }
674        }
675       
676        // tell the exporter that we are previewing and to copy the texture files
677        $command += " -p \"" + $dir_text + "\"";
678       
679        textScrollList -edit -da animDefLst;
680       
681        string $files[] = `getFileList -fld $dir_text -fs "*.jpg"`;
682        int $num_files = size($files);
683       
684        int $i;
685        for($i = 0; $i < $num_files; $i++)
686        {
687                string $file_to_delete = $dir_text + $files[$i];
688                sysFile -delete $file_to_delete;
689        }
690       
691        string $files[] = `getFileList -fld $dir_text -fs "*.bmp"`;
692        $num_files = size($files);
693       
694        for($i = 0; $i < $num_files; $i++)
695        {
696                string $file_to_delete = $dir_text + $files[$i];
697                sysFile -delete $file_to_delete;
698        }
699       
700        string $files[] = `getFileList -fld $dir_text -fs "*.gif"`;
701        $num_files = size($files);
702       
703        for($i = 0; $i < $num_files; $i++)
704        {
705                string $file_to_delete = $dir_text + $files[$i];
706                sysFile -delete $file_to_delete;
707        }
708       
709        string $files[] = `getFileList -fld $dir_text -fs "*.png"`;
710        $num_files = size($files);
711       
712        for($i = 0; $i < $num_files; $i++)
713        {
714                string $file_to_delete = $dir_text + $files[$i];
715                sysFile -delete $file_to_delete;
716        }
717       
718        string $files[] = `getFileList -fld $dir_text -fs "*.tga"`;
719        $num_files = size($files);
720       
721        for($i = 0; $i < $num_files; $i++)
722        {
723                string $file_to_delete = $dir_text + $files[$i];
724                sysFile -delete $file_to_delete;
725        }
726       
727        // call and end command
728        evalEcho($command);
729       
730        // call the material upgrader
731        if($mat_bool == 1)
732        {
733                system("start " + $dir_text + "OgreMaterialUpgrade.exe " + "\"" + $dir_text + $file_text + ".material\"");
734        }
735       
736        // see whether or not to export to binary
737        string $binary = `checkBox -query -v meshBinary`;
738       
739        if($mesh_bool && $binary)
740        {
741                //$command += " -bin " + $binary;
742                // call the xml convertor       
743                system("start " + $dir_text + "OgreXMLConverter.exe " + "\"" + $dir_text + $file_text + ".mesh.xml\"");
744        }
745       
746        // see whether or not to export skeletion to binary
747        string $skl_binary = `checkBox -query -v animBinary`;
748       
749        if($anim_exp && $skl_binary)
750        {       
751                //$command += " -bsk " + $skl_binary;
752                system("start " + $dir_text + "OgreXMLConverter.exe " + "\"" + $dir_text + $file_text + ".skeleton.xml\"");
753        }
754       
755        // call the viewer
756        system("start " + $dir_text + "OgreViewerClient.exe " + "\"" + $dir_text + $file_text + ".mesh\"");
757}
758
759global proc OgreExporter()
760{
761        if( `window -exists OgreWindow` )
762                deleteUI -window OgreWindow;
763               
764        if( !`window -exists OgreWindow` )
765        {
766                // the main window
767                string $window = `window -title "Ogre Exporter"
768                        -iconName "Ogre Exporter"
769                        -width 450
770                        -height 500
771                        -resizeToFitChildren false
772                        -minimizeButton false
773                        -maximizeButton false
774                        -sizeable false
775                        OgreWindow`;
776               
777                // the main layout for window to aloow for scrolling
778                string $mainLayout = `scrollLayout -childResizable false -p $window`;
779               
780                // the main layout ontop of the scroll layout
781                string $mainInsideLayout = `formLayout -numberOfDivisions 100 -width 413 -p $mainLayout`;
782               
783                // the frame layouts
784                string $materialFrame = `frameLayout -collapsable true -label "Materials" -collapse true -width 413 -labelVisible true -p $mainInsideLayout`;
785                string $animationFrame = `frameLayout -collapsable true -label "Animation" -collapse true -width 413 -labelVisible true -p $mainInsideLayout`;
786                string $meshFrame = `frameLayout -collapsable true -label "Mesh" -collapse true -width 413 -labelVisible true -p $mainInsideLayout`;
787                string $advancedFrame = `frameLayout -collapsable true -label "Advanced Options" -collapse true -width 413 -labelVisible true -p $mainInsideLayout`;
788                string $exportFrame = `frameLayout -collapsable true -label "Export" -collapse true -width 413 -labelVisible true -p $mainInsideLayout`;
789               
790                // formlayouts on the framelayouts
791                string $exportFormLayout = `formLayout -numberOfDivisions 100 -p $exportFrame`;
792                string $advancedFormLayout = `formLayout -numberOfDivisions 100 -p $advancedFrame`;
793                string $materialFormLayout = `formLayout -numberOfDivisions 100 -p $materialFrame`;
794                string $meshFormLayout = `formLayout -numberOfDivisions 100 -p $meshFrame`;
795                string $animationFormLayout = `formLayout -numberOfDivisions 100 -p $animationFrame`;
796               
797                // mesh controls
798                string $meshExportToXML = `checkBox -label "Export mesh to Ogre .xml file format" -cc("UpdateGUI()") -p $meshFormLayout meshExportXML`;
799                string $meshBoneAssignment = `checkBox -label "Include vertex bone assignments" -en false -p $meshFormLayout meshBoneAssign`;
800                string $meshVertexNormals = `checkBox -label "Include vertex normals" -en false -p $meshFormLayout meshNormals`;
801                string $meshDiffuseColor = `checkBox -label "Include diffuse vertex colors" -en false -p $meshFormLayout meshDiffuseColor`;
802                string $meshTextureCoords = `checkBox -label "Include texture coordinates" -en false -p $meshFormLayout meshTexCoords`;
803                string $meshToBinary = `checkBox -label "Also create binary .mesh file" -en false -p $meshFormLayout meshBinary`;
804                string $meshSubmeshNames = `checkBox -label "Include Submesh names" -en false -p $meshFormLayout meshSub`;
805               
806                // material controls
807                string $materialExportToMaterial = `checkBox -label "Export materials to Ogre .material file format" -cc("UpdateGUI()") -p $materialFormLayout materialExport`;
808                //string $materialMaterialLabel = `text -label "Material Filename:" -en false -p $materialFormLayout materialLbl`;
809                //string $materialMaterialText = `textField -width 300 -en false -p $materialFormLayout materialTxt`;
810               
811                // animation controls
812                string $animationExportToXML = `checkBox -label "Export skeleton to Ogre .xml file format" -cc("UpdateGUI()") -p $animationFormLayout animExport`;
813                string $animationToBinary = `checkBox -label "Also create binary .skeleton file" -en false -p $animationFormLayout animBinary`;
814                string $animationAnimations = `checkBox -label "Include Animations" -en false -cc("UpdateGUI()") -p $animationFormLayout animAnims`;
815                               
816                string $animationDefsLabel = `text -label "Animation Definitions:" -en false -p $animationFormLayout animDefsLbl`;
817                string $animationDefsLst = `textScrollList -allowMultiSelection false -numberOfRows 10 -w 400 -en false -sc("PreRemoveAnim()") -p $animationFormLayout animDefLst`;
818               
819                string $animationAddLabel = `text -label "Add a new animation:" -en false -p $animationFormLayout animAddLbl`;
820                string $animationAddAnimName = `text -label "Name" -en false -p $animationFormLayout animNameLbl`;
821                string $animationAddAnimNameTxt = `textField -width 175 -en false -p $animationFormLayout animNameTxt`;
822                string $animationAddAnimStart = `text -label "Start Time" -en false -p$animationFormLayout animStart`;
823                string $animationAddAnimStartTxt = `textField -width 50 -text "0" -en false -p $animationFormLayout animStartTxt`;
824                string $animationAddAnimEnd = `text -label "End Time" -en false -p $animationFormLayout animEnd`;
825                string $animationAddAnimEndTxt = `textField -width 50 -text "0" -en false -p $animationFormLayout animEndTxt`;
826                string $animationAddAnimSkip = `text -label "Step" -en false -p $animationFormLayout animSkip`;
827                string $animationAddAnimSkipTxt = `textField -width 25 -text "1" -en false -p $animationFormLayout animSkipTxt`;
828                string $aniamtionAddAnimBttn = `button -label "Add" -w 35 -en false -p $animationFormLayout -command("AddAnim()") animBttn`;
829                string $aniamtionRemoveAnimBttn = `button -label "Remove" -w 50 -en false -p $animationFormLayout -command("RemoveAnim()") animRBttn`;
830               
831               
832                // advanced controls
833                string $advancedRadioCollection = `radioCollection -p $advancedFormLayout`;
834                string $advancedMayaUVs = `radioButton -label "Maya UVs:" -select -cl $advancedRadioCollection -p $advancedFormLayout mayaUVs`;
835                string $advancedNormUVs = `radioButton -label "Normal UVs:" -cl $advancedRadioCollection -p $advancedFormLayout normUVs`;
836               
837                // get the path to the script file for relative paths to the .bmps
838                string $file_path = `file -q -loc OgreExporter.mel`;
839                string $buffer[];
840                int $numTokens = `tokenize $file_path "//" $buffer`;
841                int $i;
842                $file_path = "";
843                for($i = 0; $i < $numTokens-2; $i++)
844                {
845                        $file_path += $buffer[$i] + "/";               
846                }
847                string $norm_uv_bmp = $file_path + "normalUVs.bmp";
848                string $maya_uv_bmp = $file_path + "mayaUVs.bmp";
849               
850                // advanced control continued....
851                string $advancedNormImage = `image -image $norm_uv_bmp -w 32 -h 32 -p $advancedFormLayout`;
852                string $advancedMayaImage = `image -image $maya_uv_bmp -w 32 -h 32 -p $advancedFormLayout`;
853                //string $advancedMatOptLabel = `text -label "Material Prefix:" -p $advancedFormLayout`;
854                //string $advancedMatOptTxt = `textField -width 300 -p $advancedFormLayout`;
855                //string $advancedTriangulate = `checkBox -label "Triangulate Geometry" -p $advancedFormLayout advTriangulate`;
856                //string $advancedOptimize = `checkBox -label "Optimize Geometry" -p $advancedFormLayout advOptimize`;
857               
858                // export controls
859                string $exportOutLabel = `text -label "Output Directory:" -p $exportFormLayout`;
860                string $exportOutTxt = `textField -width 380 -p $exportFormLayout exportOutputTxt`;
861                string $exportDirLocation = `button -label "...." -p $exportFormLayout -command("GetOutputDir()")`;
862               
863                string $exportXMLLabel = `text -label "XML Filename for Mesh and Skeleton(without extension):" -en true -p $exportFormLayout exportXMLLbl`;
864                string $exportXMLText = `textField -width 300 -en true -p $exportFormLayout exportXMLTxt`;
865               
866                string $exportOptionLabel = `text -label "Export Options:" -p $exportFormLayout`;
867               
868                string $exportRadioCollection = `radioCollection -p $advancedFormLayout`;
869                string $radioExportEverything = `radioButton -label "Everything" -recomputeSize true -select -cl $exportRadioCollection -p $exportFormLayout exportEverything`;
870                string $radioExportSelected = `radioButton -label "Selected" -recomputeSize true -enable false -cl $exportRadioCollection -p $exportFormLayout exportSelected`;
871               
872                string $exportViewButton = `button -label "Preview" -p $exportFormLayout -command("Preview()")`;
873                string $exportButton = `button -label "Export" -p $exportFormLayout -command("Export()")`;
874               
875                // edit animation form
876                formLayout -edit
877                        -attachPosition $animationExportToXML "left" 5 0
878                        -attachPosition $animationExportToXML "top" 5 0
879                        -attachControl $animationToBinary "top" 1 $animationExportToXML
880                        -attachPosition $animationToBinary "left" 5 0
881                                               
882                        -attachControl $animationAnimations "top" 2 $animationToBinary
883                        -attachPosition $animationAnimations "left" 5 0
884                        -attachControl $animationDefsLabel "top" 1 $animationAnimations
885                        -attachPosition $animationDefsLabel "left" 5 0
886                        -attachControl $animationDefsLst "top" 1 $animationDefsLabel
887                        -attachPosition $animationDefsLst "left" 5 0
888                        -attachControl $animationAddLabel "top" 2 $animationDefsLst
889                        -attachPosition $animationAddLabel "left" 5 0
890                       
891                        -attachControl $animationAddAnimName "top" 2 $animationAddLabel
892                        -attachPosition $animationAddAnimName "left" 5 0
893                        -attachControl $animationAddAnimNameTxt "top" 1 $animationAddAnimName
894                        -attachPosition $animationAddAnimNameTxt "left" 5 0
895                        -attachControl $animationAddAnimStart "top" 1 $animationAddLabel
896                        -attachControl $animationAddAnimStart "left" 150 $animationAddAnimName
897                        -attachControl $animationAddAnimStartTxt "top" 1 $animationAddAnimName
898                        -attachControl $animationAddAnimStartTxt "left" 5 $animationAddAnimNameTxt
899                        -attachControl $animationAddAnimEnd "top" 1 $animationAddLabel
900                        -attachControl $animationAddAnimEnd "left" 5 $animationAddAnimStart
901                        -attachControl $animationAddAnimEndTxt "top" 1 $animationAddAnimEnd
902                        -attachControl $animationAddAnimEndTxt "left" 5 $animationAddAnimStartTxt
903                        -attachControl $animationAddAnimSkip "top" 1 $animationAddLabel
904                        -attachControl $animationAddAnimSkip "left" 8 $animationAddAnimEnd
905                        -attachControl $animationAddAnimSkipTxt "top" 1 $animationAddAnimSkip
906                        -attachControl $animationAddAnimSkipTxt "left" 5 $animationAddAnimEndTxt
907                        -attachControl $aniamtionAddAnimBttn "top" 1 $animationAddAnimName
908                        -attachControl $aniamtionAddAnimBttn "left" 1 $animationAddAnimSkipTxt
909                        -attachControl $aniamtionRemoveAnimBttn "left" 1 $aniamtionAddAnimBttn
910                        -attachControl $aniamtionRemoveAnimBttn "top" 1 $animationAddAnimName
911                $animationFormLayout;
912               
913                // edit form layout or frames
914                formLayout -edit
915                        -attachPosition $meshFrame "top" 5 0
916                        -attachPosition $meshFrame "left" 5 0
917                        -attachPosition $meshFrame "right" 5 100
918                        -attachControl $materialFrame "top" 1 $meshFrame
919                        -attachPosition $materialFrame "left" 5 0
920                        -attachPosition $materialFrame "right" 5 100
921                        -attachControl $animationFrame "top" 1 $materialFrame
922                        -attachPosition $animationFrame "left" 5 0
923                        -attachPosition $animationFrame "right" 5 100
924                        -attachControl $advancedFrame "top" 1 $animationFrame
925                        -attachPosition $advancedFrame "left" 5 0
926                        -attachPosition $advancedFrame "right" 5 100
927                        -attachControl $exportFrame "top" 1 $advancedFrame
928                        -attachPosition $exportFrame "left" 5 0
929                        -attachPosition $exportFrame "right" 5 100
930                $mainInsideLayout;
931               
932                // edit mesh form
933                formLayout -edit
934                        -attachPosition $meshExportToXML "top" 5 0
935                        -attachPosition $meshExportToXML "left" 5 0
936                        -attachControl $meshBoneAssignment "top" 1 $meshExportToXML
937                        -attachPosition $meshBoneAssignment "left" 5 0
938                        -attachControl $meshVertexNormals "top" 1 $meshBoneAssignment
939                        -attachPosition $meshVertexNormals "left" 5 0
940                        -attachControl $meshDiffuseColor "top" 1 $meshVertexNormals
941                        -attachPosition $meshDiffuseColor "left" 5 0
942                        -attachControl $meshTextureCoords "top" 1 $meshDiffuseColor
943                        -attachPosition $meshTextureCoords "left" 5 0
944                        -attachControl $meshSubmeshNames "top" 1 $meshTextureCoords
945                        -attachPosition $meshSubmeshNames "left" 5 0
946                        -attachControl $meshToBinary "top" 1 $meshSubmeshNames
947                        -attachPosition $meshToBinary "left" 5 0
948                $meshFormLayout;
949               
950                // edit material form
951                formLayout -edit
952                        -attachPosition $materialExportToMaterial "top" 5 0
953                        -attachPosition $materialExportToMaterial "left" 5 0
954                $materialFormLayout;
955               
956               
957               
958                // edit advanced form
959                formLayout -edit
960                        -attachPosition $advancedMayaUVs "top" 5 0
961                        -attachPosition $advancedMayaUVs "left" 5 0
962                        -attachControl $advancedNormUVs "left" 15 $advancedMayaUVs
963                        -attachPosition $advancedNormUVs "top" 5 0
964                        -attachControl $advancedMayaImage "top" 1 $advancedMayaUVs
965                        -attachPosition $advancedMayaImage "left" 25 0
966                        -attachControl $advancedNormImage "left" 60 $advancedMayaImage
967                        -attachControl $advancedNormImage "top" 1 $advancedNormUVs
968                $advancedFormLayout;
969               
970                // edit export form
971                formLayout -edit
972                        -attachPosition $exportOutLabel "top" 5 0
973                        -attachPosition $exportOutLabel "left" 5 0
974                        -attachControl $exportOutTxt "top" 1 $exportOutLabel
975                        -attachPosition $exportOutTxt "left" 5 0
976                        -attachControl $exportDirLocation "left" 1 $exportOutTxt
977                        -attachControl $exportDirLocation "top" 1 $exportOutLabel
978                       
979                        -attachControl $exportXMLLabel "top" 1 $exportDirLocation
980                        -attachPosition $exportXMLLabel "left" 5 0
981                        -attachControl $exportXMLText "top" 1 $exportXMLLabel
982                        -attachPosition $exportXMLText "left" 5 0
983                       
984                        -attachControl $exportOptionLabel "top" 5 $exportXMLText
985                        -attachPosition $exportOptionLabel "left" 5 0
986                        -attachControl $radioExportEverything "top" 1 $exportOptionLabel
987                        -attachPosition $radioExportEverything "left" 5 0
988                        -attachControl $radioExportSelected "left" 1 $radioExportEverything
989                        -attachControl $radioExportSelected "top" 1 $exportOptionLabel
990                        -attachControl $exportViewButton "top" 5 $radioExportEverything
991                        -attachPosition $exportViewButton "left" 5 0
992                        -attachPosition $exportViewButton "right" 5 100
993                        -attachControl $exportButton "top" 5 $exportViewButton
994                        -attachPosition $exportButton "left" 5 0
995                        -attachPosition $exportButton "right" 5 100
996                $exportFormLayout;
997               
998                // set parent for main window
999                setParent ..;
1000               
1001                // script job for deleting window from windowPref
1002                scriptJob -uiDeleted $window ("windowPref -remove " + $window);
1003                       
1004                showWindow $window;
1005                ReadSettings();                 
1006        }
1007}
Note: See TracBrowser for help on using the repository browser.