source: OGRE/trunk/ogrenew/Tools/MayaExport/mel/maya2ogre/maya2ogre_export.mel @ 657

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

added ogre dependencies and patched ogre sources

Line 
1/*
2============================================================================
3This source file is part of the Ogre-Maya Tools.
4Distributed as part of Ogre (Object-oriented Graphics Rendering Engine).
5Copyright (C) 2003 Fifty1 Software Inc.
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; either version 2
10of the License, or (at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20or go to http://www.gnu.org/licenses/gpl.txt
21============================================================================
22*/
23
24namespace -add "maya2ogre";
25namespace -set "maya2ogre";
26
27
28// ===== Export
29global proc ExportToOgre()
30{
31        saveFileInfo;
32       
33        // ===== Files and directories
34        string $sceneFile    = `file -query -sceneName`;
35        string $mayaFile     = basename($sceneFile, "");
36        string $sceneDir     = toNativePath(dirname($sceneFile));
37        string $baseFile     = basename($sceneFile, ".mb");
38        string $outputDir    = toNativePath(`textField -query -text OutputDirectory`);
39        string $meshFile     = toNativePath(`textField -query -text ExportMeshFilename`);
40        string $materialFile = toNativePath(`textField -query -text ExportMaterialFilename`);
41        string $skeletonFile = toNativePath(`textField -query -text ExportSkeletonFilename`);
42       
43
44        // ===== Make working copy of Maya file
45        // (Removes need to save before exporting)
46        string $mayaWorkingFile = `internalVar -userScriptDir` + "maya2ogre.mb";
47        file -rename $mayaWorkingFile;
48        file -save -force;
49        file -rename $mayaFile;
50
51       
52        // ===== Options
53        string $options = "";
54       
55        // --- Common params
56        $options += " -in \"" + $mayaWorkingFile + "\"";
57        string $materialPrefix = `textField -query -text MaterialPrefix`;
58        if ($materialPrefix != "")
59        {
60                $options += " -mprefix " + $materialPrefix;
61        }
62       
63        // --- Mesh export
64        int $exportMesh = `checkBox -query -value ExportMesh`;
65        int $convertMesh = `checkBox -query -value ExportMeshBinary`;
66        if ($exportMesh)
67        {
68                $options += " -mesh \"" + $outputDir + $meshFile + "\"";
69
70                if (`checkBox -query -value ExportMeshVBA`)
71                {
72                        $options += " -vba";
73                }
74                if (`checkBox -query -value ExportMeshNormals`)
75                {
76                        $options += " -n";
77                }
78                if (`checkBox -query -value ExportMeshColours`)
79                {
80                        $options += " -c";
81                }
82                if (`checkBox -query -value ExportMeshUVs`)
83                {
84                        $options += " -t";
85                }
86        }
87       
88        // --- Material export
89        int $exportMaterial = `checkBox -query -value ExportMaterial`;
90        if ($exportMaterial)
91        {
92                $options += " -mat \"" + $outputDir + $materialFile + "\"";
93        }
94
95        // --- Skeleton/Animation export
96        int $exportSkeleton = `checkBox -query -value ExportSkeleton`;
97        int $convertSkeleton = `checkBox -query -value ExportSkeletonBinary`;
98        if ($exportSkeleton)
99        {
100                $options += " -skel \"" + $outputDir + $skeletonFile + "\"";
101               
102                if (`checkBox -query -value ExportAnim`)
103                {
104                        int $iAnim;
105                        string $animNameField;
106                        string $animStartField;
107                        string $animEndField;
108                        string $animStepField;
109
110                        for ($iAnim=1; $iAnim<=8; $iAnim++)
111                        {
112                                $animNameField  = "AnimName0"  + $iAnim;
113                                $animStartField = "AnimStart0" + $iAnim;
114                                $animEndField   = "AnimEnd0"   + $iAnim;
115                                $animStepField  = "AnimStep0"  + $iAnim;
116                               
117                                if (`textField -query -text $animNameField` != "")
118                                {
119                                        $options += " -anim " + `textField -query -text $animNameField`;
120                                        $options += " " + `intField -query -value $animStartField`;
121                                        $options += " " + `intField -query -value $animEndField`;
122                                        $options += " " + `intField -query -value $animStepField`;
123                                }
124                        }
125                }
126        }
127       
128       
129       
130        // ===== Export
131       
132        // --- Windows
133        if (`about -windows`)
134        {
135                string $commands;
136                $commands += "rem ==================" + "\n";
137                $commands += "rem Export to Ogre XML" + "\n";
138                $commands += "rem ==================" + "\n";
139               
140                $commands += "set path=" + toNativePath(`internalVar -userScriptDir`) + ";%path%" + "\n";
141                $commands += "pushd " + $sceneDir + "\n";
142                $commands += "maya2ogre.exe " + $options + "\n";
143                if ($exportMesh && $convertMesh)
144                {
145                        $commands += "rem ======================" + "\n";
146                        $commands += "rem Convert Mesh to Binary" + "\n";
147                        $commands += "rem ======================" + "\n";
148                        $commands += "pushd " + $outputDir + "\n";
149                        $commands += "OgreXMLConverter " + $meshFile + "\n";
150                        $commands += "popd" + "\n";
151                }
152                if ($exportSkeleton && $convertSkeleton)
153                {
154                        $commands += "rem ==========================" + "\n";
155                        $commands += "rem Convert Skeleton to Binary" + "\n";
156                        $commands += "rem ==========================" + "\n";
157                        $commands += "pushd " + $outputDir + "\n";
158                        $commands += "OgreXMLConverter " + $skeletonFile + "\n";
159                        $commands += "popd" + "\n";
160                }
161                $commands += "popd" + "\n";
162                $commands += "pause" + "\n";
163               
164                string $commandFile = `internalVar -userScriptDir` + "maya2ogre_mel.bat";
165                $fileID = `fopen $commandFile "w"`;
166                fprint $fileID $commands;
167                fclose $fileID;
168
169                system("start \"" + `toNativePath $commandFile` + "\"");
170        }
171       
172        // --- Linux
173        else if (`about -linux`)
174        {
175                confirmDialog
176                   -title "Ogre Exporter"
177                   -message "Sorry, but there is no command-line exporter or plug-in available for Linux yet. "
178                   -button "Ok";
179        }
180
181        // --- Mac
182        else if (`about -mac`)
183        {
184                confirmDialog
185                   -title "Ogre Exporter"
186                   -message "Sorry, but there is no command-line exporter or plug-in available for Mac yet. ";
187        }
188       
189}
190
191
192// ===== Load preferences from fileInfo
193// fileInfo is stored with Maya files so that export preferences
194// are preserved with each source file.
195global proc loadFileInfo()
196{
197        // Common parameters
198        textField -edit -fileName `fileInfo -query "maya2ogre_outputDir"` OutputDirectory;
199        textField -edit -text `fileInfo -query "maya2ogre_matPrefix"` MaterialPrefix;
200
201        // Mesh
202        string $valStrings[] = `fileInfo -query "maya2ogre_exportMesh"`;
203        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportMesh;
204
205        string $valStrings[] = `fileInfo -query "maya2ogre_convertMesh"`;
206        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportMeshBinary;
207       
208        string $valStrings[] = `fileInfo -query "maya2ogre_exportMeshNormals"`;
209        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportMeshNormals;
210
211        string $valStrings[] = `fileInfo -query "maya2ogre_exportMeshColours"`;
212        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportMeshColours;
213
214        string $valStrings[] = `fileInfo -query "maya2ogre_exportMeshVBA"`;
215        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportMeshVBA;
216
217        string $valStrings[] = `fileInfo -query "maya2ogre_exportMeshUVs"`;
218        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportMeshUVs;
219
220        string $valStrings[] = `fileInfo -query "maya2ogre_exportMeshFile"`;
221        if ($valStrings[0] != "")
222        {
223                textField -edit -text `fileInfo -query "maya2ogre_exportMeshFile"` ExportMeshFilename;
224        }
225       
226        // Material
227        string $valStrings[] = `fileInfo -query "maya2ogre_exportMat"`;
228        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportMaterial;
229
230        string $valStrings[] = `fileInfo -query "maya2ogre_exportMatFile"`;
231        if ($valStrings[0] != "")
232        {
233                textField -edit -text `fileInfo -query "maya2ogre_exportMatFile"` ExportMaterialFilename;
234        }
235
236        // Skeleton     
237        string $valStrings[] = `fileInfo -query "maya2ogre_exportSkel"`;
238        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportSkeleton;
239
240        string $valStrings[] = `fileInfo -query "maya2ogre_convertSkel"`;
241        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportSkeletonBinary;
242
243        string $valStrings[] = `fileInfo -query "maya2ogre_exportSkelFile"`;
244        if ($valStrings[0] != "")
245        {
246                textField -edit -text `fileInfo -query "maya2ogre_exportSkelFile"` ExportSkeletonFilename;
247        }
248       
249        // Animation
250        string $valStrings[] = `fileInfo -query "maya2ogre_exportAnim"`;
251        checkBox -edit -value `gmatch $valStrings[0] "1"` ExportAnim;
252
253        int $iAnim;
254        string $animNameField;
255        string $animFileInfoKey;
256        string $animFileInfoValue[];
257        string $animStartField;
258        string $animEndField;
259        string $animStepField;
260        for ($iAnim=1; $iAnim<=8; $iAnim++)
261        {
262                $animFileInfoKey = "maya2ogre_anim0" + $iAnim;
263                $animNameField   = "AnimName0"  + $iAnim;
264                $animStartField  = "AnimStart0" + $iAnim;
265                $animEndField    = "AnimEnd0"   + $iAnim;
266                $animStepField   = "AnimStep0"  + $iAnim;
267               
268                $animFileInfoValue = `fileInfo -query $animFileInfoKey`;
269                string $animFileInfoDetails[];
270                tokenize $animFileInfoValue[0] "," $animFileInfoDetails;
271               
272                string $animName = $animFileInfoDetails[0];
273                if ($animName == "!") $animName = "";
274                textField -edit -text $animName $animNameField;
275                int $start = (int)$animFileInfoDetails[1];
276                int $end   = (int)$animFileInfoDetails[2];
277                int $step  = (int)$animFileInfoDetails[3];
278                intField -edit -value $start $animStartField;
279                intField -edit -value $end $animEndField;
280                intField -edit -value $step $animStepField;
281        }
282}
283
284
285// ===== Save preferences to fileInfo
286global proc saveFileInfo()
287{
288        // Common parameters
289        fileInfo "maya2ogre_outputDir" `textField -query -fileName OutputDirectory`;
290        fileInfo "maya2ogre_matPrefix" `textField -query -text MaterialPrefix`;
291
292        // Mesh
293        fileInfo "maya2ogre_exportMesh" `checkBox -query -value ExportMesh`;
294        fileInfo "maya2ogre_convertMesh" `checkBox -query -value ExportMeshBinary`;
295        fileInfo "maya2ogre_exportMeshNormals" `checkBox -query -value ExportMeshNormals`;
296        fileInfo "maya2ogre_exportMeshColours" `checkBox -query -value ExportMeshColours`;
297        fileInfo "maya2ogre_exportMeshVBA" `checkBox -query -value ExportMeshVBA`;
298        fileInfo "maya2ogre_exportMeshUVs" `checkBox -query -value ExportMeshUVs`;
299        fileInfo "maya2ogre_exportMeshFile" `textField -query -text ExportMeshFilename`;
300       
301        // Material
302        fileInfo "maya2ogre_exportMat" `checkBox -query -value ExportMaterial`;
303        fileInfo "maya2ogre_exportMatFile" `textField -query -text ExportMaterialFilename`;
304       
305        // Skeleton     
306        fileInfo "maya2ogre_exportSkel" `checkBox -query -value ExportSkeleton`;
307        fileInfo "maya2ogre_convertSkel" `checkBox -query -value ExportSkeletonBinary`;
308        fileInfo "maya2ogre_exportSkelFile" `textField -query -text ExportSkeletonFilename`;
309       
310        // Animation
311        fileInfo "maya2ogre_exportAnim" `checkBox -query -value ExportAnim`;
312        int $iAnim;
313        string $animNameField;
314        string $animFileInfoKey;
315        string $animFileInfoValue;
316        string $animStartField;
317        string $animEndField;
318        string $animStepField;
319        for ($iAnim=1; $iAnim<=8; $iAnim++)
320        {
321                $animFileInfoKey = "maya2ogre_anim0" + $iAnim;
322                $animNameField   = "AnimName0"  + $iAnim;
323                $animStartField  = "AnimStart0" + $iAnim;
324                $animEndField    = "AnimEnd0"   + $iAnim;
325                $animStepField   = "AnimStep0"  + $iAnim;
326               
327                string $animName = `textField -query -text $animNameField`;
328                if ($animName == "") $animName = "!";
329                $animFileInfoValue = $animName;
330                $animFileInfoValue += ", " + `intField -query -value $animStartField`;
331                $animFileInfoValue += ", " + `intField -query -value $animEndField`;
332                $animFileInfoValue += ", " + `intField -query -value $animStepField`;
333               
334                fileInfo $animFileInfoKey $animFileInfoValue;
335        }
336}
Note: See TracBrowser for help on using the repository browser.