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