Changeset 2341 for GTP/trunk/Lib/Geom/shared/GeoTool/src
- Timestamp:
- 04/30/07 08:16:31 (17 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GeoTool/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
r2324 r2341 37 37 y = fltk::event_y(); 38 38 39 40 39 switch (button) 41 40 { … … 139 138 } 140 139 141 //------------------------------------------------------------------------- --140 //------------------------------------------------------------------------- 142 141 // Get the number of frames per second. 143 //------------------------------------------------------------------------- --142 //------------------------------------------------------------------------- 144 143 size_t GeoMeshView::getFPS() 145 144 { … … 147 146 } 148 147 149 //------------------------------------------------------------------------- --148 //------------------------------------------------------------------------- 150 149 // Calculate the number of frames per second. 151 //------------------------------------------------------------------------- --150 //------------------------------------------------------------------------- 152 151 void GeoMeshView::calcFPS() 153 152 { … … 643 642 { 644 643 // The end of the index array. 645 indexEnd = 646 size =indexEnd - indexBegin;644 indexEnd = &geosubmesh->mIndex[geosubmesh->mIndexCount]; 645 size = indexEnd - indexBegin; 647 646 } 648 647 else … … 678 677 } 679 678 680 // VERTEX ARRAYS679 // VERTEX ARRAYS. 681 680 glEnableClientState(GL_VERTEX_ARRAY); 682 681 glEnableClientState(GL_NORMAL_ARRAY); … … 938 937 // For each one of the strips. 939 938 int indices_to_render = lodTreeLib->GetValidTrunkIndexCount(submesh); 940 939 941 940 glBegin(GL_TRIANGLE_STRIP); 942 941 -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
r2323 r2341 104 104 } 105 105 106 107 108 106 //------------------------------------------------------------------------- 109 107 // Repaint the FPS label. … … 156 154 cb_menuFileSave_i(o,v); 157 155 } 156 158 157 159 158 //------------------------------------------------------------------------- … … 1086 1085 stripify(); 1087 1086 1087 // Debug. 1088 //writeStrips(mGeoMesh); 1089 1088 1090 break; 1089 1091 … … 1298 1300 { 1299 1301 char *file_name = NULL; 1302 char *ptr; 1303 char message[255]; 1300 1304 GeoMeshSaver *mesh_saver; 1301 1305 Serializer *oSerializer; 1306 int answer_yes; 1302 1307 1303 1308 // Sets the progress bar to process bar. … … 1320 1325 if (file_name) 1321 1326 { 1322 // Undo the simplification changes. 1323 undo(); 1324 1325 // Stripify the mesh object. 1326 stripify(); 1327 1328 // Reset the build bar. 1329 mBuildBar->position(0); 1330 1331 // Simplification sequence. 1332 oMeshSimpSequence = mMeshSimplifier->GetSimplificationSequence(); 1333 1334 // If the simplification sequence and the mesh exist. 1335 if (oMeshSimpSequence && mGeoMesh) 1336 { 1337 oLodStrip = new LodStripsConstructor( mGeoMesh, 1338 oMeshSimpSequence, 1339 idMeshLeaves, 1340 progress_function); 1341 1342 oLodStrip->UpdateMesh(); 1343 1344 // Deletes the previous mesh. 1345 delete mUndoMesh; 1346 1347 mUndoMesh = new Mesh(); 1348 1349 // Sets the undo mesh. 1350 *mUndoMesh = *mGeoMesh; 1351 1352 delete mGeoMesh; 1353 1354 mGeoMesh = oLodStrip->GetMesh(); 1355 1356 geoMeshView->setMesh(mGeoMesh); 1357 1358 mesh_saver = new GeoMeshSaver(); 1359 1360 mesh_saver->leavesSubMesh = idMeshLeaves; 1361 mesh_saver->leavesVB = origSubMeshVB; 1362 mesh_saver->numindices = orig_numindices; 1363 mesh_saver->indices = orig_indices; 1364 1365 mesh_saver->save(mGeoMesh,file_name); 1366 1367 delete mesh_saver; 1368 1369 oLodStrip->Save(file_name); 1327 // Cut extension. 1328 ptr = strtok(file_name,"."); 1329 1330 // If has extension. 1331 if (ptr) 1332 { 1333 strcpy(file_name,ptr); 1334 } 1335 1336 // Adds mesh extension. 1337 strcat(file_name,".mesh"); 1338 1339 // If File Exists. 1340 if (fileExists(file_name)) 1341 { 1342 // Compose message. 1343 strcpy(message,"Do you want to replace "); 1344 strcat(message,filename_name(file_name)); 1345 strcat(message,"?"); 1346 1347 // Question. 1348 answer_yes = fltk::ask(message); 1349 } 1350 1351 // If answer yes to replace question 1352 // or if file not exists. 1353 if (answer_yes) 1354 { 1355 1356 // Undo the simplification changes. 1357 undo(); 1358 1359 // Stripify the mesh object. 1360 stripify(); 1361 1362 // Reset the build bar. 1363 mBuildBar->position(0); 1364 1365 // Simplification sequence. 1366 oMeshSimpSequence = mMeshSimplifier->GetSimplificationSequence(); 1367 1368 // If the simplification sequence and the mesh exist. 1369 if (oMeshSimpSequence && mGeoMesh) 1370 { 1371 oLodStrip = new LodStripsConstructor( mGeoMesh, 1372 oMeshSimpSequence, 1373 idMeshLeaves, 1374 progress_function); 1375 1376 oLodStrip->UpdateMesh(); 1377 1378 // Deletes the previous mesh. 1379 delete mUndoMesh; 1380 1381 mUndoMesh = new Mesh(); 1382 1383 // Sets the undo mesh. 1384 *mUndoMesh = *mGeoMesh; 1385 1386 delete mGeoMesh; 1387 1388 mGeoMesh = oLodStrip->GetMesh(); 1389 1390 geoMeshView->setMesh(mGeoMesh); 1391 1392 mesh_saver = new GeoMeshSaver(); 1393 1394 mesh_saver->leavesSubMesh = idMeshLeaves; 1395 mesh_saver->leavesVB = origSubMeshVB; 1396 mesh_saver->numindices = orig_numindices; 1397 mesh_saver->indices = orig_indices; 1398 1399 mesh_saver->save(mGeoMesh,file_name); 1400 1401 delete mesh_saver; 1402 1403 oLodStrip->Save(file_name); 1404 } 1370 1405 } 1371 1406 else … … 1837 1872 { 1838 1873 char type[10]; 1874 1839 1875 unsigned int group_index; 1840 1876 unsigned int group_count; 1841 1877 unsigned int bone_count; 1878 1842 1879 fltk::ItemGroup **info_group; 1843 1880 … … 1867 1904 char *skel_name = new char[256]; 1868 1905 char *bone_assig = new char[256]; 1906 1869 1907 sprintf(group_name,"Skeleton"); 1870 1908 info_group[group_index] = new fltk::ItemGroup(group_name); … … 1879 1917 bone_count += mGeoMesh->mSubMesh[i].mBones.size(); 1880 1918 } 1919 1881 1920 sprintf(bone_assig,"Bone assignamets: %d",bone_count); 1882 1921 new fltk::Item(bone_assig); … … 1886 1925 } 1887 1926 1888 for(int i =0; i<mGeoMesh->mSubMeshCount;i++)1927 for(int i = 0; i < mGeoMesh->mSubMeshCount; i++) 1889 1928 { 1890 1929 char *group_name = new char[256]; … … 1907 1946 1908 1947 // Submesh identifier. 1909 sprintf(group_name,"SubMesh %d %s",i,type); 1948 sprintf(group_name, 1949 "SubMesh %d %s:%s", 1950 i, 1951 type, 1952 mGeoMesh->mSubMesh[i].mName); 1910 1953 1911 1954 info_group[group_index] = new fltk::ItemGroup(group_name); 1912 1955 info_group[group_index]->begin(); 1913 1956 fltk::Item *sharedGeometry; 1957 1914 1958 if (mGeoMesh->mSubMesh[i].mSharedVertexBuffer) 1915 1959 { … … 1922 1966 1923 1967 // Adds material name. 1924 char *cadena2 =new char[100];1968 char *cadena2 = new char[100]; 1925 1969 sprintf(cadena2, "Material: %s",mGeoMesh->mSubMesh[i].mMaterialName); 1926 1970 1927 1971 fltk::Item *geomaterial = new fltk::Item(cadena2); 1928 1972 1929 char *cadena3 =new char[100];1973 char *cadena3 = new char[100]; 1930 1974 1931 sprintf(cadena3, "Number of indexes: %d",mGeoMesh->mSubMesh[i].mIndexCount); 1975 sprintf(cadena3, 1976 "Number of indexes: %d", 1977 mGeoMesh->mSubMesh[i].mIndexCount); 1978 1932 1979 fltk::Item *numberIndex = new fltk::Item(cadena3); 1980 1933 1981 if (mGeoMesh->mSubMesh[i].mType==Geometry::GEO_TRIANGLE_LIST) 1934 1982 { 1935 fltk::Item *type =new fltk::Item("Triangle List");1983 fltk::Item *type = new fltk::Item("Triangle List"); 1936 1984 } 1937 1985 else 1938 1986 { 1939 fltk::Item *type =new fltk::Item("Triangle Strips");1987 fltk::Item *type = new fltk::Item("Triangle Strips"); 1940 1988 } 1941 1989 1942 char *cadenavertex=new char[30]; 1943 sprintf(cadenavertex, "Number of vertices: %d",mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount); 1944 fltk::Item *numberVertex = new fltk::Item(cadenavertex); 1945 1946 if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 1990 char *cadenavertex = new char[30]; 1991 1992 sprintf(cadenavertex, 1993 "Number of vertices: %d", 1994 mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount); 1995 1996 fltk::Item *numberVertex = new fltk::Item(cadenavertex); 1997 1998 if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo 1999 & 2000 Geometry::VERTEX_NORMAL) 1947 2001 { 1948 fltk::Item *normals =new fltk::Item("Normals: Yes");2002 fltk::Item *normals = new fltk::Item("Normals: Yes"); 1949 2003 } 1950 2004 else 1951 2005 { 1952 fltk::Item *normals =new fltk::Item("Normals: No");2006 fltk::Item *normals = new fltk::Item("Normals: No"); 1953 2007 } 1954 2008 1955 if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 2009 if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo 2010 & 2011 Geometry::VERTEX_TEXCOORDS) 1956 2012 { 1957 fltk::Item *textures =new fltk::Item("Textures: Yes");2013 fltk::Item *textures = new fltk::Item("Textures: Yes"); 1958 2014 } 1959 2015 else 1960 2016 { 1961 fltk::Item *textures =new fltk::Item("Textures: No");2017 fltk::Item *textures = new fltk::Item("Textures: No"); 1962 2018 } 1963 2019 1964 1965 2020 info_group[group_index]->end(); 1966 2021 } 2022 1967 2023 ogeometry->end(); 1968 2024 this->mMeshInfo->add(ogeometry); … … 2057 2113 break; 2058 2114 case GEO_TRIANGLE_STRIPS: 2059 triangle_count += geoSubMesh->mIndexCount - 2; 2115 triangle_count += geoSubMesh->mIndexCount 2116 - 2117 2; 2060 2118 break; 2061 2119 } … … 2064 2122 2065 2123 return triangle_count; 2124 } 2125 2126 //------------------------------------------------------------------------- 2127 // Get the number of degenerated triangles. 2128 //------------------------------------------------------------------------- 2129 size_t GeoMeshViewUI::getDegeneratedCount(Geometry::Mesh *geoMesh) 2130 { 2131 size_t degenerated; 2132 size_t same_index; 2133 SubMesh *geoSubMesh; 2134 2135 // Initialize the degenerated count. 2136 degenerated = 0; 2137 2138 // Initiazlize same index count. 2139 same_index = 1; 2140 2141 // For each submesh. 2142 for (size_t submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 2143 { 2144 // Gets the actual submesh. 2145 geoSubMesh = &geoMesh->mSubMesh[submesh]; 2146 2147 if (geoSubMesh->mType == GEO_TRIANGLE_STRIPS) 2148 { 2149 // Find degenerated triangles. 2150 for (size_t i = 0; i < (geoSubMesh->mIndexCount - 1); i++) 2151 { 2152 if (geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i + 1]) 2153 { 2154 same_index++; 2155 } 2156 else 2157 { 2158 if (same_index > 1) 2159 { 2160 degenerated += same_index; 2161 } 2162 else if (i < (geoSubMesh->mIndexCount - 2)) 2163 { 2164 if (geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i + 2]) 2165 { 2166 degenerated++; 2167 } 2168 } 2169 2170 same_index = 1; 2171 } 2172 } 2173 } 2174 } 2175 2176 return degenerated; 2066 2177 } 2067 2178 … … 2460 2571 static char vertices_value[50]; 2461 2572 static char triangles_value[50]; 2573 static char degenerated_value[50]; 2462 2574 static char strips_value[50]; 2463 2575 … … 2471 2583 2472 2584 mTriangles->label(triangles_value); 2585 2586 // Translate the degenerated count to a char value. 2587 sprintf(degenerated_value,"Degenerated %d",getDegeneratedCount(mGeoMesh)); 2588 2589 mDegenerated->label(degenerated_value); 2473 2590 2474 2591 // Translate the triangle count to a char value. … … 2679 2796 } 2680 2797 2798 //------------------------------------------------------------------------- 2681 2799 // Set textures to mesh model. 2800 //------------------------------------------------------------------------- 2682 2801 void GeoMeshViewUI::setTextures() 2683 2802 { … … 3241 3360 { 3242 3361 fltk::Widget* o; 3243 o = mStrips = new fltk::Widget(354, 3, 30, 15, "Strips"); 3362 o = mDegenerated = new fltk::Widget(354, 3, 30, 15, "Degenerated"); 3363 o->box(fltk::NO_BOX); 3364 o->labelfont(fltk::HELVETICA_BOLD); 3365 o->color((fltk::Color)0xe0dfe300); 3366 } 3367 3368 { 3369 fltk::Widget* o; 3370 o = mStrips = new fltk::Widget(454, 3, 30, 15, "Strips"); 3244 3371 o->box(fltk::NO_BOX); 3245 3372 o->labelfont(fltk::HELVETICA_BOLD); … … 3320 3447 } 3321 3448 3449 //------------------------------------------------------------------------- 3450 // Write file of strips. 3451 //------------------------------------------------------------------------- 3452 void GeoMeshViewUI::writeStrips(Mesh *geomesh) 3453 { 3454 Index *index; 3455 Index *indexBegin; 3456 Index *indexEnd; 3457 SubMesh *geosubmesh; 3458 3459 ofstream out ("strips.txt"); 3460 3461 // For each submesh. 3462 for (size_t submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 3463 { 3464 geosubmesh = &geomesh->mSubMesh[submesh]; 3465 3466 // For each one of the strips. 3467 for (size_t strip = 0; strip < geosubmesh->mStripCount; strip++) 3468 { 3469 // First index of the strip. 3470 indexBegin = geosubmesh->mStrip[strip]; 3471 3472 // If is the final strip 3473 if (strip == (geosubmesh->mStripCount - 1)) 3474 { 3475 // The end of the index array. 3476 indexEnd = &geosubmesh->mIndex[geosubmesh->mIndexCount]; 3477 } 3478 else 3479 { 3480 // The beginning of the next strip. 3481 indexEnd = geosubmesh->mStrip[strip + 1]; 3482 } 3483 3484 for (index = indexBegin; index < indexEnd; index++) 3485 { 3486 out << index[0] 3487 << " "; 3488 } 3489 3490 out << endl; 3491 } 3492 } 3493 3494 out.close(); 3495 } 3496
Note: See TracChangeset
for help on using the changeset viewer.