- Timestamp:
- 02/19/07 09:16:59 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp
r2103 r2127 158 158 mGeoMesh = m_qslim->GetMesh(); 159 159 160 // Debug.161 cout << "Number of bone assignaments: "162 << mGeoMesh->mBones.size()163 << endl;164 165 // if the initial mesh had shared vertex,166 // convert the mesh to shared vertex167 //Mesh *sharedMesh = mGeoMesh->toSharedVertex();168 //delete mGeoMesh;169 //mGeoMesh = sharedMesh;170 171 // Sort bones.172 //sortBones();173 174 160 delete m_qslim; 175 161 } … … 191 177 mGeoMesh = m_qslim->GetMesh(); 192 178 193 // if the initial mesh had shared vertex,194 // convert the mesh to shared vertex195 //Mesh *sharedMesh = mGeoMesh->toSharedVertex();196 //delete mGeoMesh;197 //mGeoMesh = sharedMesh;198 199 // Sort bones.200 //sortBones();201 202 179 delete m_qslim; 203 180 } … … 453 430 vmi_mesh->vertices[i].y = vertex_buffer->mPosition[i].y; 454 431 vmi_mesh->vertices[i].z = vertex_buffer->mPosition[i].z; 455 432 456 433 vmi_mesh->vertices[i].numTriangles = 0; 457 434 vmi_mesh->vertices[i].triangles = NULL; 435 vmi_mesh->vertices[i].numEdges = 0; 436 vmi_mesh->vertices[i].edges = NULL; 458 437 vmi_mesh->vertices[i].enable = GL_TRUE; 459 438 vmi_mesh->vertices[i].movable = GL_TRUE; … … 503 482 504 483 // Reallocate memory for the new adjacent triangle. 505 vmi_mesh->vertices[v1].triangles = ( GLuint *)realloc(vmi_mesh->vertices[v1].triangles, (vmi_mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint));484 vmi_mesh->vertices[v1].triangles = (int *)realloc(vmi_mesh->vertices[v1].triangles, (vmi_mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 506 485 507 486 VMI::addItem( (int *)vmi_mesh->vertices[v1].triangles, … … 548 527 vmi_mesh->edges[n].u = v1; 549 528 vmi_mesh->edges[n].v = v2; 550 vmi_mesh->edges[n].triangles = NULL;551 vmi_mesh->edges[n].numTriangles = 0;552 529 vmi_mesh->edges[n].enable = GL_TRUE; 553 530 554 // Reallocate memory for the new adjacent triangle555 vmi_mesh->edges[n].triangles = (GLuint *)realloc(vmi_mesh->edges[n].triangles, (vmi_mesh->edges[n].numTriangles + 1) * sizeof(GLuint));556 557 // Adding triangle i adjacent to edge n558 VMI::addItem( (int *)vmi_mesh->edges[n].triangles,559 (int *)&vmi_mesh->edges[n].numTriangles,560 i);561 562 // Adding edge n adjacent to triangle i563 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, n);564 531 n++; 565 }566 else567 {568 // Reallocate memory for the new adjacent triangle.569 vmi_mesh->edges[e].triangles = (GLuint *)realloc(vmi_mesh->edges[e].triangles, (vmi_mesh->edges[e].numTriangles + 1) * sizeof(GLuint));570 571 // Adding triangle i adjacent to edge e572 VMI::addItem( (int *)vmi_mesh->edges[e].triangles,573 (int *)&vmi_mesh->edges[e].numTriangles,574 i);575 576 // Adding edge e adjacent to triangle i577 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, e);578 532 } 579 533 … … 582 536 vmi_mesh->edges[n].u = v2; 583 537 vmi_mesh->edges[n].v = v3; 584 vmi_mesh->edges[n].triangles = NULL;585 vmi_mesh->edges[n].numTriangles = 0;586 538 vmi_mesh->edges[n].enable = GL_TRUE; 587 539 588 // Reallocate memory for the new adjacent triangle589 vmi_mesh->edges[n].triangles = (GLuint *)realloc(vmi_mesh->edges[n].triangles, (vmi_mesh->edges[n].numTriangles + 1) * sizeof(GLuint));590 591 // Adding triangle i adjacent to edge n592 VMI::addItem((int *)vmi_mesh->edges[n].triangles, (int *)&vmi_mesh->edges[n].numTriangles, i);593 vmi_mesh->edges[n].triangles = NULL;594 vmi_mesh->edges[n].numTriangles = 0;595 596 // Adding edge n adjacent to triangle i597 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, n);598 540 n++; 599 }600 else601 {602 // Reallocate memory for the new adjacent triangle603 vmi_mesh->edges[e].triangles = (GLuint *)realloc(vmi_mesh->edges[e].triangles, (vmi_mesh->edges[e].numTriangles + 1) * sizeof(GLuint));604 605 // Adding triangle i adjacent to edge e606 VMI::addItem( (int *)vmi_mesh->edges[e].triangles,607 (int *)&vmi_mesh->edges[e].numTriangles,608 i);609 610 // Adding edge e adjacent to triangle i611 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, e);612 541 } 613 542 … … 616 545 vmi_mesh->edges[n].u = v3; 617 546 vmi_mesh->edges[n].v = v1; 618 vmi_mesh->edges[n].triangles = NULL;619 vmi_mesh->edges[n].numTriangles = 0;620 547 vmi_mesh->edges[n].enable = GL_TRUE; 621 548 622 // Reallocate memory for the new adjacent triangle.623 vmi_mesh->edges[n].triangles = (GLuint *)realloc(vmi_mesh->edges[n].triangles, (vmi_mesh->edges[n].numTriangles + 1) * sizeof(GLuint));624 625 // Adding triangle i adjacent to edge n626 VMI::addItem( (int *)vmi_mesh->edges[n].triangles,627 (int *)&vmi_mesh->edges[n].numTriangles,628 i);629 630 // Adding edge n adjacent to triangle i631 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, n);632 549 n++; 633 }634 else635 {636 // Reallocate memory for the new adjacent triangle637 vmi_mesh->edges[e].triangles = (GLuint *)realloc(vmi_mesh->edges[e].triangles, (vmi_mesh->edges[e].numTriangles + 1) * sizeof(GLuint));638 639 // Adding triangle i adjacent to edge e640 VMI::addItem((int *)vmi_mesh->edges[e].triangles, (int *)&vmi_mesh->edges[e].numTriangles, i);641 642 // Adding edge e adjacent to triangle i643 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, e);644 550 } 645 551 } … … 647 553 printf("Ok\n"); 648 554 vmi_mesh->numEdges = n; 555 556 for (i=0; i<vmi_mesh->numEdges; i++) { 557 v1 = vmi_mesh->edges[i].u; 558 v2 = vmi_mesh->edges[i].v; 559 560 vmi_mesh->vertices[v1].edges = 561 (int *)realloc(vmi_mesh->vertices[v1].edges, (vmi_mesh->vertices[v1].numEdges + 1) * sizeof(int)); 562 // Adding edge i adjacent to vertex v1 563 VMI::addItem(vmi_mesh->vertices[v1].edges, &vmi_mesh->vertices[v1].numEdges, i); 564 565 vmi_mesh->vertices[v2].edges = 566 (int *)realloc(vmi_mesh->vertices[v2].edges, (vmi_mesh->vertices[v2].numEdges + 1) * sizeof(int)); 567 // Adding edge i adjacent to vertex v2 568 VMI::addItem(vmi_mesh->vertices[v2].edges, &vmi_mesh->vertices[v2].numEdges, i); 569 } 649 570 650 571 // Creates vertex multimap. … … 1133 1054 1134 1055 //------------------------------------------------------------------------- 1135 // Modify the joined vertices sequento to an split.1136 //-------------------------------------------------------------------------1137 MeshSimplificationSequence *1138 TextureConserver::WriteRealSimpSeq(MeshSimplificationSequence *simpseq)1139 {1140 bool edge_found;1141 1142 size_t v0;1143 size_t v1;1144 size_t vertex_count;1145 size_t i,j;1146 1147 VertexBuffer *mVB;1148 GeoVertex new_vertex;1149 1150 multimap<int, int>::iterator lb0;1151 multimap<int, int>::iterator ub0;1152 multimap<int, int>::iterator lb1;1153 multimap<int, int>::iterator ub1;1154 multimap<int, int>::iterator it0;1155 1156 MeshSimplificationSequence *real_seq;1157 MeshSimplificationSequence::Step current_step;1158 1159 // Initialize vertex count.1160 vertex_count = mGeoMesh->mVertexBuffer->mVertexCount;1161 1162 // Creates new simplification sequence.1163 real_seq = new MeshSimplificationSequence();1164 1165 // For each simplification step.1166 for (i = 0; i < simpseq->mSteps.size(); i++)1167 {1168 lb0 = mVertices.lower_bound(simpseq->mSteps[i].mV0);1169 ub0 = mVertices.upper_bound(simpseq->mSteps[i].mV0);1170 lb1 = mVertices.lower_bound(simpseq->mSteps[i].mV1);1171 ub1 = mVertices.upper_bound(simpseq->mSteps[i].mV1);1172 1173 // Removed vertex.1174 while (lb1 != ub1)1175 {1176 // Real index.1177 v1 = (*lb1).second;1178 1179 // Begin of iteration v0.1180 it0 = lb0;1181 1182 edge_found = false;1183 1184 // Remaining vertex.1185 while (it0 != ub0)1186 {1187 // Real index.1188 v0 = (*it0).second;1189 1190 // If edge exists.1191 if (mEdges->exists(v0,v1))1192 {1193 mEdges->contract(v1,v0);1194 1195 // Simplification sequence.1196 current_step.mV0 = v0;1197 current_step.mV1 = v1;1198 1199 real_seq->mSteps.push_back(current_step);1200 1201 edge_found = true;1202 }1203 1204 it0++;1205 }1206 1207 // If not found a valid edge.1208 if (!edge_found)1209 {1210 // Id new vertex.1211 new_vertex.id = vertex_count;1212 new_vertex.bonefrom = v0;1213 1214 // Simplification sequence.1215 current_step.mV0 = new_vertex.id;1216 current_step.mV1 = v1;1217 1218 real_seq->mSteps.push_back(current_step);1219 1220 // Contracts lonely vertex.1221 mEdges->contract(v1,new_vertex.id);1222 1223 // New vertex adquires position of v0.1224 new_vertex.position.x = mGeoMesh->mVertexBuffer->mPosition[v0].x;1225 new_vertex.position.y = mGeoMesh->mVertexBuffer->mPosition[v0].y;1226 new_vertex.position.z = mGeoMesh->mVertexBuffer->mPosition[v0].z;1227 1228 // New vertex adquires normal of lonely one.1229 new_vertex.normal.x = mGeoMesh->mVertexBuffer->mNormal[v1].x;1230 new_vertex.normal.y = mGeoMesh->mVertexBuffer->mNormal[v1].y;1231 new_vertex.normal.z = mGeoMesh->mVertexBuffer->mNormal[v1].z;1232 1233 // New vertex adquires the texture cood of the lonely one.1234 new_vertex.texcoord.x = mGeoMesh->mVertexBuffer->mTexCoords[v1].x;1235 new_vertex.texcoord.y = mGeoMesh->mVertexBuffer->mTexCoords[v1].y;1236 1237 // New vertex stored.1238 real_seq->mNewVertices.push_back(new_vertex);1239 1240 // New vertex added.1241 vertex_count++;1242 }1243 1244 lb1++;1245 }1246 }1247 1248 // Assigns new simplification sequence.1249 delete simpseq;1250 1251 return real_seq;1252 /*1253 // New vertex buffer to add new vertices.1254 mVB = new VertexBuffer();1255 1256 mVB->mPosition = new Vector3[vertex_count];1257 mVB->mNormal = new Vector3[vertex_count];1258 mVB->mTexCoords = new Vector2[vertex_count];1259 1260 mVB->mVertexInfo = mGeoMesh->mVertexBuffer->mVertexInfo;1261 1262 // Copy original vertices.1263 for (i = 0; i < mGeoMesh->mVertexBuffer->mVertexCount; i++)1264 {1265 mVB->mPosition[i].x = mGeoMesh->mVertexBuffer->mPosition[i].x;1266 mVB->mPosition[i].y = mGeoMesh->mVertexBuffer->mPosition[i].y;1267 mVB->mPosition[i].z = mGeoMesh->mVertexBuffer->mPosition[i].z;1268 1269 mVB->mNormal[i].x = mGeoMesh->mVertexBuffer->mNormal[i].x;1270 mVB->mNormal[i].y = mGeoMesh->mVertexBuffer->mNormal[i].y;1271 mVB->mNormal[i].z = mGeoMesh->mVertexBuffer->mNormal[i].z;1272 1273 mVB->mTexCoords[i].x = mGeoMesh->mVertexBuffer->mTexCoords[i].x;1274 mVB->mTexCoords[i].y = mGeoMesh->mVertexBuffer->mTexCoords[i].y;1275 }1276 1277 // Add new vertices.1278 j = mGeoMesh->mVertexBuffer->mVertexCount;1279 1280 for (i = 0; i < new_vertices.size(); i++)1281 {1282 mVB->mPosition[j].x = new_vertices[i].position.x;1283 mVB->mPosition[j].y = new_vertices[i].position.y;1284 mVB->mPosition[j].z = new_vertices[i].position.z;1285 1286 mVB->mNormal[j].x = new_vertices[i].normal.x;1287 mVB->mNormal[j].y = new_vertices[i].normal.y;1288 mVB->mNormal[j].z = new_vertices[i].normal.z;1289 1290 mVB->mTexCoords[j].x = new_vertices[i].texcoord.x;1291 mVB->mTexCoords[j].y = new_vertices[i].texcoord.y;1292 }1293 1294 // Free memory.1295 delete []mGeoMesh->mVertexBuffer;1296 1297 // Reassigns main vertex buffer with new vertices.1298 mGeoMesh->mVertexBuffer = mVB;1299 1300 // Reassign submesh vertex buffers.1301 for (i = 0; i < mGeoMesh->mSubMeshCount; i++)1302 {1303 mGeoMesh->mSubMesh[i].mVertexBuffer = mVB;1304 }1305 */1306 }1307 1308 //-------------------------------------------------------------------------1309 1056 // Return mesh that may have repeated vertices for texture aparence. 1310 1057 //-------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.