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.

243 lines
5.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Structured Solid Class definition
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #ifndef SSOLID_H
  10. #define SSOLID_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "MapFace.h"
  15. #define MAX_FACES 120
  16. #define MAX_EDGES 512
  17. class Morph3D;
  18. class CSSolid;
  19. class CSSEdge;
  20. typedef DWORD SSHANDLE;
  21. class C2DHandle
  22. {
  23. public:
  24. C2DHandle(void) { m_bVisible = FALSE; m_bSelected = FALSE; m_bUse = TRUE; }
  25. BOOL m_bVisible; // visible?
  26. BOOL m_bSelected; // selected?
  27. BOOL m_bUse; // use this?
  28. // only valid if (m_bVisible):
  29. short m_x, m_y; // 2d position in 3d view
  30. RECT m_r; // 2d bound box in 3d view
  31. };
  32. // for GetHandleInfo():
  33. typedef enum
  34. {
  35. shtNothing = -1,
  36. shtVertex,
  37. shtEdge,
  38. shtFace
  39. } SSHANDLETYPE;
  40. typedef struct
  41. {
  42. SSHANDLETYPE Type;
  43. int iIndex;
  44. PVOID pData;
  45. C2DHandle *p2DHandle;
  46. Vector pos; // 3d position of handle
  47. } SSHANDLEINFO;
  48. // define a face:
  49. class CSSFace : public C2DHandle
  50. {
  51. public:
  52. CSSFace();
  53. ~CSSFace();
  54. void Init(void);
  55. inline int GetEdgeCount(void) { return(nEdges); }
  56. inline SSHANDLE GetEdgeHandle(int nEdge) { Assert(nEdge < GetEdgeCount()); return(Edges[nEdge]); }
  57. // edge IDs:
  58. SSHANDLE Edges[MAX_FACES];
  59. int nEdges;
  60. BOOL bModified;
  61. Vector PlanePts[3];
  62. Vector normal;
  63. TEXTURE texture; // Original face's texture info.
  64. int m_nFaceID; // Original face's unique ID.
  65. EditDispHandle_t m_hDisp; // Copy of the original faces displacement.
  66. Vector ptCenter;
  67. DWORD id;
  68. };
  69. class CSSEdge : public C2DHandle
  70. {
  71. public:
  72. CSSEdge();
  73. ~CSSEdge();
  74. void GetCenterPoint(Vector& Point);
  75. // vertex IDs:
  76. SSHANDLE hvStart;
  77. SSHANDLE hvEnd;
  78. Vector ptCenter;
  79. // faces this edge belongs to.
  80. SSHANDLE Faces[2];
  81. DWORD id;
  82. };
  83. class CSSVertex : public C2DHandle
  84. {
  85. public:
  86. CSSVertex();
  87. ~CSSVertex();
  88. void GetPosition(Vector& Position);
  89. Vector pos; // Position.
  90. DWORD id;
  91. };
  92. class CSSolid
  93. {
  94. friend Morph3D;
  95. public:
  96. // construction/destruction:
  97. CSSolid();
  98. ~CSSolid();
  99. // attach/detach mapsolid:
  100. void Attach(CMapSolid *pMapSolid);
  101. CMapSolid* Detach();
  102. // Verify that the solid (with displaced surfaces) is valid to convert back into a map solid.
  103. bool IsValidWithDisps( void );
  104. bool HasDisps( void );
  105. void DestroyDisps( void );
  106. // conversion to/from editing format:
  107. void Convert(BOOL bFromMapSolid = TRUE, bool bSkipDisplacementFaces = false);
  108. // move selected handles by a delta:
  109. void MoveSelectedHandles(const Vector &Delta);
  110. // attached map solid:
  111. CMapSolid *m_pMapSolid;
  112. inline int GetFaceCount(void) { return(m_nFaces); }
  113. inline CSSFace *GetFace(int nFace) { Assert(nFace < m_nFaces); return(&m_Faces[nFace]); }
  114. BOOL GetHandleInfo(SSHANDLEINFO * pInfo, SSHANDLE id);
  115. PVOID GetHandleData(SSHANDLE id);
  116. BOOL SplitFace(SSHANDLE h1, SSHANDLE h2);
  117. BOOL SplitFaceByVertices(CSSVertex *pVertex1, CSSVertex *pVertex2);
  118. BOOL SplitFaceByEdges(CSSEdge *pEdge1, CSSEdge *pEdge2);
  119. inline BOOL ShowEdges(void) { return(m_bShowEdges); }
  120. inline BOOL ShowVertices(void) { return(m_bShowVertices); }
  121. // check faces and report errors:
  122. void CheckFaces();
  123. // save to .dxf:
  124. void SerializeDXF(FILE* stream, int nObject);
  125. SSHANDLE GetConnectionVertex(CSSEdge *pEdge1, CSSEdge *pEdge2);
  126. private:
  127. // called by Convert():
  128. void ToMapSolid(CMapSolid* = NULL);
  129. void FromMapSolid(CMapSolid* = NULL, bool bSkipDisplacementFaces = false);
  130. void AssignFace(CSSEdge* pEdge, SSHANDLE hFace, BOOL = FALSE);
  131. // delete face/edge/vertex:
  132. void DeleteFace(int);
  133. void DeleteVertex(int);
  134. void DeleteEdge(int);
  135. SSHANDLE * MergeSameVertices(int& nDeleted);
  136. BOOL CanMergeVertices();
  137. // add face/edge/vertex:
  138. CSSFace* AddFace(int* = NULL);
  139. CSSEdge* AddEdge(int* = NULL);
  140. CSSVertex* AddVertex(int* = NULL);
  141. // get the index to the vertex at this point -
  142. // return -1 if no matching vertex.
  143. int GetVertexIndex(const Vector &Point, float fLeniency = 0.0f);
  144. // ditto for edge
  145. int GetEdgeIndex(const Vector &Point, float fLeniency = 0.0f);
  146. int GetEdgeIndex(SSHANDLE v1, SSHANDLE v2);
  147. // ditto for face
  148. int GetFaceIndex(const Vector &Point, float fLeniency = 0.0f);
  149. SSHANDLE GetNewID();
  150. void CalcEdgeCenter(CSSEdge *pEdge);
  151. CSSEdge ** FindAffectedEdges(SSHANDLE *pHandles, int iNumHandles,
  152. int& iNumEdges);
  153. Vector * CreatePointList(CSSFace & face);
  154. PINT CreatePointIndexList(CSSFace & face, PINT piPoints = NULL);
  155. SSHANDLE* CreatePointHandleList(CSSFace & face, SSHANDLE* phPoints = NULL);
  156. void SetVertexPosition(int iVertex, float x, float y, float z);
  157. SSHANDLE* CreateNewVertexList(CSSFace *pFace, CSSEdge *pEdge1,
  158. CSSEdge *pEdge2, int& nv1index, int& nv2index,
  159. CSSVertex *pNewVertex1, CSSVertex *pNewVertex2);
  160. void ShowHandles(BOOL bShowVertices, BOOL bShowEdges);
  161. int m_nVertices; // number of unique vertices
  162. BlockArray<CSSVertex, 16, 32> m_Vertices; // vertices
  163. int m_nEdges; // number of unique edges
  164. BlockArray<CSSEdge, 16, 32> m_Edges; // edges
  165. int m_nFaces; // number of faces
  166. BlockArray<CSSFace, 16, 10> m_Faces; // faces
  167. SSHANDLE m_curid;
  168. BOOL m_bShowVertices, m_bShowEdges;
  169. };
  170. #endif SSOLID_H