blob: 5162bd80e32d3f4ec2297321b03a2ac29e7fa3d4 (
plain) (
blame)
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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "flexrenderdata.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CCachedRenderData::CCachedRenderData() : m_CurrentTag(0), m_pFirstFlexIndex(0),
m_pFirstWorldIndex(0)
{
#ifdef _DEBUG
int i;
float val = VEC_T_NAN;
for( i = 0; i < MAXSTUDIOFLEXVERTS; i++ )
{
m_pFlexVerts[i].m_Position[0] = val;
m_pFlexVerts[i].m_Position[1] = val;
m_pFlexVerts[i].m_Position[2] = val;
m_pFlexVerts[i].m_Normal[0] = val;
m_pFlexVerts[i].m_Normal[1] = val;
m_pFlexVerts[i].m_Normal[2] = val;
m_pThinFlexVerts[i].m_Position[0] = val;
m_pThinFlexVerts[i].m_Position[1] = val;
m_pThinFlexVerts[i].m_Position[2] = val;
m_pThinFlexVerts[i].m_Normal[0] = val;
m_pThinFlexVerts[i].m_Normal[1] = val;
m_pThinFlexVerts[i].m_Normal[2] = val;
m_pFlexVerts[i].m_TangentS[0] = val;
m_pFlexVerts[i].m_TangentS[1] = val;
m_pFlexVerts[i].m_TangentS[2] = val;
m_pFlexVerts[i].m_TangentS[3] = val;
}
#endif
}
//-----------------------------------------------------------------------------
// Call this before rendering the model
//-----------------------------------------------------------------------------
void CCachedRenderData::StartModel()
{
++m_CurrentTag;
m_IndexCount = 0;
m_FlexVertexCount = 0;
m_ThinFlexVertexCount = 0;
m_WorldVertexCount = 0;
m_pFirstFlexIndex = 0;
m_pFirstThinFlexIndex = 0;
m_pFirstWorldIndex = 0;
}
//-----------------------------------------------------------------------------
// Used to hook ourselves into a particular body part, model, and mesh
//-----------------------------------------------------------------------------
void CCachedRenderData::SetBodyPart( int bodypart )
{
m_Body = bodypart;
m_CacheDict.EnsureCount(m_Body+1);
m_Model = m_Mesh = -1;
m_pFirstFlexIndex = 0;
m_pFirstThinFlexIndex = 0;
m_pFirstWorldIndex = 0;
}
void CCachedRenderData::SetModel( int model )
{
Assert(m_Body >= 0);
m_Model = model;
m_CacheDict[m_Body].EnsureCount(m_Model+1);
m_Mesh = -1;
m_pFirstFlexIndex = 0;
m_pFirstThinFlexIndex = 0;
m_pFirstWorldIndex = 0;
}
void CCachedRenderData::SetMesh( int mesh )
{
Assert((m_Model >= 0) && (m_Body >= 0));
m_Mesh = mesh;
m_CacheDict[m_Body][m_Model].EnsureCount(m_Mesh+1);
// At this point, we should have all 3 defined.
CacheDict_t& dict = m_CacheDict[m_Body][m_Model][m_Mesh];
if (dict.m_Tag == m_CurrentTag)
{
m_pFirstFlexIndex = &m_pFlexIndex[dict.m_FirstIndex];
m_pFirstThinFlexIndex = &m_pThinFlexIndex[dict.m_FirstIndex];
m_pFirstWorldIndex = &m_pWorldIndex[dict.m_FirstIndex];
}
else
{
m_pFirstFlexIndex = 0;
m_pFirstThinFlexIndex = 0;
m_pFirstWorldIndex = 0;
}
}
//-----------------------------------------------------------------------------
// Used to set up a flex computation
//-----------------------------------------------------------------------------
bool CCachedRenderData::IsFlexComputationDone( ) const
{
Assert((m_Model >= 0) && (m_Body >= 0) && (m_Mesh >= 0));
// Lets create the dictionary entry
// If the tags match, that means we're doing the computation twice!!!
CacheDict_t const& dict = m_CacheDict[m_Body][m_Model][m_Mesh];
return (dict.m_FlexTag == m_CurrentTag);
}
//-----------------------------------------------------------------------------
// Used to set up a computation (modifies vertex data)
//-----------------------------------------------------------------------------
void CCachedRenderData::SetupComputation( mstudiomesh_t *pMesh, bool flexComputation )
{
Assert((m_Model >= 0) && (m_Body >= 0) && (m_Mesh >= 0));
// Assert( !m_pFirstIndex );
// Lets create the dictionary entry
// If the tags match, that means we're doing the computation twice!!!
CacheDict_t& dict = m_CacheDict[m_Body][m_Model][m_Mesh];
if (dict.m_Tag != m_CurrentTag)
{
dict.m_FirstIndex = m_IndexCount;
dict.m_IndexCount = pMesh->numvertices;
dict.m_Tag = m_CurrentTag;
m_IndexCount += dict.m_IndexCount;
}
if (flexComputation)
dict.m_FlexTag = m_CurrentTag;
m_pFirstFlexIndex = &m_pFlexIndex[dict.m_FirstIndex];
m_pFirstThinFlexIndex = &m_pThinFlexIndex[dict.m_FirstIndex];
m_pFirstWorldIndex = &m_pWorldIndex[dict.m_FirstIndex];
}
//-----------------------------------------------------------------------------
// Creates a new flexed vertex to be associated with a vertex
//-----------------------------------------------------------------------------
CachedPosNormTan_t* CCachedRenderData::CreateFlexVertex( int vertex )
{
Assert( m_pFirstFlexIndex );
Assert( m_pFirstFlexIndex[vertex].m_Tag != m_CurrentTag );
Assert ( m_FlexVertexCount < MAXSTUDIOFLEXVERTS );
if ( m_FlexVertexCount >= MAXSTUDIOFLEXVERTS )
return NULL;
// Point the flex list to the new flexed vertex
m_pFirstFlexIndex[vertex].m_Tag = m_CurrentTag;
m_pFirstFlexIndex[vertex].m_VertexIndex = m_FlexVertexCount;
// Add a new flexed vert to the flexed vertex list
++m_FlexVertexCount;
return GetFlexVertex( vertex );
}
//-----------------------------------------------------------------------------
// Creates a new flexed vertex to be associated with a vertex
//-----------------------------------------------------------------------------
CachedPosNorm_t* CCachedRenderData::CreateThinFlexVertex( int vertex )
{
Assert( m_pFirstThinFlexIndex );
Assert( m_pFirstThinFlexIndex[vertex].m_Tag != m_CurrentTag );
Assert ( m_ThinFlexVertexCount < MAXSTUDIOFLEXVERTS );
if ( m_ThinFlexVertexCount >= MAXSTUDIOFLEXVERTS )
return NULL;
// Point the flex list to the new flexed vertex
m_pFirstThinFlexIndex[vertex].m_Tag = m_CurrentTag;
m_pFirstThinFlexIndex[vertex].m_VertexIndex = m_ThinFlexVertexCount;
// Add a new flexed vert to the thin flexed vertex list
++m_ThinFlexVertexCount;
return GetThinFlexVertex( vertex );
}
//-----------------------------------------------------------------------------
// Re-normalize the surface normals and tangents of the flexed vertices
// No thin ones since they're intended to be deltas, not unit vectors
//-----------------------------------------------------------------------------
void CCachedRenderData::RenormalizeFlexVertices( bool bHasTangentData )
{
int i;
for (i = 0; i < m_FlexVertexCount; i++)
{
m_pFlexVerts[ i ].m_Normal.NormalizeInPlace();
if (bHasTangentData)
{
m_pFlexVerts[ i ].m_TangentS.AsVector3D().NormalizeInPlace();
}
}
}
//-----------------------------------------------------------------------------
// Creates a new flexed vertex to be associated with a vertex
//-----------------------------------------------------------------------------
CachedPosNorm_t* CCachedRenderData::CreateWorldVertex( int vertex )
{
Assert( m_pFirstWorldIndex );
if ( m_pFirstWorldIndex[vertex].m_Tag != m_CurrentTag )
{
// Point the world list to the new world vertex
Assert( m_WorldVertexCount < MAXSTUDIOVERTS );
m_pFirstWorldIndex[vertex].m_Tag = m_CurrentTag;
m_pFirstWorldIndex[vertex].m_VertexIndex = m_WorldVertexCount;
// Add a new world vert to the world vertex list
++m_WorldVertexCount;
}
return GetWorldVertex( vertex );
}
|