Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // A class for computing things with CDmeMesh data
  4. //
  5. //=============================================================================
  6. #ifndef DMMESHCOMP_H
  7. #define DMMESHCOMP_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. // Valve includes
  12. #include "mathlib/mathlib.h"
  13. #include "tier1/utlvector.h"
  14. #include "tier1/utllinkedlist.h"
  15. // Forward declarations
  16. class CDmeMesh;
  17. class CDmeVertexData;
  18. //=============================================================================
  19. // TODO: This works in the local space of the mesh... add option to transform
  20. // the positions into world space
  21. //=============================================================================
  22. class CDmMeshComp
  23. {
  24. public:
  25. CDmMeshComp( CDmeMesh *pMesh, CDmeVertexData *pPassedBase = NULL );
  26. ~CDmMeshComp();
  27. class CVert;
  28. class CEdge;
  29. class CVert
  30. {
  31. public:
  32. CVert( int nPositionIndex, const CUtlVector< int > *pVertexIndices, const Vector *pPosition );
  33. CVert( const CVert &src );
  34. int PositionIndex() const;
  35. const Vector *Position() const;
  36. const CUtlVector< int > *VertexIndices() const;
  37. bool operator==( const CVert &rhs ) const;
  38. protected:
  39. friend class CDmMeshComp;
  40. int m_positionIndex; // Index in the position data
  41. const CUtlVector< int > *m_pVertexIndices; // Pointer to a list of the vertex indices for this vertex
  42. const Vector *m_pPosition;
  43. CUtlVector< CEdge * > m_edges; // An array of pointers to the edges containing this vertex
  44. private:
  45. CVert(); // Not used
  46. };
  47. class CEdge
  48. {
  49. public:
  50. CEdge();
  51. int GetVertPositionIndex( int edgeRelativeVertexIndex ) const;
  52. CVert *GetVert( int edgeRelativeVertexIndex ) const;
  53. bool IsBorderEdge() const { return m_faceCount == 1; }
  54. bool ConnectedTo( const CEdge *pEdge ) const { return m_pVert0 == pEdge->m_pVert0 || m_pVert0 == pEdge->m_pVert1 || m_pVert1 == pEdge->m_pVert0 || m_pVert1 == pEdge->m_pVert1; }
  55. Vector EdgeVector() const;
  56. // Returns true if the edge starts and stops at the same point in local space
  57. bool operator==( const CEdge &rhs ) const;
  58. protected:
  59. friend class CDmMeshComp;
  60. CVert *m_pVert0;
  61. CVert *m_pVert1;
  62. int m_faceCount;
  63. };
  64. class CFace
  65. {
  66. public:
  67. protected:
  68. friend class CDmMeshComp;
  69. CUtlVector< CVert * > m_verts;
  70. CUtlVector< CEdge * > m_edges;
  71. CUtlVector< bool > m_edgeReverseMap;
  72. };
  73. CDmeVertexData *BaseState() { return m_pBase; }
  74. CEdge *FindOrCreateEdge( int vIndex0, int vIndex1, bool *pReverse = NULL );
  75. CEdge *FindEdge( int vIndex0, int vIndex1, bool *pReverse = NULL );
  76. CFace *CreateFace( const CUtlVector< CVert * > &verts, const CUtlVector< CEdge * > &edges, const CUtlVector< bool > &edgeReverseMap );
  77. int FindFacesWithVert( int vIndex, CUtlVector< CFace * > &faces );
  78. int FindNeighbouringVerts( int vIndex, CUtlVector< CVert * > &verts );
  79. int GetBorderEdges( CUtlVector< CUtlVector< CEdge * > > &borderEdges );
  80. CDmeMesh *m_pMesh;
  81. CDmeVertexData *m_pBase;
  82. CUtlVector< CVert * > m_verts;
  83. CUtlVector< CEdge * > m_edges;
  84. CUtlFixedLinkedList< CFace > m_faces;
  85. };
  86. #endif // DMEMESHCOMP_H