1 | #include <iostream>
|
---|
2 | #include <fstream>
|
---|
3 | #include <time.h>
|
---|
4 | #include "GeoLodStripsConstructor.h"
|
---|
5 | #include "GeoMeshLoader.h"
|
---|
6 |
|
---|
7 | using namespace Geometry;
|
---|
8 |
|
---|
9 | //---------------------------------------------------------------------------
|
---|
10 | // Call GenerarModeloV and CopiarVectorsArraysNUEVAED to make changes.
|
---|
11 | //---------------------------------------------------------------------------
|
---|
12 | void LodStripsConstructor::GenerarModeloCompleto(TIPOFUNC upb)
|
---|
13 | {
|
---|
14 | float percent;
|
---|
15 |
|
---|
16 | this->GenerarModeloV(upb);
|
---|
17 | this->CopiarVectors2ArraysNUEVAED();
|
---|
18 |
|
---|
19 | // Last updtate of the progress bar.
|
---|
20 | percent = 100.0;
|
---|
21 | upb(percent);
|
---|
22 | }
|
---|
23 |
|
---|
24 | //---------------------------------------------------------------------------
|
---|
25 | // It makes Lods changes and count them.
|
---|
26 | //---------------------------------------------------------------------------
|
---|
27 | void LodStripsConstructor::CalcularCambiosLODsVNuevaED(TIPOFUNC upb)
|
---|
28 | {
|
---|
29 | // LODPosition pos;
|
---|
30 | // vector <LODPosition> listaPos;
|
---|
31 | long int k;
|
---|
32 | long int i;
|
---|
33 | unsigned long int t;
|
---|
34 | long int r;
|
---|
35 | unsigned long int v;
|
---|
36 | long int p0;
|
---|
37 | long int lod = 0;
|
---|
38 | long int sigue;
|
---|
39 | long int ac[3] = {0,0,0};
|
---|
40 | long int totalRegs = 0;
|
---|
41 | long int RegsCambios;
|
---|
42 | std::vector<std::vector<int> > TiraOriginal;
|
---|
43 | LODData regLOD;
|
---|
44 | //LODChanges listaCambios;
|
---|
45 | std::vector<LODData> listaCambios;
|
---|
46 | float percent;
|
---|
47 | float increment;
|
---|
48 | long int update;
|
---|
49 |
|
---|
50 | // Saves original copy.
|
---|
51 | TiraOriginal = this->cStrips;
|
---|
52 |
|
---|
53 | this->MARCAVACIO = int(10 * this->cVerts.size());
|
---|
54 |
|
---|
55 | listaCambios.clear();
|
---|
56 |
|
---|
57 | // Initialize increment.
|
---|
58 | increment = 0.0;
|
---|
59 |
|
---|
60 | for (lod = 0; ((this->cVerts[lod].Next) != -1); lod++)
|
---|
61 | {
|
---|
62 | increment += 1.0;
|
---|
63 | }
|
---|
64 |
|
---|
65 | update = -1;
|
---|
66 | increment = (float)30.0 / increment;
|
---|
67 | percent = 1.0;
|
---|
68 |
|
---|
69 | this->LodsDisp = this->TOTALCAMBIOS = lod;
|
---|
70 | pCambios = new uint32[this->TOTALCAMBIOS];
|
---|
71 | pCambios[0] = 0;
|
---|
72 |
|
---|
73 | for (lod = 0; ((this->cVerts[lod].Next) != -1); lod++)
|
---|
74 | {
|
---|
75 | /* if (update != (int)(increment * lod))
|
---|
76 | {
|
---|
77 | update = (int)(increment * lod);
|
---|
78 | upb(percent);
|
---|
79 | }*/
|
---|
80 |
|
---|
81 | tipoVertice & cVertsLOD = this->cVerts[lod];
|
---|
82 |
|
---|
83 | RegsCambios = 0;
|
---|
84 | regLOD.obligatory = this->Ordenacion[lod].obligatorio;
|
---|
85 |
|
---|
86 | for(t = 0; t < this->cStrips.size(); t++)
|
---|
87 | {
|
---|
88 |
|
---|
89 | std::vector<int> & cStripsT = this->cStrips[t];
|
---|
90 |
|
---|
91 | // Initialize.
|
---|
92 | regLOD.strip = this->MARCAVACIO;
|
---|
93 |
|
---|
94 | // Change vertices.
|
---|
95 | totalRegs = 0;
|
---|
96 |
|
---|
97 | for (v = 0; v < cStripsT.size(); v++)
|
---|
98 | {
|
---|
99 | if (cStripsT[v] == lod)
|
---|
100 | {
|
---|
101 | // Strips.
|
---|
102 | if (regLOD.strip == this->MARCAVACIO)
|
---|
103 | {
|
---|
104 | regLOD.strip = t;
|
---|
105 | }
|
---|
106 |
|
---|
107 | ++totalRegs;
|
---|
108 |
|
---|
109 | cDatos.push_back(v);
|
---|
110 |
|
---|
111 | cStripsT[v] = cVertsLOD.Next;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | regLOD.nP = char(totalRegs);
|
---|
116 |
|
---|
117 | // Simplifications length 1.
|
---|
118 | // Changes for simplification of level 1 to greater than 2.
|
---|
119 | totalRegs = 0;
|
---|
120 | i = 0;
|
---|
121 | r = 0;
|
---|
122 | sigue = 0;
|
---|
123 | k = long(cStripsT.size()-3);
|
---|
124 |
|
---|
125 | while (i < k)
|
---|
126 | {
|
---|
127 | if ( (cStripsT[i] == cStripsT[i+1])
|
---|
128 | &&
|
---|
129 | (cStripsT[i+1] == cStripsT[i+2])
|
---|
130 | )
|
---|
131 | {
|
---|
132 | // Saves beginning of repetition.
|
---|
133 | if (!r)
|
---|
134 | {
|
---|
135 | p0 = i;
|
---|
136 | }
|
---|
137 |
|
---|
138 | //cStripsT.eraseAtPos(i);
|
---|
139 | cStripsT.erase(cStripsT.begin()+i);
|
---|
140 | i--;
|
---|
141 | r++;
|
---|
142 |
|
---|
143 | if ((i+1) != cStripsT.size()-1)
|
---|
144 | {
|
---|
145 | sigue = 1;
|
---|
146 | }
|
---|
147 | else
|
---|
148 | {
|
---|
149 | sigue = 0;
|
---|
150 | }
|
---|
151 |
|
---|
152 | }
|
---|
153 | else
|
---|
154 | {
|
---|
155 | sigue = 0;
|
---|
156 | }
|
---|
157 |
|
---|
158 | if (!sigue && r)
|
---|
159 | {
|
---|
160 |
|
---|
161 |
|
---|
162 | /*
|
---|
163 | cDatos.push_back(p0);
|
---|
164 | cDatos.push_back(r);
|
---|
165 |
|
---|
166 | r = 0;
|
---|
167 | k = long(cStripsT.size()-r-3);
|
---|
168 | */
|
---|
169 | long auxp0, auxr;
|
---|
170 | //regLOD.strip= t;
|
---|
171 | auxp0= p0;
|
---|
172 | auxr= r;
|
---|
173 |
|
---|
174 | if (r==1)
|
---|
175 | {
|
---|
176 | while(r>0)
|
---|
177 | {
|
---|
178 | cStripsT.insert(cStripsT.begin()+p0,cStripsT[p0]);
|
---|
179 | r--;
|
---|
180 | }
|
---|
181 | i=p0;
|
---|
182 | }
|
---|
183 | else
|
---|
184 | {
|
---|
185 | if (r%2) //If r is odd the changes are undone
|
---|
186 | {
|
---|
187 | cStripsT.insert(cStripsT.begin()+p0,cStripsT[p0]);
|
---|
188 | r--;
|
---|
189 | auxr=r;
|
---|
190 | }
|
---|
191 | //listaPos.push_back(pos);
|
---|
192 | cDatos.push_back(auxp0);
|
---|
193 | cDatos.push_back(auxr);
|
---|
194 | if (regLOD.strip == this->MARCAVACIO)
|
---|
195 | {
|
---|
196 | regLOD.strip = t;
|
---|
197 | }
|
---|
198 |
|
---|
199 | ++totalRegs;
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | r = 0;
|
---|
204 |
|
---|
205 | k = (long)(cStripsT.size() - 3);
|
---|
206 |
|
---|
207 | }
|
---|
208 |
|
---|
209 | i++;
|
---|
210 | }
|
---|
211 |
|
---|
212 | regLOD.nL1 = char(totalRegs);
|
---|
213 |
|
---|
214 | //TERCERO: Simplificaciones de Longitud 2 tipo V1 V2 V1 V2 -> V1 V2
|
---|
215 | totalRegs = 0;
|
---|
216 | i = 0;
|
---|
217 | r = 0;
|
---|
218 | sigue = 0;
|
---|
219 | k = long(cStripsT.size() - 4);
|
---|
220 |
|
---|
221 | while (i < k)
|
---|
222 | {
|
---|
223 | if ( (cStripsT[i] == cStripsT[i+2])
|
---|
224 | &&
|
---|
225 | (cStripsT[i+1] == cStripsT[i+3])
|
---|
226 | )
|
---|
227 | {
|
---|
228 | if (!r)
|
---|
229 | {
|
---|
230 | p0 = i;
|
---|
231 | }
|
---|
232 |
|
---|
233 | //cStripsT.eraseAtPos(i);
|
---|
234 | cStripsT.erase(this->cStrips[t].begin()+i);
|
---|
235 | //cStripsT.eraseAtPos(i);
|
---|
236 | cStripsT.erase(this->cStrips[t].begin()+i);
|
---|
237 | r++;
|
---|
238 |
|
---|
239 | i -= 2;
|
---|
240 |
|
---|
241 | if ((i+1) != cStripsT.size()-3)
|
---|
242 | {
|
---|
243 | sigue = 1;
|
---|
244 | }
|
---|
245 | else
|
---|
246 | {
|
---|
247 | sigue = 0;
|
---|
248 | }
|
---|
249 |
|
---|
250 | }
|
---|
251 | else
|
---|
252 | {
|
---|
253 | sigue = 0;
|
---|
254 | }
|
---|
255 |
|
---|
256 | if (!sigue && r)
|
---|
257 | {
|
---|
258 | if (regLOD.strip == this->MARCAVACIO)
|
---|
259 | {
|
---|
260 | regLOD.strip = t;
|
---|
261 | }
|
---|
262 |
|
---|
263 | ++totalRegs;
|
---|
264 |
|
---|
265 | cDatos.push_back(p0);
|
---|
266 | cDatos.push_back(r);
|
---|
267 |
|
---|
268 | r = 0;
|
---|
269 | k = long((cStripsT.size()-4-2*r));
|
---|
270 | }
|
---|
271 |
|
---|
272 | i++;
|
---|
273 | }
|
---|
274 |
|
---|
275 | regLOD.nL2 = char(totalRegs);
|
---|
276 |
|
---|
277 | if (regLOD.strip != this->MARCAVACIO)
|
---|
278 | {
|
---|
279 | RegsCambios++;
|
---|
280 | listaCambios.push_back(regLOD);
|
---|
281 | }
|
---|
282 | }// End for t.
|
---|
283 |
|
---|
284 | pCambios[lod] = RegsCambios;
|
---|
285 | }// End for lod.
|
---|
286 |
|
---|
287 | this->cCambios = listaCambios;
|
---|
288 |
|
---|
289 | // Guardar el numero de LODS disponibles.
|
---|
290 | this->TOTALCAMBIOS = this->LodsDisp=lod;
|
---|
291 |
|
---|
292 | //Retornar a la lista original
|
---|
293 | this->cStrips = TiraOriginal;
|
---|
294 | }
|
---|
295 |
|
---|
296 | //---------------------------------------------------------------------------
|
---|
297 | //Put in order vertex of Mesh from simplification sequence
|
---|
298 | //---------------------------------------------------------------------------
|
---|
299 | void LodStripsConstructor::OrdenarModeloVQSLIM(TIPOFUNC upb)
|
---|
300 | {
|
---|
301 | unsigned long int i;
|
---|
302 | unsigned long int j;
|
---|
303 | unsigned long int t;
|
---|
304 | unsigned long int v;
|
---|
305 | long int vSig;
|
---|
306 | long int k;
|
---|
307 | VECTORVERTEX Vertices;
|
---|
308 | std::vector<tipoVertice> NuevosVerts;
|
---|
309 | //vector <VECTORINT> NuevasTiras;
|
---|
310 | std::vector<std::vector<int> > NuevasTiras;
|
---|
311 | // VECTORINT tira;
|
---|
312 | std::vector<int> tira;
|
---|
313 | vector <Index> mV1Aux;
|
---|
314 | tipoOrden Orden;
|
---|
315 | tipoOrden *Ord;
|
---|
316 | bool bEncontrado;
|
---|
317 | long int c1;
|
---|
318 | long int c2;
|
---|
319 | // Progress bar
|
---|
320 | float percent;
|
---|
321 | float increment;
|
---|
322 | long int update;
|
---|
323 |
|
---|
324 | bEncontrado = false;
|
---|
325 |
|
---|
326 | size_t mStepsSize = mGeoMeshSQ->mSteps.size();
|
---|
327 |
|
---|
328 | c1 = 0;
|
---|
329 | c2 = 0;
|
---|
330 |
|
---|
331 | update = -1;
|
---|
332 | percent = 1.0;
|
---|
333 | increment = (float)(10.0) / (float)mStepsSize;
|
---|
334 |
|
---|
335 | for (i = 0; i < mStepsSize; i++)
|
---|
336 | {
|
---|
337 | if (update != (int)(i * increment))
|
---|
338 | {
|
---|
339 | update = (int)(i * increment);
|
---|
340 | upb(percent);
|
---|
341 | }
|
---|
342 |
|
---|
343 | const Geometry::MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i];
|
---|
344 |
|
---|
345 | mV1Aux.push_back(theStep.mV1);
|
---|
346 |
|
---|
347 | Orden.vQslimNext = theStep.mV0;
|
---|
348 | Orden.vQslim = theStep.mV1;
|
---|
349 | Orden.obligatorio = theStep.obligatorio;
|
---|
350 | Orden.vLS = i;
|
---|
351 |
|
---|
352 | Orden.x = theStep.x;
|
---|
353 | Orden.vLSNext = -1;
|
---|
354 | Orden.cambio = "n";
|
---|
355 |
|
---|
356 | Ordenacion.push_back(Orden);
|
---|
357 | }
|
---|
358 |
|
---|
359 | this->NumVertsRepetidos = c2;
|
---|
360 |
|
---|
361 | update = -1;
|
---|
362 | increment = (float)(10.0) / (float)(Ordenacion.size());
|
---|
363 | percent = 1.0;
|
---|
364 |
|
---|
365 | // Change all vertices that have x != 0.
|
---|
366 | for(i = 0; i < Ordenacion.size(); i++)
|
---|
367 | {
|
---|
368 | if (update != (int)(i * increment))
|
---|
369 | {
|
---|
370 | update = (int)(i * increment);
|
---|
371 | upb(percent);
|
---|
372 | }
|
---|
373 |
|
---|
374 | Ord = &(Ordenacion[i]);
|
---|
375 |
|
---|
376 | if (Ord->x!=0)
|
---|
377 | {
|
---|
378 | // Change the simplification order.
|
---|
379 | v = Ord->vQslim;
|
---|
380 | Ord->vQslim = Ord->vQslimNext;
|
---|
381 | Ord->vQslimNext = v;
|
---|
382 |
|
---|
383 | for (j = i+1; j < Ordenacion.size(); j++)
|
---|
384 | {
|
---|
385 | tipoOrden & ordJ = Ordenacion[j];
|
---|
386 | if (ordJ.vQslim == Ord->vQslim)
|
---|
387 | {
|
---|
388 | ordJ.vQslim = Ord->vQslimNext;
|
---|
389 | ordJ.cambio = "y";
|
---|
390 | }
|
---|
391 | else if (ordJ.vQslimNext == Ord->vQslim)
|
---|
392 | {
|
---|
393 | ordJ.vQslimNext = Ord->vQslimNext;
|
---|
394 | ordJ.cambio = "y";
|
---|
395 | }
|
---|
396 | }
|
---|
397 | }
|
---|
398 | }
|
---|
399 |
|
---|
400 | update = -1;
|
---|
401 | increment = (float)(10.0) / (float)(Ordenacion.size());
|
---|
402 | percent = 1.0;
|
---|
403 |
|
---|
404 | // 3 seg.
|
---|
405 | //Ordenacion de los vertices
|
---|
406 | for(i = 0; i < Ordenacion.size(); i++)
|
---|
407 | {
|
---|
408 | if (update != (int)(i * increment))
|
---|
409 | {
|
---|
410 | update = (int)(i * increment);
|
---|
411 | upb(percent);
|
---|
412 | }
|
---|
413 |
|
---|
414 | c1++;
|
---|
415 | NuevosVerts.push_back(this->cVerts[Ordenacion[i].vQslim]);
|
---|
416 |
|
---|
417 | cVerts[Ordenacion[i].vQslim].Next = -1;
|
---|
418 |
|
---|
419 | }
|
---|
420 |
|
---|
421 | // Añadir aquellos vertices que no estaban en NuevosVerts
|
---|
422 | // y no se simplificaban.
|
---|
423 | int cont = 0;
|
---|
424 | int contestaban = 0;
|
---|
425 |
|
---|
426 | size_t cVertsSize = this->cVerts.size();
|
---|
427 | for(i = 0; i < cVertsSize; i++)
|
---|
428 | {
|
---|
429 | if (this->cVerts[i].Next != -1)
|
---|
430 | {
|
---|
431 | cont++;
|
---|
432 | NuevosVerts.push_back(this->cVerts[i]);
|
---|
433 | Orden.vLS = int(Ordenacion.size());
|
---|
434 | Orden.obligatorio = 0;
|
---|
435 | Orden.vLSNext = -1;
|
---|
436 | Orden.vQslim = i;
|
---|
437 | Orden.vQslimNext = -1;
|
---|
438 |
|
---|
439 | Ordenacion.push_back(Orden);
|
---|
440 | }
|
---|
441 | else
|
---|
442 | {
|
---|
443 | contestaban++;
|
---|
444 | }
|
---|
445 | }
|
---|
446 |
|
---|
447 | update = -1;
|
---|
448 | increment = (float)(10.0) / (float)(Ordenacion.size());
|
---|
449 | percent = 1.0;
|
---|
450 |
|
---|
451 | // 2 min.
|
---|
452 | // Calcular los siguiente teniendo en cuenta el simplif.
|
---|
453 | for (i = 0; i < Ordenacion.size(); i++)
|
---|
454 | {
|
---|
455 | if (update != (int)(i * increment))
|
---|
456 | {
|
---|
457 | update = (int)(i * increment);
|
---|
458 | upb(percent);
|
---|
459 | }
|
---|
460 |
|
---|
461 | v = Ordenacion[i].vQslimNext;
|
---|
462 |
|
---|
463 | //Buscar ese vertice v cual es ahora
|
---|
464 | vSig = 0;
|
---|
465 |
|
---|
466 | for (t = 0; t < Ordenacion.size() && !vSig;t++)
|
---|
467 | {
|
---|
468 | if (Ordenacion[t].vQslim==v)
|
---|
469 | {
|
---|
470 | vSig=Ordenacion[t].vLS;
|
---|
471 | }
|
---|
472 | }
|
---|
473 |
|
---|
474 | if (vSig!=0)
|
---|
475 | {
|
---|
476 | Ordenacion[i].vLSNext = vSig;
|
---|
477 | }
|
---|
478 | }
|
---|
479 |
|
---|
480 | //Creacion de nuevas tiras con las mismas dimensiones
|
---|
481 | size_t cStripsSize = this->cStrips.size();
|
---|
482 | for(t = 0; t < cStripsSize; t++)
|
---|
483 | {
|
---|
484 | tira.clear();
|
---|
485 |
|
---|
486 | size_t cStripsSizeT = this->cStrips[t].size();
|
---|
487 | for(i = 0; i < cStripsSizeT; i++)
|
---|
488 | tira.push_back(0);
|
---|
489 |
|
---|
490 | NuevasTiras.push_back(tira);
|
---|
491 | }
|
---|
492 |
|
---|
493 | update = -1;
|
---|
494 | increment = (float)(20.0) / (float)(NuevosVerts.size());
|
---|
495 | percent = 1.0;
|
---|
496 |
|
---|
497 | k = 0;
|
---|
498 |
|
---|
499 | // 2 min.
|
---|
500 | //Cambiar los vertices de las tiras
|
---|
501 | size_t NuevosVertsSize = NuevosVerts.size();
|
---|
502 | for(v = 0; v < NuevosVertsSize; v++)
|
---|
503 | {
|
---|
504 | if (update != (int)(v * increment))
|
---|
505 | {
|
---|
506 | update = (int)(v * increment);
|
---|
507 | upb(percent);
|
---|
508 | }
|
---|
509 |
|
---|
510 | const tipoOrden & OrdenacionV = Ordenacion[v];
|
---|
511 |
|
---|
512 | for(t = 0; t < cStrips.size(); t++)
|
---|
513 | {
|
---|
514 | std::vector<int> & thisStrip = cStrips[t];
|
---|
515 | std::vector<int> & NuevasTirasT = NuevasTiras[t];
|
---|
516 | size_t cStripsSizeT = thisStrip.size();
|
---|
517 | for(i = 0; i < cStripsSizeT; i++)
|
---|
518 | {
|
---|
519 | if (thisStrip[i] == OrdenacionV.vQslim)
|
---|
520 | {
|
---|
521 | k++;
|
---|
522 | NuevasTirasT[i] = v;
|
---|
523 | }
|
---|
524 | }
|
---|
525 | }
|
---|
526 | }
|
---|
527 |
|
---|
528 | //Cambiar a Tiras Nuevas
|
---|
529 | this->cStrips = NuevasTiras;
|
---|
530 |
|
---|
531 | //NuevosVerts y Ordenacion = tamaño.
|
---|
532 | NuevosVertsSize = NuevosVerts.size();
|
---|
533 | for(i = 0; i < NuevosVertsSize; i++)
|
---|
534 | {
|
---|
535 | NuevosVerts[i].Next = Ordenacion[i].vLSNext;
|
---|
536 | }
|
---|
537 |
|
---|
538 | //Cambiar cVerts por nuevosVerts.
|
---|
539 | this->cVerts = NuevosVerts;
|
---|
540 |
|
---|
541 | //percent = 100.0;
|
---|
542 | //upb(percent);
|
---|
543 | }
|
---|
544 |
|
---|
545 | //---------------------------------------------------------------------------
|
---|
546 | // Constructor of LodStripsConstructor object from
|
---|
547 | // a Mesh and MeshSimplificationSequence.
|
---|
548 | //---------------------------------------------------------------------------
|
---|
549 | LodStripsConstructor::LodStripsConstructor(const Mesh *m,
|
---|
550 | const MeshSimplificationSequence *ms,
|
---|
551 | size_t submesh,
|
---|
552 | TIPOFUNC upb)
|
---|
553 | {
|
---|
554 | MARCA = TOTALTIRAS = TOTALVERTS = TOTALCAMBIOS = 0;
|
---|
555 |
|
---|
556 | meshoriginal = m;
|
---|
557 |
|
---|
558 | mGeoMesh = new Mesh();
|
---|
559 | *mGeoMesh = *m;
|
---|
560 |
|
---|
561 | mInitialMesh = new Mesh();
|
---|
562 | *mInitialMesh = *m;
|
---|
563 |
|
---|
564 | this->mGeoMeshSQ = const_cast<MeshSimplificationSequence*>(ms);
|
---|
565 |
|
---|
566 | // Set the leaves submesh.
|
---|
567 | mSubMeshLeaves = submesh;
|
---|
568 |
|
---|
569 | this->GenerarModeloCompleto(upb);
|
---|
570 |
|
---|
571 | // Sort submesh bones.
|
---|
572 | this->sortBones();
|
---|
573 | }
|
---|
574 |
|
---|
575 | //---------------------------------------------------------------------------
|
---|
576 | // Destructor LodStripsConstructor object
|
---|
577 | //---------------------------------------------------------------------------
|
---|
578 | LodStripsConstructor::~LodStripsConstructor()
|
---|
579 | {
|
---|
580 | delete [] vDatos;
|
---|
581 | delete [] vCambios;
|
---|
582 | /* vector <LODData> cCambiosTemp;
|
---|
583 | cCambios.swap(cCambiosTemp);*/
|
---|
584 | cCambios.clear();
|
---|
585 |
|
---|
586 | /* VECTORUNINT cDatosTemp;
|
---|
587 | cDatos.swap(cDatosTemp);*/
|
---|
588 | cDatos.clear();
|
---|
589 |
|
---|
590 | delete [] vStrips;
|
---|
591 |
|
---|
592 | delete [] vVerts;
|
---|
593 |
|
---|
594 | // vector <VECTORINT> cStripsTemp;
|
---|
595 | // cStrips.swap(cStripsTemp);;
|
---|
596 | cStrips.clear();
|
---|
597 |
|
---|
598 | // VECTORVERTEX cVertsTemp;
|
---|
599 | // cVerts.swap(cVertsTemp);
|
---|
600 | cVerts.clear();
|
---|
601 |
|
---|
602 | delete [] pCambios;
|
---|
603 |
|
---|
604 | delete mInitialMesh;
|
---|
605 | delete mGeoMesh;
|
---|
606 | }
|
---|
607 |
|
---|
608 | //---------------------------------------------------------------------------
|
---|
609 | // Build lod file with necessary information and save all changes at
|
---|
610 | // lodStripConstructor object.
|
---|
611 | //---------------------------------------------------------------------------
|
---|
612 | void LodStripsConstructor::Save(std::string filename)
|
---|
613 | {
|
---|
614 | unsigned int i, j;
|
---|
615 | int k = 0;
|
---|
616 | char simp[256];
|
---|
617 |
|
---|
618 | int vertexCount = this->cVerts.size();
|
---|
619 | int changesCount = this->cCambios.size();
|
---|
620 | int dataCount = this->cDatos.size();
|
---|
621 | int cambiosCount = this->TOTALCAMBIOS;
|
---|
622 | int size = changesCount*sizeof(LODData) +
|
---|
623 | (vertexCount + dataCount + cambiosCount + 4)*sizeof(int) +
|
---|
624 | CHUNK_OVERHEAD_SIZE;
|
---|
625 |
|
---|
626 | FILE *f = fopen(filename.c_str(),"ab");
|
---|
627 |
|
---|
628 | unsigned short chunkid = 0xabcd;
|
---|
629 | fwrite(&chunkid,sizeof(unsigned short),1,f);
|
---|
630 | fwrite(&size,sizeof(unsigned long),1,f);
|
---|
631 |
|
---|
632 | fwrite(&vertexCount, sizeof(int), 1, f);
|
---|
633 | for(i = 0; i < this->cVerts.size(); i++)
|
---|
634 | {
|
---|
635 | int auxv = cVerts[i].Next;
|
---|
636 | fwrite(&auxv, sizeof(int), 1, f);
|
---|
637 | }
|
---|
638 |
|
---|
639 | // VERTICES.
|
---|
640 | /* for(i = 0; i < this->cVerts.size(); i++)
|
---|
641 | {
|
---|
642 | sprintf(simp,"v %d\n",cVerts[i].Next);
|
---|
643 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
644 | }
|
---|
645 | */
|
---|
646 |
|
---|
647 | // CSTRIPS.
|
---|
648 | this->TOTALINDICES = 0;
|
---|
649 |
|
---|
650 | for(i = 0; i < this->cStrips.size(); i++)
|
---|
651 | {
|
---|
652 | this->TOTALINDICES += int(this->cStrips[i].size());
|
---|
653 | }
|
---|
654 |
|
---|
655 | // lines starting with a d.
|
---|
656 | // Changes
|
---|
657 | fwrite(&changesCount, sizeof(int), 1, f);
|
---|
658 | for(i = 0; i < this->cCambios.size(); i++)
|
---|
659 | {
|
---|
660 | LODData change= cCambios[i];
|
---|
661 | fwrite(&change, sizeof(LODData), 1, f);
|
---|
662 | }
|
---|
663 |
|
---|
664 |
|
---|
665 | /* for(i = 0; i < this->cCambios.size(); i++)
|
---|
666 | {
|
---|
667 | sprintf(simp,"c\n");
|
---|
668 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
669 |
|
---|
670 | sprintf(simp,
|
---|
671 | "d %u %u %u %u %u\n",
|
---|
672 | cCambios[i].strip,
|
---|
673 | cCambios[i].nP,
|
---|
674 | cCambios[i].nL1,
|
---|
675 | cCambios[i].nL2,
|
---|
676 | cCambios[i].obligatory);
|
---|
677 |
|
---|
678 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
679 | }
|
---|
680 | */ // Lines starting with a b.
|
---|
681 | // Data.
|
---|
682 |
|
---|
683 | fwrite(&dataCount, sizeof(int), 1, f);
|
---|
684 | for(i = 0; i < this->cDatos.size(); i++)
|
---|
685 | {
|
---|
686 | int data= cDatos[i];
|
---|
687 | fwrite(&data, sizeof(int), 1, f);
|
---|
688 | }
|
---|
689 |
|
---|
690 | sprintf(simp,"a\n");
|
---|
691 | /* oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
692 |
|
---|
693 | for(i = 0; i < this->cDatos.size(); i++)
|
---|
694 | {
|
---|
695 | sprintf(simp,"b %d\n",cDatos[i]);
|
---|
696 |
|
---|
697 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
698 | }
|
---|
699 | */
|
---|
700 |
|
---|
701 |
|
---|
702 | // lines starting with a p.
|
---|
703 | // Chages made in a LOD.
|
---|
704 | fwrite(&cambiosCount, sizeof(int), 1, f);
|
---|
705 | for(i = 0; i < this->TOTALCAMBIOS; i++)
|
---|
706 | {
|
---|
707 | int cambio= pCambios[i];
|
---|
708 | fwrite(&cambio, sizeof(int), 1, f);
|
---|
709 | }
|
---|
710 |
|
---|
711 | fclose(f);
|
---|
712 |
|
---|
713 |
|
---|
714 | /*
|
---|
715 | // VERTICES.
|
---|
716 | for(i = 0; i < this->cVerts.size(); i++)
|
---|
717 | {
|
---|
718 | sprintf(simp,"v %d\n",cVerts[i].Next);
|
---|
719 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
720 | }
|
---|
721 |
|
---|
722 | // CSTRIPS.
|
---|
723 | this->TOTALINDICES = 0;
|
---|
724 |
|
---|
725 | for(i = 0; i < this->cStrips.size(); i++)
|
---|
726 | {
|
---|
727 | this->TOTALINDICES += int(this->cStrips[i].size());
|
---|
728 | }
|
---|
729 |
|
---|
730 | // lines starting with a d.
|
---|
731 | // Changes
|
---|
732 | for(i = 0; i < this->cCambios.size(); i++)
|
---|
733 | {
|
---|
734 | sprintf(simp,"c\n");
|
---|
735 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
736 |
|
---|
737 | sprintf(simp,
|
---|
738 | "d %u %u %u %u %u\n",
|
---|
739 | cCambios[i].strip,
|
---|
740 | cCambios[i].nP,
|
---|
741 | cCambios[i].nL1,
|
---|
742 | cCambios[i].nL2,
|
---|
743 | cCambios[i].obligatory);
|
---|
744 |
|
---|
745 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
746 | }
|
---|
747 | // Lines starting with a b.
|
---|
748 | // Data.
|
---|
749 | sprintf(simp,"a\n");
|
---|
750 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
751 |
|
---|
752 | for(i = 0; i < this->cDatos.size(); i++)
|
---|
753 | {
|
---|
754 | sprintf(simp,"b %d\n",cDatos[i]);
|
---|
755 |
|
---|
756 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
757 | }
|
---|
758 |
|
---|
759 | // lines starting with a p.
|
---|
760 | // Chages made in a LOD.
|
---|
761 | for(i = 0; i < this->TOTALCAMBIOS; i++)
|
---|
762 | {
|
---|
763 | sprintf(simp,"p %d\n",this->pCambios[i]);
|
---|
764 |
|
---|
765 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
766 | }
|
---|
767 |
|
---|
768 | oSerializer.WriteData("\n",sizeof(char),1); */
|
---|
769 | }
|
---|
770 |
|
---|
771 | int LodStripsConstructor::igual(Geometry::Vector3 vo,Geometry::Vector3 vc)
|
---|
772 | {
|
---|
773 | if (vo.x==vc.x && vo.y==vc.y && vo.z==vc.z)
|
---|
774 | return 1;
|
---|
775 | else
|
---|
776 | return 0;
|
---|
777 | }
|
---|
778 |
|
---|
779 | int LodStripsConstructor::igual(Geometry::Vector2 vo,Geometry::Vector2 vc)
|
---|
780 | {
|
---|
781 | if (vo.x==vc.x && vo.y==vc.y)
|
---|
782 | return 1;
|
---|
783 | else
|
---|
784 | return 0;
|
---|
785 | }
|
---|
786 |
|
---|
787 | /*void LodStripsConstructor::Load(Serializer &oSerializer)
|
---|
788 | {
|
---|
789 | }*/
|
---|
790 |
|
---|
791 | //---------------------------------------------------------------------------
|
---|
792 | // Call leeVerticesyTirasDeMesh, OrdenarModeloVQSLIM
|
---|
793 | // and CalcularCambiosLODsVNuevaED to make changes at vertex
|
---|
794 | // and index strutures.
|
---|
795 | //---------------------------------------------------------------------------
|
---|
796 | void LodStripsConstructor::GenerarModeloV(TIPOFUNC upb)
|
---|
797 | {
|
---|
798 | long int max;
|
---|
799 | long int t;
|
---|
800 | unsigned long int i;
|
---|
801 | float percent;
|
---|
802 |
|
---|
803 | percent = 10;
|
---|
804 |
|
---|
805 | this->leeVerticesyTirasDeMesh();
|
---|
806 |
|
---|
807 | upb(percent);
|
---|
808 |
|
---|
809 | // 6 min.
|
---|
810 | this->OrdenarModeloVQSLIM(upb);
|
---|
811 |
|
---|
812 | //Calcular el tamaño maximo de tira
|
---|
813 | max = 0;
|
---|
814 |
|
---|
815 | for(i = 0; i < this->TOTALTIRAS; i++)
|
---|
816 | {
|
---|
817 | t = long(this->cStrips[i].size());
|
---|
818 |
|
---|
819 | if (t > max)
|
---|
820 | {
|
---|
821 | max = t;
|
---|
822 | }
|
---|
823 | }
|
---|
824 |
|
---|
825 | this->MARCA = max + 1;
|
---|
826 | this->CalcularCambiosLODsVNuevaED(upb);
|
---|
827 | }
|
---|
828 |
|
---|
829 | //---------------------------------------------------------------------------
|
---|
830 | // It fills structs with vertex and index information.
|
---|
831 | //---------------------------------------------------------------------------
|
---|
832 | void LodStripsConstructor::CopiarVectors2ArraysNUEVAED()
|
---|
833 | {
|
---|
834 | unsigned int i;
|
---|
835 | unsigned int j;
|
---|
836 | uint32 max;
|
---|
837 | uint32 t;
|
---|
838 | VECTORINT tira;
|
---|
839 | LODChanges listaCambios;
|
---|
840 |
|
---|
841 | // ALLOCATE----------------
|
---|
842 | this->TOTALVERTS = int(this->cVerts.size());
|
---|
843 | this->TOTALTIRAS = int(this->cStrips.size());
|
---|
844 | this->vVerts = new tipoVertice[this->TOTALVERTS];
|
---|
845 | this->lStripsV = new VECTORINT[this->TOTALTIRAS];
|
---|
846 | this->vDatos = new uint32[cDatos.size()];
|
---|
847 |
|
---|
848 | // Calcular el tamaño maximo de tira y el numero de caras total.
|
---|
849 | max = 0;
|
---|
850 | this->TOTALCARAS = 0;
|
---|
851 |
|
---|
852 | for (i = 0; i < this->cStrips.size(); i++)
|
---|
853 | {
|
---|
854 | t = int(this->cStrips[i].size());
|
---|
855 |
|
---|
856 | if (t > max)
|
---|
857 | {
|
---|
858 | max = t;
|
---|
859 | }
|
---|
860 |
|
---|
861 | this->TOTALCARAS += (t-2);
|
---|
862 | }
|
---|
863 |
|
---|
864 | this->vStrips = Allocate2DArrayINT(this->TOTALTIRAS,max+1);
|
---|
865 | this->MARCA = int(this->cVerts.size());
|
---|
866 | vCambios = new LODData[this->cCambios.size()];
|
---|
867 |
|
---|
868 | // Rellenar vChanges.
|
---|
869 | for (i = 0; i < this->cCambios.size();++i)
|
---|
870 | {
|
---|
871 | vCambios[i] = cCambios[i];
|
---|
872 | }
|
---|
873 |
|
---|
874 | for (i = 0; i < this->cStrips.size(); i++)
|
---|
875 | {
|
---|
876 | for (j = 0; j < this->cStrips[i].size(); j++)
|
---|
877 | {
|
---|
878 | // Rellenar el array vStrips.
|
---|
879 | this->vStrips[i][j] = this->cStrips[i][j];
|
---|
880 |
|
---|
881 | // Rellenar el vVector.
|
---|
882 | this->lStripsV[i].push_back(this->cStrips[i][j]);
|
---|
883 | }
|
---|
884 |
|
---|
885 | this->vStrips[i][j] = this->MARCA;
|
---|
886 | }
|
---|
887 |
|
---|
888 | for (i = 0; i < cDatos.size(); i++)
|
---|
889 | {
|
---|
890 | vDatos[i] = cDatos[i];
|
---|
891 | }
|
---|
892 |
|
---|
893 | pCurrentData = vDatos;
|
---|
894 |
|
---|
895 | // Meter los vertices en vVerts.
|
---|
896 | for (i = 0; i < this->cVerts.size(); i++)
|
---|
897 | {
|
---|
898 | this->vVerts[i] = this->cVerts[i];
|
---|
899 | }
|
---|
900 |
|
---|
901 | }
|
---|
902 |
|
---|
903 | //---------------------------------------------------------------------------
|
---|
904 | // It fills cVerts and cStrips with original Mesh vertex and strips
|
---|
905 | // information.
|
---|
906 | //---------------------------------------------------------------------------
|
---|
907 | void LodStripsConstructor::leeVerticesyTirasDeMesh()
|
---|
908 | {
|
---|
909 | tipoVertice vAux;
|
---|
910 | std::vector<int> tira;
|
---|
911 | size_t i;
|
---|
912 | size_t j;
|
---|
913 | bool error;
|
---|
914 |
|
---|
915 | error = false;
|
---|
916 |
|
---|
917 | if(this->mGeoMesh->mSubMeshCount == 1)
|
---|
918 | {
|
---|
919 | error = false;
|
---|
920 | }
|
---|
921 | else
|
---|
922 | {
|
---|
923 | for (i = 0; i < this->mGeoMesh->mSubMeshCount;i++)
|
---|
924 | {
|
---|
925 | if (this->mGeoMesh->mSubMesh[i].mSharedVertexBuffer == true)
|
---|
926 | {
|
---|
927 | error = false;
|
---|
928 | }
|
---|
929 | else
|
---|
930 | {
|
---|
931 | error = true;
|
---|
932 | break;
|
---|
933 | }
|
---|
934 | }
|
---|
935 | }
|
---|
936 |
|
---|
937 | if(!error)
|
---|
938 | {
|
---|
939 | if ( (this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer == true)
|
---|
940 | &&
|
---|
941 | (this->mGeoMesh->mSubMeshCount > 1)
|
---|
942 | )
|
---|
943 | {
|
---|
944 | for (j = 0; j < this->mGeoMesh->mVertexBuffer->mVertexCount; j++)
|
---|
945 | {
|
---|
946 | // Si hay mas de un submesh ListaIndices no se rellena correctamente
|
---|
947 | vAux.Vertex[0] = this->mGeoMesh->mVertexBuffer->mPosition[j].x;
|
---|
948 | vAux.Vertex[1] = this->mGeoMesh->mVertexBuffer->mPosition[j].y;
|
---|
949 | vAux.Vertex[2] = this->mGeoMesh->mVertexBuffer->mPosition[j].z;
|
---|
950 |
|
---|
951 | // Añadimos las normales en cVerts.
|
---|
952 | if ( this->mGeoMesh->mVertexBuffer->mVertexInfo
|
---|
953 | &
|
---|
954 | Geometry::VERTEX_NORMAL
|
---|
955 | )
|
---|
956 | {
|
---|
957 | vAux.Normal[0] = this->mGeoMesh->mVertexBuffer->mNormal[j].x;
|
---|
958 | vAux.Normal[1] = this->mGeoMesh->mVertexBuffer->mNormal[j].y;
|
---|
959 | vAux.Normal[2] = this->mGeoMesh->mVertexBuffer->mNormal[j].z;
|
---|
960 | }
|
---|
961 |
|
---|
962 | // Añadimos las coordenadas de textura a cVerts.
|
---|
963 | if ( this->mGeoMesh->mVertexBuffer->mVertexInfo
|
---|
964 | &
|
---|
965 | Geometry::VERTEX_TEXCOORDS
|
---|
966 | )
|
---|
967 | {
|
---|
968 | vAux.TexCoords[0] = this->mGeoMesh->mVertexBuffer->mTexCoords[j].x;
|
---|
969 | vAux.TexCoords[1] = this->mGeoMesh->mVertexBuffer->mTexCoords[j].y;
|
---|
970 | }
|
---|
971 |
|
---|
972 | vAux.Next = -10;
|
---|
973 | vAux.numMesh = 0;
|
---|
974 |
|
---|
975 | vAux.obligatorio = 0;
|
---|
976 |
|
---|
977 | this->cVerts.push_back(vAux);
|
---|
978 | }
|
---|
979 | }
|
---|
980 | else
|
---|
981 | {
|
---|
982 | for (i = 0; i < this->mGeoMesh->mSubMeshCount; i++)
|
---|
983 | {
|
---|
984 | for ( j = 0;
|
---|
985 | j < this->mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount;
|
---|
986 | j++)
|
---|
987 | {
|
---|
988 | // Si hay mas de un submesh ListaIndices
|
---|
989 | // no se rellena correctamente.
|
---|
990 | vAux.Vertex[0] = this->mGeoMesh->mSubMesh[i].
|
---|
991 | mVertexBuffer->mPosition[j].x;
|
---|
992 | vAux.Vertex[1] = this->mGeoMesh->mSubMesh[i].
|
---|
993 | mVertexBuffer->mPosition[j].y;
|
---|
994 | vAux.Vertex[2] = this->mGeoMesh->mSubMesh[i].
|
---|
995 | mVertexBuffer->mPosition[j].z;
|
---|
996 | // Añadimos las normales en cVerts.
|
---|
997 | vAux.Normal[0] = this->mGeoMesh->mSubMesh[i].
|
---|
998 | mVertexBuffer->mNormal[j].x;
|
---|
999 | vAux.Normal[1] = this->mGeoMesh->mSubMesh[i].
|
---|
1000 | mVertexBuffer->mNormal[j].y;
|
---|
1001 | vAux.Normal[2] = this->mGeoMesh->mSubMesh[i].
|
---|
1002 | mVertexBuffer->mNormal[j].z;
|
---|
1003 |
|
---|
1004 | // Añadimos las coordenadas de textura a cVerts.
|
---|
1005 | vAux.TexCoords[0] = this->mGeoMesh->mSubMesh[i].
|
---|
1006 | mVertexBuffer->mTexCoords[j].x;
|
---|
1007 | vAux.TexCoords[1] = this->mGeoMesh->mSubMesh[i].
|
---|
1008 | mVertexBuffer->mTexCoords[j].y;
|
---|
1009 |
|
---|
1010 | vAux.Next = -10;
|
---|
1011 | vAux.numMesh = int(i);
|
---|
1012 |
|
---|
1013 | this->cVerts.push_back(vAux);
|
---|
1014 | }
|
---|
1015 | }
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | Index indice_acum;
|
---|
1019 | Index num_vert;
|
---|
1020 |
|
---|
1021 | num_vert = 0;
|
---|
1022 |
|
---|
1023 | for (i = 0; i < this->mGeoMesh->mSubMeshCount; i++)
|
---|
1024 | {
|
---|
1025 | // If is not the leaves submesh.
|
---|
1026 | if (mSubMeshLeaves != i)
|
---|
1027 | {
|
---|
1028 | indice_acum = 0;
|
---|
1029 |
|
---|
1030 | for (j = 0; j < this->mGeoMesh->mSubMesh[i].mStripCount; j++)
|
---|
1031 | {
|
---|
1032 | Index *aux = this->mGeoMesh->mSubMesh[i].mStrip[j];
|
---|
1033 |
|
---|
1034 | /*
|
---|
1035 | if (j != 0)
|
---|
1036 | {
|
---|
1037 | // La primera tira no empieza por índices repetidos.
|
---|
1038 | aux = aux+1;
|
---|
1039 |
|
---|
1040 | indice_acum++;
|
---|
1041 | }
|
---|
1042 | */
|
---|
1043 |
|
---|
1044 | if (j+1 < this->mGeoMesh->mSubMesh[i].mStripCount)
|
---|
1045 | {
|
---|
1046 | Index *siguiente = this->mGeoMesh->mSubMesh[i].mStrip[j+1];
|
---|
1047 |
|
---|
1048 | tira.clear();
|
---|
1049 |
|
---|
1050 | while (aux != siguiente)
|
---|
1051 | {
|
---|
1052 | tira.push_back(*aux);
|
---|
1053 | indice_acum++;
|
---|
1054 |
|
---|
1055 | aux = aux + 1;
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | //tira.pop_back();
|
---|
1059 |
|
---|
1060 | this->cStrips.push_back(tira);
|
---|
1061 | }
|
---|
1062 | else
|
---|
1063 | {
|
---|
1064 | // Insertar los indices de la última tira en el cStrips
|
---|
1065 | tira.clear();
|
---|
1066 |
|
---|
1067 | for ( unsigned int k = indice_acum;
|
---|
1068 | k < this->mGeoMesh->mSubMesh[i].mIndexCount;
|
---|
1069 | k++)
|
---|
1070 | {
|
---|
1071 | tira.push_back(this->mGeoMesh->mSubMesh[i].mIndex[k]);
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | this->cStrips.push_back(tira);
|
---|
1075 | }
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | num_vert += int(this->mGeoMesh->mSubMesh[i].
|
---|
1079 | mVertexBuffer->mVertexCount);
|
---|
1080 | }
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | this->TOTALVERTS = int(cVerts.size());
|
---|
1084 | this->TOTALTIRAS = int(cStrips.size());
|
---|
1085 | }
|
---|
1086 | else
|
---|
1087 | {
|
---|
1088 | // Error.
|
---|
1089 | }
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | //---------------------------------------------------------------------------
|
---|
1093 | // GetMesh: Return de current Mesh.
|
---|
1094 | //---------------------------------------------------------------------------
|
---|
1095 | Mesh * LodStripsConstructor::GetMesh()
|
---|
1096 | {
|
---|
1097 | Mesh *mesh_built;
|
---|
1098 |
|
---|
1099 | mesh_built = new Mesh();
|
---|
1100 | *mesh_built = *mGeoMesh;
|
---|
1101 |
|
---|
1102 | return mesh_built;
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | //---------------------------------------------------------------------------
|
---|
1106 | // Sets what is the submesh that stores the leaves.
|
---|
1107 | //---------------------------------------------------------------------------
|
---|
1108 | void LodStripsConstructor::SetSubMeshLeaves(size_t submesh)
|
---|
1109 | {
|
---|
1110 | mSubMeshLeaves = submesh;
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | //---------------------------------------------------------------------------
|
---|
1114 | // Sort submesh bones.
|
---|
1115 | //---------------------------------------------------------------------------
|
---|
1116 | void LodStripsConstructor::sortBones()
|
---|
1117 | {
|
---|
1118 | bool shared_found;
|
---|
1119 | int n;
|
---|
1120 | int o;
|
---|
1121 | int p;
|
---|
1122 | VertexBoneAssignment assign;
|
---|
1123 | SubMesh *submesh;
|
---|
1124 | SubMesh *copysubmesh;
|
---|
1125 | VertexBuffer *mesh_vb;
|
---|
1126 | VertexBuffer *copy_vb;
|
---|
1127 |
|
---|
1128 | std::vector<VertexBoneAssignment> *mesh_bones;
|
---|
1129 | std::vector<VertexBoneAssignment> *copy_bones;
|
---|
1130 |
|
---|
1131 | // Initialize shared vertex flag.
|
---|
1132 | shared_found = false;
|
---|
1133 |
|
---|
1134 | // For each submesh.
|
---|
1135 | for (size_t i = 0; i < mGeoMesh->mSubMeshCount; i++)
|
---|
1136 | {
|
---|
1137 | submesh = &mGeoMesh->mSubMesh[i];
|
---|
1138 | copysubmesh = &mInitialMesh->mSubMesh[i];
|
---|
1139 |
|
---|
1140 | // If submesh has shared vertex.
|
---|
1141 | if (submesh->mSharedVertexBuffer)
|
---|
1142 | {
|
---|
1143 | if (shared_found)
|
---|
1144 | {
|
---|
1145 | continue;
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | shared_found = true;
|
---|
1149 |
|
---|
1150 | // Vertex buffers.
|
---|
1151 | mesh_vb = mGeoMesh->mVertexBuffer;
|
---|
1152 | copy_vb = mInitialMesh->mVertexBuffer;
|
---|
1153 |
|
---|
1154 | // Bones.
|
---|
1155 | mesh_bones = &mGeoMesh->mBones;
|
---|
1156 | copy_bones = &mInitialMesh->mBones;
|
---|
1157 | }
|
---|
1158 | else
|
---|
1159 | {
|
---|
1160 | // Vertex buffers.
|
---|
1161 | mesh_vb = submesh->mVertexBuffer;
|
---|
1162 | copy_vb = copysubmesh->mVertexBuffer;
|
---|
1163 |
|
---|
1164 | // Bones.
|
---|
1165 | mesh_bones = &submesh->mBones;
|
---|
1166 | copy_bones = ©submesh->mBones;
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | if (!mesh_bones->empty())
|
---|
1170 | {
|
---|
1171 | assign.boneIndex = 0;
|
---|
1172 | assign.weight = 1;
|
---|
1173 |
|
---|
1174 | for ( size_t m = copy_vb->mVertexCount;
|
---|
1175 | m < mesh_vb->mVertexCount;
|
---|
1176 | m++)
|
---|
1177 | {
|
---|
1178 | assign.vertexIndex = (unsigned int)m;
|
---|
1179 |
|
---|
1180 | mesh_bones->push_back(assign);
|
---|
1181 | }
|
---|
1182 |
|
---|
1183 | // Change bones.
|
---|
1184 | for (size_t m = 0; m < mesh_bones->size(); m++)
|
---|
1185 | {
|
---|
1186 | n = (*mesh_bones)[m].vertexIndex;
|
---|
1187 |
|
---|
1188 | o = 0;
|
---|
1189 |
|
---|
1190 | while (!( (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x)
|
---|
1191 | &&
|
---|
1192 | (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y)
|
---|
1193 | &&
|
---|
1194 | (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z)))
|
---|
1195 | {
|
---|
1196 | o++;
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | p = 0;
|
---|
1200 |
|
---|
1201 | while ((*copy_bones)[p].vertexIndex != o)
|
---|
1202 | {
|
---|
1203 | p++;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | // Same bone for 'm' and 'p'.
|
---|
1207 | (*mesh_bones)[m].boneIndex = (*copy_bones)[p].boneIndex;
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | // Look for repeated bones.
|
---|
1211 | for (size_t m = 0; m < mesh_vb->mVertexCount; m++)
|
---|
1212 | {
|
---|
1213 | for (size_t n = m + 1; n < mesh_vb->mVertexCount; n++)
|
---|
1214 | {
|
---|
1215 | if ((mesh_vb->mPosition[m].x == mesh_vb->mPosition[n].x)
|
---|
1216 | &&
|
---|
1217 | (mesh_vb->mPosition[m].y == mesh_vb->mPosition[n].y)
|
---|
1218 | &&
|
---|
1219 | (mesh_vb->mPosition[m].z == mesh_vb->mPosition[n].z))
|
---|
1220 | {
|
---|
1221 | o = 0;
|
---|
1222 |
|
---|
1223 | while ((*mesh_bones)[o].vertexIndex != m)
|
---|
1224 | {
|
---|
1225 | o++;
|
---|
1226 | }
|
---|
1227 |
|
---|
1228 | p = 0;
|
---|
1229 |
|
---|
1230 | while ((*mesh_bones)[p].vertexIndex != n)
|
---|
1231 | {
|
---|
1232 | p++;
|
---|
1233 | }
|
---|
1234 |
|
---|
1235 | if ((*mesh_bones)[o].boneIndex != (*mesh_bones)[p].boneIndex)
|
---|
1236 | {
|
---|
1237 | printf("-->Error en los vertices %d y %d\n",m,n);
|
---|
1238 | }
|
---|
1239 | }
|
---|
1240 | }
|
---|
1241 | }
|
---|
1242 | }
|
---|
1243 | }
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 | void Geometry::LodStripsConstructor::UpdateMesh(void)
|
---|
1247 | {
|
---|
1248 | int num_no = 0;
|
---|
1249 | int i=0,j=0;
|
---|
1250 |
|
---|
1251 | if(this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer == true)
|
---|
1252 | {
|
---|
1253 | //mPosition
|
---|
1254 | delete[] this->mGeoMesh->mVertexBuffer->mPosition;
|
---|
1255 | this->mGeoMesh->mVertexBuffer->mPosition = new Vector3[this->cVerts.size()];
|
---|
1256 |
|
---|
1257 | //mNormal
|
---|
1258 | if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
|
---|
1259 | {
|
---|
1260 | delete[] this->mGeoMesh->mVertexBuffer->mNormal;
|
---|
1261 | this->mGeoMesh->mVertexBuffer->mNormal = new Vector3[this->cVerts.size()];
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | //mTexCoords
|
---|
1265 | if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
|
---|
1266 | {
|
---|
1267 | delete[] this->mGeoMesh->mVertexBuffer->mTexCoords;
|
---|
1268 | this->mGeoMesh->mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()];
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | this->mGeoMesh->mVertexBuffer->mVertexCount = this->cVerts.size();
|
---|
1272 | this->mGeoMesh->mVertexBuffer->mVertexInfo = this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo;
|
---|
1273 |
|
---|
1274 | for(i = 0; i < this->mGeoMesh->mSubMeshCount; i++)
|
---|
1275 | {
|
---|
1276 | this->mGeoMesh->mSubMesh[i].mVertexBuffer = this->mGeoMesh->mVertexBuffer;
|
---|
1277 | this->mGeoMesh->mSubMesh[i].mSharedVertexBuffer = true;
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 | int indice = 0;
|
---|
1281 |
|
---|
1282 | for (j = 0; j < this->cVerts.size(); j++)
|
---|
1283 | {
|
---|
1284 | //Copiamos las coordeandas de posicion
|
---|
1285 | this->mGeoMesh->mVertexBuffer->mPosition[indice].x = this->cVerts[j].Vertex[0];
|
---|
1286 | this->mGeoMesh->mVertexBuffer->mPosition[indice].y = this->cVerts[j].Vertex[1];
|
---|
1287 | this->mGeoMesh->mVertexBuffer->mPosition[indice].z = this->cVerts[j].Vertex[2];
|
---|
1288 |
|
---|
1289 | //Copiamos las normales
|
---|
1290 | if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
|
---|
1291 | {
|
---|
1292 | this->mGeoMesh->mVertexBuffer->mNormal[indice].x = this->cVerts[j].Normal[0];
|
---|
1293 | this->mGeoMesh->mVertexBuffer->mNormal[indice].y = this->cVerts[j].Normal[1];
|
---|
1294 | this->mGeoMesh->mVertexBuffer->mNormal[indice].z = this->cVerts[j].Normal[2];
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | //Copiamos las coordenadas de textura
|
---|
1298 | if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
|
---|
1299 | {
|
---|
1300 | this->mGeoMesh->mVertexBuffer->mTexCoords[indice].x = this->cVerts[j].TexCoords[0];
|
---|
1301 | this->mGeoMesh->mVertexBuffer->mTexCoords[indice].y = this->cVerts[j].TexCoords[1];
|
---|
1302 | }
|
---|
1303 |
|
---|
1304 | indice++;
|
---|
1305 |
|
---|
1306 | }
|
---|
1307 |
|
---|
1308 | this->mGeoMesh->mVertexBuffer->mVertexCount = indice;
|
---|
1309 | }
|
---|
1310 | else //OSCAR
|
---|
1311 | {
|
---|
1312 | //Supondre que solo tengo un submesh con vertices no compartidos
|
---|
1313 | //mPosition
|
---|
1314 | delete[] this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition;
|
---|
1315 |
|
---|
1316 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition = new Vector3[this->cVerts.size()];
|
---|
1317 |
|
---|
1318 | //mNormal
|
---|
1319 | if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
|
---|
1320 | {
|
---|
1321 | delete[] this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal;
|
---|
1322 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal = new Vector3[this->cVerts.size()];
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | //mTexCoords
|
---|
1326 | if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
|
---|
1327 | {
|
---|
1328 | delete[] this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords;
|
---|
1329 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()];
|
---|
1330 | }
|
---|
1331 |
|
---|
1332 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =this->cVerts.size();
|
---|
1333 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexInfo = this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo;
|
---|
1334 |
|
---|
1335 | this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer=false;
|
---|
1336 |
|
---|
1337 | int indice=0;
|
---|
1338 | for (j=0; j<this->cVerts.size(); j++)
|
---|
1339 | {
|
---|
1340 | //Copiamos las coordeandas de posicion
|
---|
1341 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].x=this->cVerts[j].Vertex[0];
|
---|
1342 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].y=this->cVerts[j].Vertex[1];
|
---|
1343 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].z=this->cVerts[j].Vertex[2];
|
---|
1344 |
|
---|
1345 | //Copiamos las normales
|
---|
1346 | if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
|
---|
1347 | {
|
---|
1348 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].x=this->cVerts[j].Normal[0];
|
---|
1349 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].y=this->cVerts[j].Normal[1];
|
---|
1350 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].z=this->cVerts[j].Normal[2];
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | //Copiamos las coordenadas de textura
|
---|
1354 | if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
|
---|
1355 | {
|
---|
1356 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].x=this->cVerts[j].TexCoords[0];
|
---|
1357 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].y=this->cVerts[j].TexCoords[1];
|
---|
1358 | }
|
---|
1359 | indice++;
|
---|
1360 | }
|
---|
1361 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =indice;
|
---|
1362 | }
|
---|
1363 |
|
---|
1364 |
|
---|
1365 |
|
---|
1366 | int indice_acum = 0;
|
---|
1367 | for(i=0;i<this->mGeoMesh->mSubMeshCount;i++)
|
---|
1368 | {
|
---|
1369 | Geometry::SubMesh & subMesh = meshoriginal->mSubMesh[i];
|
---|
1370 | Geometry::SubMesh & mGeoMeshSubMesh = this->mGeoMesh->mSubMesh[i];
|
---|
1371 |
|
---|
1372 | for (size_t ind=0; ind < subMesh.mIndexCount; ind++)
|
---|
1373 | {
|
---|
1374 | Index indIndex = subMesh.mIndex[ind];
|
---|
1375 | if (subMesh.mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
|
---|
1376 | {
|
---|
1377 | //Hay coordenadas de textura y normales
|
---|
1378 | if(subMesh.mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
|
---|
1379 | {
|
---|
1380 | for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++)
|
---|
1381 | {
|
---|
1382 | if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo]))
|
---|
1383 | {
|
---|
1384 | if (igual(subMesh.mVertexBuffer->mNormal[indIndex],mGeoMeshSubMesh.mVertexBuffer->mNormal[indvo]))
|
---|
1385 | {
|
---|
1386 | if (igual(subMesh.mVertexBuffer->mTexCoords[indIndex],mGeoMeshSubMesh.mVertexBuffer->mTexCoords[indvo]))
|
---|
1387 | {
|
---|
1388 | mGeoMeshSubMesh.mIndex[ind]= int(indvo);//+indice_acum;
|
---|
1389 | }
|
---|
1390 | }
|
---|
1391 | }
|
---|
1392 | }
|
---|
1393 | }
|
---|
1394 | else //Hay coordenadas de textura pero no hay normales
|
---|
1395 | {
|
---|
1396 | for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++)
|
---|
1397 | {
|
---|
1398 | if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo]))
|
---|
1399 | {
|
---|
1400 | if (igual(subMesh.mVertexBuffer->mTexCoords[indIndex],mGeoMeshSubMesh.mVertexBuffer->mTexCoords[indvo]))
|
---|
1401 | {
|
---|
1402 | mGeoMeshSubMesh.mIndex[ind]=int(indvo);//+indice_acum;
|
---|
1403 | }
|
---|
1404 | }
|
---|
1405 | }
|
---|
1406 | }
|
---|
1407 | }
|
---|
1408 | else
|
---|
1409 | {
|
---|
1410 | // No hay coordenadas de textura pero si normales
|
---|
1411 | if(subMesh.mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
|
---|
1412 | {
|
---|
1413 | for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++)
|
---|
1414 | {
|
---|
1415 | if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo]))
|
---|
1416 | {
|
---|
1417 | if (igual(subMesh.mVertexBuffer->mNormal[indIndex],mGeoMeshSubMesh.mVertexBuffer->mNormal[indvo]))
|
---|
1418 | {
|
---|
1419 | mGeoMeshSubMesh.mIndex[ind]=int(indvo);//+indice_acum;
|
---|
1420 | }
|
---|
1421 | }
|
---|
1422 | }
|
---|
1423 | }
|
---|
1424 | else //No hay coordenadas de texturas ni normales
|
---|
1425 | {
|
---|
1426 | for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++)
|
---|
1427 | {
|
---|
1428 | if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo]))
|
---|
1429 | {
|
---|
1430 | mGeoMeshSubMesh.mIndex[ind]=int(indvo);//+indice_acum;
|
---|
1431 | }
|
---|
1432 | }
|
---|
1433 | }
|
---|
1434 | }
|
---|
1435 | }
|
---|
1436 | }
|
---|
1437 |
|
---|
1438 | } |
---|