1 //////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright 2003, Andrew Ross 4 // 5 // Walk through an indexed triangle list, splitting vertices that 6 // share "sharp" edges, and calculate normals for the resulting mesh. 7 // 8 // This code should really live inside the OptVertexList class in 9 // ssgOptimizer.cxx, whose data model is almost 1:1 compatible with 10 // the indexed triangle representation here. It is a separate file 11 // because it comes from separate code that Andy Ross wrote for a 12 // different project, and this was the cleanest way to do the port. 13 // 14 //////////////////////////////////////////////////////////////////////// 15 16 #ifndef _SSGA_VERTSPLITTER_H 17 #define _SSGA_VERTSPLITTER_H 18 19 class ssgVertSplitter { 20 public: 21 ssgVertSplitter(int nVerts, int nTris); 22 virtual ~ssgVertSplitter(); 23 void setSharpAngle(float deg); 24 vert(int i)25 float* vert(int i) { return _verts + 3*i; } norm(int i)26 float* norm(int i) { return _norms + 3*i; } 27 28 // Initialize a triangle. The vertex indices might change. 29 void setTri(int tidx, int va, int vb, int vc); 30 31 // Grab the new/different indices post-split 32 int* getTri(int t); 33 34 // Number of new vertices (indices start after the original list) newVerts()35 int newVerts() { return _nextNewVert; } 36 37 // Original vertex associated with a given "new" vertex 38 int origVert(int i); 39 40 void splitAndCalcNormals(); 41 42 private: 43 struct Tri { 44 int verts[3]; 45 int oVerts[3]; 46 bool degenerate; 47 }; 48 49 void condenseGeometry(); 50 void expandDuplicates(); 51 52 int findTriWithVert(int fidx, int vidx, int* tris, int ntris); 53 int nextTri(int fidx, int vidx, int* tris, int ntris); 54 int prevTri(int fidx, int vidx, int* tris, int ntris); 55 static void fixVidx(Tri* t, int oldIdx, int newIdx); 56 57 float _threshold; 58 59 int _origVerts; 60 int _vertsAlloced; 61 62 int _nVerts; 63 float* _verts; 64 float* _norms; 65 66 int _nTris; 67 Tri* _tris; 68 float* _triNorms; 69 70 int* _newVertMap; 71 int _nextNewVert; 72 73 int* _geomVerts; 74 75 void DUMP(); 76 }; 77 78 #endif // _SSGA_VERTSPLITTER_H 79