1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | #include "CMesh.h"
|
---|
28 | /*->#include "Ogre.h"
|
---|
29 | #include "OgreXMLMeshSerializer.h"
|
---|
30 | #include "OgreMeshSerializer.h"
|
---|
31 | #include "OgreXMLSkeletonSerializer.h"
|
---|
32 | #include "OgreSkeletonSerializer.h"
|
---|
33 | #include "OgreXMLPrerequisites.h"
|
---|
34 | #include "OgreDefaultHardwareBufferManager.h"
|
---|
35 | #include <iostream>
|
---|
36 | #include <sys/stat.h>
|
---|
37 | #include "SNStr.h"*/
|
---|
38 |
|
---|
39 | using namespace std;
|
---|
40 | using namespace Ogre;
|
---|
41 |
|
---|
42 | /*->struct XmlOptions
|
---|
43 | {
|
---|
44 | String source;
|
---|
45 | String dest;
|
---|
46 | String sourceExt;
|
---|
47 | String destExt;
|
---|
48 | String logFile;
|
---|
49 | bool interactiveMode;
|
---|
50 | unsigned short numLods;
|
---|
51 | Real lodDist;
|
---|
52 | Real lodPercent;
|
---|
53 | size_t lodFixed;
|
---|
54 | bool usePercent;
|
---|
55 | bool generateEdgeLists;
|
---|
56 | bool generateTangents;
|
---|
57 | bool reorganiseBuffers;
|
---|
58 | bool optimiseAnimations;
|
---|
59 | bool quietMode;
|
---|
60 | bool d3d;
|
---|
61 | bool gl;
|
---|
62 | Serializer::Endian endian;
|
---|
63 | };*/
|
---|
64 |
|
---|
65 | void help(void)
|
---|
66 | {
|
---|
67 | // Print help message
|
---|
68 | cout << endl << "OgreXMLConvert: Converts data between XML and OGRE binary formats." << endl;
|
---|
69 | cout << "Provided for OGRE by Steve Streeting 2002" << endl << endl;
|
---|
70 | cout << "Usage: OgreXMLConverter [options] sourcefile [destfile] " << endl;
|
---|
71 | cout << endl << "Available options:" << endl;
|
---|
72 | cout << "-i = interactive mode - prompt for options" << endl;
|
---|
73 | cout << "(The next 4 options are only applicable when converting XML to Mesh)" << endl;
|
---|
74 | cout << "-l lodlevels = number of LOD levels" << endl;
|
---|
75 | cout << "-d loddist = distance increment to reduce LOD" << endl;
|
---|
76 | cout << "-p lodpercent = Percentage triangle reduction amount per LOD" << endl;
|
---|
77 | cout << "-f lodnumtris = Fixed vertex reduction per LOD" << endl;
|
---|
78 | cout << "-e = DON'T generate edge lists (for stencil shadows)" << endl;
|
---|
79 | cout << "-r = DON'T reorganise vertex buffers to OGRE recommended format." << endl;
|
---|
80 | cout << "-t = Generate tangents (for normal mapping)" << endl;
|
---|
81 | cout << "-o = DON'T optimise out redundant tracks & keyframes" << endl;
|
---|
82 | cout << "-d3d = Prefer D3D packed colour formats (default on Windows)" << endl;
|
---|
83 | cout << "-gl = Prefer GL packed colour formats (default on non-Windows)" << endl;
|
---|
84 | cout << "-E endian = Set endian mode 'big' 'little' or 'native' (default)" << endl;
|
---|
85 | cout << "-q = Quiet mode, less output" << endl;
|
---|
86 | cout << "-log filename = name of the log file (default: 'OgreXMLConverter.log')" << endl;
|
---|
87 | cout << "sourcefile = name of file to convert" << endl;
|
---|
88 | cout << "destfile = optional name of file to write to. If you don't" << endl;
|
---|
89 | cout << " specify this OGRE works it out through the extension " << endl;
|
---|
90 | cout << " and the XML contents if the source is XML. For example" << endl;
|
---|
91 | cout << " test.mesh becomes test.xml, test.xml becomes test.mesh " << endl;
|
---|
92 | cout << " if the XML document root is <mesh> etc." << endl;
|
---|
93 |
|
---|
94 | cout << endl;
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | XmlOptions parseArgs(int numArgs, char **args)
|
---|
99 | {
|
---|
100 | XmlOptions opts;
|
---|
101 |
|
---|
102 | opts.interactiveMode = false;
|
---|
103 | opts.lodDist = 500;
|
---|
104 | opts.lodFixed = 0;
|
---|
105 | opts.lodPercent = 20;
|
---|
106 | opts.numLods = 0;
|
---|
107 | opts.usePercent = true;
|
---|
108 | opts.generateEdgeLists = true;
|
---|
109 | opts.generateTangents = false;
|
---|
110 | opts.reorganiseBuffers = true;
|
---|
111 | opts.optimiseAnimations = true;
|
---|
112 | opts.quietMode = false;
|
---|
113 | opts.endian = Serializer::ENDIAN_NATIVE;
|
---|
114 |
|
---|
115 | // ignore program name
|
---|
116 | char* source = 0;
|
---|
117 | char* dest = 0;
|
---|
118 |
|
---|
119 | // Set up options
|
---|
120 | UnaryOptionList unOpt;
|
---|
121 | BinaryOptionList binOpt;
|
---|
122 |
|
---|
123 | unOpt["-i"] = false;
|
---|
124 | unOpt["-e"] = false;
|
---|
125 | unOpt["-r"] = false;
|
---|
126 | unOpt["-t"] = false;
|
---|
127 | unOpt["-o"] = false;
|
---|
128 | unOpt["-q"] = false;
|
---|
129 | unOpt["-d3d"] = false;
|
---|
130 | unOpt["-gl"] = false;
|
---|
131 | binOpt["-l"] = "";
|
---|
132 | binOpt["-d"] = "";
|
---|
133 | binOpt["-p"] = "";
|
---|
134 | binOpt["-f"] = "";
|
---|
135 | binOpt["-E"] = "";
|
---|
136 | binOpt["-log"] = "OgreXMLConverter.log";
|
---|
137 |
|
---|
138 | int startIndex = findCommandLineOpts(numArgs, args, unOpt, binOpt);
|
---|
139 | UnaryOptionList::iterator ui;
|
---|
140 | BinaryOptionList::iterator bi;
|
---|
141 |
|
---|
142 | ui = unOpt.find("-q");
|
---|
143 | if (ui->second)
|
---|
144 | {
|
---|
145 | opts.quietMode = true;
|
---|
146 | }
|
---|
147 |
|
---|
148 | ui = unOpt.find("-i");
|
---|
149 | if (ui->second)
|
---|
150 | {
|
---|
151 | opts.interactiveMode = true;
|
---|
152 | }
|
---|
153 | else
|
---|
154 | {
|
---|
155 | ui = unOpt.find("-e");
|
---|
156 | if (ui->second)
|
---|
157 | {
|
---|
158 | opts.generateEdgeLists = false;
|
---|
159 | }
|
---|
160 |
|
---|
161 | ui = unOpt.find("-r");
|
---|
162 | if (ui->second)
|
---|
163 | {
|
---|
164 | opts.reorganiseBuffers = false;
|
---|
165 | }
|
---|
166 |
|
---|
167 | ui = unOpt.find("-t");
|
---|
168 | if (ui->second)
|
---|
169 | {
|
---|
170 | opts.generateTangents = true;
|
---|
171 | }
|
---|
172 |
|
---|
173 | ui = unOpt.find("-o");
|
---|
174 | if (ui->second)
|
---|
175 | {
|
---|
176 | opts.optimiseAnimations = false;
|
---|
177 | }
|
---|
178 |
|
---|
179 | bi = binOpt.find("-l");
|
---|
180 | if (!bi->second.empty())
|
---|
181 | {
|
---|
182 | opts.numLods = StringConverter::parseInt(bi->second);
|
---|
183 | }
|
---|
184 |
|
---|
185 | bi = binOpt.find("-d");
|
---|
186 | if (!bi->second.empty())
|
---|
187 | {
|
---|
188 | opts.lodDist = StringConverter::parseReal(bi->second);
|
---|
189 | }
|
---|
190 |
|
---|
191 | bi = binOpt.find("-p");
|
---|
192 | if (!bi->second.empty())
|
---|
193 | {
|
---|
194 | opts.lodPercent = StringConverter::parseReal(bi->second);
|
---|
195 | opts.usePercent = true;
|
---|
196 | }
|
---|
197 |
|
---|
198 |
|
---|
199 | bi = binOpt.find("-f");
|
---|
200 | if (!bi->second.empty())
|
---|
201 | {
|
---|
202 | opts.lodFixed = StringConverter::parseInt(bi->second);
|
---|
203 | opts.usePercent = false;
|
---|
204 | }
|
---|
205 |
|
---|
206 | bi = binOpt.find("-log");
|
---|
207 | if (!bi->second.empty())
|
---|
208 | {
|
---|
209 | opts.logFile = bi->second;
|
---|
210 | }
|
---|
211 |
|
---|
212 | bi = binOpt.find("-E");
|
---|
213 | if (!bi->second.empty())
|
---|
214 | {
|
---|
215 | if (bi->second == "big")
|
---|
216 | opts.endian = Serializer::ENDIAN_BIG;
|
---|
217 | else if (bi->second == "little")
|
---|
218 | opts.endian = Serializer::ENDIAN_LITTLE;
|
---|
219 | else
|
---|
220 | opts.endian = Serializer::ENDIAN_NATIVE;
|
---|
221 | }
|
---|
222 |
|
---|
223 | ui = unOpt.find("-d3d");
|
---|
224 | if (ui->second)
|
---|
225 | {
|
---|
226 | opts.d3d = true;
|
---|
227 | }
|
---|
228 |
|
---|
229 | ui = unOpt.find("-gl");
|
---|
230 | if (ui->second)
|
---|
231 | {
|
---|
232 | opts.gl = true;
|
---|
233 | opts.d3d = false;
|
---|
234 | }
|
---|
235 |
|
---|
236 | }
|
---|
237 | // Source / dest
|
---|
238 | if (numArgs > startIndex)
|
---|
239 | source = args[startIndex];
|
---|
240 | if (numArgs > startIndex+1)
|
---|
241 | dest = args[startIndex+1];
|
---|
242 |
|
---|
243 | if (!source)
|
---|
244 | {
|
---|
245 | cout << "Missing source file - abort. " << endl;
|
---|
246 | help();
|
---|
247 | exit(1);
|
---|
248 | }
|
---|
249 | // Work out what kind of conversion this is
|
---|
250 | opts.source = source;
|
---|
251 | std::vector<String> srcparts = StringUtil::split(opts.source, ".");
|
---|
252 | String& ext = srcparts.back();
|
---|
253 | StringUtil::toLowerCase(ext);
|
---|
254 | opts.sourceExt = ext;
|
---|
255 |
|
---|
256 | if (!dest)
|
---|
257 | {
|
---|
258 | if (opts.sourceExt == "xml")
|
---|
259 | {
|
---|
260 | // dest is source minus .xml
|
---|
261 | opts.dest = opts.source.substr(0, opts.source.size() - 4);
|
---|
262 | }
|
---|
263 | else
|
---|
264 | {
|
---|
265 | // dest is source + .xml
|
---|
266 | opts.dest = opts.source;
|
---|
267 | opts.dest.append(".xml");
|
---|
268 | }
|
---|
269 |
|
---|
270 | }
|
---|
271 | else
|
---|
272 | {
|
---|
273 | opts.dest = dest;
|
---|
274 | }
|
---|
275 | std::vector<String> dstparts = StringUtil::split(opts.dest, ".");
|
---|
276 | ext = dstparts.back();
|
---|
277 | StringUtil::toLowerCase(ext);
|
---|
278 | opts.destExt = ext;
|
---|
279 |
|
---|
280 | if (!opts.quietMode)
|
---|
281 | {
|
---|
282 | cout << endl;
|
---|
283 | cout << "-- OPTIONS --" << endl;
|
---|
284 | cout << "source file = " << opts.source << endl;
|
---|
285 | cout << "destination file = " << opts.dest << endl;
|
---|
286 | cout << "log file = " << opts.logFile << endl;
|
---|
287 | cout << "interactive mode = " << StringConverter::toString(opts.interactiveMode) << endl;
|
---|
288 | if (opts.numLods == 0)
|
---|
289 | {
|
---|
290 | cout << "lod levels = none (or use existing)" << endl;
|
---|
291 | }
|
---|
292 | else
|
---|
293 | {
|
---|
294 | cout << "lod levels = " << opts.numLods << endl;
|
---|
295 | cout << "lod distance = " << opts.lodDist << endl;
|
---|
296 | if (opts.usePercent)
|
---|
297 | {
|
---|
298 | cout << "lod reduction = " << opts.lodPercent << "%" << endl;
|
---|
299 | }
|
---|
300 | else
|
---|
301 | {
|
---|
302 | cout << "lod reduction = " << opts.lodFixed << " verts" << endl;
|
---|
303 | }
|
---|
304 | }
|
---|
305 | cout << "Generate edge lists = " << opts.generateEdgeLists << endl;
|
---|
306 | cout << "Generate tangents = " << opts.generateTangents << endl;
|
---|
307 | cout << "Reorganise vertex buffers = " << opts.reorganiseBuffers << endl;
|
---|
308 | cout << "Optimise animations = " << opts.optimiseAnimations << endl;
|
---|
309 |
|
---|
310 | cout << "-- END OPTIONS --" << endl;
|
---|
311 | cout << endl;
|
---|
312 | }
|
---|
313 |
|
---|
314 |
|
---|
315 | return opts;
|
---|
316 | }
|
---|
317 |
|
---|
318 | // Crappy globals
|
---|
319 | // NB some of these are not directly used, but are required to
|
---|
320 | // instantiate the singletons used in the dlls
|
---|
321 | /*LogManager* logMgr;
|
---|
322 | Math* mth;
|
---|
323 | MaterialManager* matMgr;
|
---|
324 | SkeletonManager* skelMgr;
|
---|
325 | MeshSerializer* meshSerializer;
|
---|
326 | XMLMeshSerializer* xmlMeshSerializer;
|
---|
327 | SkeletonSerializer* skeletonSerializer;
|
---|
328 | XMLSkeletonSerializer* xmlSkeletonSerializer;
|
---|
329 | DefaultHardwareBufferManager *bufferManager;
|
---|
330 | MeshManager* meshMgr;
|
---|
331 | ResourceGroupManager* rgm;
|
---|
332 |
|
---|
333 |
|
---|
334 | void meshToXML(XmlOptions opts)
|
---|
335 | {
|
---|
336 | std::ifstream ifs;
|
---|
337 | ifs.open(opts.source.c_str(), std::ios_base::in | std::ios_base::binary);
|
---|
338 | // pass false for freeOnClose to FileStreamDataStream since ifs is created on stack
|
---|
339 | DataStreamPtr stream(new FileStreamDataStream(opts.source, &ifs, false));
|
---|
340 |
|
---|
341 | MeshPtr mesh = MeshManager::getSingleton().create("conversion",
|
---|
342 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
343 |
|
---|
344 |
|
---|
345 | meshSerializer->importMesh(stream, mesh.getPointer());
|
---|
346 |
|
---|
347 | //xmlMeshSerializer->exportMesh(mesh.getPointer(), opts.dest);
|
---|
348 |
|
---|
349 | }
|
---|
350 |
|
---|
351 | void NormalizeIt(snObject &m_pObject)
|
---|
352 | {
|
---|
353 | float WBMax[3], WBMin[3];
|
---|
354 | int i, j;
|
---|
355 |
|
---|
356 | WBMax[0] = m_pObject._geo[0]._triSet[0]._ver[0];
|
---|
357 | WBMax[1] = m_pObject._geo[0]._triSet[0]._ver[1];
|
---|
358 | WBMax[2] = m_pObject._geo[0]._triSet[0]._ver[2];
|
---|
359 | WBMin[0] = m_pObject._geo[0]._triSet[0]._ver[0];
|
---|
360 | WBMin[1] = m_pObject._geo[0]._triSet[0]._ver[1];
|
---|
361 | WBMin[2] = m_pObject._geo[0]._triSet[0]._ver[2];
|
---|
362 |
|
---|
363 | for (i = 0; i < m_pObject._geo[0]._numTriSets; i++)
|
---|
364 | for (j = 0; j < m_pObject._geo[0]._triSet[i]._numVer; j++)
|
---|
365 | {
|
---|
366 | if (WBMax[0] < m_pObject._geo[0]._triSet[i]._ver[3 * j]) WBMax[0] = m_pObject._geo[0]._triSet[i]._ver[3 * j];
|
---|
367 | if (WBMax[1] < m_pObject._geo[0]._triSet[i]._ver[3 * j + 1]) WBMax[1] = m_pObject._geo[0]._triSet[i]._ver[3 * j + 1];
|
---|
368 | if (WBMax[2] < m_pObject._geo[0]._triSet[i]._ver[3 * j + 2]) WBMax[2] = m_pObject._geo[0]._triSet[i]._ver[3 * j + 2];
|
---|
369 | if (WBMin[0] > m_pObject._geo[0]._triSet[i]._ver[3 * j]) WBMin[0] = m_pObject._geo[0]._triSet[i]._ver[3 * j];
|
---|
370 | if (WBMin[1] > m_pObject._geo[0]._triSet[i]._ver[3 * j + 1]) WBMin[1] = m_pObject._geo[0]._triSet[i]._ver[3 * j + 1];
|
---|
371 | if (WBMin[2] > m_pObject._geo[0]._triSet[i]._ver[3 * j + 2]) WBMin[2] = m_pObject._geo[0]._triSet[i]._ver[3 * j + 2];
|
---|
372 | }
|
---|
373 |
|
---|
374 |
|
---|
375 | float sizeX = WBMax[0] - WBMin[0];
|
---|
376 | float sizeY = WBMax[1] - WBMin[1];
|
---|
377 | float sizeZ = WBMax[2] - WBMin[2];
|
---|
378 | float dispX = 0.5*(WBMax[0] + WBMin[0]);
|
---|
379 | float dispY = 0.5*(WBMax[1] + WBMin[1]);
|
---|
380 | float dispZ = 0.5*(WBMax[2] + WBMin[2]);
|
---|
381 | float norm;
|
---|
382 |
|
---|
383 | if (sizeX>=sizeY)
|
---|
384 | {
|
---|
385 | if (sizeX>=sizeZ) norm = 0.5*sizeX;
|
---|
386 | else norm = 0.5*sizeZ;
|
---|
387 | }
|
---|
388 | else
|
---|
389 | {
|
---|
390 | if (sizeY>=sizeZ) norm = 0.5*sizeY;
|
---|
391 | else norm = 0.5*sizeZ;
|
---|
392 | }
|
---|
393 |
|
---|
394 | for (i = 0; i < m_pObject._geo[0]._numTriSets; i++)
|
---|
395 | for (j = 0; j < m_pObject._geo[0]._triSet[i]._numVer; j++)
|
---|
396 | {
|
---|
397 | m_pObject._geo[0]._triSet[i]._ver[3 * j] = (m_pObject._geo[0]._triSet[i]._ver[3 * j] - dispX) / norm;
|
---|
398 | m_pObject._geo[0]._triSet[i]._ver[3 * j + 1] = (m_pObject._geo[0]._triSet[i]._ver[3 * j + 1] - dispY) / norm;
|
---|
399 | m_pObject._geo[0]._triSet[i]._ver[3 * j + 2] = (m_pObject._geo[0]._triSet[i]._ver[3 * j + 2] - dispZ) / norm;
|
---|
400 | }
|
---|
401 |
|
---|
402 | }
|
---|
403 |
|
---|
404 | void XMLToSNStr(snObject &m_pObject, XmlOptions opts)
|
---|
405 | {
|
---|
406 | int i = 0, j = 0;
|
---|
407 |
|
---|
408 | // Read root element and decide from there what type
|
---|
409 | String response;
|
---|
410 | TiXmlDocument* doc = new TiXmlDocument(opts.source);
|
---|
411 | // Some double-parsing here but never mind
|
---|
412 | if (!doc->LoadFile())
|
---|
413 | {
|
---|
414 | cout << "Unable to open file " << opts.source << " - fatal error." << endl;
|
---|
415 | exit (1);
|
---|
416 | }
|
---|
417 |
|
---|
418 | TiXmlElement *root = 0;
|
---|
419 | root = doc->RootElement();
|
---|
420 |
|
---|
421 | /*->if (!stricmp(root->Value(), "mesh"))
|
---|
422 | {
|
---|
423 | cout<<"\n"<<root->Value();
|
---|
424 | doc->Clear();
|
---|
425 | delete doc;
|
---|
426 | cout<<"\nError parsing XML file 1";
|
---|
427 | exit(-1);
|
---|
428 | }*/
|
---|
429 |
|
---|
430 | /*->if (!root)
|
---|
431 | {
|
---|
432 | doc->Clear();
|
---|
433 | delete doc;
|
---|
434 | cout<<"\nError parsing XML file 1";
|
---|
435 | exit(-1);
|
---|
436 | }
|
---|
437 |
|
---|
438 |
|
---|
439 | TiXmlElement *element = root->FirstChildElement("submeshes");
|
---|
440 | if (!element)
|
---|
441 | {
|
---|
442 | doc->Clear();
|
---|
443 | delete doc;
|
---|
444 | cout<<"\nError parsing XML file 2";
|
---|
445 | exit(-1);
|
---|
446 | }
|
---|
447 |
|
---|
448 | element = element->FirstChildElement("submesh");
|
---|
449 | if (!element)
|
---|
450 | {
|
---|
451 | doc->Clear();
|
---|
452 | delete doc;
|
---|
453 | cout<<"\nError parsing XML file 3";
|
---|
454 | exit(-1);
|
---|
455 | }
|
---|
456 |
|
---|
457 | m_pObject._numGeos = 1;
|
---|
458 | m_pObject._geo = new snGeo[1];
|
---|
459 |
|
---|
460 | m_pObject._geo[0]._numTriSets = 0;
|
---|
461 |
|
---|
462 | TiXmlElement *cnt;
|
---|
463 |
|
---|
464 | for (cnt = element; cnt; cnt = cnt->NextSiblingElement()) m_pObject._geo[0]._numTriSets += 1;
|
---|
465 |
|
---|
466 | m_pObject._geo[0]._triSet = new snTriSet[m_pObject._geo[0]._numTriSets];
|
---|
467 |
|
---|
468 | for (element = element; element; element = element->NextSiblingElement())
|
---|
469 | {
|
---|
470 | cout<<"\n"<<element->Value()<<"\n";
|
---|
471 |
|
---|
472 | cnt = element->FirstChildElement("faces");
|
---|
473 | if (!cnt)
|
---|
474 | {
|
---|
475 | doc->Clear();
|
---|
476 | delete doc;
|
---|
477 | cout<<"\nError parsing XML file 4";
|
---|
478 | exit(-1);
|
---|
479 | }
|
---|
480 |
|
---|
481 | const char *auxString = cnt->Attribute("count");
|
---|
482 |
|
---|
483 | m_pObject._geo[0]._triSet[i]._numTris = atoi(auxString);
|
---|
484 | m_pObject._geo[0]._triSet[i]._index = new int[m_pObject._geo[0]._triSet[i]._numTris * 3];
|
---|
485 | /*->m_pObject._geo[0]._triSet[0]._ver = new float[m_pObject._geo[0]._triSet[0]._numTris * 9];
|
---|
486 | m_pObject._geo[0]._triSet[0]._nor = new float[m_pObject._geo[0]._triSet[0]._numTris * 9];
|
---|
487 | m_pObject._geo[0]._triSet[0]._tex = new float[m_pObject._geo[0]._triSet[0]._numTris * 6];
|
---|
488 | m_pObject._geo[0]._triSet[0]._refl = new float[m_pObject._geo[0]._triSet[0]._numTris * 9];*/
|
---|
489 |
|
---|
490 |
|
---|
491 | /*->TiXmlElement *tri, *aux;
|
---|
492 |
|
---|
493 | j = 0;
|
---|
494 | for(tri = cnt; tri; tri = cnt->NextSiblingElement("faces"))
|
---|
495 | {
|
---|
496 | for (aux = tri->FirstChildElement(); aux; aux = aux->NextSiblingElement())
|
---|
497 | {
|
---|
498 | m_pObject._geo[0]._triSet[i]._index[3 * j] = atoi(aux->Attribute("v1"));
|
---|
499 | m_pObject._geo[0]._triSet[i]._index[3 * j + 1] = atoi(aux->Attribute("v2"));
|
---|
500 | m_pObject._geo[0]._triSet[i]._index[3 * j + 3] = atoi(aux->Attribute("v3"));
|
---|
501 | j++;
|
---|
502 | }
|
---|
503 | }
|
---|
504 |
|
---|
505 |
|
---|
506 | tri = cnt->NextSiblingElement("geometry");
|
---|
507 |
|
---|
508 | int NVer = atoi(tri->Attribute("vertexcount"));
|
---|
509 |
|
---|
510 | tri = tri->FirstChildElement("vertexbuffer");
|
---|
511 |
|
---|
512 | m_pObject._geo[0]._triSet[i]._numVer = NVer;
|
---|
513 |
|
---|
514 | cout<<"\n"<<tri->Value()<<"\n";
|
---|
515 |
|
---|
516 | cout<<"\nNombre de vertexs: "<<NVer<<"\n";
|
---|
517 |
|
---|
518 | cout<<"\nAqui 1, numero de triSet: "<<i<<"\n";
|
---|
519 |
|
---|
520 | m_pObject._geo[0]._triSet[i]._ver = new float[NVer * 3];
|
---|
521 | cout<<"\nAqui 2\n";
|
---|
522 | m_pObject._geo[0]._triSet[i]._nor = new float[NVer * 3];
|
---|
523 | cout<<"\nAqui 3\n";
|
---|
524 | m_pObject._geo[0]._triSet[i]._tex = new float[NVer * 2];
|
---|
525 | cout<<"\nAqui 4\n";
|
---|
526 | m_pObject._geo[0]._triSet[i]._refl = new float[NVer * 3];
|
---|
527 | cout<<"\nAqui 5\n";
|
---|
528 |
|
---|
529 |
|
---|
530 | TiXmlElement *aux1;
|
---|
531 |
|
---|
532 | //->aux = tri->FirstChildElement();
|
---|
533 |
|
---|
534 | aux = tri->FirstChildElement();
|
---|
535 |
|
---|
536 |
|
---|
537 | for (j = 0; j < NVer; j++)
|
---|
538 | {
|
---|
539 | aux1 = aux->FirstChildElement("position");
|
---|
540 | m_pObject._geo[0]._triSet[i]._ver[3 * j] = atof(aux1->Attribute("x"));
|
---|
541 | m_pObject._geo[0]._triSet[i]._ver[3 * j + 1] = atof(aux1->Attribute("y"));
|
---|
542 | m_pObject._geo[0]._triSet[i]._ver[3 * j + 2] = atof(aux1->Attribute("z"));
|
---|
543 |
|
---|
544 | aux1 = aux1->NextSiblingElement("normal");
|
---|
545 | m_pObject._geo[0]._triSet[i]._nor[3 * j] = atof(aux1->Attribute("x"));
|
---|
546 | m_pObject._geo[0]._triSet[i]._nor[3 * j + 1] = atof(aux1->Attribute("y"));
|
---|
547 | m_pObject._geo[0]._triSet[i]._nor[3 * j + 2] = atof(aux1->Attribute("z"));
|
---|
548 |
|
---|
549 | aux1 = aux1->NextSiblingElement("texcoord");
|
---|
550 | m_pObject._geo[0]._triSet[i]._tex[2 * j] = atof(aux1->Attribute("u"));
|
---|
551 | m_pObject._geo[0]._triSet[i]._tex[2 * j + 1] = atof(aux1->Attribute("v"));
|
---|
552 |
|
---|
553 | m_pObject._geo[0]._triSet[i]._refl[3 * j] = 0.5;
|
---|
554 | m_pObject._geo[0]._triSet[i]._refl[3 * j + 1] = 0.5;
|
---|
555 | m_pObject._geo[0]._triSet[i]._refl[3 * j + 2] = 0.5;
|
---|
556 |
|
---|
557 | aux = aux->NextSiblingElement();
|
---|
558 | }
|
---|
559 |
|
---|
560 | i++;
|
---|
561 | }
|
---|
562 |
|
---|
563 | NormalizeIt(m_pObject);
|
---|
564 |
|
---|
565 | /*->FILE *file = NULL;
|
---|
566 |
|
---|
567 | file = fopen("tmp.txt", "w");
|
---|
568 |
|
---|
569 | for (i = 0; i < m_pObject._geo[0]._numTriSets; i++)
|
---|
570 | for (j = 0; j < m_pObject._geo[0]._triSet[i]._numVer; j++)
|
---|
571 | fprintf(file, "\nx = %f, y = %f, z = %f", m_pObject._geo[0]._triSet[i]._ver[3 * j], m_pObject._geo[0]._triSet[i]._ver[3 * j + 1], m_pObject._geo[0]._triSet[i]._ver[3 * j + 2]);
|
---|
572 |
|
---|
573 | fclose(file);
|
---|
574 |
|
---|
575 | /*->aux1 = aux->FirstChildElement("position");
|
---|
576 | m_pObject._geo[0]._triSet[0]._ver[3 * i] = atof(aux1->Attribute("x"));
|
---|
577 | m_pObject._geo[0]._triSet[0]._ver[3 * i + 1] = atof(aux1->Attribute("y"));
|
---|
578 | m_pObject._geo[0]._triSet[0]._ver[3 * i + 2] = atof(aux1->Attribute("z"));
|
---|
579 | cout<<"\n\n"<<m_pObject._geo[0]._triSet[0]._ver[3 * i]<<"\n"<<m_pObject._geo[0]._triSet[0]._ver[3 * i + 1]<<"\n"<<m_pObject._geo[0]._triSet[0]._ver[3 * i + 2]<<"\n\n";
|
---|
580 | aux1 = aux1->NextSiblingElement("normal");
|
---|
581 | m_pObject._geo[0]._triSet[0]._nor[3 * i] = atof(aux1->Attribute("x"));
|
---|
582 | m_pObject._geo[0]._triSet[0]._nor[3 * i + 1] = atof(aux1->Attribute("y"));
|
---|
583 | m_pObject._geo[0]._triSet[0]._nor[3 * i + 2] = atof(aux1->Attribute("z"));
|
---|
584 | cout<<"\n\n"<<m_pObject._geo[0]._triSet[0]._nor[3 * i]<<"\n"<<m_pObject._geo[0]._triSet[0]._nor[3 * i + 1]<<"\n"<<m_pObject._geo[0]._triSet[0]._nor[3 * i + 2]<<"\n\n";
|
---|
585 | aux1 = aux1->NextSiblingElement("texcoord");
|
---|
586 | m_pObject._geo[0]._triSet[0]._tex[2 * i] = atof(aux1->Attribute("u"));
|
---|
587 | m_pObject._geo[0]._triSet[0]._tex[2 * i + 1] = atof(aux1->Attribute("v"));
|
---|
588 | cout<<"\n\n"<<m_pObject._geo[0]._triSet[0]._tex[2 * i]<<"\n"<<m_pObject._geo[0]._triSet[0]._tex[2 * i + 1]<<"\n\n";
|
---|
589 | i = NVer - 1;
|
---|
590 | aux = aux->NextSiblingElement();
|
---|
591 | aux1 = aux->FirstChildElement("position");
|
---|
592 | m_pObject._geo[0]._triSet[0]._ver[3 * i] = atof(aux1->Attribute("x"));
|
---|
593 | m_pObject._geo[0]._triSet[0]._ver[3 * i + 1] = atof(aux1->Attribute("y"));
|
---|
594 | m_pObject._geo[0]._triSet[0]._ver[3 * i + 2] = atof(aux1->Attribute("z"));
|
---|
595 | cout<<"\n\n"<<m_pObject._geo[0]._triSet[0]._ver[3 * i]<<"\n"<<m_pObject._geo[0]._triSet[0]._ver[3 * i + 1]<<"\n"<<m_pObject._geo[0]._triSet[0]._ver[3 * i + 2]<<"\n\n";
|
---|
596 | aux1 = aux1->NextSiblingElement("normal");
|
---|
597 | m_pObject._geo[0]._triSet[0]._nor[3 * i] = atof(aux1->Attribute("x"));
|
---|
598 | m_pObject._geo[0]._triSet[0]._nor[3 * i + 1] = atof(aux1->Attribute("y"));
|
---|
599 | m_pObject._geo[0]._triSet[0]._nor[3 * i + 2] = atof(aux1->Attribute("z"));
|
---|
600 | cout<<"\n\n"<<m_pObject._geo[0]._triSet[0]._nor[3 * i]<<"\n"<<m_pObject._geo[0]._triSet[0]._nor[3 * i + 1]<<"\n"<<m_pObject._geo[0]._triSet[0]._nor[3 * i + 2]<<"\n\n";
|
---|
601 | aux1 = aux1->NextSiblingElement("texcoord");
|
---|
602 | m_pObject._geo[0]._triSet[0]._tex[2 * i] = atof(aux1->Attribute("u"));
|
---|
603 | m_pObject._geo[0]._triSet[0]._tex[2 * i + 1] = atof(aux1->Attribute("v"));
|
---|
604 | cout<<"\n\n"<<m_pObject._geo[0]._triSet[0]._tex[2 * i]<<"\n"<<m_pObject._geo[0]._triSet[0]._tex[2 * i + 1]<<"\n\n";*/
|
---|
605 |
|
---|
606 | /*->i = 0;
|
---|
607 | //->for (i = 0; i < NVer; i++)
|
---|
608 | for (aux = tri->FirstChildElement(); aux; aux->NextSiblingElement())
|
---|
609 | {
|
---|
610 | aux1 = aux->FirstChildElement("position");
|
---|
611 | m_pObject._geo[0]._triSet[0]._ver[3 * i] = atof(aux1->Attribute("x"));
|
---|
612 | m_pObject._geo[0]._triSet[0]._ver[3 * i + 1] = atof(aux1->Attribute("y"));
|
---|
613 | m_pObject._geo[0]._triSet[0]._ver[3 * i + 2] = atof(aux1->Attribute("z"));
|
---|
614 | //->cout<<"\n\n"<<m_pObject._geo[0]._triSet[0]._ver[3 * i]<<"\n"<<m_pObject._geo[0]._triSet[0]._ver[3 * i + 1]<<"\n"<<m_pObject._geo[0]._triSet[0]._ver[3 * i + 2]<<"\n\n";
|
---|
615 | aux1 = aux1->NextSiblingElement("normal");
|
---|
616 | m_pObject._geo[0]._triSet[0]._nor[3 * i] = atof(aux1->Attribute("x"));
|
---|
617 | m_pObject._geo[0]._triSet[0]._nor[3 * i + 1] = atof(aux1->Attribute("y"));
|
---|
618 | m_pObject._geo[0]._triSet[0]._nor[3 * i + 2] = atof(aux1->Attribute("z"));
|
---|
619 | aux1 = aux1->NextSiblingElement("texcoord");
|
---|
620 | m_pObject._geo[0]._triSet[0]._tex[2 * i] = atof(aux1->Attribute("u"));
|
---|
621 | m_pObject._geo[0]._triSet[0]._tex[2 * i + 1] = atof(aux1->Attribute("v"));
|
---|
622 | /*->aux->NextSiblingElement("vertex");
|
---|
623 | cout<<"\n"<<aux->Value();*/
|
---|
624 | /*->i++;
|
---|
625 | cout<<"\n"<<i;
|
---|
626 | }*/
|
---|
627 |
|
---|
628 |
|
---|
629 | /*->doc->Clear();
|
---|
630 |
|
---|
631 | delete doc;
|
---|
632 |
|
---|
633 | /*->TiXmlNode *node = 0;
|
---|
634 | node = root->FirstChild();
|
---|
635 | cout<<"\n"<<node->Value();
|
---|
636 | node = node->FirstChild();
|
---|
637 | cout<<"\n"<<node->Value();
|
---|
638 | node = node->FirstChild();
|
---|
639 | cout<<"\n"<<node->Value();
|
---|
640 |
|
---|
641 | if (!node)
|
---|
642 | {
|
---|
643 | doc->Clear();
|
---|
644 | delete doc;
|
---|
645 | cout<<"\nError parsing XML file 2";
|
---|
646 | exit(-1);
|
---|
647 | }
|
---|
648 |
|
---|
649 | /*->TiXmlElement *element = 0;
|
---|
650 | element = root->FirstChildElement("submeshes");
|
---|
651 | if (!element)
|
---|
652 | {
|
---|
653 | doc->Clear();
|
---|
654 | delete doc;
|
---|
655 | cout<<"\nError parsing XML file 2";
|
---|
656 | exit(-1);
|
---|
657 | }
|
---|
658 |
|
---|
659 | /*->TiXmlElement* root = doc->RootElement();
|
---|
660 | TiXmlNode *node = root->FirstChild();
|
---|
661 |
|
---|
662 | TiXmlElement *element = 0;
|
---|
663 |
|
---|
664 | element = root->FirstChildElement("faces count");*/
|
---|
665 |
|
---|
666 | /*->if (!stricmp(root->Value(), "mesh"))
|
---|
667 | {
|
---|
668 | }
|
---|
669 |
|
---|
670 | /*->if (!stricmp(root->Value(), "mesh"))
|
---|
671 | {
|
---|
672 | delete doc;
|
---|
673 | MeshPtr newMesh = MeshManager::getSingleton().createManual("conversion",
|
---|
674 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
675 | xmlMeshSerializer->importMesh(opts.source, newMesh.getPointer());
|
---|
676 |
|
---|
677 | // Re-jig the buffers?
|
---|
678 | if (opts.reorganiseBuffers)
|
---|
679 | {
|
---|
680 | logMgr->logMessage("Reorganising vertex buffers to automatic layout..");
|
---|
681 | // Shared geometry
|
---|
682 | if (newMesh->sharedVertexData)
|
---|
683 | {
|
---|
684 | // Automatic
|
---|
685 | VertexDeclaration* newDcl =
|
---|
686 | newMesh->sharedVertexData->vertexDeclaration->getAutoOrganisedDeclaration(
|
---|
687 | newMesh->hasSkeleton());
|
---|
688 | if (*newDcl != *(newMesh->sharedVertexData->vertexDeclaration))
|
---|
689 | {
|
---|
690 | // Usages don't matter here since we're onlly exporting
|
---|
691 | BufferUsageList bufferUsages;
|
---|
692 | for (size_t u = 0; u <= newDcl->getMaxSource(); ++u)
|
---|
693 | bufferUsages.push_back(HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
---|
694 | newMesh->sharedVertexData->reorganiseBuffers(newDcl, bufferUsages);
|
---|
695 | }
|
---|
696 | }
|
---|
697 | // Dedicated geometry
|
---|
698 | Mesh::SubMeshIterator smIt = newMesh->getSubMeshIterator();
|
---|
699 | unsigned short idx = 0;
|
---|
700 | while (smIt.hasMoreElements())
|
---|
701 | {
|
---|
702 | SubMesh* sm = smIt.getNext();
|
---|
703 | if (!sm->useSharedVertices)
|
---|
704 | {
|
---|
705 | // Automatic
|
---|
706 | VertexDeclaration* newDcl =
|
---|
707 | sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(
|
---|
708 | newMesh->hasSkeleton());
|
---|
709 | if (*newDcl != *(sm->vertexData->vertexDeclaration))
|
---|
710 | {
|
---|
711 | // Usages don't matter here since we're onlly exporting
|
---|
712 | BufferUsageList bufferUsages;
|
---|
713 | for (size_t u = 0; u <= newDcl->getMaxSource(); ++u)
|
---|
714 | bufferUsages.push_back(HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
---|
715 | sm->vertexData->reorganiseBuffers(newDcl, bufferUsages);
|
---|
716 | }
|
---|
717 | }
|
---|
718 | }
|
---|
719 |
|
---|
720 | }
|
---|
721 |
|
---|
722 | // Prompt for LOD generation?
|
---|
723 | bool genLod = false;
|
---|
724 | bool askLodDtls = false;
|
---|
725 | if (!opts.interactiveMode) // derive from params if in batch mode
|
---|
726 | {
|
---|
727 | askLodDtls = false;
|
---|
728 | if (opts.numLods == 0)
|
---|
729 | {
|
---|
730 | genLod = false;
|
---|
731 | }
|
---|
732 | else
|
---|
733 | {
|
---|
734 | genLod = true;
|
---|
735 | }
|
---|
736 | }
|
---|
737 | else if(opts.numLods == 0) // otherwise only ask if not specified on command line
|
---|
738 | {
|
---|
739 | if (newMesh->getNumLodLevels() > 1)
|
---|
740 | {
|
---|
741 | std::cout << "\nXML already contains level-of detail information.\n"
|
---|
742 | "Do you want to: (u)se it, (r)eplace it, or (d)rop it?";
|
---|
743 | while (response == "")
|
---|
744 | {
|
---|
745 | cin >> response;
|
---|
746 | StringUtil::toLowerCase(response);
|
---|
747 | if (response == "u")
|
---|
748 | {
|
---|
749 | // Do nothing
|
---|
750 | }
|
---|
751 | else if (response == "d")
|
---|
752 | {
|
---|
753 | newMesh->removeLodLevels();
|
---|
754 | }
|
---|
755 | else if (response == "r")
|
---|
756 | {
|
---|
757 | genLod = true;
|
---|
758 | askLodDtls = true;
|
---|
759 |
|
---|
760 | }
|
---|
761 | else
|
---|
762 | {
|
---|
763 | response = "";
|
---|
764 | }
|
---|
765 | }// while response == ""
|
---|
766 | }
|
---|
767 | else // no existing LOD
|
---|
768 | {
|
---|
769 | std::cout << "\nWould you like to generate LOD information? (y/n)";
|
---|
770 | while (response == "")
|
---|
771 | {
|
---|
772 | cin >> response;
|
---|
773 | StringUtil::toLowerCase(response);
|
---|
774 | if (response == "n")
|
---|
775 | {
|
---|
776 | // Do nothing
|
---|
777 | }
|
---|
778 | else if (response == "y")
|
---|
779 | {
|
---|
780 | genLod = true;
|
---|
781 | askLodDtls = true;
|
---|
782 | }
|
---|
783 | }
|
---|
784 | }
|
---|
785 | }
|
---|
786 |
|
---|
787 | if (genLod)
|
---|
788 | {
|
---|
789 | unsigned short numLod;
|
---|
790 | ProgressiveMesh::VertexReductionQuota quota;
|
---|
791 | Real reduction;
|
---|
792 | Mesh::LodDistanceList distanceList;
|
---|
793 |
|
---|
794 | if (askLodDtls)
|
---|
795 | {
|
---|
796 | cout << "\nHow many extra LOD levels would you like to generate?";
|
---|
797 | cin >> numLod;
|
---|
798 |
|
---|
799 | cout << "\nWhat unit of reduction would you like to use:" <<
|
---|
800 | "\n(f)ixed or (p)roportional?";
|
---|
801 | cin >> response;
|
---|
802 | StringUtil::toLowerCase(response);
|
---|
803 | if (response == "f")
|
---|
804 | {
|
---|
805 | quota = ProgressiveMesh::VRQ_CONSTANT;
|
---|
806 | cout << "\nHow many vertices should be removed at each LOD?";
|
---|
807 | }
|
---|
808 | else
|
---|
809 | {
|
---|
810 | quota = ProgressiveMesh::VRQ_PROPORTIONAL;
|
---|
811 | cout << "\nWhat percentage of remaining vertices should be removed "
|
---|
812 | "\at each LOD (e.g. 50)?";
|
---|
813 | }
|
---|
814 | cin >> reduction;
|
---|
815 | if (quota == ProgressiveMesh::VRQ_PROPORTIONAL)
|
---|
816 | {
|
---|
817 | // Percentage -> parametric
|
---|
818 | reduction = reduction * 0.01f;
|
---|
819 | }
|
---|
820 |
|
---|
821 | cout << "\nEnter the distance for each LOD to come into effect.";
|
---|
822 |
|
---|
823 | Real distance;
|
---|
824 | for (unsigned short iLod = 0; iLod < numLod; ++iLod)
|
---|
825 | {
|
---|
826 | cout << "\nLOD Level " << (iLod+1) << ":";
|
---|
827 | cin >> distance;
|
---|
828 | distanceList.push_back(distance);
|
---|
829 | }
|
---|
830 | }
|
---|
831 | else
|
---|
832 | {
|
---|
833 | numLod = opts.numLods;
|
---|
834 | quota = opts.usePercent?
|
---|
835 | ProgressiveMesh::VRQ_PROPORTIONAL : ProgressiveMesh::VRQ_CONSTANT;
|
---|
836 | if (opts.usePercent)
|
---|
837 | {
|
---|
838 | reduction = opts.lodPercent * 0.01f;
|
---|
839 | }
|
---|
840 | else
|
---|
841 | {
|
---|
842 | reduction = opts.lodFixed;
|
---|
843 | }
|
---|
844 | Real currDist = 0;
|
---|
845 | for (unsigned short iLod = 0; iLod < numLod; ++iLod)
|
---|
846 | {
|
---|
847 | currDist += opts.lodDist;
|
---|
848 | distanceList.push_back(currDist);
|
---|
849 | }
|
---|
850 |
|
---|
851 | }
|
---|
852 |
|
---|
853 | newMesh->generateLodLevels(distanceList, quota, reduction);
|
---|
854 | }
|
---|
855 |
|
---|
856 | if (opts.interactiveMode)
|
---|
857 | {
|
---|
858 | std::cout << "\nWould you like to include edge lists to enable stencil shadows with this mesh? (y/n)";
|
---|
859 | while (response == "")
|
---|
860 | {
|
---|
861 | cin >> response;
|
---|
862 | StringUtil::toLowerCase(response);
|
---|
863 | if (response == "y")
|
---|
864 | {
|
---|
865 | // Do nothing
|
---|
866 | }
|
---|
867 | else if (response == "n")
|
---|
868 | {
|
---|
869 | opts.generateEdgeLists = false;
|
---|
870 | }
|
---|
871 | else
|
---|
872 | {
|
---|
873 | response = "";
|
---|
874 | }
|
---|
875 | }
|
---|
876 |
|
---|
877 |
|
---|
878 | std::cout << "\nWould you like to generate tangents to enable normal mapping with this mesh? (y/n)";
|
---|
879 | while (response == "")
|
---|
880 | {
|
---|
881 | cin >> response;
|
---|
882 | StringUtil::toLowerCase(response);
|
---|
883 | if (response == "y")
|
---|
884 | {
|
---|
885 | opts.generateTangents = true;
|
---|
886 | }
|
---|
887 | else if (response == "n")
|
---|
888 | {
|
---|
889 | // Do nothing
|
---|
890 | }
|
---|
891 | else
|
---|
892 | {
|
---|
893 | response = "";
|
---|
894 | }
|
---|
895 | }
|
---|
896 | }
|
---|
897 |
|
---|
898 | if (opts.generateEdgeLists)
|
---|
899 | {
|
---|
900 | std::cout << "Generating edge lists...." << std::endl;
|
---|
901 | newMesh->buildEdgeList();
|
---|
902 | }
|
---|
903 |
|
---|
904 | if (opts.generateTangents)
|
---|
905 | {
|
---|
906 | unsigned short srcTex, destTex;
|
---|
907 | bool existing = newMesh->suggestTangentVectorBuildParams(srcTex, destTex);
|
---|
908 | if (existing)
|
---|
909 | {
|
---|
910 | std::cout << "\nThis mesh appears to already have a set of 3D texture coordinates, " <<
|
---|
911 | "which would suggest tangent vectors have already been calculated. Do you really " <<
|
---|
912 | "want to generate new tangent vectors (may duplicate)? (y/n)";
|
---|
913 | while (response == "")
|
---|
914 | {
|
---|
915 | cin >> response;
|
---|
916 | StringUtil::toLowerCase(response);
|
---|
917 | if (response == "y")
|
---|
918 | {
|
---|
919 | // Do nothing
|
---|
920 | }
|
---|
921 | else if (response == "n")
|
---|
922 | {
|
---|
923 | opts.generateTangents = false;
|
---|
924 | }
|
---|
925 | else
|
---|
926 | {
|
---|
927 | response = "";
|
---|
928 | }
|
---|
929 | }
|
---|
930 |
|
---|
931 | }
|
---|
932 | if (opts.generateTangents)
|
---|
933 | {
|
---|
934 | std::cout << "Generating tangent vectors...." << std::endl;
|
---|
935 | newMesh->buildTangentVectors(srcTex, destTex);
|
---|
936 | }
|
---|
937 | }
|
---|
938 |
|
---|
939 |
|
---|
940 | meshSerializer->exportMesh(newMesh.getPointer(), opts.dest);
|
---|
941 | }
|
---|
942 | else if (!stricmp(root->Value(), "skeleton"))
|
---|
943 | {
|
---|
944 | delete doc;
|
---|
945 | SkeletonPtr newSkel = SkeletonManager::getSingleton().create("conversion",
|
---|
946 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
947 | xmlSkeletonSerializer->importSkeleton(opts.source, newSkel.getPointer());
|
---|
948 | skeletonSerializer->exportSkeleton(newSkel.getPointer(), opts.dest);
|
---|
949 | }*/
|
---|
950 |
|
---|
951 | /*->}
|
---|
952 |
|
---|
953 | void XMLToBinary(XmlOptions opts)
|
---|
954 | {
|
---|
955 | // Read root element and decide from there what type
|
---|
956 | String response;
|
---|
957 | TiXmlDocument* doc = new TiXmlDocument(opts.source);
|
---|
958 | // Some double-parsing here but never mind
|
---|
959 | if (!doc->LoadFile())
|
---|
960 | {
|
---|
961 | cout << "Unable to open file " << opts.source << " - fatal error." << endl;
|
---|
962 | exit (1);
|
---|
963 | }
|
---|
964 | TiXmlElement* root = doc->RootElement();
|
---|
965 | if (!stricmp(root->Value(), "mesh"))
|
---|
966 | {
|
---|
967 | delete doc;
|
---|
968 | MeshPtr newMesh = MeshManager::getSingleton().createManual("conversion",
|
---|
969 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
970 | VertexElementType colourElementType;
|
---|
971 | if (opts.d3d)
|
---|
972 | colourElementType = VET_COLOUR_ARGB;
|
---|
973 | else
|
---|
974 | colourElementType = VET_COLOUR_ABGR;
|
---|
975 |
|
---|
976 | xmlMeshSerializer->importMesh(opts.source, colourElementType, newMesh.getPointer());
|
---|
977 |
|
---|
978 | // Re-jig the buffers?
|
---|
979 | if (opts.reorganiseBuffers)
|
---|
980 | {
|
---|
981 | logMgr->logMessage("Reorganising vertex buffers to automatic layout..");
|
---|
982 | // Shared geometry
|
---|
983 | if (newMesh->sharedVertexData)
|
---|
984 | {
|
---|
985 | // Automatic
|
---|
986 | VertexDeclaration* newDcl =
|
---|
987 | newMesh->sharedVertexData->vertexDeclaration->getAutoOrganisedDeclaration(
|
---|
988 | newMesh->hasSkeleton(), newMesh->hasVertexAnimation());
|
---|
989 | if (*newDcl != *(newMesh->sharedVertexData->vertexDeclaration))
|
---|
990 | {
|
---|
991 | // Usages don't matter here since we're onlly exporting
|
---|
992 | BufferUsageList bufferUsages;
|
---|
993 | for (size_t u = 0; u <= newDcl->getMaxSource(); ++u)
|
---|
994 | bufferUsages.push_back(HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
---|
995 | newMesh->sharedVertexData->reorganiseBuffers(newDcl, bufferUsages);
|
---|
996 | }
|
---|
997 | }
|
---|
998 | // Dedicated geometry
|
---|
999 | Mesh::SubMeshIterator smIt = newMesh->getSubMeshIterator();
|
---|
1000 | unsigned short idx = 0;
|
---|
1001 | while (smIt.hasMoreElements())
|
---|
1002 | {
|
---|
1003 | SubMesh* sm = smIt.getNext();
|
---|
1004 | if (!sm->useSharedVertices)
|
---|
1005 | {
|
---|
1006 | // Automatic
|
---|
1007 | VertexDeclaration* newDcl =
|
---|
1008 | sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(
|
---|
1009 | newMesh->hasSkeleton(), newMesh->hasVertexAnimation());
|
---|
1010 | if (*newDcl != *(sm->vertexData->vertexDeclaration))
|
---|
1011 | {
|
---|
1012 | // Usages don't matter here since we're onlly exporting
|
---|
1013 | BufferUsageList bufferUsages;
|
---|
1014 | for (size_t u = 0; u <= newDcl->getMaxSource(); ++u)
|
---|
1015 | bufferUsages.push_back(HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
---|
1016 | sm->vertexData->reorganiseBuffers(newDcl, bufferUsages);
|
---|
1017 | }
|
---|
1018 | }
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | // Prompt for LOD generation?
|
---|
1024 | bool genLod = false;
|
---|
1025 | bool askLodDtls = false;
|
---|
1026 | if (!opts.interactiveMode) // derive from params if in batch mode
|
---|
1027 | {
|
---|
1028 | askLodDtls = false;
|
---|
1029 | if (opts.numLods == 0)
|
---|
1030 | {
|
---|
1031 | genLod = false;
|
---|
1032 | }
|
---|
1033 | else
|
---|
1034 | {
|
---|
1035 | genLod = true;
|
---|
1036 | }
|
---|
1037 | }
|
---|
1038 | else if(opts.numLods == 0) // otherwise only ask if not specified on command line
|
---|
1039 | {
|
---|
1040 | if (newMesh->getNumLodLevels() > 1)
|
---|
1041 | {
|
---|
1042 | std::cout << "\nXML already contains level-of detail information.\n"
|
---|
1043 | "Do you want to: (u)se it, (r)eplace it, or (d)rop it?";
|
---|
1044 | while (response == "")
|
---|
1045 | {
|
---|
1046 | cin >> response;
|
---|
1047 | StringUtil::toLowerCase(response);
|
---|
1048 | if (response == "u")
|
---|
1049 | {
|
---|
1050 | // Do nothing
|
---|
1051 | }
|
---|
1052 | else if (response == "d")
|
---|
1053 | {
|
---|
1054 | newMesh->removeLodLevels();
|
---|
1055 | }
|
---|
1056 | else if (response == "r")
|
---|
1057 | {
|
---|
1058 | genLod = true;
|
---|
1059 | askLodDtls = true;
|
---|
1060 |
|
---|
1061 | }
|
---|
1062 | else
|
---|
1063 | {
|
---|
1064 | response = "";
|
---|
1065 | }
|
---|
1066 | }// while response == ""
|
---|
1067 | }
|
---|
1068 | else // no existing LOD
|
---|
1069 | {
|
---|
1070 | std::cout << "\nWould you like to generate LOD information? (y/n)";
|
---|
1071 | while (response == "")
|
---|
1072 | {
|
---|
1073 | cin >> response;
|
---|
1074 | StringUtil::toLowerCase(response);
|
---|
1075 | if (response == "n")
|
---|
1076 | {
|
---|
1077 | // Do nothing
|
---|
1078 | }
|
---|
1079 | else if (response == "y")
|
---|
1080 | {
|
---|
1081 | genLod = true;
|
---|
1082 | askLodDtls = true;
|
---|
1083 | }
|
---|
1084 | }
|
---|
1085 | }
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | if (genLod)
|
---|
1089 | {
|
---|
1090 | unsigned short numLod;
|
---|
1091 | ProgressiveMesh::VertexReductionQuota quota;
|
---|
1092 | Real reduction;
|
---|
1093 | Mesh::LodDistanceList distanceList;
|
---|
1094 |
|
---|
1095 | if (askLodDtls)
|
---|
1096 | {
|
---|
1097 | cout << "\nHow many extra LOD levels would you like to generate?";
|
---|
1098 | cin >> numLod;
|
---|
1099 |
|
---|
1100 | cout << "\nWhat unit of reduction would you like to use:" <<
|
---|
1101 | "\n(f)ixed or (p)roportional?";
|
---|
1102 | cin >> response;
|
---|
1103 | StringUtil::toLowerCase(response);
|
---|
1104 | if (response == "f")
|
---|
1105 | {
|
---|
1106 | quota = ProgressiveMesh::VRQ_CONSTANT;
|
---|
1107 | cout << "\nHow many vertices should be removed at each LOD?";
|
---|
1108 | }
|
---|
1109 | else
|
---|
1110 | {
|
---|
1111 | quota = ProgressiveMesh::VRQ_PROPORTIONAL;
|
---|
1112 | cout << "\nWhat percentage of remaining vertices should be removed "
|
---|
1113 | "\at each LOD (e.g. 50)?";
|
---|
1114 | }
|
---|
1115 | cin >> reduction;
|
---|
1116 | if (quota == ProgressiveMesh::VRQ_PROPORTIONAL)
|
---|
1117 | {
|
---|
1118 | // Percentage -> parametric
|
---|
1119 | reduction = reduction * 0.01f;
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | cout << "\nEnter the distance for each LOD to come into effect.";
|
---|
1123 |
|
---|
1124 | Real distance;
|
---|
1125 | for (unsigned short iLod = 0; iLod < numLod; ++iLod)
|
---|
1126 | {
|
---|
1127 | cout << "\nLOD Level " << (iLod+1) << ":";
|
---|
1128 | cin >> distance;
|
---|
1129 | distanceList.push_back(distance);
|
---|
1130 | }
|
---|
1131 | }
|
---|
1132 | else
|
---|
1133 | {
|
---|
1134 | numLod = opts.numLods;
|
---|
1135 | quota = opts.usePercent?
|
---|
1136 | ProgressiveMesh::VRQ_PROPORTIONAL : ProgressiveMesh::VRQ_CONSTANT;
|
---|
1137 | if (opts.usePercent)
|
---|
1138 | {
|
---|
1139 | reduction = opts.lodPercent * 0.01f;
|
---|
1140 | }
|
---|
1141 | else
|
---|
1142 | {
|
---|
1143 | reduction = opts.lodFixed;
|
---|
1144 | }
|
---|
1145 | Real currDist = 0;
|
---|
1146 | for (unsigned short iLod = 0; iLod < numLod; ++iLod)
|
---|
1147 | {
|
---|
1148 | currDist += opts.lodDist;
|
---|
1149 | distanceList.push_back(currDist);
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | newMesh->generateLodLevels(distanceList, quota, reduction);
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | if (opts.interactiveMode)
|
---|
1158 | {
|
---|
1159 | std::cout << "\nWould you like to include edge lists to enable stencil shadows with this mesh? (y/n)";
|
---|
1160 | while (response == "")
|
---|
1161 | {
|
---|
1162 | cin >> response;
|
---|
1163 | StringUtil::toLowerCase(response);
|
---|
1164 | if (response == "y")
|
---|
1165 | {
|
---|
1166 | // Do nothing
|
---|
1167 | }
|
---|
1168 | else if (response == "n")
|
---|
1169 | {
|
---|
1170 | opts.generateEdgeLists = false;
|
---|
1171 | }
|
---|
1172 | else
|
---|
1173 | {
|
---|
1174 | response = "";
|
---|
1175 | }
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 |
|
---|
1179 | std::cout << "\nWould you like to generate tangents to enable normal mapping with this mesh? (y/n)";
|
---|
1180 | while (response == "")
|
---|
1181 | {
|
---|
1182 | cin >> response;
|
---|
1183 | StringUtil::toLowerCase(response);
|
---|
1184 | if (response == "y")
|
---|
1185 | {
|
---|
1186 | opts.generateTangents = true;
|
---|
1187 | }
|
---|
1188 | else if (response == "n")
|
---|
1189 | {
|
---|
1190 | // Do nothing
|
---|
1191 | }
|
---|
1192 | else
|
---|
1193 | {
|
---|
1194 | response = "";
|
---|
1195 | }
|
---|
1196 | }
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | if (opts.generateEdgeLists)
|
---|
1200 | {
|
---|
1201 | if (!opts.quietMode)
|
---|
1202 | {
|
---|
1203 | std::cout << "Generating edge lists...." << std::endl;
|
---|
1204 | }
|
---|
1205 | newMesh->buildEdgeList();
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | if (opts.generateTangents)
|
---|
1209 | {
|
---|
1210 | unsigned short srcTex, destTex;
|
---|
1211 | bool existing = newMesh->suggestTangentVectorBuildParams(srcTex, destTex);
|
---|
1212 | if (existing)
|
---|
1213 | {
|
---|
1214 | std::cout << "\nThis mesh appears to already have a set of 3D texture coordinates, " <<
|
---|
1215 | "which would suggest tangent vectors have already been calculated. Do you really " <<
|
---|
1216 | "want to generate new tangent vectors (may duplicate)? (y/n)";
|
---|
1217 | while (response == "")
|
---|
1218 | {
|
---|
1219 | cin >> response;
|
---|
1220 | StringUtil::toLowerCase(response);
|
---|
1221 | if (response == "y")
|
---|
1222 | {
|
---|
1223 | // Do nothing
|
---|
1224 | }
|
---|
1225 | else if (response == "n")
|
---|
1226 | {
|
---|
1227 | opts.generateTangents = false;
|
---|
1228 | }
|
---|
1229 | else
|
---|
1230 | {
|
---|
1231 | response = "";
|
---|
1232 | }
|
---|
1233 | }
|
---|
1234 |
|
---|
1235 | }
|
---|
1236 | if (opts.generateTangents)
|
---|
1237 | {
|
---|
1238 | if (!opts.quietMode)
|
---|
1239 | {
|
---|
1240 | std::cout << "Generating tangent vectors...." << std::endl;
|
---|
1241 | }
|
---|
1242 | newMesh->buildTangentVectors(srcTex, destTex);
|
---|
1243 | }
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 |
|
---|
1247 | meshSerializer->exportMesh(newMesh.getPointer(), opts.dest, opts.endian);
|
---|
1248 | }
|
---|
1249 | else if (!stricmp(root->Value(), "skeleton"))
|
---|
1250 | {
|
---|
1251 | delete doc;
|
---|
1252 | SkeletonPtr newSkel = SkeletonManager::getSingleton().create("conversion",
|
---|
1253 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
1254 | xmlSkeletonSerializer->importSkeleton(opts.source, newSkel.getPointer());
|
---|
1255 | if (opts.optimiseAnimations)
|
---|
1256 | {
|
---|
1257 | newSkel->optimiseAllAnimations();
|
---|
1258 | }
|
---|
1259 | skeletonSerializer->exportSkeleton(newSkel.getPointer(), opts.dest, opts.endian);
|
---|
1260 | }
|
---|
1261 |
|
---|
1262 |
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | void skeletonToXML(XmlOptions opts)
|
---|
1266 | {
|
---|
1267 |
|
---|
1268 | std::ifstream ifs;
|
---|
1269 | ifs.open(opts.source.c_str(), std::ios_base::in | std::ios_base::binary);
|
---|
1270 | if (!ifs)
|
---|
1271 | {
|
---|
1272 | cout << "Unable to load file " << opts.source << endl;
|
---|
1273 | exit(1);
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | SkeletonPtr skel = SkeletonManager::getSingleton().create("conversion",
|
---|
1277 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
1278 |
|
---|
1279 | // pass false for freeOnClose to FileStreamDataStream since ifs is created localy on stack
|
---|
1280 | DataStreamPtr stream(new FileStreamDataStream(opts.source, &ifs, false));
|
---|
1281 | skeletonSerializer->importSkeleton(stream, skel.getPointer());
|
---|
1282 |
|
---|
1283 | xmlSkeletonSerializer->exportSkeleton(skel.getPointer(), opts.dest);
|
---|
1284 |
|
---|
1285 | }*/
|
---|
1286 |
|
---|
1287 | int main(int numargs, char** args)
|
---|
1288 | {
|
---|
1289 | CMesh mesh;
|
---|
1290 |
|
---|
1291 | mesh.LoadMesh(numargs, args);
|
---|
1292 |
|
---|
1293 | /*->snObject m_pObject;
|
---|
1294 |
|
---|
1295 | if (numargs < 2)
|
---|
1296 | {
|
---|
1297 | help();
|
---|
1298 | return -1;
|
---|
1299 | }
|
---|
1300 |
|
---|
1301 | XmlOptions opts = parseArgs(numargs, args);
|
---|
1302 |
|
---|
1303 | logMgr = new LogManager();
|
---|
1304 | logMgr->createLog(opts.logFile, false, !opts.quietMode);
|
---|
1305 | rgm = new ResourceGroupManager();
|
---|
1306 | mth = new Math();
|
---|
1307 | meshMgr = new MeshManager();
|
---|
1308 | matMgr = new MaterialManager();
|
---|
1309 | matMgr->initialise();
|
---|
1310 | skelMgr = new SkeletonManager();
|
---|
1311 | meshSerializer = new MeshSerializer();
|
---|
1312 | xmlMeshSerializer = new XMLMeshSerializer();
|
---|
1313 | skeletonSerializer = new SkeletonSerializer();
|
---|
1314 | xmlSkeletonSerializer = new XMLSkeletonSerializer();
|
---|
1315 | bufferManager = new DefaultHardwareBufferManager(); // needed because we don't have a rendersystem
|
---|
1316 |
|
---|
1317 |
|
---|
1318 |
|
---|
1319 | if (opts.sourceExt == "mesh")
|
---|
1320 | {
|
---|
1321 | meshToXML(opts);
|
---|
1322 | opts.source = opts.dest;
|
---|
1323 | opts.sourceExt = opts.destExt;
|
---|
1324 | XMLToSNStr(m_pObject, opts);
|
---|
1325 | }
|
---|
1326 | /*->else if (opts.sourceExt == "skeleton")
|
---|
1327 | {
|
---|
1328 | skeletonToXML(opts);
|
---|
1329 | }
|
---|
1330 | else if (opts.sourceExt == "xml")
|
---|
1331 | {
|
---|
1332 | XMLToBinary(opts);
|
---|
1333 | }*/
|
---|
1334 | /*->else
|
---|
1335 | {
|
---|
1336 | cout << "Unknown input type.\n";
|
---|
1337 | exit(1);
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 |
|
---|
1341 |
|
---|
1342 | delete xmlSkeletonSerializer;
|
---|
1343 | delete skeletonSerializer;
|
---|
1344 | delete xmlMeshSerializer;
|
---|
1345 | delete meshSerializer;
|
---|
1346 | delete skelMgr;
|
---|
1347 | delete matMgr;
|
---|
1348 | delete meshMgr;
|
---|
1349 | delete bufferManager;
|
---|
1350 | delete mth;
|
---|
1351 | delete rgm;
|
---|
1352 | delete logMgr;*/
|
---|
1353 |
|
---|
1354 | return 0;
|
---|
1355 |
|
---|
1356 | }
|
---|
1357 |
|
---|