Changeset 980 for GTP/trunk/Lib/Geom/shared/GeoTool/src
- Timestamp:
- 05/24/06 10:47:49 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GeoTool/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp
r891 r980 1 /* 1 /*========================================================================== 2 2 * (C) 2005 Universitat Jaume I 3 * 3 *========================================================================== 4 4 * PROYECT: GAME TOOLS 5 * ==========================================================================*/ 6 /** CONTENT: 7 * 8 * 9 * @file GeoMeshLoader.cpp 10 /*===========================================================================*/ 5 *==========================================================================*/ 6 /* CONTENT: 7 * 8 * 9 * @file GeoMeshLoader.cpp 10 *==========================================================================*/ 11 11 12 #include "GeoMeshLoader.h" 12 13 … … 55 56 vType = static_cast<VertexElementType>(aux.type); 56 57 58 /* 57 59 if (vType == VET_FLOAT3) 58 60 { … … 69 71 printf("%u es float2 ",aux.type); 70 72 } 73 */ 71 74 72 75 // unsigned short semantic; // VertexElementSemantic … … 115 118 list.push_back(aux2); 116 119 } 117 118 // Debug.119 cout << "Finish Vertex Element" << endl;120 120 } 121 121 … … 134 134 { 135 135 case M_GEOMETRY_VERTEX_ELEMENT: 136 cout << "M_GEOMETRY_VERTEX_ELEMENT" << endl; 136 137 // Debug. 138 cout << " M_GEOMETRY_VERTEX_ELEMENT" 139 << endl; 140 137 141 readGeometryVertexElement(f, geoMesh); 142 138 143 break; 139 144 } … … 153 158 154 159 }// End if (!feof(f)) 155 } 160 }// End readGeometryVertexDeclaration. 156 161 157 162 // Read geometry vertex buffer. … … 172 177 k = 0; 173 178 encontrado = false; 174 175 179 176 180 if (option == GEOMESH_BUILD) … … 196 200 fread(&vertexSize,sizeof(unsigned short),1,f); 197 201 198 // Debug.199 cout << "Per-vertex size: "200 << vertexSize201 << endl;202 203 202 // Check for vertex data header 204 203 headerID = readChunk(f); … … 211 210 else 212 211 { 213 cout << "M_GEOMETRY_VERTEX_BUFFER_DATA" << endl; 212 // Debug. 213 cout << " M_GEOMETRY_VERTEX_BUFFER_DATA" 214 << endl; 214 215 } 215 216 … … 226 227 } 227 228 228 // Considero q los van por grupitos de vertices+normales+...229 // para cada uno de los vertices230 229 if (encontrado) 231 230 { 232 FILE * salida; 233 salida=fopen(nom_salida,"a"); 234 cout << "----->Leo los vertices" 235 << endl; 236 237 for (k=0;k<numVertices;k++) 238 { 239 //Para cada uno de los elementos de ese source. 240 for(int j=0;j<list[i].list.size();j++) 241 { 242 // Son posiciones, vertices 243 if (list[i].list[j].semantic==1) 231 for (k = 0; k < numVertices; k++) 232 { 233 // For each element in this source. 234 for(int j = 0; j < list[i].list.size(); j++) 235 { 236 // Positions. 237 if (list[i].list[j].semantic == 1) 244 238 { 245 239 fread(&x,sizeof(float),1,f); … … 255 249 } 256 250 } 257 // si no son vertices no lo quiero251 // If are not vertices. 258 252 else 259 253 { 260 //Se tendría que hacer con un fseek 261 if (list[i].list[j].type==2) //Son 3 floats 254 if (list[i].list[j].type == 2) 262 255 { 263 256 fread(&x,sizeof(float),1,f); … … 273 266 } 274 267 } 275 if (list[i].list[j].type ==1) //Son 2 floats268 if (list[i].list[j].type == 1) 276 269 { 277 270 fread(&x,sizeof(float),1,f); … … 288 281 } 289 282 } 290 fclose(salida);291 283 } 292 284 else 293 285 { 294 cout << "Error" 286 // Debug. 287 cout << "Error: Source not found." 295 288 << endl; 296 289 } … … 298 291 } 299 292 300 // Read geometry.293 // Read Geometry. 301 294 void GeoMeshLoader::readGeometry(FILE *f, Mesh *geoMesh, int option) 302 295 { … … 350 343 { 351 344 case M_GEOMETRY_VERTEX_DECLARATION: 352 cout<<"M_GEOMETRY_VERTEX_DECLARATION\n"; 345 346 // Debug. 347 cout << " M_GEOMETRY_VERTEX_DECLARATION" 348 << endl; 349 353 350 readGeometryVertexDeclaration(f, geoMesh); 351 354 352 break; 353 355 354 case M_GEOMETRY_VERTEX_BUFFER: 356 cout<<"M_GEOMETRY_VERTEX_BUFFER\n"; 355 356 // Debug. 357 cout << " M_GEOMETRY_VERTEX_BUFFER" 358 << endl; 359 357 360 readGeometryVertexBuffer(f, geoMesh,option); 361 358 362 break; 359 363 } … … 365 369 } 366 370 } 371 367 372 if (!feof(f)) 368 373 { … … 379 384 { 380 385 unsigned short opType; 386 381 387 fread(&opType,sizeof(unsigned short),1,f); 382 printf("\tLa render operation es %d\n",opType);383 388 384 389 if (option == GEOMESH_BUILD) … … 404 409 unsigned int numIndices; 405 410 bool idx32bit; 406 FILE *salida;407 411 408 412 switch (option) … … 413 417 case GEOMESH_BUILD: 414 418 415 // Debug.416 cout << "Build GEOMESH" << endl;417 418 419 // Initialize the new subMesh. 419 420 geoSubMesh = &geoMesh->mSubMesh[currentSubMesh]; 420 421 cout << "Current SubMesh: " 422 << currentSubMesh 423 << endl; 424 } 425 426 //La vacio antes de leer el mesh 421 } 422 427 423 list.clear(); 428 424 425 // Gets material name. 429 426 fgets(materialName,255,f); 430 printf("\tmaterialName: %s",materialName);431 427 432 428 fread(&useSharedVertices,sizeof(bool),1,f); … … 434 430 if (option == GEOMESH_BUILD) 435 431 { 432 // Obtain the material name. 433 strcpy(geoSubMesh->mMaterialName,materialName); 434 436 435 // Obtain the flag of vertex shared. 437 436 geoSubMesh->mSharedVertexBuffer = useSharedVertices; … … 441 440 // The VB of the submesh points to the VB of the mesh. 442 441 geoSubMesh->mVertexBuffer = geoMesh->mVertexBuffer; 443 444 cout << "\tUse Shared Vertices"445 << endl;446 447 442 } 448 443 } 449 444 450 445 fread(&numIndices,sizeof(unsigned int),1,f); 451 printf("\tnumIndices: %u\n",numIndices);452 printf("\tnumTriangles: %u\n",numIndices/3);453 446 fread(&idx32bit,sizeof(bool),1,f); 454 447 … … 462 455 } 463 456 457 /* 464 458 if (idx32bit) 465 459 { … … 470 464 printf("\tSon 16 bits por indice\n"); 471 465 } 472 473 salida = fopen(nom_salida,"a"); 474 475 fprintf(salida,"\n#----->Leo un subMesh:"); 476 477 if (useSharedVertices) 478 { 479 fprintf(salida," shared vertices"); 480 } 481 else 482 { 483 fprintf(salida, 484 " no shared vertices %d triangles", 485 numIndices/3); 486 } 487 488 fprintf(salida,"\n# Indexes:"); 489 466 */ 467 490 468 //Sumo uno a los vertices porque en el obj no puede hacer un vertice 0 491 469 if (idx32bit) … … 518 496 } 519 497 520 fclose(salida);521 522 498 // M_GEOMETRY chunk 523 499 // (Optional: present only if useSharedVertices = false) … … 528 504 if (chunkID != M_GEOMETRY) 529 505 { 530 printf("Missing geometry data in mesh file\n"); //Error 506 // Debug. 507 cout << "Error: Missing mesh geometry." 508 << endl; 531 509 } 532 510 … … 546 524 case M_SUBMESH_OPERATION: 547 525 548 cout<<"M_SUBMESH_OPERATION\n"; 526 // Debug. 527 cout << " M_SUBMESH_OPERATION" 528 << endl; 549 529 550 530 readSubMeshOperation(f, geoMesh, option); 551 531 552 532 break; 533 553 534 case M_SUBMESH_BONE_ASSIGNMENT: 554 jumpChunk(f); 535 536 // Debug. 537 //cout << " M_SUBMESH_BONE_ASSIGNMENT" 538 // << endl; 539 540 if (option == GEOMESH_BUILD) 541 { 542 readSubMeshBoneAssignment(f, geoSubMesh, option); 543 } 544 else 545 { 546 jumpChunk(f); 547 } 548 555 549 break; 556 550 } … … 564 558 if (!feof(f)) 565 559 { 566 // Backpedal back to start of chunk 560 // Backpedal back to start of chunk. 567 561 fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1); 568 562 } … … 591 585 if (chunkID != M_MESH_LOD_USAGE) 592 586 { 593 printf("Missing M_MESH_LOD_USAGE chunk\n"); //Error 594 } 595 else printf("\tM_MESH_LOD_USAGE (%d bytes) ",long_actual); 587 // Debug. 588 cout << "Error: Missing M_MESH_LOD_USAGE chunk" 589 << endl; 590 } 591 else 592 { 593 cout << " M_MESH_LOD_USAGE" 594 << endl; 595 } 596 596 597 jumpChunk(f); 597 598 … … 612 613 while (!feof(f) && (chunkID == M_SUBMESH_NAME_TABLE_ELEMENT )) 613 614 { 614 printf("M_SUBMESH_NAME_TABLE_ELEMENT %d bytes\n",long_actual); 615 // Debug. 616 cout << " M_SUBMESH_NAME_TABLE_ELEMENT" 617 << endl; 615 618 616 619 // Read in the index of the submesh. … … 619 622 // Read in the String and map it to its index. 620 623 fgets(string,255,f); 621 printf("index %u name %s\n",subMeshIndex,string); 622 623 // If we're not end of file get the next chunk ID 624 625 // If we're not end of file get the next chunk ID. 624 626 if (!feof(f)) 625 627 { … … 629 631 if (!feof(f)) 630 632 { 631 // Backpedal back to start of chunk 633 // Backpedal back to start of chunk. 632 634 fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1); 633 635 } … … 641 643 bool nada; 642 644 643 // Debug.644 cout << "Read Mesh"645 << endl;646 647 645 // Create the VertexBuffer of the mesh. 648 646 geoMesh->mVertexBuffer = new VertexBuffer(); … … 675 673 676 674 // Debug. 677 cout << "Geometry" << endl; 675 cout << " M_GEOMETRY" 676 << endl; 678 677 679 678 readGeometry(f, geoMesh, option); … … 682 681 case M_SUBMESH: 683 682 684 cout << "SubMesh" << endl; 683 // Debug. 684 cout << " M_SUBMESH" 685 << endl; 685 686 686 687 if (option == GEOMESH_BUILD) … … 696 697 case M_MESH_SKELETON_LINK: 697 698 698 cout << "M_MESH_SKELETON_LINK " 699 << long_actual 700 << " bytes\n"; 699 // Debug. 700 cout << " M_MESH_SKELETON_LINK " 701 << endl; 702 703 704 readSkeletonLink(f, geoMesh, option); 705 706 break; 707 708 case M_MESH_BONE_ASSIGNMENT: 709 710 // Debug. 711 //cout << " M_MESH_BONE_ASSIGNMENT " 712 // << endl; 713 714 //OSCAR 715 readMeshBoneAssignment(f, geoMesh, option); 716 717 break; 718 719 case M_MESH_LOD: 720 721 // Debug. 722 cout << " M_MESH_LOD" 723 << endl; 724 725 readMeshLodInfo(f, geoMesh); 726 break; 727 728 case M_MESH_BOUNDS: 729 730 // Debug. 731 cout << " M_MESH_BOUNDS " 732 << endl; 733 734 //jumpChunk(f); 735 readMeshBounds(f, geoMesh, option); 736 break; 737 738 case M_SUBMESH_NAME_TABLE: 739 740 // Debug. 741 cout << " M_SUBMESH_NAME_TABLE " 742 << endl; 743 744 readSubMeshNameTable(f, geoMesh); 745 break; 746 747 case M_EDGE_LISTS: 748 749 // Debug. 750 cout << " M_EDGE_LISTS " 751 << endl; 701 752 702 753 jumpChunk(f); 703 754 break; 704 705 case M_MESH_BONE_ASSIGNMENT:706 707 cout << "M_MESH_BONE_ASSIGNMENT "708 << long_actual709 << " bytes\n";710 711 break;712 713 case M_MESH_LOD:714 715 cout << "M_MESH_LOD\n";716 readMeshLodInfo(f, geoMesh);717 break;718 719 case M_MESH_BOUNDS:720 721 cout << "M_MESH_BOUNDS "722 << long_actual723 << " bytes\n";724 725 jumpChunk(f);726 break;727 728 case M_SUBMESH_NAME_TABLE:729 730 cout << "M_SUBMESH_NAME_TABLE "731 << long_actual732 << " bytes\n";733 734 readSubMeshNameTable(f, geoMesh);735 break;736 737 case M_EDGE_LISTS:738 739 cout << "M_EDGE_LISTS "740 << long_actual741 << " bytes\n";742 743 jumpChunk(f);744 break;745 755 } 746 756 … … 756 766 // Backpedal back to start of chunk 757 767 fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1); 758 printf("Malo\n"); 768 769 // Debug. 770 cout << "Error: Reading failure." 771 << endl; 759 772 } 760 773 } … … 974 987 char version[255]; 975 988 char kk; 976 FILE *salida;977 989 FILE *pFile; 978 990 SubMesh *geosubmesh; … … 981 993 currentSubMesh = -1; 982 994 983 std::cout << "Load a new Mesh" 984 << std::endl; 995 // Debug. 996 cout << "---------------------------------" 997 << endl 998 << "\t LOAD MESH" 999 << endl 1000 << "---------------------------------" 1001 << endl; 985 1002 986 1003 // Initialize the return value. … … 992 1009 if (!pFile) 993 1010 { 994 printf("No he encontrado el fichero\n"); 1011 // Debug. 1012 cout << "Error: File " 1013 << nameFileMesh 1014 << " not found." 1015 << endl; 1016 995 1017 exit(0); 996 1018 } … … 1004 1026 if (uno != M_HEADER) 1005 1027 { 1006 cout << "no se ha encontrado el header" 1028 // Debug. 1029 cout << "Error: Header not found." 1007 1030 << endl; 1008 1031 } … … 1015 1038 if (strcmp(version,"[MeshSerializer_v1.30]\n")) 1016 1039 { 1017 cout << 1018 "No se puede trabajar con versiones de" 1019 << 1020 " .mesh diferentes de la 1.3" 1021 << 1022 endl; 1023 } 1024 1025 salida = fopen(nom_salida,"w"); 1026 1027 fprintf(salida,"# Empiezo el fichero:"); 1028 1029 fclose(salida); 1040 // Debug. 1041 cout << "Error: Wrong mesh version." 1042 << endl 1043 << "Only version 1.3 or older allowed." 1044 << endl; 1045 } 1030 1046 1031 1047 while(!feof(pFile)) … … 1044 1060 if (option == SUBMESH_COUNT) 1045 1061 { 1046 cout << "---------------"1047 << endl;1048 1049 cout << "SubMesh Count: "1050 << geoMesh->mSubMeshCount1051 << endl;1052 1053 1062 geoMesh->mSubMesh = new SubMesh[geoMesh->mSubMeshCount]; 1054 1063 } 1055 1064 1056 if (feof(pFile))1057 {1058 cout << "------->Hemos llegado al final del fichero"1059 << endl;1060 }1061 1062 //cout << "Press enter to exit\n";1063 1064 1065 // Move the curso to the begining of the file. 1065 1066 fseek(pFile,0,SEEK_SET); … … 1087 1088 } 1088 1089 1090 // Sets coods between -1 and 1. 1091 normalizeModel(geoMesh); 1092 1089 1093 return geoMesh; 1094 } 1095 1096 // Sets coords between -1 and 1. 1097 void GeoMeshLoader::normalizeModel(Mesh *geoMesh) 1098 { 1099 unsigned int i; 1100 float maxx, minx, maxy, miny, maxz, minz; 1101 float cx, cy, cz, w, h, d, max; 1102 float scale; 1103 VertexBuffer *vertex_buffer; 1104 1105 // Gets vertex buffer. 1106 vertex_buffer = geoMesh->mSubMesh[0].mVertexBuffer; 1107 1108 // Get the max/mins. 1109 maxx = minx = vertex_buffer->mPosition[0].x; 1110 maxy = miny = vertex_buffer->mPosition[0].y; 1111 maxz = minz = vertex_buffer->mPosition[0].z; 1112 1113 // For each submesh. 1114 for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 1115 { 1116 // Gets the actual submesh. 1117 vertex_buffer = geoMesh->mSubMesh[submesh].mVertexBuffer; 1118 1119 // For each index of the strip. 1120 for (int i = 0; i < vertex_buffer->mVertexCount; i++) 1121 { 1122 if (maxx < vertex_buffer->mPosition[i].x) 1123 { 1124 maxx = vertex_buffer->mPosition[i].x; 1125 } 1126 1127 if (minx > vertex_buffer->mPosition[i].x) 1128 { 1129 minx = vertex_buffer->mPosition[i].x; 1130 } 1131 1132 if (maxy < vertex_buffer->mPosition[i].y) 1133 { 1134 maxy = vertex_buffer->mPosition[i].y; 1135 } 1136 1137 if (miny > vertex_buffer->mPosition[i].y) 1138 { 1139 miny = vertex_buffer->mPosition[i].y; 1140 } 1141 1142 if (maxz < vertex_buffer->mPosition[i].z) 1143 { 1144 maxz = vertex_buffer->mPosition[i].z; 1145 } 1146 1147 if (minz > vertex_buffer->mPosition[i].z) 1148 { 1149 minz = vertex_buffer->mPosition[i].z; 1150 } 1151 } 1152 1153 // If is a shared vertex Buffer. 1154 if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer) 1155 { 1156 break; 1157 } 1158 } 1159 1160 // Calculate model width, height, and depth. 1161 w = fabs(maxx) + fabs(minx); 1162 h = fabs(maxy) + fabs(miny); 1163 d = fabs(maxz) + fabs(minz); 1164 1165 // Calculate center of the model. 1166 cx = (maxx + minx) / 2.0; 1167 cy = (maxy + miny) / 2.0; 1168 cz = (maxz + minz) / 2.0; 1169 1170 1171 // Calculate max dimension. 1172 if (w > h) 1173 { 1174 max = w; 1175 } 1176 else 1177 { 1178 max = h; 1179 } 1180 1181 if (d > max) 1182 { 1183 max = d; 1184 } 1185 1186 // Calculate unitizing scale factor. 1187 scale = 1.0 / max; 1188 1189 geoMesh->mMeshBounds.scaleFactor = scale; 1190 1191 // Translate around center then scale. 1192 // For each submesh. 1193 for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 1194 { 1195 // Gets the actual submesh. 1196 vertex_buffer = geoMesh->mSubMesh[submesh].mVertexBuffer; 1197 1198 // For each index of the strip. 1199 for (int i = 0; i < vertex_buffer->mVertexCount; i++) 1200 { 1201 vertex_buffer->mPosition[i].x -= cx; 1202 vertex_buffer->mPosition[i].y -= cy; 1203 vertex_buffer->mPosition[i].z -= cz; 1204 vertex_buffer->mPosition[i].x *= scale; 1205 vertex_buffer->mPosition[i].y *= scale; 1206 vertex_buffer->mPosition[i].z *= scale; 1207 } 1208 1209 // If is a shared vertex Buffer. 1210 if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer) 1211 { 1212 break; 1213 } 1214 } 1215 1090 1216 } 1091 1217 … … 1099 1225 GeoMeshLoader::GeoMeshLoader() 1100 1226 { 1101 nom_salida = "salida22.obj";1102 1227 geoMesh = NULL; 1103 1228 mFileSize = 0; … … 1110 1235 } 1111 1236 1237 //OSCAR 1238 void GeoMeshLoader::readSubMeshBoneAssignment(FILE* f, SubMesh* geoSubMesh,int option) 1239 { 1240 if (option == GEOMESH_BUILD) 1241 { 1242 VertexBoneAssignment assign; 1243 1244 // unsigned int vertexIndex; 1245 fread(&(assign.vertexIndex),sizeof(unsigned int),1,f); 1246 // unsigned short boneIndex; 1247 fread(&(assign.boneIndex),sizeof(unsigned short),1,f); 1248 // float weight 1249 fread(&(assign.weight),sizeof(float),1,f); 1250 1251 geoSubMesh->mBones.push_back(assign); 1252 } 1253 } 1254 1255 //OSCAR 1256 void GeoMeshLoader::readMeshBoneAssignment(FILE* f, Mesh* geoMesh,int option) 1257 { 1258 if (option == GEOMESH_BUILD) 1259 { 1260 VertexBoneAssignment assign; 1261 1262 // unsigned int vertexIndex; 1263 fread(&(assign.vertexIndex),sizeof(unsigned int),1,f); 1264 // unsigned short boneIndex; 1265 fread(&(assign.boneIndex),sizeof(unsigned short),1,f); 1266 // float weight 1267 fread(&(assign.weight),sizeof(float),1,f); 1268 1269 1270 geoMesh->mBones.push_back(assign); 1271 } 1272 } 1273 1274 //OSCAR 1275 void GeoMeshLoader::readSkeletonLink(FILE* f, Mesh* geoMesh,int option) 1276 { 1277 if (option == GEOMESH_BUILD) 1278 { 1279 fgets(geoMesh->mSkeletonName,255,f); 1280 1281 geoMesh->hasSkeleton = true; 1282 1283 // Debug. 1284 cout << "Skeleton Name: " 1285 << geoMesh->mSkeletonName 1286 << endl; 1287 } 1288 } 1289 1290 // Read bounding box settings. 1291 void GeoMeshLoader::readMeshBounds(FILE *f, Mesh *geoMesh, int option) 1292 { 1293 if (option == GEOMESH_BUILD) 1294 { 1295 fread(&(geoMesh->mMeshBounds.minX),sizeof(float),1,f); 1296 fread(&(geoMesh->mMeshBounds.minY),sizeof(float),1,f); 1297 fread(&(geoMesh->mMeshBounds.minZ),sizeof(float),1,f); 1298 fread(&(geoMesh->mMeshBounds.maxX),sizeof(float),1,f); 1299 fread(&(geoMesh->mMeshBounds.maxY),sizeof(float),1,f); 1300 fread(&(geoMesh->mMeshBounds.maxZ),sizeof(float),1,f); 1301 fread(&(geoMesh->mMeshBounds.radius),sizeof(float),1,f); 1302 } 1303 } 1304 -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshSaver.cpp
r891 r980 23 23 GeoMeshSaver::GeoMeshSaver() 24 24 { 25 mMaterialName = "";26 mSkeletallyAnimated = false;27 28 // Initializa the mesh bounds.29 mMeshBounds.minx = 0.0;30 mMeshBounds.miny = 0.0;31 mMeshBounds.minz = 0.0;32 mMeshBounds.maxx = 0.0;33 mMeshBounds.maxy = 0.0;34 mMeshBounds.maxz = 0.0;35 mMeshBounds.radius = 0.0;36 }37 38 GeoMeshSaver::GeoMeshSaver(GeometryBounds bounds)39 {40 mMaterialName = "";41 mSkeletallyAnimated = false;42 43 // Initializa the mesh bounds.44 mMeshBounds.minx = bounds.minx;45 mMeshBounds.miny = bounds.miny;46 mMeshBounds.minz = bounds.minz;47 mMeshBounds.maxx = bounds.maxx;48 mMeshBounds.maxy = bounds.maxy;49 mMeshBounds.maxz = bounds.maxz;50 mMeshBounds.radius = bounds.radius;51 25 } 52 26 … … 56 30 GeoMeshSaver::~GeoMeshSaver() 57 31 { 32 delete mGeoMesh; 58 33 } 59 34 … … 63 38 int size; 64 39 String name(fileNameMesh); 65 40 41 mGeoMesh = new Mesh(); 42 43 // Set the mesh. 44 *mGeoMesh = *geoMesh; 45 46 // Debug. 47 cout << endl 48 << endl 49 << "-----------------------------------" 50 << endl 51 << "\t SAVE MESH" 52 << endl 53 << "-----------------------------------" 54 << endl 55 << endl; 56 57 // Unnormalize geometry model. 58 unnormalizeModel(mGeoMesh); 59 66 60 // Open the file. 67 61 mSerializer = new Serializer( name, 68 62 Serializer::WRITE); 69 63 70 // Set the mesh.71 mGeoMesh = geoMesh;72 64 73 65 // Write the file header. … … 75 67 76 68 // Write the mesh data. 77 writeMesh(geoMesh); 78 79 // Debug. 80 cout << "Write mesh finish" 81 << endl; 82 69 writeMesh(mGeoMesh); 70 83 71 size = mSerializer->GetSize(); 84 72 … … 97 85 void GeoMeshSaver::writeMesh(Mesh *geoMesh) 98 86 { 99 // Debug.100 cout << "Write the chunk header"101 << endl;102 103 87 // Header 104 88 writeChunkHeader(M_MESH, calcMeshSize(geoMesh)); 105 89 90 // Debug. 91 cout << " M_MESH" 92 << endl; 93 106 94 // Write the skeletally animated flag. 107 writeBools(mSkeletallyAnimated,1); 108 109 cout << "1 - VertexCount: " 110 << geoMesh->mVertexBuffer->mVertexCount 111 << endl; 112 95 writeBools(geoMesh->hasSkeleton,1); 96 113 97 // Write shared geometry. 114 98 if (geoMesh->mVertexBuffer->mVertexCount > 0) 115 99 { 116 // Debug.117 cout << "Write the shared vertex buffer"118 << endl;119 120 100 writeGeometry(geoMesh->mVertexBuffer); 121 101 } … … 124 104 for (int i = 0; i < geoMesh->mSubMeshCount; i++) 125 105 { 126 // Debug.127 cout << "Write the submesh "128 << i129 << endl;130 131 106 writeSubMesh(&geoMesh->mSubMesh[i]); 132 107 } 133 108 109 //OSCAR 110 // Write skeleton info if required 111 if (geoMesh->hasSkeleton) 112 { 113 // Write skeleton link 114 writeSkeletonLink(geoMesh->mSkeletonName); 115 116 // Write bone assignments 117 if (!geoMesh->mBones.empty()) 118 { 119 120 for (int i=0; i< geoMesh->mBones.size(); i++) 121 { 122 writeMeshBoneAssignment(geoMesh->mBones[i]); 123 } 124 125 } 126 } 127 134 128 // Write the mesh bounds. 135 writeMeshBounds( mMeshBounds);136 129 writeMeshBounds(geoMesh); 130 137 131 /* 138 // Write skeleton info if required139 if (pMesh->hasSkeleton())140 {141 LogManager::getSingleton().logMessage("Exporting skeleton link...");142 // Write skeleton link143 writeSkeletonLink(pMesh->getSkeletonName());144 LogManager::getSingleton().logMessage("Skeleton link exported.");145 146 // Write bone assignments147 if (!pMesh->mBoneAssignments.empty())148 {149 LogManager::getSingleton().logMessage("Exporting shared geometry bone assignments...");150 151 Mesh::VertexBoneAssignmentList::const_iterator vi;152 for (vi = pMesh->mBoneAssignments.begin();153 vi != pMesh->mBoneAssignments.end(); ++vi)154 {155 writeMeshBoneAssignment(vi->second);156 }157 158 LogManager::getSingleton().logMessage("Shared geometry bone assignments exported.");159 }160 }161 162 132 // Write LOD data if any 163 133 if (pMesh->getNumLodLevels() > 1) … … 186 156 } 187 157 */ 188 } 158 }// End write mesh. 189 159 190 160 // Write a submesh. … … 193 163 bool idx32bit; 194 164 unsigned long indexCount; 195 String materialName;196 165 Index *index; 197 166 Index *indexBegin; 198 167 Index *indexEnd; 199 168 200 // Debug.201 cout << "Write the submesh chunk header"202 << endl;203 204 169 // Header. 205 170 writeChunkHeader(M_SUBMESH, calcSubMeshSize(geoSubMesh)); 206 171 207 172 // Debug. 208 cout << " Write the material name"173 cout << " M_SUBMESH" 209 174 << endl; 210 175 211 176 // Material Name. 212 materialName = getMaterialName(); 213 writeString(materialName); 214 215 // Debug. 216 cout << "Write the shared vertex buffer flag: " 217 << endl; 177 mSerializer->WriteData(geoSubMesh->mMaterialName); 218 178 219 179 // bool useSharedVertices … … 228 188 } 229 189 190 // Write index count. 230 191 writeInts(indexCount, 1); 231 192 … … 234 195 writeBools(idx32bit, 1); 235 196 236 // Debug.237 cout << "Write the mIndex array"238 << endl;239 240 197 // If the submesh is in triangle strips. 241 198 if (geoSubMesh->mType == GEO_TRIANGLE_STRIPS) 242 199 { 243 // Debug.244 cout << "Write triangle strips"245 << endl;246 247 200 // For each one of the strips. 248 201 for (int strip = 0; strip < geoSubMesh->mStripCount; strip++) … … 300 253 if (!geoSubMesh->mSharedVertexBuffer) 301 254 { 302 // Debug.303 cout << "Write the geometry of the submesh"304 << endl;305 306 255 writeGeometry(geoSubMesh->mVertexBuffer); 307 256 } 308 309 // Debug.310 cout << "mIndex array written"311 << endl;312 257 313 258 // Operation type 314 259 writeSubMeshOperation(geoSubMesh); 315 260 316 //TODO:Bones.317 /*318 261 // Bone assignments 319 if (!s->mBoneAssignments.empty()) 320 { 321 LogManager::getSingleton().logMessage("Exporting dedicated geometry bone assignments..."); 322 323 SubMesh::VertexBoneAssignmentList::const_iterator vi; 324 325 for (vi = s->mBoneAssignments.begin(); 326 vi != s->mBoneAssignments.end(); ++vi) 262 if (!geoSubMesh->mBones.empty()) 263 { 264 for (int i = 0; i < geoSubMesh->mBones.size(); i++) 327 265 { 328 writeSubMeshBoneAssignment( vi->second);266 writeSubMeshBoneAssignment(geoSubMesh->mBones[i]); 329 267 } 330 331 LogManager::getSingleton().logMessage("Dedicated geometry bone assignments exported."); 332 } 333 */ 268 } 334 269 } 335 270 … … 340 275 unsigned long size; 341 276 342 // Debug.343 cout << "Write submesh operation"344 << endl;345 346 277 size = CHUNK_OVERHEAD_SIZE + sizeof(unsigned short); 347 278 … … 349 280 writeChunkHeader(M_SUBMESH_OPERATION, size); 350 281 282 // Debug. 283 cout << " M_SUBMESH_OPERATION" 284 << endl; 285 351 286 // If the mesh is in triangle strips. 352 287 if (geoSubMesh->mType == GEO_TRIANGLE_STRIPS) … … 361 296 362 297 writeShorts(opType, 1); 363 364 // Debug.365 cout << "Submesh operation Written"366 << endl;367 298 } 368 299 … … 385 316 writeChunkHeader(M_GEOMETRY, size); 386 317 318 // Debug. 319 cout << " M_GEOMETRY" 320 << endl; 321 387 322 writeInts(vertexBuffer->mVertexCount,1); 388 323 … … 398 333 writeChunkHeader( M_GEOMETRY_VERTEX_DECLARATION,size); 399 334 335 // Debug. 336 cout << " M_GEOMETRY_VERTEX_DECLARATION" 337 << endl; 338 400 339 // Obtain the size of the vertex element chunk. 401 340 size = CHUNK_OVERHEAD_SIZE + (sizeof(unsigned short) * 5); … … 405 344 writeChunkHeader( M_GEOMETRY_VERTEX_ELEMENT,size); 406 345 346 // Debug. 347 cout << " M_GEOMETRY_VERTEX_ELEMENT" 348 << endl; 349 407 350 element = 0; 408 351 writeShorts(element,1); … … 424 367 writeChunkHeader( M_GEOMETRY_VERTEX_ELEMENT,size); 425 368 369 // Debug. 370 cout << " M_GEOMETRY_VERTEX_ELEMENT" 371 << endl; 372 426 373 element = 1; 427 374 writeShorts(element,1); … … 443 390 writeChunkHeader(M_GEOMETRY_VERTEX_ELEMENT,size); 444 391 392 // Debug. 393 cout << " M_GEOMETRY_VERTEX_ELEMENT" 394 << endl; 395 445 396 element = 2; 446 397 writeShorts(element,1); … … 463 414 // Write the vertex buffer header for positions. 464 415 writeChunkHeader(M_GEOMETRY_VERTEX_BUFFER, size); 416 417 // Debug. 418 cout << " M_GEOMETRY_VERTEX_BUFFER" 419 << endl; 465 420 466 421 element = 0; … … 478 433 writeChunkHeader(M_GEOMETRY_VERTEX_BUFFER_DATA, size); 479 434 435 // Debug. 436 cout << " M_GEOMETRY_VERTEX_BUFFER_DATA" 437 << endl; 438 480 439 // Write all the positions coords. 481 440 mSerializer->WriteArray(vertexBuffer->mPosition, … … 487 446 // Write the vertex buffer header. 488 447 writeChunkHeader( M_GEOMETRY_VERTEX_BUFFER, size); 448 449 // Debug. 450 cout << " M_GEOMETRY_VERTEX_BUFFER" 451 << endl; 489 452 490 453 element = 1; … … 502 465 writeChunkHeader(M_GEOMETRY_VERTEX_BUFFER_DATA, size); 503 466 467 // Debug. 468 cout << " M_GEOMETRY_VERTEX_BUFFER_DATA" 469 << endl; 470 504 471 // Write all the normals coords. 505 472 mSerializer->WriteArray(vertexBuffer->mNormal, … … 511 478 // Write the vertex buffer header for textures. 512 479 writeChunkHeader(M_GEOMETRY_VERTEX_BUFFER, size); 480 481 // Debug. 482 cout << " M_GEOMETRY_VERTEX_BUFFER" 483 << endl; 513 484 514 485 element = 2; … … 527 498 528 499 // Debug. 529 cout << "-7-" << endl; 500 cout << " M_GEOMETRY_VERTEX_BUFFER_DATA" 501 << endl; 530 502 531 503 // Write all the texture coords. 532 504 mSerializer->WriteArray(vertexBuffer->mTexCoords, 533 505 vertexBuffer->mVertexCount); 534 535 // Debug. 536 cout << "-8-" << endl; 537 538 } 539 540 // TODO: Write Mesh Bounds. 541 void GeoMeshSaver::writeMeshBounds(GeometryBounds bounds) 506 } 507 508 // Write Mesh Bounds. 509 void GeoMeshSaver::writeMeshBounds(Mesh *geoMesh) 542 510 { 543 511 size_t size; … … 549 517 writeChunkHeader(M_MESH_BOUNDS, size); 550 518 551 writeFloats(bounds.minx,1); 552 writeFloats(bounds.miny,1); 553 writeFloats(bounds.minz,1); 554 writeFloats(bounds.maxx,1); 555 writeFloats(bounds.maxy,1); 556 writeFloats(bounds.maxz,1); 557 writeFloats(bounds.radius,1); 519 // Debug. 520 cout << " M_MESH_BOUNDS" 521 << endl; 522 523 writeFloats(geoMesh->mMeshBounds.minX,1); 524 writeFloats(geoMesh->mMeshBounds.minY,1); 525 writeFloats(geoMesh->mMeshBounds.minZ,1); 526 writeFloats(geoMesh->mMeshBounds.maxX,1); 527 writeFloats(geoMesh->mMeshBounds.maxY,1); 528 writeFloats(geoMesh->mMeshBounds.maxZ,1); 529 writeFloats(geoMesh->mMeshBounds.radius,1); 558 530 } 559 531 … … 563 535 size_t size = CHUNK_OVERHEAD_SIZE; 564 536 565 // Debug.566 cout << "Calc the size of the mesh"567 << endl;568 569 537 // Num shared vertices 570 538 size += sizeof(uint32); 571 539 572 // Debug.573 cout << "VertexCount: "574 << geoMesh->mVertexBuffer->mVertexCount575 << endl;576 577 540 // Geometry 578 541 if (geoMesh->mVertexBuffer->mVertexCount > 0) 579 542 { 580 // Debug.581 cout << "Calc the size of the shared vertex buffer"582 << endl;583 584 543 size += calcGeometrySize(geoMesh->mVertexBuffer); 585 544 } … … 588 547 for (unsigned short i = 0; i < geoMesh->mSubMeshCount; ++i) 589 548 { 590 // Debug.591 cout << "Calc the size of the submesh "592 << i593 << endl;594 595 549 size += calcSubMeshSize(&geoMesh->mSubMesh[i]); 596 550 } … … 601 555 (sizeof(float) * 7); 602 556 603 /*604 557 // Skeleton link 605 if (geoMesh->hasSkeleton()) 606 { 607 size += calcSkeletonLinkSize(geoMesh->getSkeletonName()); 608 } 609 */ 558 if (geoMesh->hasSkeleton) 559 { 560 size += calcSkeletonLinkSize(geoMesh); 561 } 610 562 611 563 /* … … 629 581 630 582 // Material name 631 size += getMaterialName().length() + 1;583 size += strlen(geoSubMesh->mMaterialName); 632 584 633 585 // bool useSharedVertices … … 682 634 } 683 635 636 // Calculate the skeleton link size in bytes. 637 size_t GeoMeshSaver::calcSkeletonLinkSize(const Mesh *geoMesh) 638 { 639 size_t size = CHUNK_OVERHEAD_SIZE; 640 size += strlen(geoMesh->mSkeletonName); 641 642 // Debug. 643 cout << "Length Skeleton Link: " 644 << strlen(geoMesh->mSkeletonName) 645 << endl; 646 647 return size; 648 } 649 684 650 // Write the file header. 685 651 void GeoMeshSaver::writeFileHeader(void) 686 652 { 687 String mesh_version("[MeshSerializer_v1.30] ");653 String mesh_version("[MeshSerializer_v1.30]\n"); 688 654 689 655 writeShorts(M_HEADER, 1); … … 735 701 } 736 702 737 // Sets the material of the mesh. 738 void GeoMeshSaver::setMaterialName(String materialName) 739 { 740 mMaterialName = materialName; 741 } 742 743 // Gets the material of the mesh. 744 String GeoMeshSaver::getMaterialName() 745 { 746 return mMaterialName; 747 } 748 749 // Set Mesh Bounds. 750 void GeoMeshSaver::setMeshBounds(GeometryBounds bounds) 751 { 752 mMeshBounds.minx = bounds.minx; 753 mMeshBounds.miny = bounds.miny; 754 mMeshBounds.minz = bounds.minz; 755 mMeshBounds.maxx = bounds.maxx; 756 mMeshBounds.maxy = bounds.maxy; 757 mMeshBounds.maxz = bounds.maxz; 758 mMeshBounds.radius = bounds.radius; 759 } 760 703 void GeoMeshSaver::writeSkeletonLink(const String& skelName) 704 { 705 writeChunkHeader(M_MESH_SKELETON_LINK, calcSkeletonLinkSize(mGeoMesh)); 706 707 // Debug. 708 cout << " M_MESH_SKELETON_LINK" 709 << endl; 710 711 writeString(skelName); 712 } 713 714 void GeoMeshSaver::writeMeshBoneAssignment(const VertexBoneAssignment& assign) 715 { 716 size_t size = CHUNK_OVERHEAD_SIZE + sizeof(unsigned int) + sizeof(unsigned short)+ sizeof(float); 717 718 writeChunkHeader(M_MESH_BONE_ASSIGNMENT, size); 719 720 // unsigned int vertexIndex; 721 writeInts(assign.vertexIndex, 1); 722 // unsigned short boneIndex; 723 writeShorts(assign.boneIndex, 1); 724 // float weight; 725 writeFloats(assign.weight, 1); 726 } 727 728 void GeoMeshSaver::writeSubMeshBoneAssignment(const VertexBoneAssignment& assign) 729 { 730 size_t size = CHUNK_OVERHEAD_SIZE + sizeof(unsigned int) + sizeof(unsigned short)+ sizeof(float); 731 732 writeChunkHeader(M_SUBMESH_BONE_ASSIGNMENT, size); 733 734 // unsigned int vertexIndex; 735 writeInts(assign.vertexIndex, 1); 736 // unsigned short boneIndex; 737 writeShorts(assign.boneIndex, 1); 738 // float weight; 739 writeFloats(assign.weight, 1); 740 } 741 742 // unnormalize geometry model. 743 void GeoMeshSaver::unnormalizeModel(Mesh *geoMesh) 744 { 745 float maxx; 746 float maxy; 747 float maxz; 748 float minx; 749 float miny; 750 float minz; 751 float cx; 752 float cy; 753 float cz; 754 float scale; 755 756 VertexBuffer *vertex_buffer; 757 758 maxx = geoMesh->mMeshBounds.maxX; 759 maxy = geoMesh->mMeshBounds.maxY; 760 maxz = geoMesh->mMeshBounds.maxZ; 761 minx = geoMesh->mMeshBounds.minX; 762 miny = geoMesh->mMeshBounds.minY; 763 minz = geoMesh->mMeshBounds.minZ; 764 scale = geoMesh->mMeshBounds.scaleFactor; 765 766 // Calculate center of the model. 767 cx = (maxx + minx) / 2.0; 768 cy = (maxy + miny) / 2.0; 769 cz = (maxz + minz) / 2.0; 770 771 // Translate around center then scale. 772 // For each submesh. 773 for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 774 { 775 // Gets the actual submesh. 776 vertex_buffer = geoMesh->mSubMesh[submesh].mVertexBuffer; 777 778 // For each index of the strip. 779 for (int i = 0; i < vertex_buffer->mVertexCount; i++) 780 { 781 vertex_buffer->mPosition[i].x /= scale; 782 vertex_buffer->mPosition[i].y /= scale; 783 vertex_buffer->mPosition[i].z /= scale; 784 vertex_buffer->mPosition[i].x += cx; 785 vertex_buffer->mPosition[i].y += cy; 786 vertex_buffer->mPosition[i].z += cz; 787 } 788 789 // If is a shared vertex Buffer. 790 if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer) 791 { 792 break; 793 } 794 } 795 } 796 -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
r895 r980 200 200 // Set the color to the submesh sumbmeshIndex 201 201 //--------------------------------------------------------------------------- 202 void GeoMeshView::set ColorSubmeshi(int submeshIndex)203 { 204 colorsubmeshi= submeshIndex;202 void GeoMeshView::setSubMeshSelected(int submeshIndex) 203 { 204 mSubMeshSelected = submeshIndex; 205 205 } 206 206 … … 208 208 // Sets the leaves submesh index. 209 209 //--------------------------------------------------------------------------- 210 void GeoMeshView::setLeavesSub mesh(int submeshIndex)211 { 212 leavesSub mesh = submeshIndex;210 void GeoMeshView::setLeavesSubMesh(int submeshIndex) 211 { 212 leavesSubMesh = submeshIndex; 213 213 } 214 214 … … 216 216 // Gets the leaves submesh index. 217 217 //--------------------------------------------------------------------------- 218 int GeoMeshView::getLeavesSub mesh()219 { 220 return leavesSub mesh;218 int GeoMeshView::getLeavesSubMesh() 219 { 220 return leavesSubMesh; 221 221 } 222 222 … … 277 277 } 278 278 279 /* 279 280 //--------------------------------------------------------------------------- 280 281 // Get the bounding box of the object. … … 386 387 return bounds; 387 388 } 389 */ 388 390 389 391 //--------------------------------------------------------------------------- … … 446 448 GLfloat color_blanco[] = {1.0f,1.0f,1.0f,1.0f}; 447 449 448 this->geoMesh = geomesh; 449 colorsubmeshi = -1; 450 leavesSubmesh = -1; 450 this->geoMesh = geomesh; 451 mSubMeshSelected = -1; 452 leavesSubMesh = -1; 453 mScaleFactor = geomesh->mMeshBounds.scaleFactor; 451 454 452 455 // Refresh vertices to the vertex array. … … 577 580 // Repaint the Mesh. 578 581 //--------------------------------------------------------------------------- 579 void GeoMeshView::drawGeoMesh( int selectedMesh)582 void GeoMeshView::drawGeoMesh(bool paintWire) 580 583 { 581 584 SubMesh *geosubmesh; … … 601 604 if (geosubmesh->mType == GEO_TRIANGLE_LIST) 602 605 { 603 if ( selectedMesh== submesh)606 if (mSubMeshSelected == submesh) 604 607 { 605 608 submesh_selected = true; … … 611 614 612 615 // Draw the actual submesh in triangle list. 613 drawTriangleList(submesh,submesh_selected );616 drawTriangleList(submesh,submesh_selected,paintWire); 614 617 } 615 618 else … … 618 621 drawTriangleStrip(submesh); 619 622 } 620 } 621 } 622 /* 623 // Choose the render operation. 624 else if (geoMesh->mType == GEO_TRIANGLE_LIST) 625 { 626 // Paint vertices. 627 drawTriangleList(selectedMesh); 628 } 629 else 630 { 631 // Paint vertices. 632 drawTriangleStrip(); 633 } 634 */ 623 } 624 } 635 625 } 636 626 }// End drawGeoMesh. … … 743 733 //--------------------------------------------------------------------------- 744 734 void GeoMeshView::drawTriangleList( int submesh, 745 bool selectedSubMesh) 735 bool selectedSubMesh, 736 bool paintWire) 746 737 { 747 738 SubMesh *geosubmesh; … … 761 752 geosubmesh = &geoMesh->mSubMesh[submesh]; 762 753 763 // If a mesh is selected. 764 if (selectedSubMesh) 765 { 766 glColor3d(1.0,0.0,0.0); 767 GLfloat red[] = {1.0f,0.0f,0.0f,1.0f}; 768 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,red); 769 } 770 // If is a tree. 771 else if (leavesSubmesh >= 0) 772 { 773 glColor3d(1.0, 0.5, 0.5); 774 GLfloat brown[] = {1.0f,0.5f,0.5f,1.0f}; 775 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,brown); 776 777 // For each index of the strip. 778 if (submesh == leavesSubmesh) 779 { 780 glColor3d(0.0,1.0,0.0); 781 GLfloat green[] = {0.0f,1.0f,0.0f,1.0f}; 782 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,green); 783 } 784 } 785 // If is NOT a tree. 786 else 787 { 788 // Set white color to the object. 789 glColor3d(1.0, 1.0, 1.0); 790 GLfloat white[] = {1.0f,1.0f,1.0f,1.0f}; 791 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,white); 792 } 793 794 754 // If wire is not selected. 755 if (!paintWire) 756 { 757 // If a mesh is selected. 758 if (selectedSubMesh) 759 { 760 glColor3d(1.0,0.0,0.0); 761 GLfloat red[] = {1.0f,0.0f,0.0f,1.0f}; 762 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,red); 763 } 764 // If is a tree. 765 else if (leavesSubMesh >= 0) 766 { 767 glColor3d(1.0, 0.5, 0.5); 768 GLfloat brown[] = {1.0f,0.5f,0.5f,1.0f}; 769 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,brown); 770 771 // For each index of the strip. 772 if (submesh == leavesSubMesh) 773 { 774 glColor3d(0.0,1.0,0.0); 775 GLfloat green[] = {0.0f,1.0f,0.0f,1.0f}; 776 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,green); 777 } 778 } 779 // If is NOT a tree. 780 else 781 { 782 // Set white color to the object. 783 glColor3d(1.0, 1.0, 1.0); 784 GLfloat white[] = {1.0f,1.0f,1.0f,1.0f}; 785 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,white); 786 } 787 } 788 795 789 // Enable arrays. 796 790 glEnableClientState(GL_VERTEX_ARRAY); … … 1056 1050 // Frustrum. 1057 1051 glViewport(0,0,w(),h()); 1058 gluPerspective(60, 1,0.1,1000);1052 gluPerspective(60,(float)w()/(float)h(),0.1,1000); 1059 1053 1060 1054 glMatrixMode(GL_MODELVIEW); … … 1082 1076 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1083 1077 1084 gluLookAt(0,0, mScaleFactor*2+size, 0,0,0, 0,1,0);1078 gluLookAt(0,0,2/*mScaleFactor*/ + size * 0.25, 0,0,0, 0,1,0); 1085 1079 1086 1080 glTranslatef(xshift,yshift,0); 1087 1081 glRotatef(hAng,0,1,0); 1088 1082 glRotatef(vAng,1,0,0); 1089 glTranslatef(-xMed,-yMed,-zMed);1083 //glTranslatef(-xMed,-yMed,-zMed); 1090 1084 1091 1085 // Set white color to the object. … … 1094 1088 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color_blanco); 1095 1089 1090 glClearColor(0,0,0,0); 1091 1096 1092 if (mCW) 1097 1093 { … … 1117 1113 glDisable(GL_LIGHTING); 1118 1114 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 1119 drawGeoMesh( colorsubmeshi);1115 drawGeoMesh(false); 1120 1116 } 1121 1117 else … … 1130 1126 glColor3d(0.0, 0.0, 1.0); 1131 1127 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 1132 drawGeoMesh( -1);1128 drawGeoMesh(true); 1133 1129 } 1134 1130 else … … 1139 1135 glEnable(GL_LIGHTING); 1140 1136 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 1141 drawGeoMesh( colorsubmeshi);1137 drawGeoMesh(false); 1142 1138 } 1143 1139 } -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
r895 r980 63 63 { 64 64 // Create a mesh saver with mesh bounds. 65 mesh_saver = new GeoMeshSaver( mMeshBounds);65 mesh_saver = new GeoMeshSaver(); 66 66 67 67 // Save the file mesh. … … 99 99 if (fcho->value()) 100 100 { 101 mesh_saver = new GeoMeshSaver( mMeshBounds);101 mesh_saver = new GeoMeshSaver(); 102 102 mesh_saver->save(mGeoMesh,filename_name(fcho->value())); 103 103 delete mesh_saver; … … 953 953 // Simplify the mesh object. 954 954 simplifyEdgeCollapse(); 955 956 delete mMeshSimplifier; 957 geoMeshView->restoreContext(); 955 958 } 956 959 break; … … 1043 1046 // Create the qslim simplification sequence. 1044 1047 createQslimSequence(); 1048 1049 delete mMeshSimplifier; 1050 geoMeshView->restoreContext(); 1045 1051 } 1046 1052 … … 1053 1059 1054 1060 // Set the leaves submesh. 1055 geoMeshView->setLeavesSub mesh(idMeshLeaves);1061 geoMeshView->setLeavesSubMesh(idMeshLeaves); 1056 1062 1057 1063 // Refresh mesh info. … … 1193 1199 geoMeshView->setMesh(mGeoMesh); 1194 1200 1195 mesh_saver = new GeoMeshSaver( mMeshBounds);1201 mesh_saver = new GeoMeshSaver(); 1196 1202 file_name[strlen(file_name) - 4] = '\0'; 1197 1203 mesh_saver->save(mGeoMesh, strcat(file_name,".mesh")); … … 1354 1360 mGeometryBased->set(); 1355 1361 1356 m ImageBased->set_visible();1357 m ImageBased->activate();1362 mViewPointDriven->set_visible(); 1363 mViewPointDriven->activate(); 1358 1364 1359 1365 /* … … 1401 1407 mGeometryBased->deactivate(); 1402 1408 1403 m ImageBased->hide();1404 m ImageBased->deactivate();1409 mViewPointDriven->hide(); 1410 mViewPointDriven->deactivate(); 1405 1411 1406 1412 /* … … 1443 1449 mGeometryBased->set(); 1444 1450 1445 m ImageBased->set_visible();1446 m ImageBased->activate();1451 mViewPointDriven->set_visible(); 1452 mViewPointDriven->activate(); 1447 1453 1448 1454 /* … … 1486 1492 mGeometryBased->deactivate(); 1487 1493 1488 m ImageBased->hide();1489 m ImageBased->deactivate();1494 mViewPointDriven->hide(); 1495 mViewPointDriven->deactivate(); 1490 1496 1491 1497 /* … … 1662 1668 char *cadena=new char[12]; 1663 1669 1664 if (geoMeshView->getLeavesSub mesh() >= 0)1670 if (geoMeshView->getLeavesSubMesh() >= 0) 1665 1671 { 1666 if (geoMeshView->getLeavesSub mesh() == i)1672 if (geoMeshView->getLeavesSubMesh() == i) 1667 1673 { 1668 1674 strcpy(type,"(Leaves)"); … … 1693 1699 } 1694 1700 1695 char *cadena2=new char[30]; 1696 sprintf(cadena2, "Number of indexes: %d",mGeoMesh->mSubMesh[i].mIndexCount); 1697 fltk::Item *numberIndex = new fltk::Item(cadena2); 1701 // Adds material name. 1702 char *cadena2=new char[100]; 1703 sprintf(cadena2, "Material: %s",mGeoMesh->mSubMesh[i].mMaterialName); 1704 1705 fltk::Item *geomaterial = new fltk::Item(cadena2); 1706 1707 char *cadena3=new char[100]; 1708 1709 sprintf(cadena3, "Number of indexes: %d",mGeoMesh->mSubMesh[i].mIndexCount); 1710 fltk::Item *numberIndex = new fltk::Item(cadena3); 1698 1711 if (mGeoMesh->mSubMesh[i].mType==Geometry::GEO_TRIANGLE_LIST) 1699 1712 { … … 1884 1897 } 1885 1898 1886 geoMeshView->set ColorSubmeshi(meshNumber);1899 geoMeshView->setSubMeshSelected(meshNumber); 1887 1900 geoMeshView->redraw(); 1888 1901 … … 1897 1910 Real percent; 1898 1911 1899 simplificacionState = QSLIM; 1900 1901 mMeshSimplifier = new GeometryBasedSimplifier(mGeoMesh, progress_function); 1912 //----------------- 1913 geoMeshView->saveContext(); 1914 1915 // Gets simplify option. 1916 if (mGeometryBased->value()) 1917 { 1918 simplificationState = QSLIM; 1919 mMeshSimplifier = new GeometryBasedSimplifier(mGeoMesh, 1920 progress_function); 1921 } 1922 else 1923 { 1924 simplificationState = VIEWPOINTDRIVEN; 1925 mMeshSimplifier = new ViewPointDrivenSimplifier(mGeoMesh, 1926 progress_function); 1927 } 1902 1928 1903 1929 mMeshSimplifier->setMeshLeaves(idMeshLeaves); 1904 1930 1905 if (mPercent->value() == true)1931 if (mPercent->value()) 1906 1932 { 1907 1933 // Simplificación por porcentaje … … 1910 1936 percent = mMeshReduction->fvalue(); 1911 1937 percent = percent / 100.0; 1938 1912 1939 1913 1940 // Simplifica el geomesh -> Parámetro es un factor LOD [0,1]. … … 1928 1955 // Visualize mesh. 1929 1956 geoMeshView->setMesh(mGeoMesh); 1957 1930 1958 } 1931 1959 else … … 1970 1998 // Initialize error flag. 1971 1999 error = false; 1972 2000 1973 2001 // Check submeshes for triangles strips. 1974 2002 for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) … … 1980 2008 } 1981 2009 } 1982 2010 1983 2011 // if the mesh is stripified. 1984 2012 if (error) … … 1988 2016 // if the mesh is in triangle list. 1989 2017 else 1990 { 1991 simplifica cionState = HOJAS;2018 { 2019 simplificationState = HOJAS; 1992 2020 1993 2021 mTreeSimplifier = new TreeSimplifier(mGeoMesh, progress_function); … … 2308 2336 geoMeshView->setMesh(mGeoMesh); 2309 2337 2310 // Get the mesh bounds.2311 mMeshBounds = geoMeshView->getBoundingBox();2312 2313 2338 // Hide right panel. 2314 2339 hideRightPanel(); … … 2400 2425 { 2401 2426 fltk::Group* o; 2402 o = MainView = new fltk::Group(0, 0, 600, 500);2427 o = MainView = new fltk::Group(0, 0, 500, 530); 2403 2428 o->begin(); 2404 2429 2405 2430 { 2406 2431 fltk::InvisibleBox* o; 2407 o = cframe = new fltk::InvisibleBox(0, 0, 600, 500);2432 o = cframe = new fltk::InvisibleBox(0, 0, 500, 530); 2408 2433 o->box(fltk::FLAT_BOX); 2409 2434 o->color((fltk::Color)0xffffff00); … … 2413 2438 { 2414 2439 GeoMeshView* o; 2415 o = geoMeshView = new GeoMeshView( 0,0, 600,500,0,this);2440 o = geoMeshView = new GeoMeshView( 0,0,500,530,0,this); 2416 2441 } 2417 2442 … … 2424 2449 { 2425 2450 fltk::Group* o; 2426 o = MainView = new fltk::Group( 600, 0, 200, 500);2451 o = MainView = new fltk::Group(500, 0, 300, 530); 2427 2452 o->begin(); 2428 2453 … … 2509 2534 { 2510 2535 mGeometryBased = new fltk::RadioButton(0, 8, 25, 25, "Geometry based"); 2511 m ImageBased = new fltk::RadioButton(0, 23, 25, 25, "Image based");2536 mViewPointDriven = new fltk::RadioButton(0, 23, 25, 25, "Viewpoint driven"); 2512 2537 } 2513 2538 o->end(); … … 2517 2542 2518 2543 { 2519 mProcessTitle = new fltk::Widget(0, 0, 200, 25, "");2544 mProcessTitle = new fltk::Widget(0, 0, 300, 25, ""); 2520 2545 fltk::Widget* o = mProcessTitle; 2521 2546 o->set_vertical(); … … 2582 2607 2583 2608 { 2584 fltk::Browser* o = mMeshInfo = new fltk::Browser(0, 20, 200, 380);2609 fltk::Browser* o = mMeshInfo = new fltk::Browser(0, 20, 300, 380); 2585 2610 o->set_vertical(); 2586 2611 o->callback((fltk::Callback*)cb_mMeshInfo); … … 2618 2643 } 2619 2644 2620 //{2621 //fltk::Item* o = menuMeshExportOBJ = new fltk::Item("Export to OBJ");2622 //o->callback((fltk::Callback*)cb_menuMeshExportOBJ);2623 //}2645 { 2646 fltk::Item* o = menuMeshExportOBJ = new fltk::Item("Export to OBJ"); 2647 o->callback((fltk::Callback*)cb_menuMeshExportOBJ); 2648 } 2624 2649 2625 2650 //{ -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoTool.cpp
r774 r980 1 #include "GL/glew.h" 2 #ifdef _WIN32 3 #include "GL/wglew.h" 4 #endif 5 1 6 #include "GeoMeshViewUI.h" 2 7
Note: See TracChangeset
for help on using the changeset viewer.