home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / PieceLODGen.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-08  |  3.1 KB  |  95 lines

  1. #ifndef PIECELODGEN_H
  2. #define PIECELODGEN_H
  3.  
  4. #pragma once
  5.  
  6.  
  7. // description of an edge collapse
  8. struct EdgeCollapse
  9. {
  10.     unsigned m_Tris[2];        // triangles being collapsed
  11.     unsigned m_Verts[2];    // edge being collapsed
  12. };
  13.  
  14.  
  15. // builds a new LOD given some parameters and a source piece LOD
  16. class CBuildPieceLOD
  17. {
  18. public:
  19.     // lod generation settings
  20.     float m_Distance;                // distance at which this lod kicks in
  21.     float m_Percent;                // percentage of tris this lod will ideally have
  22.     float m_MaxEdgeLen;                // maximum length of an edge in the lod
  23.     unsigned m_MinNumTris;            // minimum number of tris in the lod
  24.  
  25.     Model* m_Model;                    // pointer to the model
  26.     PieceLOD* m_PieceLOD;            // pointer to the source piece LOD
  27.     ModelPiece* m_ModelPiece;        // pointer to the piece containing the source piece LOD
  28.     int m_LODNum;                    // which LOD the source piece LOD is within the piece
  29.  
  30.     // default constructor
  31.     CBuildPieceLOD() : m_TriActive(20000), m_Tris(20000), m_Verts(10000) {}
  32.  
  33.     // generate the LOD from the source LOD
  34.     bool BuildLOD();
  35.  
  36. private:
  37.     CMoArray<bool> m_TriActive;            // is the specified triangle active
  38.     CMoArray<ModelTri> m_Tris;            // new triangles
  39.     CMoArray<ModelVert> m_Verts;        // new vertices
  40.     CMoArray<EdgeCollapse> m_Collapses;    // array of edge collapses to get new LOD
  41.  
  42.     // initialize internal structures
  43.     void SetupGenLODModel();
  44.  
  45.     // find the best edge collapse candidate
  46.     bool FindShortestEdge( EdgeCollapse& edgeCollapse );
  47.  
  48.     // returns true if 2 and only 2 triangles share the edge
  49.     // fills in tris with the tris that share the edge
  50.     bool TestEdgeCollapse( unsigned vert0, unsigned vert1, unsigned* tris );
  51.  
  52.     // count the number of uncollapsed triangles
  53.     unsigned CalcNumActiveTris();
  54.  
  55.     // updates structures with an edge collapse
  56.     bool ProcessEdgeCollapse( const EdgeCollapse& edgeCollapse );
  57.  
  58.     // given a triangle and a vert index, get which vert on the tri has that index
  59.     bool GetTriVert( unsigned tri, unsigned vertIndex, unsigned& vert );
  60.  
  61.     // merge two verts into a new vert
  62.     void MergeVerts( const EdgeCollapse& edgeCollapse );
  63.  
  64.     // check to see if a vert already has a weight for a node
  65.     NewVertexWeight* FindWeight( ModelVert* vert, unsigned node );
  66.  
  67.     // update any m_iReplacements referencing vertIndex to newVertIndex
  68.     void MarkReplacements( unsigned vertIndex, unsigned newVertIndex );
  69.  
  70.     // any verts that reference only the removed triangles need to have any replacements
  71.     // referencing them updated to reference the new vertex instead
  72.     void UpdateDeadVertexReferences( const EdgeCollapse& edgeCollapse, unsigned newIndex );
  73.  
  74.     // add a new LOD to the model using the current set of edge collapses
  75.     bool AddLOD();
  76. };
  77.  
  78.  
  79. // used for efficient initialization of an array of arrays
  80. class ModelTriPtrArray
  81. {
  82.     enum { SIZE=20 };
  83.  
  84. public:
  85.     ModelTriPtrArray() : m_MaskedData(SIZE) {}
  86.     int GetSize() { return m_MaskedData.GetSize(); }
  87.     void Append( ModelTri* type ) { m_MaskedData.Append( type ); }
  88.     ModelTri* operator[]( int val ) { return m_MaskedData[val]; }
  89.     
  90. private:
  91.     CMoArray<ModelTri*> m_MaskedData;
  92. };
  93.  
  94.  
  95. #endif // PIECELODGEN_H