- Timestamp:
- 09/28/06 17:49:37 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp
r1136 r1526 27 27 void LodStripsConstructor::CalcularCambiosLODsVNuevaED(TIPOFUNC upb) 28 28 { 29 // LODPosition pos; 30 // vector <LODPosition> listaPos; 31 long int k; 32 long int i; 33 unsigned long int t; 34 long int r; 35 unsigned long int v; 36 long int p0; 37 long int lod = 0; 38 long int sigue; 39 long int ac[3] = {0,0,0}; 40 long int totalRegs = 0; 41 long int RegsCambios; 42 std::vector<std::vector<int> > TiraOriginal; 43 LODData regLOD; 44 //LODChanges listaCambios; 45 std::vector<LODData> listaCambios; 46 float percent; 47 float increment; 48 long int update; 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; 49 46 50 47 // Saves original copy. … … 68 65 69 66 this->LodsDisp = this->TOTALCAMBIOS = lod; 70 pCambios 71 pCambios[0] 67 pCambios = new uint32[this->TOTALCAMBIOS]; 68 pCambios[0] = 0; 72 69 73 70 for (lod = 0; ((this->cVerts[lod].Next) != -1); lod++) 74 71 { 75 /* if (update != (int)(increment * lod))76 {77 update = (int)(increment * lod);78 upb(percent);79 }*/80 81 72 tipoVertice & cVertsLOD = this->cVerts[lod]; 82 73 83 74 RegsCambios = 0; 84 regLOD.obligatory = this->Ordenacion[lod].obligator io;75 regLOD.obligatory = this->Ordenacion[lod].obligatory; 85 76 86 77 for(t = 0; t < this->cStrips.size(); t++) 87 78 { 88 89 79 std::vector<int> & cStripsT = this->cStrips[t]; 90 80 … … 101 91 // Strips. 102 92 if (regLOD.strip == this->MARCAVACIO) 103 { 104 regLOD.strip = t; 105 } 93 regLOD.strip = t; 106 94 107 95 ++totalRegs; … … 118 106 // Changes for simplification of level 1 to greater than 2. 119 107 totalRegs = 0; 120 i 121 r 122 sigue 123 k 108 i = 0; 109 r = 0; 110 sigue = 0; 111 k = long(cStripsT.size()-3); 124 112 125 113 while (i < k) … … 305 293 long int vSig; 306 294 long int k; 307 VECTORVERTEX 295 VECTORVERTEX Vertices; 308 296 std::vector<tipoVertice> NuevosVerts; 309 //vector <VECTORINT> NuevasTiras; 310 std::vector<std::vector<int> > NuevasTiras; 311 // VECTORINT tira; 312 std::vector<int> tira; 313 vector <Index> mV1Aux; 314 tipoOrden Orden; 315 tipoOrden *Ord; 316 bool bEncontrado; 317 long int c1; 318 long int c2; 297 std::vector<std::vector<int> > NuevasTiras; 298 std::vector<int> tira; 299 tipoOrden Orden; 300 tipoOrden *Ord; 301 bool bEncontrado; 302 303 319 304 // Progress bar 320 305 float percent; … … 326 311 size_t mStepsSize = mGeoMeshSQ->mSteps.size(); 327 312 328 c1 = 0;329 c2 = 0;330 331 313 update = -1; 332 314 percent = 1.0; … … 341 323 } 342 324 343 const Geometry::MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i]; 344 345 mV1Aux.push_back(theStep.mV1); 325 const MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i]; 346 326 347 327 Orden.vQslimNext = theStep.mV0; 348 Orden.vQslim 349 Orden.obligator io = theStep.obligatorio;350 Orden.vLS 351 352 Orden.x 353 Orden.vLSNext 354 Orden.cambio 328 Orden.vQslim = theStep.mV1; 329 Orden.obligatory = theStep.obligatory; 330 Orden.vLS = i; 331 332 Orden.x = theStep.x; 333 Orden.vLSNext = -1; 334 Orden.cambio = "n"; 355 335 356 336 Ordenacion.push_back(Orden); 357 337 } 358 338 359 this->NumVertsRepetidos = c2;360 339 361 340 update = -1; … … 363 342 percent = 1.0; 364 343 365 // Change all vertices that have x != 0.366 for(i = 0; i < Ordenacion.size(); i++)367 {368 if (update != (int)(i * increment))369 {370 update = (int)(i * increment);371 upb(percent);372 }373 374 Ord = &(Ordenacion[i]);375 376 if (Ord->x!=0)377 {378 // Change the simplification order.379 v = Ord->vQslim;380 Ord->vQslim = Ord->vQslimNext;381 Ord->vQslimNext = v;382 383 for (j = i+1; j < Ordenacion.size(); j++)384 {385 tipoOrden & ordJ = Ordenacion[j];386 if (ordJ.vQslim == Ord->vQslim)387 {388 ordJ.vQslim = Ord->vQslimNext;389 ordJ.cambio = "y";390 }391 else if (ordJ.vQslimNext == Ord->vQslim)392 {393 ordJ.vQslimNext = Ord->vQslimNext;394 ordJ.cambio = "y";395 }396 }397 }398 }399 400 344 update = -1; 401 345 increment = (float)(10.0) / (float)(Ordenacion.size()); … … 412 356 } 413 357 414 c1++; 415 NuevosVerts.push_back(this->cVerts[Ordenacion[i].vQslim]); 416 417 cVerts[Ordenacion[i].vQslim].Next = -1; 358 int OrdvQslim = Ordenacion[i].vQslim; 359 int OrdvQslimNext = Ordenacion[i].vQslimNext; 360 361 NuevosVerts.push_back(this->cVerts[OrdvQslim]); 362 363 cVerts[OrdvQslim].Next = -1; 418 364 419 365 } … … 421 367 // Añadir aquellos vertices que no estaban en NuevosVerts 422 368 // y no se simplificaban. 423 int cont 369 int cont = 0; 424 370 int contestaban = 0; 425 371 … … 431 377 cont++; 432 378 NuevosVerts.push_back(this->cVerts[i]); 433 Orden.vLS 434 Orden.obligator io= 0;435 Orden.vLSNext 436 Orden.vQslim 379 Orden.vLS = int(Ordenacion.size()); 380 Orden.obligatory = 0; 381 Orden.vLSNext = -1; 382 Orden.vQslim = i; 437 383 Orden.vQslimNext = -1; 438 384 … … 466 412 for (t = 0; t < Ordenacion.size() && !vSig;t++) 467 413 { 468 if (Ordenacion[t].vQslim ==v)469 { 470 vSig =Ordenacion[t].vLS;471 } 472 } 473 474 if (vSig !=0)414 if (Ordenacion[t].vQslim == v) 415 { 416 vSig = Ordenacion[t].vLS; 417 } 418 } 419 420 if (vSig != 0) 475 421 { 476 422 Ordenacion[i].vLSNext = vSig; … … 485 431 486 432 size_t cStripsSizeT = this->cStrips[t].size(); 433 487 434 for(i = 0; i < cStripsSizeT; i++) 435 { 488 436 tira.push_back(0); 437 } 489 438 490 439 NuevasTiras.push_back(tira); … … 499 448 // 2 min. 500 449 //Cambiar los vertices de las tiras 501 size_t NuevosVertsSize = NuevosVerts.size(); 450 size_t NuevosVertsSize = NuevosVerts.size(); 451 502 452 for(v = 0; v < NuevosVertsSize; v++) 503 453 { … … 515 465 std::vector<int> & NuevasTirasT = NuevasTiras[t]; 516 466 size_t cStripsSizeT = thisStrip.size(); 467 517 468 for(i = 0; i < cStripsSizeT; i++) 518 469 { … … 531 482 //NuevosVerts y Ordenacion = tamaño. 532 483 NuevosVertsSize = NuevosVerts.size(); 484 533 485 for(i = 0; i < NuevosVertsSize; i++) 534 486 { … … 563 515 564 516 this->mGeoMeshSQ = const_cast<MeshSimplificationSequence*>(ms); 517 518 // Add new vertices to mesh. 519 AddNewVertices(); 565 520 566 521 // Set the leaves submesh. … … 612 567 void LodStripsConstructor::Save(std::string filename) 613 568 { 614 //size_t i, j;615 int k = 0;616 char simp[256];617 618 569 int vertexCount = (int)this->cVerts.size(); 619 570 int changesCount = (int)this->cCambios.size(); 620 int dataCount 571 int dataCount = (int)this->cDatos.size(); 621 572 int cambiosCount = this->TOTALCAMBIOS; 622 int size 573 int size = changesCount*sizeof(LODData) + 623 574 (vertexCount + dataCount + cambiosCount + 4)*sizeof(int) + 624 575 CHUNK_OVERHEAD_SIZE; … … 630 581 fwrite(&size,sizeof(unsigned long),1,f); 631 582 583 // VERTICES 632 584 fwrite(&vertexCount, sizeof(int), 1, f); 633 585 for(size_t i = 0; i < this->cVerts.size(); i++) … … 636 588 fwrite(&auxv, sizeof(int), 1, f); 637 589 } 638 639 // VERTICES.640 /* for(i = 0; i < this->cVerts.size(); i++)641 {642 sprintf(simp,"v %d\n",cVerts[i].Next);643 oSerializer.WriteData(simp,sizeof(char),strlen(simp));644 }645 */646 590 647 591 // CSTRIPS. … … 649 593 650 594 for(size_t i = 0; i < this->cStrips.size(); i++) 651 {652 595 this->TOTALINDICES += int(this->cStrips[i].size()); 653 }654 596 655 597 // lines starting with a d. … … 662 604 } 663 605 664 665 /* for(i = 0; i < this->cCambios.size(); i++)666 {667 sprintf(simp,"c\n");668 oSerializer.WriteData(simp,sizeof(char),strlen(simp));669 670 sprintf(simp,671 "d %u %u %u %u %u\n",672 cCambios[i].strip,673 cCambios[i].nP,674 cCambios[i].nL1,675 cCambios[i].nL2,676 cCambios[i].obligatory);677 678 oSerializer.WriteData(simp,sizeof(char),strlen(simp));679 }680 */ // Lines starting with a b.681 606 // Data. 682 683 607 fwrite(&dataCount, sizeof(int), 1, f); 684 685 608 for(size_t i = 0; i < this->cDatos.size(); i++) 686 609 { … … 688 611 fwrite(&data, sizeof(int), 1, f); 689 612 } 690 691 sprintf(simp,"a\n");692 /* oSerializer.WriteData(simp,sizeof(char),strlen(simp));693 694 for(i = 0; i < this->cDatos.size(); i++)695 {696 sprintf(simp,"b %d\n",cDatos[i]);697 698 oSerializer.WriteData(simp,sizeof(char),strlen(simp));699 }700 */701 613 702 614 // lines starting with a p. … … 711 623 712 624 fclose(f); 713 714 /*715 // VERTICES.716 for(i = 0; i < this->cVerts.size(); i++)717 {718 sprintf(simp,"v %d\n",cVerts[i].Next);719 oSerializer.WriteData(simp,sizeof(char),strlen(simp));720 }721 722 // CSTRIPS.723 this->TOTALINDICES = 0;724 725 for(i = 0; i < this->cStrips.size(); i++)726 {727 this->TOTALINDICES += int(this->cStrips[i].size());728 }729 730 // lines starting with a d.731 // Changes732 for(i = 0; i < this->cCambios.size(); i++)733 {734 sprintf(simp,"c\n");735 oSerializer.WriteData(simp,sizeof(char),strlen(simp));736 737 sprintf(simp,738 "d %u %u %u %u %u\n",739 cCambios[i].strip,740 cCambios[i].nP,741 cCambios[i].nL1,742 cCambios[i].nL2,743 cCambios[i].obligatory);744 745 oSerializer.WriteData(simp,sizeof(char),strlen(simp));746 }747 // Lines starting with a b.748 // Data.749 sprintf(simp,"a\n");750 oSerializer.WriteData(simp,sizeof(char),strlen(simp));751 752 for(i = 0; i < this->cDatos.size(); i++)753 {754 sprintf(simp,"b %d\n",cDatos[i]);755 756 oSerializer.WriteData(simp,sizeof(char),strlen(simp));757 }758 759 // lines starting with a p.760 // Chages made in a LOD.761 for(i = 0; i < this->TOTALCAMBIOS; i++)762 {763 sprintf(simp,"p %d\n",this->pCambios[i]);764 765 oSerializer.WriteData(simp,sizeof(char),strlen(simp));766 }767 768 oSerializer.WriteData("\n",sizeof(char),1); */769 625 } 770 626 … … 815 671 for(i = 0; i < this->TOTALTIRAS; i++) 816 672 { 817 t =long(this->cStrips[i].size());673 t = long(this->cStrips[i].size()); 818 674 819 675 if (t > max) 820 { 821 max = t; 822 } 676 max = t; 823 677 } 824 678 … … 970 824 } 971 825 972 vAux.Next = -10; 973 vAux.numMesh = 0; 974 975 vAux.obligatorio = 0; 826 vAux.Next = -10; 827 vAux.numMesh = 0; 828 vAux.obligatory = 0; 976 829 977 830 this->cVerts.push_back(vAux); … … 1170 1023 { 1171 1024 assign.boneIndex = 0; 1172 assign.weight 1173 1174 for ( 1025 assign.weight = 1; 1026 1027 for (size_t m = copy_vb->mVertexCount; 1175 1028 m < mesh_vb->mVertexCount; 1176 1029 m++) 1177 1030 { 1178 1031 assign.vertexIndex = (unsigned int)m; 1179 1180 1032 mesh_bones->push_back(assign); 1181 1033 } … … 1185 1037 { 1186 1038 n = (*mesh_bones)[m].vertexIndex; 1187 1188 1039 o = 0; 1189 1040 1190 while (!( (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x) 1191 && 1192 (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y) 1193 && 1194 (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z))) 1041 while (!( (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x) && 1042 (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y) && 1043 (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z))) 1195 1044 { 1196 1045 o++; … … 1200 1049 1201 1050 while ((*copy_bones)[p].vertexIndex != o) 1202 {1203 1051 p++; 1204 }1205 1052 1206 1053 // Same bone for 'm' and 'p'. … … 1244 1091 } 1245 1092 1246 void Geometry::LodStripsConstructor::UpdateMesh(void)1093 void LodStripsConstructor::UpdateMesh(void) 1247 1094 { 1248 1095 int num_no = 0; … … 1303 1150 1304 1151 indice++; 1305 1306 1152 } 1307 1153 … … 1436 1282 } 1437 1283 } 1284 1285 //--------------------------------------------------------------------------- 1286 // Add new vertices to mesh. 1287 //--------------------------------------------------------------------------- 1288 void LodStripsConstructor::AddNewVertices() 1289 { 1290 int num_vertices; 1291 SubMesh *geosubmesh; 1292 VertexBuffer *vertex_buffer; 1293 VertexBuffer *new_vertex_buffer; 1294 1295 // Gets old vertex buffer. 1296 vertex_buffer = mGeoMesh->mVertexBuffer; 1297 1298 num_vertices = vertex_buffer->mVertexCount 1299 + 1300 mGeoMeshSQ->mNewVertices.size(); 1301 1302 // Initialize auxiliar vertex buffer. 1303 new_vertex_buffer = new VertexBuffer(); 1304 1305 new_vertex_buffer->mVertexCount = num_vertices; 1306 1307 new_vertex_buffer->mPosition = new Vector3[num_vertices]; 1308 new_vertex_buffer->mNormal = new Vector3[num_vertices]; 1309 new_vertex_buffer->mTexCoords = new Vector2[num_vertices]; 1310 1311 new_vertex_buffer->mVertexInfo = vertex_buffer->mVertexInfo; 1312 1313 // Num old vertices. 1314 num_vertices = vertex_buffer->mVertexCount; 1315 1316 // Copy the old vertex buffer. 1317 for (unsigned int i = 0; i < num_vertices; i++) 1318 { 1319 new_vertex_buffer->mPosition[i] = vertex_buffer->mPosition[i]; 1320 new_vertex_buffer->mNormal[i] = vertex_buffer->mNormal[i]; 1321 new_vertex_buffer->mTexCoords[i]= vertex_buffer->mTexCoords[i]; 1322 } 1323 1324 1325 // Copy new vertices. 1326 for (unsigned int i = 0; i < mGeoMeshSQ->mNewVertices.size(); i++) 1327 { 1328 new_vertex_buffer->mPosition[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].position; 1329 new_vertex_buffer->mTexCoords[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].texcoord; 1330 new_vertex_buffer->mNormal[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].normal; 1331 1332 // check if my twin-vertex-bone has a bone assignment 1333 // we check only the GeoMesh bones because the lodstrips only works for sharedvertex bones 1334 for (std::vector<VertexBoneAssignment>::iterator it = mGeoMesh->mBones.begin(); it != mGeoMesh->mBones.end(); it ++) 1335 { 1336 if (it->vertexIndex == mGeoMeshSQ->mNewVertices[i].bonefrom) 1337 { 1338 VertexBoneAssignment vba; 1339 vba.boneIndex = it->boneIndex; 1340 vba.vertexIndex = mGeoMeshSQ->mNewVertices[i].id; 1341 vba.weight = it->weight; 1342 mGeoMesh->mBones.push_back(vba); 1343 } 1344 } 1345 } 1346 1347 // For each submesh. 1348 for (unsigned int submesh = 0; submesh < mGeoMesh->mSubMeshCount; submesh++) 1349 { 1350 geosubmesh = &mGeoMesh->mSubMesh[submesh]; 1351 1352 geosubmesh->mVertexBuffer = new_vertex_buffer; 1353 } 1354 1355 delete vertex_buffer; 1356 1357 mGeoMesh->mVertexBuffer = new_vertex_buffer; 1358 } 1359
Note: See TracChangeset
for help on using the changeset viewer.