Changeset 891 for GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp
- Timestamp:
- 05/04/06 12:56:05 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp
r826 r891 858 858 } 859 859 860 // Remove degenerate triangles of a submesh given. 861 geoSubMesh = removeDegenerateTriangles(geoSubMesh); 862 863 return geoSubMesh; 864 } 865 866 // Remove degenerate triangles of a submesh given. 867 SubMesh * GeoMeshLoader::removeDegenerateTriangles(SubMesh *geoSubMesh) 868 { 869 Index *indices; 870 Index *index; 871 Index *indexBegin; 872 Index *indexEnd; 873 Index *new_strip_starts; 874 size_t new_index_count; 875 size_t current_index; 876 877 // Stores the new starts of strips. 878 new_strip_starts = new Index[geoSubMesh->mStripCount]; 879 880 // Calculate the new index count. 881 new_index_count = geoSubMesh->mIndexCount 882 - 883 (2 * geoSubMesh->mStripCount) 884 + 885 2; 886 887 // Auxiliar index array. 888 indices = new Index[new_index_count]; 889 890 // Initialize the current index; 891 current_index = 0; 892 893 // For each one of the strips. 894 for (int strip = 0; strip < geoSubMesh->mStripCount; strip++) 895 { 896 // Stars of strip without degenerate triangles. 897 new_strip_starts[strip] = current_index; 898 899 // First index of the strip. 900 indexBegin = geoSubMesh->mStrip[strip]; 901 902 // If is the final strip 903 if (strip == (geoSubMesh->mStripCount - 1)) 904 { 905 // The end of the index array. 906 indexEnd = &geoSubMesh->mIndex[geoSubMesh->mIndexCount]; 907 } 908 else 909 { 910 // The beginning of the next strip. 911 indexEnd = geoSubMesh->mStrip[strip + 1]; 912 } 913 914 int i; 915 i = 0; 916 917 // If is not the first strip. 918 if (strip != 0) 919 { 920 indexBegin++; 921 } 922 923 // If is not the last strip. 924 if (strip != (geoSubMesh->mStripCount - 1)) 925 { 926 indexEnd--; 927 } 928 929 // For each index of the strip. 930 for (index = indexBegin; index < indexEnd; index++) 931 { 932 indices[current_index++] = indexBegin[i]; 933 934 // Increments i. 935 i++; 936 } 937 938 } 939 940 // Free Index memory. 941 delete []geoSubMesh->mIndex; 942 943 // Update index count. 944 geoSubMesh->mIndexCount = new_index_count; 945 946 geoSubMesh->mIndex = new Index[new_index_count]; 947 948 // Store new index array without degenerate triangles. 949 for (size_t i = 0; i < geoSubMesh->mIndexCount; i++) 950 { 951 geoSubMesh->mIndex[i] = indices[i]; 952 } 953 954 // Free auxiliar index array; 955 delete []indices; 956 957 // Update start of the strip. 958 for (int strip = 0; strip < geoSubMesh->mStripCount; strip++) 959 { 960 geoSubMesh->mStrip[strip] = &geoSubMesh->mIndex[new_strip_starts[strip]]; 961 } 962 963 // Free auxiliar strip starts. 964 delete []new_strip_starts; 965 860 966 return geoSubMesh; 861 967 }
Note: See TracChangeset
for help on using the changeset viewer.