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