1 | // ===== Create Ogre menu
|
---|
2 | namespace -add "GTPSceneExporter";
|
---|
3 | namespace -set "GTPSceneExporter";
|
---|
4 |
|
---|
5 | setParent "MayaWindow";
|
---|
6 | menu -label "GTP" -tearOff false;
|
---|
7 | menuItem -label "Export Scene" -command "GTPSceneExporter";
|
---|
8 | menuItem -label "Path Map" -subMenu true;
|
---|
9 | menuItem -label "Add Path Map attributes" -command "GTPAddPathMapAttr";
|
---|
10 |
|
---|
11 | //GTPSceneExporter();
|
---|
12 |
|
---|
13 | global proc runGTPSceneExport()
|
---|
14 | {
|
---|
15 | string $outputDir = (`textField -query -text OutputDirectory`);
|
---|
16 | if (!endsWith($outputDir,"\\") && !endsWith($outputDir,"/") && (size($outputDir)>0))
|
---|
17 | $outputDir += "/";
|
---|
18 | string $sceneFile = (`textField -query -text SceneFileName`);
|
---|
19 |
|
---|
20 | $sceneFileName = $outputDir + $sceneFile;
|
---|
21 | $fileId = `fopen $sceneFileName "w"`;
|
---|
22 |
|
---|
23 | string $options;
|
---|
24 | string $shapes[];
|
---|
25 | $shapes=`ls -geometry`;
|
---|
26 |
|
---|
27 | string $commandFile = $outputDir + "GTP_SceneExport.bat";
|
---|
28 | int $comandFileID;
|
---|
29 | string $commands = "";
|
---|
30 | if (`checkBox -query -value CreateBinary`)
|
---|
31 | {
|
---|
32 | $comandFileID = `fopen $commandFile "w"`;
|
---|
33 | string $OgreDir = (`textField -query -text OgrePath`);
|
---|
34 | $OgreDir = toNativePath($OgreDir);
|
---|
35 | $commands += "path=" + $OgreDir + "\n";
|
---|
36 | }
|
---|
37 |
|
---|
38 | //geometry
|
---|
39 | for($index=0;$index<size($shapes);$index++)
|
---|
40 | {
|
---|
41 | string $shapename = $shapes[$index];
|
---|
42 | string $shapeNameTokens[];
|
---|
43 | tokenize $shapename "|" $shapeNameTokens;
|
---|
44 | $shapename = $shapeNameTokens[size($shapeNameTokens) - 1];
|
---|
45 | $meshFileName = encodeString(toNativePath($outputDir+$shapename + ".mesh.xml"));
|
---|
46 |
|
---|
47 | fprint $fileId("mesh "+$shapename+"\n{\n");
|
---|
48 | fprint $fileId("\togreXMLfile "+$shapename + ".mesh.xml"+"\n");
|
---|
49 | fprint $fileId("\togrefile "+$shapename + ".mesh"+"\n");
|
---|
50 | int $exportPM = `checkBox -q -v ExportPMAttr`;
|
---|
51 | if($exportPM)
|
---|
52 | {
|
---|
53 | select $shapes[$index];
|
---|
54 | $PRMRes = 64;
|
---|
55 | if(attributeExists("PhotonMapResolution", $shapes[$index]))
|
---|
56 | $PRMRes = `getAttr .prmRes`;
|
---|
57 | fprint $fileId("\tpathmapresolution " + $PRMRes + "\n");
|
---|
58 | $PRMDiv = 1;
|
---|
59 | if(attributeExists("PhotonMapSubdivision", $shapes[$index]))
|
---|
60 | $PRMDiv = `getAttr .prmDiv`;
|
---|
61 | fprint $fileId("\tdivide " + $PRMDiv + "\n");
|
---|
62 | }
|
---|
63 | fprint $fileId "}\n\n";
|
---|
64 |
|
---|
65 | //mesh export
|
---|
66 | int $exportMeshes = `checkBox -query -value ExportMeshes`;
|
---|
67 | if($exportMeshes)
|
---|
68 | {
|
---|
69 | select $shapename;
|
---|
70 | $options += " -sel";
|
---|
71 | $options += " -obj";
|
---|
72 | $options = "";
|
---|
73 | $options += " -mesh";
|
---|
74 | $options += " \"" + $meshFileName + "\"";
|
---|
75 | $options += " -shared -n -t";
|
---|
76 | eval ("ogreExport" + $options);
|
---|
77 | }
|
---|
78 |
|
---|
79 | //binary creation
|
---|
80 | if (`checkBox -query -value CreateBinary`)
|
---|
81 | {
|
---|
82 | int $size = size($meshFileName);
|
---|
83 | $size -= 4;
|
---|
84 | string $binMeshFileName = startString($meshFileName, $size);
|
---|
85 | $commands += "OgreXMLConverter";
|
---|
86 | if (!`checkBox -query -value BuildEdgeList`)
|
---|
87 | $commands += " -e ";
|
---|
88 | if (`checkBox -query -value BuildTangents`)
|
---|
89 | $commands += " -t ";
|
---|
90 | $commands += " \"" + $meshFileName + "\"" + " \"" + $binMeshFileName + "\"" + "\n";
|
---|
91 | //$commands += "pause \n";
|
---|
92 | }
|
---|
93 |
|
---|
94 | //entities with transforms
|
---|
95 | string $transforms[] = `listRelatives -ap $shapes[$index]`;
|
---|
96 | for($i = 0; $i<size($transforms);$i++)
|
---|
97 | {
|
---|
98 | $entityName = $transforms[$i];
|
---|
99 |
|
---|
100 | select $entityName;
|
---|
101 | float $transformation[] = `getAttr .worldMatrix`;
|
---|
102 | string $transformationString = "";
|
---|
103 |
|
---|
104 | for($start = 0; $start < 4 ; $start++)
|
---|
105 | for($t = 0; $t < 4 ; $t++)
|
---|
106 | $transformationString += ($transformation[$start + $t * 4] + " ");
|
---|
107 |
|
---|
108 | fprint $fileId("entity "+ $entityName + "\n{\n" );
|
---|
109 | fprint $fileId("\tmesh "+ $shapename + "\n");
|
---|
110 | fprint $fileId("\ttransformation "+ $transformationString + "\n");
|
---|
111 | if($exportPM)
|
---|
112 | {
|
---|
113 | $PRMClus = 32;
|
---|
114 | if(attributeExists("PathMapClusters", $shapes[$index]))
|
---|
115 | $PRMClus = `getAttr .prmClus`;
|
---|
116 | fprint $fileId("\tpathmapclusters " + $PRMClus + "\n");
|
---|
117 | string $PMTexturePath = (`textField -query -text PMPath`);
|
---|
118 | if (!endsWith($PMTexturePath,"\\") && !endsWith($PMTexturePath,"/") && (size($PMTexturePath)>0))
|
---|
119 | $PMTexturePath += "/";
|
---|
120 | fprint $fileId("\tpathmapfile " + toNativePath($PMTexturePath) + $entityName + "\n");
|
---|
121 | }
|
---|
122 | fprint $fileId "}\n\n";
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (`checkBox -query -value CreateBinary`)
|
---|
127 | {
|
---|
128 | fprint $comandFileID $commands;
|
---|
129 | fclose $comandFileID;
|
---|
130 | system("\"" + `toNativePath $commandFile` + "\"");
|
---|
131 | }
|
---|
132 |
|
---|
133 | //material export
|
---|
134 | int $exportMaterials = `checkBox -query -value ExportMaterials`;
|
---|
135 | if($exportMaterials)
|
---|
136 | {
|
---|
137 | string $materialFile = (`textField -query -text MaterialFilename`);
|
---|
138 | string $materialFileName = encodeString(toNativePath($outputDir + $materialFile));
|
---|
139 | $options = "-all";
|
---|
140 | $options += " -mat \"" + $materialFileName + "\"";
|
---|
141 | string $matPrefix = `textField -query -text MaterialPrefix`;
|
---|
142 | if ($matPrefix != "")
|
---|
143 | {
|
---|
144 | $options += " -matPrefix \"" + $matPrefix + "\"";
|
---|
145 | }
|
---|
146 | eval ("ogreExport" + $options);
|
---|
147 | }
|
---|
148 |
|
---|
149 | fclose $fileId;
|
---|
150 | }
|
---|
151 |
|
---|
152 | // ===== Launch exporter UI
|
---|
153 | global proc GTPSceneExporter()
|
---|
154 | {
|
---|
155 | defineGTPExportUIView();
|
---|
156 | }
|
---|
157 |
|
---|
158 | global proc formatGTPExportUI()
|
---|
159 | {
|
---|
160 | int $exportMaterials = `checkBox -q -v ExportMaterials`;
|
---|
161 | text -edit -enable $exportMaterials MaterialFilenameLabel;
|
---|
162 | textField -edit -enable $exportMaterials MaterialFilename;
|
---|
163 | text -edit -enable $exportMaterials MaterialPrefixLabel;
|
---|
164 | textField -edit -enable $exportMaterials MaterialPrefix;
|
---|
165 |
|
---|
166 | int $exportMeshes = `checkBox -q -v ExportMeshes`;
|
---|
167 | checkBox -edit -enable $exportMeshes CreateBinary;
|
---|
168 | checkBox -edit -enable $exportMeshes BuildEdgeList;
|
---|
169 | checkBox -edit -enable $exportMeshes BuildTangents;
|
---|
170 | if (!$exportMeshes)
|
---|
171 | checkBox -edit -value false CreateBinary;
|
---|
172 |
|
---|
173 | int $createBinary = `checkBox -q -v CreateBinary`;
|
---|
174 | checkBox -edit -enable $createBinary BuildEdgeList;
|
---|
175 | checkBox -edit -enable $createBinary BuildTangents;
|
---|
176 | text -edit -enable $createBinary OgrePathLabel;
|
---|
177 | textField -edit -enable $createBinary OgrePath;
|
---|
178 |
|
---|
179 | int $exportPM = `checkBox -q -v ExportPMAttr`;
|
---|
180 | text -edit -enable $exportPM PMPathLabel;
|
---|
181 | textField -edit -enable $exportPM PMPath;
|
---|
182 | }
|
---|
183 |
|
---|
184 | global proc defineGTPExportUIView()
|
---|
185 | {
|
---|
186 | string $sceneFile = `file -query -sceneName`;
|
---|
187 | string $mayaFile = basename($sceneFile, "." + fileExtension($sceneFile));
|
---|
188 | if($mayaFile == "")
|
---|
189 | $mayaFile = "untitled";
|
---|
190 |
|
---|
191 | // --- Main window for Ogre exporter
|
---|
192 | if (`window -exists GTPSceneExportWindow`)
|
---|
193 | {
|
---|
194 | deleteUI GTPSceneExportWindow;
|
---|
195 | }
|
---|
196 | window
|
---|
197 | -title "GTP Scene Exporter"
|
---|
198 | -widthHeight 305 300
|
---|
199 | GTPSceneExportWindow;
|
---|
200 |
|
---|
201 | scrollLayout
|
---|
202 | GTPSceneExportScrollLayout;
|
---|
203 | columnLayout
|
---|
204 | GTPSceneExportMainLayout;
|
---|
205 | frameLayout
|
---|
206 | -parent GTPSceneExportMainLayout
|
---|
207 | -label "General"
|
---|
208 | -collapsable true
|
---|
209 | GeneralControls;
|
---|
210 | columnLayout
|
---|
211 | GTPGeneralControlsLayout;
|
---|
212 | text
|
---|
213 | -parent GTPGeneralControlsLayout
|
---|
214 | -label "Output Directory"
|
---|
215 | OutputDirectoryLabel;
|
---|
216 | textField
|
---|
217 | -parent GTPGeneralControlsLayout
|
---|
218 | -width 305
|
---|
219 | OutputDirectory;
|
---|
220 | text
|
---|
221 | -parent GTPGeneralControlsLayout
|
---|
222 | -label "Scene File Name"
|
---|
223 | SceneFileNameLabel;
|
---|
224 | textField
|
---|
225 | -parent GTPGeneralControlsLayout
|
---|
226 | -width 305
|
---|
227 | -text ($mayaFile + ".level")
|
---|
228 | SceneFileName;
|
---|
229 |
|
---|
230 | frameLayout
|
---|
231 | -parent GTPSceneExportMainLayout
|
---|
232 | -label "Materials"
|
---|
233 | -collapsable true
|
---|
234 | MaterialControls;
|
---|
235 | columnLayout
|
---|
236 | MaterialControlsLayout;
|
---|
237 | checkBox
|
---|
238 | -parent MaterialControlsLayout
|
---|
239 | -value false
|
---|
240 | -changeCommand "formatGTPExportUI"
|
---|
241 | -label "Export Materials"
|
---|
242 | ExportMaterials;
|
---|
243 | text
|
---|
244 | -parent MaterialControlsLayout
|
---|
245 | -label "Material File Name"
|
---|
246 | -enable false
|
---|
247 | MaterialFilenameLabel;
|
---|
248 | textField
|
---|
249 | -parent MaterialControlsLayout
|
---|
250 | -width 305
|
---|
251 | -enable false
|
---|
252 | -text ($mayaFile + ".material")
|
---|
253 | MaterialFilename;
|
---|
254 | text
|
---|
255 | -parent MaterialControlsLayout
|
---|
256 | -label "Material name prefix"
|
---|
257 | -enable false
|
---|
258 | MaterialPrefixLabel;
|
---|
259 | textField
|
---|
260 | -parent MaterialControlsLayout
|
---|
261 | -width 305
|
---|
262 | -enable false
|
---|
263 | -text $mayaFile
|
---|
264 | MaterialPrefix;
|
---|
265 |
|
---|
266 | frameLayout
|
---|
267 | -parent GTPSceneExportMainLayout
|
---|
268 | -label "Meshes"
|
---|
269 | -collapsable true
|
---|
270 | -width 309
|
---|
271 | MeshControls;
|
---|
272 | columnLayout
|
---|
273 | MeshControlsLayout;
|
---|
274 | checkBox
|
---|
275 | -parent MeshControlsLayout
|
---|
276 | -value true
|
---|
277 | -changeCommand "formatGTPExportUI"
|
---|
278 | -label "Export Meshes"
|
---|
279 | ExportMeshes;
|
---|
280 | checkBox
|
---|
281 | -parent MeshControlsLayout
|
---|
282 | -value true
|
---|
283 | -changeCommand "formatGTPExportUI"
|
---|
284 | -label "Create Binary Mesh Files"
|
---|
285 | CreateBinary;
|
---|
286 | checkBox
|
---|
287 | -parent MeshControlsLayout
|
---|
288 | -value false
|
---|
289 | -changeCommand "formatGTPExportUI"
|
---|
290 | -label "Build Edge List"
|
---|
291 | BuildEdgeList;
|
---|
292 | checkBox
|
---|
293 | -parent MeshControlsLayout
|
---|
294 | -value false
|
---|
295 | -changeCommand "formatGTPExportUI"
|
---|
296 | -label "Build Tangent Vectors"
|
---|
297 | BuildTangents;
|
---|
298 | text
|
---|
299 | -parent MeshControlsLayout
|
---|
300 | -label "Ogre Dir(where dlls and OgreXMLConverter.exe are located)"
|
---|
301 | -enable true
|
---|
302 | OgrePathLabel;
|
---|
303 | textField
|
---|
304 | -parent MeshControlsLayout
|
---|
305 | -width 305
|
---|
306 | -enable true
|
---|
307 | -text "%OGRE_PATH%/Samples/Common/bin/Release"
|
---|
308 | OgrePath;
|
---|
309 |
|
---|
310 | frameLayout
|
---|
311 | -parent GTPSceneExportMainLayout
|
---|
312 | -label "Path Map Options"
|
---|
313 | -collapsable true
|
---|
314 | -width 309
|
---|
315 | PathMapControls;
|
---|
316 | columnLayout
|
---|
317 | PathMapControlsLayout;
|
---|
318 | checkBox
|
---|
319 | -parent PathMapControlsLayout
|
---|
320 | -value false
|
---|
321 | -changeCommand "formatGTPExportUI"
|
---|
322 | -label "Export Path Map Attributes"
|
---|
323 | ExportPMAttr;
|
---|
324 | text
|
---|
325 | -parent PathMapControlsLayout
|
---|
326 | -label "Path Map Texture Directory"
|
---|
327 | -enable false
|
---|
328 | PMPathLabel;
|
---|
329 | textField
|
---|
330 | -parent PathMapControlsLayout
|
---|
331 | -width 305
|
---|
332 | -enable false
|
---|
333 | -text "prm"
|
---|
334 | PMPath;
|
---|
335 |
|
---|
336 | button
|
---|
337 | -parent GTPSceneExportMainLayout
|
---|
338 | -label "EXPORT"
|
---|
339 | -command "runGTPSceneExport"
|
---|
340 | -width 305
|
---|
341 | ButtonExport;
|
---|
342 |
|
---|
343 | showWindow GTPSceneExportWindow;
|
---|
344 | }
|
---|
345 |
|
---|
346 | global proc GTPAddPathMapAttr()
|
---|
347 | {
|
---|
348 | string $selected[] = `selectedNodes`;
|
---|
349 | for($i = 0; $i < size($selected); $i++ )
|
---|
350 | {
|
---|
351 | select $selected[$i];
|
---|
352 | $isGeometry = `objectType -isType mesh $selected[$i]`;
|
---|
353 | if($isGeometry)
|
---|
354 | {
|
---|
355 | if(!attributeExists("PhotonMapResolution", $selected[$i]))
|
---|
356 | addAttr -at short -ln PhotonMapResolution -sn prmRes -min 16 -max 1024 -dv 64;
|
---|
357 | if(!attributeExists("PhotonMapSubdivision", $selected[$i]))
|
---|
358 | addAttr -at short -ln PhotonMapSubdivision -sn prmDiv -min 1 -dv 1;
|
---|
359 |
|
---|
360 | string $transforms[] = `listRelatives -ap $selected[$i]`;
|
---|
361 | for($j = 0; $j<size($transforms);$j++)
|
---|
362 | {
|
---|
363 | select $transforms[$j];
|
---|
364 | if(!attributeExists("PathMapClusters", $transforms[$j]))
|
---|
365 | addAttr -at short -ln PathMapClusters -sn prmRes -min 1 -max 64 -dv 32;
|
---|
366 | }
|
---|
367 | }
|
---|
368 | else
|
---|
369 | {
|
---|
370 | select $selected[$i];
|
---|
371 | $isTransform = `objectType -isType transform $selected[$i]`;
|
---|
372 | if($isTransform)
|
---|
373 | {
|
---|
374 | string $relatives[] = `listRelatives $selected[$i]`;
|
---|
375 | int $numRelatives = size($relatives);
|
---|
376 | for($j=0;$j<$numRelatives;$j++)
|
---|
377 | {
|
---|
378 | $isGeometry = `objectType -isType mesh $relatives[$j]`;
|
---|
379 | if($isGeometry)
|
---|
380 | {
|
---|
381 | select $relatives[$j];
|
---|
382 | if(!attributeExists("PhotonMapResolution", $relatives[$j]))
|
---|
383 | addAttr -at short -ln PhotonMapResolution -sn prmRes -min 16 -max 1024 -dv 64;
|
---|
384 | if(!attributeExists("PhotonMapSubdivision", $relatives[$j]))
|
---|
385 | addAttr -at short -ln PhotonMapSubdivision -sn prmDiv -min 1 -dv 1;
|
---|
386 |
|
---|
387 | select $selected[$i];
|
---|
388 | if(!attributeExists("PathMapClusters", $selected[$i]))
|
---|
389 | addAttr -at short -ln PathMapClusters -sn prmClus -min 1 -max 64 -dv 32;
|
---|
390 | }
|
---|
391 | }
|
---|
392 | }
|
---|
393 | }
|
---|
394 | }
|
---|
395 | }
|
---|
396 |
|
---|
397 | namespace -set ":"; |
---|