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