forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimorph.h
251 lines (201 loc) · 6.67 KB
/
imorph.h
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
244
245
246
247
248
249
250
251
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// The copyright to the contents herein is the property of Valve, L.L.C.
// The contents may be used and/or copied only with the written permission of
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
// the agreement/contract under which the contents have been supplied.
//
// $Header: $
// $NoKeywords: $
//
// Interface used to construct morph buffers
//=============================================================================
#ifndef IMORPH_H
#define IMORPH_H
#ifdef _WIN32
#pragma once
#endif
#include "mathlib/vector.h"
#include <float.h>
#include "tier0/dbg.h"
#include "materialsystem/imaterial.h"
//-----------------------------------------------------------------------------
// Single morph data
//-----------------------------------------------------------------------------
struct MorphVertexInfo_t
{
int m_nVertexId; // What vertex is this going to affect?
int m_nMorphTargetId; // What morph did it come from?
Vector m_PositionDelta; // Positional morph delta
Vector m_NormalDelta; // Normal morph delta
float m_flWrinkleDelta; // Wrinkle morph delta
float m_flSpeed;
float m_flSide;
};
//-----------------------------------------------------------------------------
// Morph weight data
//-----------------------------------------------------------------------------
enum MorphWeightType_t
{
MORPH_WEIGHT = 0,
MORPH_WEIGHT_LAGGED,
MORPH_WEIGHT_STEREO,
MORPH_WEIGHT_STEREO_LAGGED,
MORPH_WEIGHT_COUNT,
};
struct MorphWeight_t
{
float m_pWeight[MORPH_WEIGHT_COUNT];
};
//-----------------------------------------------------------------------------
// Interface to the morph
//-----------------------------------------------------------------------------
abstract_class IMorph
{
public:
// Locks the morph, destroys any existing contents
virtual void Lock( float flFloatToFixedScale = 1.0f ) = 0;
// Adds a morph
virtual void AddMorph( const MorphVertexInfo_t &info ) = 0;
// Unlocks the morph
virtual void Unlock( ) = 0;
};
//-----------------------------------------------------------------------------
// Morph builders
//-----------------------------------------------------------------------------
class CMorphBuilder
{
public:
CMorphBuilder();
~CMorphBuilder();
// Start building the morph
void Begin( IMorph *pMorph, float flFloatToFixedScale = 1.0f );
// End building the morph
void End();
void PositionDelta3fv( const float *pDelta );
void PositionDelta3f( float dx, float dy, float dz );
void PositionDelta3( const Vector &vec );
void NormalDelta3fv( const float *pDelta );
void NormalDelta3f( float dx, float dy, float dz );
void NormalDelta3( const Vector &vec );
void WrinkleDelta1f( float flWrinkle );
// Both are 0-1 values indicating which morph target to use (for stereo morph targets)
// and how much to blend between using lagged weights vs actual weights
// Speed: 0 - use lagged, 1 - use actual
void Speed1f( float flSpeed );
void Side1f( float flSide );
void AdvanceMorph( int nSourceVertex, int nMorphTargetId );
private:
MorphVertexInfo_t m_Info;
IMorph *m_pMorph;
};
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
inline CMorphBuilder::CMorphBuilder()
{
m_pMorph = NULL;
}
inline CMorphBuilder::~CMorphBuilder()
{
// You forgot to call End()!
Assert( !m_pMorph );
}
//-----------------------------------------------------------------------------
// Start building the morph
//-----------------------------------------------------------------------------
inline void CMorphBuilder::Begin( IMorph *pMorph, float flFloatToFixedScale )
{
Assert( pMorph && !m_pMorph );
m_pMorph = pMorph;
m_pMorph->Lock( flFloatToFixedScale );
#ifdef _DEBUG
m_Info.m_PositionDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
m_Info.m_NormalDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
m_Info.m_flWrinkleDelta = VEC_T_NAN;
m_Info.m_flSpeed = VEC_T_NAN;
m_Info.m_flSide = VEC_T_NAN;
#endif
}
// End building the morph
inline void CMorphBuilder::End()
{
Assert( m_pMorph );
m_pMorph->Unlock();
m_pMorph = NULL;
}
//-----------------------------------------------------------------------------
// Set position delta
//-----------------------------------------------------------------------------
inline void CMorphBuilder::PositionDelta3fv( const float *pDelta )
{
Assert( m_pMorph );
m_Info.m_PositionDelta.Init( pDelta[0], pDelta[1], pDelta[2] );
}
inline void CMorphBuilder::PositionDelta3f( float dx, float dy, float dz )
{
Assert( m_pMorph );
m_Info.m_PositionDelta.Init( dx, dy, dz );
}
inline void CMorphBuilder::PositionDelta3( const Vector &vec )
{
Assert( m_pMorph );
m_Info.m_PositionDelta = vec;
}
//-----------------------------------------------------------------------------
// Set normal delta
//-----------------------------------------------------------------------------
inline void CMorphBuilder::NormalDelta3fv( const float *pDelta )
{
Assert( m_pMorph );
m_Info.m_NormalDelta.Init( pDelta[0], pDelta[1], pDelta[2] );
}
inline void CMorphBuilder::NormalDelta3f( float dx, float dy, float dz )
{
Assert( m_pMorph );
m_Info.m_NormalDelta.Init( dx, dy, dz );
}
inline void CMorphBuilder::NormalDelta3( const Vector &vec )
{
Assert( m_pMorph );
m_Info.m_NormalDelta = vec;
}
//-----------------------------------------------------------------------------
// Set wrinkle delta
//-----------------------------------------------------------------------------
inline void CMorphBuilder::WrinkleDelta1f( float flWrinkle )
{
Assert( m_pMorph );
m_Info.m_flWrinkleDelta = flWrinkle;
}
//-----------------------------------------------------------------------------
// Set speed,side data
//-----------------------------------------------------------------------------
inline void CMorphBuilder::Speed1f( float flSpeed )
{
Assert( m_pMorph );
m_Info.m_flSpeed = flSpeed;
}
inline void CMorphBuilder::Side1f( float flSide )
{
Assert( m_pMorph );
m_Info.m_flSide = flSide;
}
//-----------------------------------------------------------------------------
// Advance morph
//-----------------------------------------------------------------------------
inline void CMorphBuilder::AdvanceMorph( int nSourceVertex, int nMorphTargetId )
{
Assert( m_pMorph );
m_Info.m_nVertexId = nSourceVertex;
m_Info.m_nMorphTargetId = nMorphTargetId;
m_pMorph->AddMorph( m_Info );
#ifdef _DEBUG
m_Info.m_PositionDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
m_Info.m_NormalDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
m_Info.m_flWrinkleDelta = VEC_T_NAN;
m_Info.m_flSpeed = VEC_T_NAN;
m_Info.m_flSide = VEC_T_NAN;
#endif
}
#endif // IMORPH_H