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