[774] | 1 | #include <iostream>
|
---|
| 2 | #include <fstream>
|
---|
[1070] | 3 | #include <time.h>
|
---|
[774] | 4 | #include "GeoLodStripsConstructor.h"
|
---|
[1090] | 5 | #include "GeoMeshLoader.h"
|
---|
[774] | 6 |
|
---|
| 7 | using namespace Geometry;
|
---|
| 8 |
|
---|
| 9 | //---------------------------------------------------------------------------
|
---|
[1070] | 10 | // Call GenerarModeloV and CopiarVectorsArraysNUEVAED to make changes.
|
---|
| 11 | //---------------------------------------------------------------------------
|
---|
[774] | 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.
|
---|
[996] | 20 | percent = 100.0;
|
---|
[774] | 21 | upb(percent);
|
---|
| 22 | }
|
---|
| 23 |
|
---|
[1070] | 24 | //---------------------------------------------------------------------------
|
---|
| 25 | // It makes Lods changes and count them.
|
---|
| 26 | //---------------------------------------------------------------------------
|
---|
[774] | 27 | void LodStripsConstructor::CalcularCambiosLODsVNuevaED(TIPOFUNC upb)
|
---|
| 28 | {
|
---|
[1017] | 29 | // LODPosition pos;
|
---|
| 30 | // vector <LODPosition> listaPos;
|
---|
[774] | 31 | long int k;
|
---|
| 32 | long int i;
|
---|
[996] | 33 | unsigned long int t;
|
---|
[774] | 34 | long int r;
|
---|
[996] | 35 | unsigned long int v;
|
---|
[774] | 36 | long int p0;
|
---|
[1017] | 37 | long int lod = 0;
|
---|
[774] | 38 | long int sigue;
|
---|
[1017] | 39 | long int ac[3] = {0,0,0};
|
---|
[774] | 40 | long int totalRegs = 0;
|
---|
| 41 | long int RegsCambios;
|
---|
[1018] | 42 | std::vector<std::vector<int> > TiraOriginal;
|
---|
[993] | 43 | LODData regLOD;
|
---|
[1017] | 44 | //LODChanges listaCambios;
|
---|
[1018] | 45 | std::vector<LODData> listaCambios;
|
---|
[993] | 46 | float percent;
|
---|
[996] | 47 | float increment;
|
---|
[993] | 48 | long int update;
|
---|
[774] | 49 |
|
---|
[996] | 50 | // Saves original copy.
|
---|
| 51 | TiraOriginal = this->cStrips;
|
---|
[774] | 52 |
|
---|
[985] | 53 | this->MARCAVACIO = int(10 * this->cVerts.size());
|
---|
[774] | 54 |
|
---|
| 55 | listaCambios.clear();
|
---|
| 56 |
|
---|
[996] | 57 | // Initialize increment.
|
---|
| 58 | increment = 0.0;
|
---|
[774] | 59 |
|
---|
| 60 | for (lod = 0; ((this->cVerts[lod].Next) != -1); lod++)
|
---|
| 61 | {
|
---|
[996] | 62 | increment += 1.0;
|
---|
[774] | 63 | }
|
---|
| 64 |
|
---|
[996] | 65 | update = -1;
|
---|
| 66 | increment = (float)30.0 / increment;
|
---|
| 67 | percent = 1.0;
|
---|
[774] | 68 |
|
---|
[1017] | 69 | this->LodsDisp = this->TOTALCAMBIOS = lod;
|
---|
[774] | 70 | pCambios = new uint32[this->TOTALCAMBIOS];
|
---|
| 71 | pCambios[0] = 0;
|
---|
| 72 |
|
---|
[1017] | 73 | for (lod = 0; ((this->cVerts[lod].Next) != -1); lod++)
|
---|
[774] | 74 | {
|
---|
[1017] | 75 | /* if (update != (int)(increment * lod))
|
---|
[774] | 76 | {
|
---|
[996] | 77 | update = (int)(increment * lod);
|
---|
[774] | 78 | upb(percent);
|
---|
[1017] | 79 | }*/
|
---|
| 80 |
|
---|
| 81 | tipoVertice & cVertsLOD = this->cVerts[lod];
|
---|
[774] | 82 |
|
---|
[1017] | 83 | RegsCambios = 0;
|
---|
| 84 | regLOD.obligatory = this->Ordenacion[lod].obligatorio;
|
---|
[774] | 85 |
|
---|
[1017] | 86 | for(t = 0; t < this->cStrips.size(); t++)
|
---|
[774] | 87 | {
|
---|
[1017] | 88 |
|
---|
[1018] | 89 | std::vector<int> & cStripsT = this->cStrips[t];
|
---|
[1017] | 90 |
|
---|
[996] | 91 | // Initialize.
|
---|
[774] | 92 | regLOD.strip = this->MARCAVACIO;
|
---|
| 93 |
|
---|
[996] | 94 | // Change vertices.
|
---|
[774] | 95 | totalRegs = 0;
|
---|
| 96 |
|
---|
[1017] | 97 | for (v = 0; v < cStripsT.size(); v++)
|
---|
[774] | 98 | {
|
---|
[1017] | 99 | if (cStripsT[v] == lod)
|
---|
| 100 | {
|
---|
[996] | 101 | // Strips.
|
---|
[774] | 102 | if (regLOD.strip == this->MARCAVACIO)
|
---|
| 103 | {
|
---|
| 104 | regLOD.strip = t;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | ++totalRegs;
|
---|
| 108 |
|
---|
| 109 | cDatos.push_back(v);
|
---|
| 110 |
|
---|
[1017] | 111 | cStripsT[v] = cVertsLOD.Next;
|
---|
[774] | 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[985] | 115 | regLOD.nP = char(totalRegs);
|
---|
[774] | 116 |
|
---|
[996] | 117 | // Simplifications length 1.
|
---|
| 118 | // Changes for simplification of level 1 to greater than 2.
|
---|
[774] | 119 | totalRegs = 0;
|
---|
| 120 | i = 0;
|
---|
| 121 | r = 0;
|
---|
| 122 | sigue = 0;
|
---|
[1017] | 123 | k = long(cStripsT.size()-3);
|
---|
| 124 |
|
---|
[774] | 125 | while (i < k)
|
---|
| 126 | {
|
---|
[1017] | 127 | if ( (cStripsT[i] == cStripsT[i+1])
|
---|
| 128 | &&
|
---|
| 129 | (cStripsT[i+1] == cStripsT[i+2])
|
---|
| 130 | )
|
---|
| 131 | {
|
---|
[996] | 132 | // Saves beginning of repetition.
|
---|
[774] | 133 | if (!r)
|
---|
| 134 | {
|
---|
| 135 | p0 = i;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[1018] | 138 | //cStripsT.eraseAtPos(i);
|
---|
[1048] | 139 | cStripsT.erase(cStripsT.begin()+i);
|
---|
[774] | 140 | i--;
|
---|
| 141 | r++;
|
---|
| 142 |
|
---|
[1017] | 143 | if ((i+1) != cStripsT.size()-1)
|
---|
[774] | 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 | {
|
---|
[1048] | 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);
|
---|
[774] | 194 | if (regLOD.strip == this->MARCAVACIO)
|
---|
| 195 | {
|
---|
| 196 | regLOD.strip = t;
|
---|
| 197 | }
|
---|
[1048] | 198 |
|
---|
[774] | 199 | ++totalRegs;
|
---|
[1048] | 200 | }
|
---|
[774] | 201 |
|
---|
| 202 |
|
---|
[1070] | 203 | r = 0;
|
---|
[1048] | 204 |
|
---|
[1070] | 205 | k = (long)(cStripsT.size() - 3);
|
---|
| 206 |
|
---|
[774] | 207 | }
|
---|
| 208 |
|
---|
| 209 | i++;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
[985] | 212 | regLOD.nL1 = char(totalRegs);
|
---|
[774] | 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;
|
---|
[1017] | 219 | k = long(cStripsT.size() - 4);
|
---|
[774] | 220 |
|
---|
| 221 | while (i < k)
|
---|
| 222 | {
|
---|
[1017] | 223 | if ( (cStripsT[i] == cStripsT[i+2])
|
---|
| 224 | &&
|
---|
| 225 | (cStripsT[i+1] == cStripsT[i+3])
|
---|
| 226 | )
|
---|
[774] | 227 | {
|
---|
| 228 | if (!r)
|
---|
| 229 | {
|
---|
| 230 | p0 = i;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
[1018] | 233 | //cStripsT.eraseAtPos(i);
|
---|
| 234 | cStripsT.erase(this->cStrips[t].begin()+i);
|
---|
| 235 | //cStripsT.eraseAtPos(i);
|
---|
| 236 | cStripsT.erase(this->cStrips[t].begin()+i);
|
---|
[774] | 237 | r++;
|
---|
| 238 |
|
---|
| 239 | i -= 2;
|
---|
| 240 |
|
---|
[1017] | 241 | if ((i+1) != cStripsT.size()-3)
|
---|
[774] | 242 | {
|
---|
| 243 | sigue = 1;
|
---|
| 244 | }
|
---|
| 245 | else
|
---|
| 246 | {
|
---|
| 247 | sigue = 0;
|
---|
| 248 | }
|
---|
[1017] | 249 |
|
---|
[774] | 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;
|
---|
[1017] | 269 | k = long((cStripsT.size()-4-2*r));
|
---|
[774] | 270 | }
|
---|
| 271 |
|
---|
| 272 | i++;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[985] | 275 | regLOD.nL2 = char(totalRegs);
|
---|
[774] | 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.
|
---|
[1017] | 290 | this->TOTALCAMBIOS = this->LodsDisp=lod;
|
---|
[774] | 291 |
|
---|
| 292 | //Retornar a la lista original
|
---|
| 293 | this->cStrips = TiraOriginal;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[1070] | 296 | //---------------------------------------------------------------------------
|
---|
[774] | 297 | //Put in order vertex of Mesh from simplification sequence
|
---|
[1070] | 298 | //---------------------------------------------------------------------------
|
---|
[774] | 299 | void LodStripsConstructor::OrdenarModeloVQSLIM(TIPOFUNC upb)
|
---|
| 300 | {
|
---|
[985] | 301 | unsigned long int i;
|
---|
| 302 | unsigned long int j;
|
---|
| 303 | unsigned long int t;
|
---|
| 304 | unsigned long int v;
|
---|
[774] | 305 | long int vSig;
|
---|
[1017] | 306 | long int k;
|
---|
[774] | 307 | VECTORVERTEX Vertices;
|
---|
[1018] | 308 | std::vector<tipoVertice> NuevosVerts;
|
---|
[1017] | 309 | //vector <VECTORINT> NuevasTiras;
|
---|
[1018] | 310 | std::vector<std::vector<int> > NuevasTiras;
|
---|
[1017] | 311 | // VECTORINT tira;
|
---|
[1018] | 312 | std::vector<int> tira;
|
---|
[774] | 313 | vector <Index> mV1Aux;
|
---|
| 314 | tipoOrden Orden;
|
---|
| 315 | tipoOrden *Ord;
|
---|
| 316 | bool bEncontrado;
|
---|
| 317 | long int c1;
|
---|
| 318 | long int c2;
|
---|
[1017] | 319 | // Progress bar
|
---|
[996] | 320 | float percent;
|
---|
| 321 | float increment;
|
---|
[774] | 322 | long int update;
|
---|
| 323 |
|
---|
| 324 | bEncontrado = false;
|
---|
| 325 |
|
---|
[1070] | 326 | size_t mStepsSize = mGeoMeshSQ->mSteps.size();
|
---|
[1014] | 327 |
|
---|
[996] | 328 | c1 = 0;
|
---|
| 329 | c2 = 0;
|
---|
[774] | 330 |
|
---|
[996] | 331 | update = -1;
|
---|
| 332 | percent = 1.0;
|
---|
[1017] | 333 | increment = (float)(10.0) / (float)mStepsSize;
|
---|
| 334 |
|
---|
| 335 | for (i = 0; i < mStepsSize; i++)
|
---|
[774] | 336 | {
|
---|
[996] | 337 | if (update != (int)(i * increment))
|
---|
[774] | 338 | {
|
---|
[996] | 339 | update = (int)(i * increment);
|
---|
[774] | 340 | upb(percent);
|
---|
| 341 | }
|
---|
| 342 |
|
---|
[1070] | 343 | const Geometry::MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i];
|
---|
[774] | 344 |
|
---|
[1017] | 345 | mV1Aux.push_back(theStep.mV1);
|
---|
| 346 |
|
---|
| 347 | Orden.vQslimNext = theStep.mV0;
|
---|
| 348 | Orden.vQslim = theStep.mV1;
|
---|
| 349 | Orden.obligatorio = theStep.obligatorio;
|
---|
[774] | 350 | Orden.vLS = i;
|
---|
| 351 |
|
---|
[1017] | 352 | Orden.x = theStep.x;
|
---|
[774] | 353 | Orden.vLSNext = -1;
|
---|
| 354 | Orden.cambio = "n";
|
---|
| 355 |
|
---|
| 356 | Ordenacion.push_back(Orden);
|
---|
| 357 | }
|
---|
[1017] | 358 |
|
---|
[774] | 359 | this->NumVertsRepetidos = c2;
|
---|
| 360 |
|
---|
[996] | 361 | update = -1;
|
---|
[1017] | 362 | increment = (float)(10.0) / (float)(Ordenacion.size());
|
---|
[996] | 363 | percent = 1.0;
|
---|
[774] | 364 |
|
---|
| 365 | // Change all vertices that have x != 0.
|
---|
[1017] | 366 | for(i = 0; i < Ordenacion.size(); i++)
|
---|
[774] | 367 | {
|
---|
[996] | 368 | if (update != (int)(i * increment))
|
---|
[774] | 369 | {
|
---|
[996] | 370 | update = (int)(i * increment);
|
---|
[774] | 371 | upb(percent);
|
---|
| 372 | }
|
---|
[996] | 373 |
|
---|
[1017] | 374 | Ord = &(Ordenacion[i]);
|
---|
| 375 |
|
---|
| 376 | if (Ord->x!=0)
|
---|
[774] | 377 | {
|
---|
| 378 | // Change the simplification order.
|
---|
| 379 | v = Ord->vQslim;
|
---|
| 380 | Ord->vQslim = Ord->vQslimNext;
|
---|
| 381 | Ord->vQslimNext = v;
|
---|
[1017] | 382 |
|
---|
| 383 | for (j = i+1; j < Ordenacion.size(); j++)
|
---|
[774] | 384 | {
|
---|
[1017] | 385 | tipoOrden & ordJ = Ordenacion[j];
|
---|
| 386 | if (ordJ.vQslim == Ord->vQslim)
|
---|
[774] | 387 | {
|
---|
[1017] | 388 | ordJ.vQslim = Ord->vQslimNext;
|
---|
| 389 | ordJ.cambio = "y";
|
---|
[774] | 390 | }
|
---|
[1017] | 391 | else if (ordJ.vQslimNext == Ord->vQslim)
|
---|
[774] | 392 | {
|
---|
[1017] | 393 | ordJ.vQslimNext = Ord->vQslimNext;
|
---|
| 394 | ordJ.cambio = "y";
|
---|
[774] | 395 | }
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
| 398 | }
|
---|
| 399 |
|
---|
[996] | 400 | update = -1;
|
---|
[1017] | 401 | increment = (float)(10.0) / (float)(Ordenacion.size());
|
---|
[996] | 402 | percent = 1.0;
|
---|
[774] | 403 |
|
---|
[1017] | 404 | // 3 seg.
|
---|
| 405 | //Ordenacion de los vertices
|
---|
| 406 | for(i = 0; i < Ordenacion.size(); i++)
|
---|
[774] | 407 | {
|
---|
[996] | 408 | if (update != (int)(i * increment))
|
---|
[774] | 409 | {
|
---|
[996] | 410 | update = (int)(i * increment);
|
---|
[774] | 411 | upb(percent);
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | c1++;
|
---|
[1017] | 415 | NuevosVerts.push_back(this->cVerts[Ordenacion[i].vQslim]);
|
---|
[774] | 416 |
|
---|
[1017] | 417 | cVerts[Ordenacion[i].vQslim].Next = -1;
|
---|
[774] | 418 |
|
---|
| 419 | }
|
---|
| 420 |
|
---|
[1017] | 421 | // Añadir aquellos vertices que no estaban en NuevosVerts
|
---|
| 422 | // y no se simplificaban.
|
---|
[774] | 423 | int cont = 0;
|
---|
| 424 | int contestaban = 0;
|
---|
| 425 |
|
---|
[1070] | 426 | size_t cVertsSize = this->cVerts.size();
|
---|
[1017] | 427 | for(i = 0; i < cVertsSize; i++)
|
---|
[774] | 428 | {
|
---|
| 429 | if (this->cVerts[i].Next != -1)
|
---|
| 430 | {
|
---|
| 431 | cont++;
|
---|
| 432 | NuevosVerts.push_back(this->cVerts[i]);
|
---|
[985] | 433 | Orden.vLS = int(Ordenacion.size());
|
---|
[774] | 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 |
|
---|
[996] | 447 | update = -1;
|
---|
[1017] | 448 | increment = (float)(10.0) / (float)(Ordenacion.size());
|
---|
[996] | 449 | percent = 1.0;
|
---|
[774] | 450 |
|
---|
[1017] | 451 | // 2 min.
|
---|
[1025] | 452 | // Calcular los siguiente teniendo en cuenta el simplif.
|
---|
[1017] | 453 | for (i = 0; i < Ordenacion.size(); i++)
|
---|
[774] | 454 | {
|
---|
[996] | 455 | if (update != (int)(i * increment))
|
---|
[774] | 456 | {
|
---|
[996] | 457 | update = (int)(i * increment);
|
---|
[774] | 458 | upb(percent);
|
---|
| 459 | }
|
---|
[996] | 460 |
|
---|
[1017] | 461 | v = Ordenacion[i].vQslimNext;
|
---|
| 462 |
|
---|
| 463 | //Buscar ese vertice v cual es ahora
|
---|
[774] | 464 | vSig = 0;
|
---|
[1017] | 465 |
|
---|
| 466 | for (t = 0; t < Ordenacion.size() && !vSig;t++)
|
---|
[774] | 467 | {
|
---|
[1017] | 468 | if (Ordenacion[t].vQslim==v)
|
---|
[774] | 469 | {
|
---|
[1017] | 470 | vSig=Ordenacion[t].vLS;
|
---|
[774] | 471 | }
|
---|
| 472 | }
|
---|
| 473 |
|
---|
[1017] | 474 | if (vSig!=0)
|
---|
[774] | 475 | {
|
---|
[1017] | 476 | Ordenacion[i].vLSNext = vSig;
|
---|
[774] | 477 | }
|
---|
| 478 | }
|
---|
[1017] | 479 |
|
---|
[774] | 480 | //Creacion de nuevas tiras con las mismas dimensiones
|
---|
[1070] | 481 | size_t cStripsSize = this->cStrips.size();
|
---|
[1017] | 482 | for(t = 0; t < cStripsSize; t++)
|
---|
[774] | 483 | {
|
---|
| 484 | tira.clear();
|
---|
| 485 |
|
---|
[1070] | 486 | size_t cStripsSizeT = this->cStrips[t].size();
|
---|
[1017] | 487 | for(i = 0; i < cStripsSizeT; i++)
|
---|
[774] | 488 | tira.push_back(0);
|
---|
| 489 |
|
---|
| 490 | NuevasTiras.push_back(tira);
|
---|
| 491 | }
|
---|
| 492 |
|
---|
[1017] | 493 | update = -1;
|
---|
| 494 | increment = (float)(20.0) / (float)(NuevosVerts.size());
|
---|
| 495 | percent = 1.0;
|
---|
| 496 |
|
---|
| 497 | k = 0;
|
---|
| 498 |
|
---|
[774] | 499 | // 2 min.
|
---|
| 500 | //Cambiar los vertices de las tiras
|
---|
[1070] | 501 | size_t NuevosVertsSize = NuevosVerts.size();
|
---|
[1017] | 502 | for(v = 0; v < NuevosVertsSize; v++)
|
---|
[774] | 503 | {
|
---|
[1017] | 504 | if (update != (int)(v * increment))
|
---|
[774] | 505 | {
|
---|
[1017] | 506 | update = (int)(v * increment);
|
---|
[774] | 507 | upb(percent);
|
---|
[1017] | 508 | }
|
---|
[1014] | 509 |
|
---|
[1017] | 510 | const tipoOrden & OrdenacionV = Ordenacion[v];
|
---|
| 511 |
|
---|
| 512 | for(t = 0; t < cStrips.size(); t++)
|
---|
[774] | 513 | {
|
---|
[1018] | 514 | std::vector<int> & thisStrip = cStrips[t];
|
---|
| 515 | std::vector<int> & NuevasTirasT = NuevasTiras[t];
|
---|
[1070] | 516 | size_t cStripsSizeT = thisStrip.size();
|
---|
[1017] | 517 | for(i = 0; i < cStripsSizeT; i++)
|
---|
[774] | 518 | {
|
---|
[1017] | 519 | if (thisStrip[i] == OrdenacionV.vQslim)
|
---|
[774] | 520 | {
|
---|
[1017] | 521 | k++;
|
---|
| 522 | NuevasTirasT[i] = v;
|
---|
[774] | 523 | }
|
---|
| 524 | }
|
---|
| 525 | }
|
---|
| 526 | }
|
---|
| 527 |
|
---|
[1017] | 528 | //Cambiar a Tiras Nuevas
|
---|
[774] | 529 | this->cStrips = NuevasTiras;
|
---|
| 530 |
|
---|
[1017] | 531 | //NuevosVerts y Ordenacion = tamaño.
|
---|
| 532 | NuevosVertsSize = NuevosVerts.size();
|
---|
| 533 | for(i = 0; i < NuevosVertsSize; i++)
|
---|
[774] | 534 | {
|
---|
| 535 | NuevosVerts[i].Next = Ordenacion[i].vLSNext;
|
---|
| 536 | }
|
---|
| 537 |
|
---|
| 538 | //Cambiar cVerts por nuevosVerts.
|
---|
| 539 | this->cVerts = NuevosVerts;
|
---|
| 540 |
|
---|
[996] | 541 | //percent = 100.0;
|
---|
| 542 | //upb(percent);
|
---|
| 543 | }
|
---|
[774] | 544 |
|
---|
[1070] | 545 | //---------------------------------------------------------------------------
|
---|
[774] | 546 | // Constructor of LodStripsConstructor object from
|
---|
[1070] | 547 | // a Mesh and MeshSimplificationSequence.
|
---|
| 548 | //---------------------------------------------------------------------------
|
---|
[774] | 549 | LodStripsConstructor::LodStripsConstructor(const Mesh *m,
|
---|
| 550 | const MeshSimplificationSequence *ms,
|
---|
[841] | 551 | size_t submesh,
|
---|
[774] | 552 | TIPOFUNC upb)
|
---|
| 553 | {
|
---|
| 554 | MARCA = TOTALTIRAS = TOTALVERTS = TOTALCAMBIOS = 0;
|
---|
| 555 |
|
---|
[1070] | 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);
|
---|
[774] | 565 |
|
---|
[841] | 566 | // Set the leaves submesh.
|
---|
| 567 | mSubMeshLeaves = submesh;
|
---|
[1070] | 568 |
|
---|
[774] | 569 | this->GenerarModeloCompleto(upb);
|
---|
[1070] | 570 |
|
---|
| 571 | // Sort submesh bones.
|
---|
| 572 | this->sortBones();
|
---|
[774] | 573 | }
|
---|
| 574 |
|
---|
[1070] | 575 | //---------------------------------------------------------------------------
|
---|
[774] | 576 | // Destructor LodStripsConstructor object
|
---|
[1070] | 577 | //---------------------------------------------------------------------------
|
---|
[774] | 578 | LodStripsConstructor::~LodStripsConstructor()
|
---|
| 579 | {
|
---|
| 580 | delete [] vDatos;
|
---|
| 581 | delete [] vCambios;
|
---|
[1017] | 582 | /* vector <LODData> cCambiosTemp;
|
---|
| 583 | cCambios.swap(cCambiosTemp);*/
|
---|
| 584 | cCambios.clear();
|
---|
[774] | 585 |
|
---|
[1017] | 586 | /* VECTORUNINT cDatosTemp;
|
---|
| 587 | cDatos.swap(cDatosTemp);*/
|
---|
| 588 | cDatos.clear();
|
---|
[774] | 589 |
|
---|
| 590 | delete [] vStrips;
|
---|
| 591 |
|
---|
| 592 | delete [] vVerts;
|
---|
| 593 |
|
---|
[1017] | 594 | // vector <VECTORINT> cStripsTemp;
|
---|
| 595 | // cStrips.swap(cStripsTemp);;
|
---|
| 596 | cStrips.clear();
|
---|
[774] | 597 |
|
---|
[1017] | 598 | // VECTORVERTEX cVertsTemp;
|
---|
| 599 | // cVerts.swap(cVertsTemp);
|
---|
| 600 | cVerts.clear();
|
---|
[774] | 601 |
|
---|
| 602 | delete [] pCambios;
|
---|
| 603 |
|
---|
[1070] | 604 | delete mInitialMesh;
|
---|
| 605 | delete mGeoMesh;
|
---|
[774] | 606 | }
|
---|
| 607 |
|
---|
[1070] | 608 | //---------------------------------------------------------------------------
|
---|
| 609 | // Build lod file with necessary information and save all changes at
|
---|
| 610 | // lodStripConstructor object.
|
---|
| 611 | //---------------------------------------------------------------------------
|
---|
[1078] | 612 | void LodStripsConstructor::Save(std::string filename)
|
---|
[774] | 613 | {
|
---|
[1136] | 614 | //size_t i, j;
|
---|
| 615 | int k = 0;
|
---|
| 616 | char simp[256];
|
---|
[774] | 617 |
|
---|
[1136] | 618 | int vertexCount = (int)this->cVerts.size();
|
---|
| 619 | int changesCount = (int)this->cCambios.size();
|
---|
| 620 | int dataCount = (int)this->cDatos.size();
|
---|
| 621 | int cambiosCount = this->TOTALCAMBIOS;
|
---|
| 622 | int size = changesCount*sizeof(LODData) +
|
---|
[1090] | 623 | (vertexCount + dataCount + cambiosCount + 4)*sizeof(int) +
|
---|
| 624 | CHUNK_OVERHEAD_SIZE;
|
---|
[774] | 625 |
|
---|
[1078] | 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);
|
---|
[1136] | 633 | for(size_t i = 0; i < this->cVerts.size(); i++)
|
---|
[774] | 634 | {
|
---|
[1078] | 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 | {
|
---|
[774] | 642 | sprintf(simp,"v %d\n",cVerts[i].Next);
|
---|
| 643 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
| 644 | }
|
---|
[1078] | 645 | */
|
---|
| 646 |
|
---|
[774] | 647 | // CSTRIPS.
|
---|
| 648 | this->TOTALINDICES = 0;
|
---|
| 649 |
|
---|
[1136] | 650 | for(size_t i = 0; i < this->cStrips.size(); i++)
|
---|
[774] | 651 | {
|
---|
[985] | 652 | this->TOTALINDICES += int(this->cStrips[i].size());
|
---|
[774] | 653 | }
|
---|
| 654 |
|
---|
| 655 | // lines starting with a d.
|
---|
| 656 | // Changes
|
---|
[1078] | 657 | fwrite(&changesCount, sizeof(int), 1, f);
|
---|
[1136] | 658 | for(size_t i = 0; i < this->cCambios.size(); i++)
|
---|
[774] | 659 | {
|
---|
[1078] | 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 | {
|
---|
[774] | 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 | }
|
---|
[1078] | 680 | */ // Lines starting with a b.
|
---|
[774] | 681 | // Data.
|
---|
[1078] | 682 |
|
---|
| 683 | fwrite(&dataCount, sizeof(int), 1, f);
|
---|
[1136] | 684 |
|
---|
| 685 | for(size_t i = 0; i < this->cDatos.size(); i++)
|
---|
[1078] | 686 | {
|
---|
| 687 | int data= cDatos[i];
|
---|
| 688 | fwrite(&data, sizeof(int), 1, f);
|
---|
| 689 | }
|
---|
| 690 |
|
---|
[774] | 691 | sprintf(simp,"a\n");
|
---|
[1078] | 692 | /* oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
[774] | 693 |
|
---|
| 694 | for(i = 0; i < this->cDatos.size(); i++)
|
---|
| 695 | {
|
---|
| 696 | sprintf(simp,"b %d\n",cDatos[i]);
|
---|
| 697 |
|
---|
| 698 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
| 699 | }
|
---|
[1078] | 700 | */
|
---|
[774] | 701 |
|
---|
| 702 | // lines starting with a p.
|
---|
| 703 | // Chages made in a LOD.
|
---|
[1078] | 704 | fwrite(&cambiosCount, sizeof(int), 1, f);
|
---|
[1136] | 705 |
|
---|
| 706 | for(size_t i = 0; i < this->TOTALCAMBIOS; i++)
|
---|
[774] | 707 | {
|
---|
[1078] | 708 | int cambio= pCambios[i];
|
---|
| 709 | fwrite(&cambio, sizeof(int), 1, f);
|
---|
[774] | 710 | }
|
---|
| 711 |
|
---|
[1078] | 712 | fclose(f);
|
---|
[774] | 713 |
|
---|
[1078] | 714 | /*
|
---|
| 715 | // VERTICES.
|
---|
| 716 | for(i = 0; i < this->cVerts.size(); i++)
|
---|
[774] | 717 | {
|
---|
[1078] | 718 | sprintf(simp,"v %d\n",cVerts[i].Next);
|
---|
| 719 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
| 720 | }
|
---|
[774] | 721 |
|
---|
[1078] | 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 | }
|
---|
[774] | 729 |
|
---|
[1078] | 730 | // lines starting with a d.
|
---|
| 731 | // Changes
|
---|
| 732 | for(i = 0; i < this->cCambios.size(); i++)
|
---|
[774] | 733 | {
|
---|
[1078] | 734 | sprintf(simp,"c\n");
|
---|
| 735 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
[774] | 736 |
|
---|
[1078] | 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));
|
---|
[774] | 746 | }
|
---|
[1078] | 747 | // Lines starting with a b.
|
---|
| 748 | // Data.
|
---|
| 749 | sprintf(simp,"a\n");
|
---|
| 750 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
[774] | 751 |
|
---|
[1078] | 752 | for(i = 0; i < this->cDatos.size(); i++)
|
---|
| 753 | {
|
---|
| 754 | sprintf(simp,"b %d\n",cDatos[i]);
|
---|
[1017] | 755 |
|
---|
[1078] | 756 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
| 757 | }
|
---|
[1017] | 758 |
|
---|
[1078] | 759 | // lines starting with a p.
|
---|
| 760 | // Chages made in a LOD.
|
---|
| 761 | for(i = 0; i < this->TOTALCAMBIOS; i++)
|
---|
[774] | 762 | {
|
---|
[1078] | 763 | sprintf(simp,"p %d\n",this->pCambios[i]);
|
---|
[1017] | 764 |
|
---|
[1078] | 765 | oSerializer.WriteData(simp,sizeof(char),strlen(simp));
|
---|
[774] | 766 | }
|
---|
[1078] | 767 |
|
---|
| 768 | oSerializer.WriteData("\n",sizeof(char),1); */
|
---|
[774] | 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 |
|
---|
[1078] | 787 | /*void LodStripsConstructor::Load(Serializer &oSerializer)
|
---|
[774] | 788 | {
|
---|
[1078] | 789 | }*/
|
---|
[774] | 790 |
|
---|
[1070] | 791 | //---------------------------------------------------------------------------
|
---|
| 792 | // Call leeVerticesyTirasDeMesh, OrdenarModeloVQSLIM
|
---|
| 793 | // and CalcularCambiosLODsVNuevaED to make changes at vertex
|
---|
| 794 | // and index strutures.
|
---|
| 795 | //---------------------------------------------------------------------------
|
---|
[774] | 796 | void LodStripsConstructor::GenerarModeloV(TIPOFUNC upb)
|
---|
| 797 | {
|
---|
| 798 | long int max;
|
---|
| 799 | long int t;
|
---|
[985] | 800 | unsigned long int i;
|
---|
[774] | 801 | float percent;
|
---|
| 802 |
|
---|
| 803 | percent = 10;
|
---|
| 804 |
|
---|
| 805 | this->leeVerticesyTirasDeMesh();
|
---|
| 806 |
|
---|
| 807 | upb(percent);
|
---|
| 808 |
|
---|
[1017] | 809 | // 6 min.
|
---|
[774] | 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 | {
|
---|
[985] | 817 | t = long(this->cStrips[i].size());
|
---|
[774] | 818 |
|
---|
| 819 | if (t > max)
|
---|
| 820 | {
|
---|
| 821 | max = t;
|
---|
| 822 | }
|
---|
| 823 | }
|
---|
| 824 |
|
---|
| 825 | this->MARCA = max + 1;
|
---|
| 826 | this->CalcularCambiosLODsVNuevaED(upb);
|
---|
| 827 | }
|
---|
| 828 |
|
---|
[1070] | 829 | //---------------------------------------------------------------------------
|
---|
| 830 | // It fills structs with vertex and index information.
|
---|
| 831 | //---------------------------------------------------------------------------
|
---|
[774] | 832 | void LodStripsConstructor::CopiarVectors2ArraysNUEVAED()
|
---|
| 833 | {
|
---|
[985] | 834 | unsigned int i;
|
---|
| 835 | unsigned int j;
|
---|
[774] | 836 | uint32 max;
|
---|
| 837 | uint32 t;
|
---|
| 838 | VECTORINT tira;
|
---|
| 839 | LODChanges listaCambios;
|
---|
| 840 |
|
---|
| 841 | // ALLOCATE----------------
|
---|
[985] | 842 | this->TOTALVERTS = int(this->cVerts.size());
|
---|
| 843 | this->TOTALTIRAS = int(this->cStrips.size());
|
---|
[774] | 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 | {
|
---|
[985] | 854 | t = int(this->cStrips[i].size());
|
---|
[774] | 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);
|
---|
[985] | 865 | this->MARCA = int(this->cVerts.size());
|
---|
[774] | 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 |
|
---|
[1070] | 903 | //---------------------------------------------------------------------------
|
---|
| 904 | // It fills cVerts and cStrips with original Mesh vertex and strips
|
---|
| 905 | // information.
|
---|
| 906 | //---------------------------------------------------------------------------
|
---|
[774] | 907 | void LodStripsConstructor::leeVerticesyTirasDeMesh()
|
---|
| 908 | {
|
---|
| 909 | tipoVertice vAux;
|
---|
[1018] | 910 | std::vector<int> tira;
|
---|
[774] | 911 | size_t i;
|
---|
| 912 | size_t j;
|
---|
| 913 | bool error;
|
---|
| 914 |
|
---|
| 915 | error = false;
|
---|
| 916 |
|
---|
[1070] | 917 | if(this->mGeoMesh->mSubMeshCount == 1)
|
---|
[774] | 918 | {
|
---|
| 919 | error = false;
|
---|
| 920 | }
|
---|
| 921 | else
|
---|
| 922 | {
|
---|
[1070] | 923 | for (i = 0; i < this->mGeoMesh->mSubMeshCount;i++)
|
---|
[774] | 924 | {
|
---|
[1070] | 925 | if (this->mGeoMesh->mSubMesh[i].mSharedVertexBuffer == true)
|
---|
[774] | 926 | {
|
---|
| 927 | error = false;
|
---|
| 928 | }
|
---|
| 929 | else
|
---|
| 930 | {
|
---|
| 931 | error = true;
|
---|
| 932 | break;
|
---|
| 933 | }
|
---|
| 934 | }
|
---|
| 935 | }
|
---|
| 936 |
|
---|
| 937 | if(!error)
|
---|
| 938 | {
|
---|
[1070] | 939 | if ( (this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer == true)
|
---|
[774] | 940 | &&
|
---|
[1070] | 941 | (this->mGeoMesh->mSubMeshCount > 1)
|
---|
[774] | 942 | )
|
---|
| 943 | {
|
---|
[1070] | 944 | for (j = 0; j < this->mGeoMesh->mVertexBuffer->mVertexCount; j++)
|
---|
[774] | 945 | {
|
---|
| 946 | // Si hay mas de un submesh ListaIndices no se rellena correctamente
|
---|
[1070] | 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;
|
---|
[774] | 950 |
|
---|
| 951 | // Añadimos las normales en cVerts.
|
---|
[1070] | 952 | if ( this->mGeoMesh->mVertexBuffer->mVertexInfo
|
---|
[774] | 953 | &
|
---|
| 954 | Geometry::VERTEX_NORMAL
|
---|
| 955 | )
|
---|
| 956 | {
|
---|
[1070] | 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;
|
---|
[774] | 960 | }
|
---|
| 961 |
|
---|
| 962 | // Añadimos las coordenadas de textura a cVerts.
|
---|
[1070] | 963 | if ( this->mGeoMesh->mVertexBuffer->mVertexInfo
|
---|
[774] | 964 | &
|
---|
| 965 | Geometry::VERTEX_TEXCOORDS
|
---|
| 966 | )
|
---|
| 967 | {
|
---|
[1070] | 968 | vAux.TexCoords[0] = this->mGeoMesh->mVertexBuffer->mTexCoords[j].x;
|
---|
| 969 | vAux.TexCoords[1] = this->mGeoMesh->mVertexBuffer->mTexCoords[j].y;
|
---|
[774] | 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 | {
|
---|
[1070] | 982 | for (i = 0; i < this->mGeoMesh->mSubMeshCount; i++)
|
---|
[774] | 983 | {
|
---|
| 984 | for ( j = 0;
|
---|
[1070] | 985 | j < this->mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount;
|
---|
[841] | 986 | j++)
|
---|
[774] | 987 | {
|
---|
| 988 | // Si hay mas de un submesh ListaIndices
|
---|
| 989 | // no se rellena correctamente.
|
---|
[1070] | 990 | vAux.Vertex[0] = this->mGeoMesh->mSubMesh[i].
|
---|
[841] | 991 | mVertexBuffer->mPosition[j].x;
|
---|
[1070] | 992 | vAux.Vertex[1] = this->mGeoMesh->mSubMesh[i].
|
---|
[841] | 993 | mVertexBuffer->mPosition[j].y;
|
---|
[1070] | 994 | vAux.Vertex[2] = this->mGeoMesh->mSubMesh[i].
|
---|
[841] | 995 | mVertexBuffer->mPosition[j].z;
|
---|
[774] | 996 | // Añadimos las normales en cVerts.
|
---|
[1070] | 997 | vAux.Normal[0] = this->mGeoMesh->mSubMesh[i].
|
---|
[841] | 998 | mVertexBuffer->mNormal[j].x;
|
---|
[1070] | 999 | vAux.Normal[1] = this->mGeoMesh->mSubMesh[i].
|
---|
[841] | 1000 | mVertexBuffer->mNormal[j].y;
|
---|
[1070] | 1001 | vAux.Normal[2] = this->mGeoMesh->mSubMesh[i].
|
---|
[841] | 1002 | mVertexBuffer->mNormal[j].z;
|
---|
[774] | 1003 |
|
---|
| 1004 | // Añadimos las coordenadas de textura a cVerts.
|
---|
[1070] | 1005 | vAux.TexCoords[0] = this->mGeoMesh->mSubMesh[i].
|
---|
[841] | 1006 | mVertexBuffer->mTexCoords[j].x;
|
---|
[1070] | 1007 | vAux.TexCoords[1] = this->mGeoMesh->mSubMesh[i].
|
---|
[841] | 1008 | mVertexBuffer->mTexCoords[j].y;
|
---|
[774] | 1009 |
|
---|
| 1010 | vAux.Next = -10;
|
---|
[985] | 1011 | vAux.numMesh = int(i);
|
---|
[841] | 1012 |
|
---|
[774] | 1013 | this->cVerts.push_back(vAux);
|
---|
| 1014 | }
|
---|
| 1015 | }
|
---|
| 1016 | }
|
---|
| 1017 |
|
---|
| 1018 | Index indice_acum;
|
---|
| 1019 | Index num_vert;
|
---|
| 1020 |
|
---|
| 1021 | num_vert = 0;
|
---|
| 1022 |
|
---|
[1070] | 1023 | for (i = 0; i < this->mGeoMesh->mSubMeshCount; i++)
|
---|
[774] | 1024 | {
|
---|
[841] | 1025 | // If is not the leaves submesh.
|
---|
| 1026 | if (mSubMeshLeaves != i)
|
---|
[774] | 1027 | {
|
---|
[841] | 1028 | indice_acum = 0;
|
---|
| 1029 |
|
---|
[1070] | 1030 | for (j = 0; j < this->mGeoMesh->mSubMesh[i].mStripCount; j++)
|
---|
[774] | 1031 | {
|
---|
[1070] | 1032 | Index *aux = this->mGeoMesh->mSubMesh[i].mStrip[j];
|
---|
[841] | 1033 |
|
---|
[891] | 1034 | /*
|
---|
[841] | 1035 | if (j != 0)
|
---|
[774] | 1036 | {
|
---|
[841] | 1037 | // La primera tira no empieza por índices repetidos.
|
---|
| 1038 | aux = aux+1;
|
---|
| 1039 |
|
---|
[774] | 1040 | indice_acum++;
|
---|
| 1041 | }
|
---|
[891] | 1042 | */
|
---|
[841] | 1043 |
|
---|
[1070] | 1044 | if (j+1 < this->mGeoMesh->mSubMesh[i].mStripCount)
|
---|
[841] | 1045 | {
|
---|
[1070] | 1046 | Index *siguiente = this->mGeoMesh->mSubMesh[i].mStrip[j+1];
|
---|
[841] | 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 |
|
---|
[891] | 1058 | //tira.pop_back();
|
---|
| 1059 |
|
---|
[841] | 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;
|
---|
[1070] | 1068 | k < this->mGeoMesh->mSubMesh[i].mIndexCount;
|
---|
[774] | 1069 | k++)
|
---|
[841] | 1070 | {
|
---|
[1070] | 1071 | tira.push_back(this->mGeoMesh->mSubMesh[i].mIndex[k]);
|
---|
[841] | 1072 | }
|
---|
| 1073 |
|
---|
| 1074 | this->cStrips.push_back(tira);
|
---|
[774] | 1075 | }
|
---|
| 1076 | }
|
---|
[841] | 1077 |
|
---|
[1070] | 1078 | num_vert += int(this->mGeoMesh->mSubMesh[i].
|
---|
[985] | 1079 | mVertexBuffer->mVertexCount);
|
---|
[774] | 1080 | }
|
---|
| 1081 | }
|
---|
| 1082 |
|
---|
[985] | 1083 | this->TOTALVERTS = int(cVerts.size());
|
---|
| 1084 | this->TOTALTIRAS = int(cStrips.size());
|
---|
[774] | 1085 | }
|
---|
| 1086 | else
|
---|
| 1087 | {
|
---|
| 1088 | // Error.
|
---|
| 1089 | }
|
---|
| 1090 | }
|
---|
| 1091 |
|
---|
[1070] | 1092 | //---------------------------------------------------------------------------
|
---|
[996] | 1093 | // GetMesh: Return de current Mesh.
|
---|
[1070] | 1094 | //---------------------------------------------------------------------------
|
---|
[774] | 1095 | Mesh * LodStripsConstructor::GetMesh()
|
---|
| 1096 | {
|
---|
| 1097 | Mesh *mesh_built;
|
---|
| 1098 |
|
---|
| 1099 | mesh_built = new Mesh();
|
---|
[1070] | 1100 | *mesh_built = *mGeoMesh;
|
---|
[774] | 1101 |
|
---|
| 1102 | return mesh_built;
|
---|
| 1103 | }
|
---|
| 1104 |
|
---|
[1070] | 1105 | //---------------------------------------------------------------------------
|
---|
[841] | 1106 | // Sets what is the submesh that stores the leaves.
|
---|
[1070] | 1107 | //---------------------------------------------------------------------------
|
---|
[841] | 1108 | void LodStripsConstructor::SetSubMeshLeaves(size_t submesh)
|
---|
| 1109 | {
|
---|
| 1110 | mSubMeshLeaves = submesh;
|
---|
| 1111 | }
|
---|
| 1112 |
|
---|
[1070] | 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 |
|
---|
[1078] | 1246 | void Geometry::LodStripsConstructor::UpdateMesh(void)
|
---|
| 1247 | {
|
---|
| 1248 | int num_no = 0;
|
---|
[1136] | 1249 | //int i=0,j=0;
|
---|
[1078] | 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 |
|
---|
[1136] | 1274 | for(size_t i = 0; i < this->mGeoMesh->mSubMeshCount; i++)
|
---|
[1078] | 1275 | {
|
---|
[1136] | 1276 | this->mGeoMesh->mSubMesh[i].mVertexBuffer = this->mGeoMesh->mVertexBuffer;
|
---|
[1078] | 1277 | this->mGeoMesh->mSubMesh[i].mSharedVertexBuffer = true;
|
---|
| 1278 | }
|
---|
| 1279 |
|
---|
| 1280 | int indice = 0;
|
---|
| 1281 |
|
---|
[1136] | 1282 | for (size_t j = 0; j < this->cVerts.size(); j++)
|
---|
[1078] | 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 |
|
---|
[1136] | 1337 | int indice = 0;
|
---|
| 1338 |
|
---|
| 1339 | for (size_t j = 0; j < this->cVerts.size(); j++)
|
---|
[1078] | 1340 | {
|
---|
| 1341 | //Copiamos las coordeandas de posicion
|
---|
| 1342 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].x=this->cVerts[j].Vertex[0];
|
---|
| 1343 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].y=this->cVerts[j].Vertex[1];
|
---|
| 1344 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].z=this->cVerts[j].Vertex[2];
|
---|
| 1345 |
|
---|
| 1346 | //Copiamos las normales
|
---|
| 1347 | if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
|
---|
| 1348 | {
|
---|
| 1349 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].x=this->cVerts[j].Normal[0];
|
---|
| 1350 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].y=this->cVerts[j].Normal[1];
|
---|
| 1351 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].z=this->cVerts[j].Normal[2];
|
---|
| 1352 | }
|
---|
| 1353 |
|
---|
| 1354 | //Copiamos las coordenadas de textura
|
---|
| 1355 | if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
|
---|
| 1356 | {
|
---|
| 1357 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].x=this->cVerts[j].TexCoords[0];
|
---|
| 1358 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].y=this->cVerts[j].TexCoords[1];
|
---|
| 1359 | }
|
---|
| 1360 | indice++;
|
---|
| 1361 | }
|
---|
| 1362 | this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =indice;
|
---|
| 1363 | }
|
---|
| 1364 |
|
---|
| 1365 | int indice_acum = 0;
|
---|
[1136] | 1366 |
|
---|
| 1367 | for(size_t i = 0; i < this->mGeoMesh->mSubMeshCount; i++)
|
---|
[1078] | 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 | }
|
---|
[1136] | 1437 | }
|
---|