forked from nillerusr/source-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmefaceset.cpp
187 lines (152 loc) · 4.44 KB
/
dmefaceset.cpp
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "movieobjects/dmefaceset.h"
#include "movieobjects/dmematerial.h"
#include "tier0/dbg.h"
#include "UtlBuffer.h"
#include "datamodel/dmelementfactoryhelper.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Expose this class to the scene database
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeFaceSet, CDmeFaceSet );
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeFaceSet::OnConstruction()
{
m_indices.Init( this, "faces" );
m_material.Init( this, "material" );
}
void CDmeFaceSet::OnDestruction()
{
}
//-----------------------------------------------------------------------------
// accessors
//-----------------------------------------------------------------------------
CDmeMaterial *CDmeFaceSet::GetMaterial()
{
return m_material.GetElement();
}
void CDmeFaceSet::SetMaterial( CDmeMaterial *pMaterial )
{
m_material = pMaterial;
}
int CDmeFaceSet::AddIndices( int nCount )
{
int nCurrentCount = m_indices.Count();
m_indices.EnsureCount( nCount + nCurrentCount );
return nCurrentCount;
}
void CDmeFaceSet::SetIndices( int nFirstIndex, int nCount, int *pIndices )
{
m_indices.SetMultiple( nFirstIndex, nCount, pIndices );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeFaceSet::SetIndex( int i, int nValue )
{
m_indices.Set( i, nValue );
}
//-----------------------------------------------------------------------------
// Returns the number of triangulated indices
//-----------------------------------------------------------------------------
int CDmeFaceSet::GetNextPolygonVertexCount( int nFirstIndex ) const
{
int nCurrIndex = nFirstIndex;
int nTotalCount = m_indices.Count();
while( nCurrIndex < nTotalCount )
{
if ( m_indices[nCurrIndex] == -1 )
break;
++nCurrIndex;
}
return nCurrIndex - nFirstIndex;
}
//-----------------------------------------------------------------------------
// Returns the number of triangulated indices total
//-----------------------------------------------------------------------------
int CDmeFaceSet::GetTriangulatedIndexCount() const
{
int nIndexCount = 0;
int nVertexCount = 0;
int nTotalCount = m_indices.Count();
for ( int nCurrIndex = 0; nCurrIndex < nTotalCount; ++nCurrIndex )
{
if ( m_indices[nCurrIndex] == -1 )
{
if ( nVertexCount >= 3 )
{
nIndexCount += ( nVertexCount - 2 ) * 3;
}
nVertexCount = 0;
continue;
}
++nVertexCount;
}
if ( nVertexCount >= 3 )
{
nIndexCount += ( nVertexCount - 2 ) * 3;
}
return nIndexCount;
}
//-----------------------------------------------------------------------------
// Returns the number of indices total
//-----------------------------------------------------------------------------
int CDmeFaceSet::GetIndexCount() const
{
int nIndexCount = 0;
int nVertexCount = 0;
int nTotalCount = m_indices.Count();
for ( int nCurrIndex = 0; nCurrIndex < nTotalCount; ++nCurrIndex )
{
if ( m_indices[nCurrIndex] == -1 )
{
nIndexCount += nVertexCount;
nVertexCount = 0;
continue;
}
++nVertexCount;
}
nIndexCount += nVertexCount;
return nIndexCount;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeFaceSet::RemoveMultiple( int elem, int num )
{
m_indices.RemoveMultiple( elem, num );
}
//-----------------------------------------------------------------------------
// Returns the number of faces in the face set
//-----------------------------------------------------------------------------
int CDmeFaceSet::GetFaceCount() const
{
int nFaceCount = 0;
int nVertexCount = 0;
const int nIndexCount = NumIndices();
for ( int i = 0; i < nIndexCount; ++i )
{
if ( GetIndex( i ) < 0 )
{
if ( nVertexCount > 0 )
{
++nFaceCount;
}
nVertexCount = 0;
continue;
}
++nVertexCount;
}
if ( nVertexCount > 0 )
{
++nFaceCount;
}
return nFaceCount;
}