-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamHandleBlendShapeAnim.cpp
More file actions
304 lines (260 loc) · 8.98 KB
/
StreamHandleBlendShapeAnim.cpp
File metadata and controls
304 lines (260 loc) · 8.98 KB
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
//*****************************************************************************
//
// Copyright (C) 2000-2005 Quantic Dream SA
//
// These coded instructions, statements and computer programs contain
// unpublished information proprietary to Quantic Dream SA and are
// protected by French and EEC copyright laws. They may not be
// disclosed to third parties or copied or duplicated, in whole or in part,
// without prior written consent of Quantic Dream SA
//
// Unpublished-rights reserved under the Copyright Laws of the EEC.
//
//*****************************************************************************
//
// CLASS: STREAM_HANDLE_BLEND_SHAPE_ANIM
//
// 03-06-05: ELE - Created
//*****************************************************************************
#include "Root.h"
#include "StreamHandleBlendShapeAnim.h"
#include INCL_KCORE(Streaming/StreamBlock)
#include INCL_KMATH(Math/Math)
#include INCL_3DENGINE(Behavior/Datas/StreamableBlendShapeAnim/StreamableBlendShapeAnim)
#include INCL_3DENGINE(Behavior/Datas/StreamableBlendShapeAnim/BlendShapeAnimBlock)
#define QDT_INCLUDE_MEMORY
#include INCL_KCORE(Includes/Includes)
//=============================================================================
// CODE STARTS HERE
//=============================================================================
//-----------------------------------------------------------------------------
// Name: STREAM_HANDLE_BLEND_SHAPE_ANIM constructor
// Object:
// 03-06-05: ELE - Created
//-----------------------------------------------------------------------------
STREAM_HANDLE_BLEND_SHAPE_ANIM::STREAM_HANDLE_BLEND_SHAPE_ANIM()
:
_StreamableBlendShapeAnimInst (COM_INSTANCE::NOT_INITIALIZED_AT_CONSTRUCTION)
{
// Do nothing
}
//-----------------------------------------------------------------------------
// Name: STREAM_HANDLE_BLEND_SHAPE_ANIM destructor
// Object:
// 03-06-05: ELE - Created
//-----------------------------------------------------------------------------
STREAM_HANDLE_BLEND_SHAPE_ANIM::~STREAM_HANDLE_BLEND_SHAPE_ANIM()
{
// Do nothing
}
//-----------------------------------------------------------------------------
// Name: SetBlendShapeAnimInst
// Object:
// 03-06-13: ELE - Created
//-----------------------------------------------------------------------------
void STREAM_HANDLE_BLEND_SHAPE_ANIM::SetBlendShapeAnimInst(const COM_INSTANCE & BlendShapeAnimInst)
{
_StreamableBlendShapeAnimInst = BlendShapeAnimInst;
}
//-----------------------------------------------------------------------------
// Name: Play
// Object:
// 03-06-11: ELE - Created
//-----------------------------------------------------------------------------
void STREAM_HANDLE_BLEND_SHAPE_ANIM::Play()
{
// Do nothing
}
//-----------------------------------------------------------------------------
// Name: Stop
// Object:
// 03-06-11: ELE - Created
//-----------------------------------------------------------------------------
void STREAM_HANDLE_BLEND_SHAPE_ANIM::Stop()
{
// Do nothing
}
//-----------------------------------------------------------------------------
// Name: Pause
// Object:
// 03-06-11: ELE - Created
//-----------------------------------------------------------------------------
void STREAM_HANDLE_BLEND_SHAPE_ANIM::Pause()
{
// Do nothing
}
//-----------------------------------------------------------------------------
// Name: Resume
// Object:
// 03-06-11: ELE - Created
//-----------------------------------------------------------------------------
void STREAM_HANDLE_BLEND_SHAPE_ANIM::Resume()
{
// Do nothing
}
//-----------------------------------------------------------------------------
// Name: IsPlaying
// Object:
// 03-06-11: ELE - Created
//-----------------------------------------------------------------------------
bool STREAM_HANDLE_BLEND_SHAPE_ANIM::IsPlaying()
{
return (false);
}
//-----------------------------------------------------------------------------
// Name: GetBSWeightsAt
// Object:
// 03-06-13: ELE - Created
//-----------------------------------------------------------------------------
bool STREAM_HANDLE_BLEND_SHAPE_ANIM::GetBSWeightsAt(Float32 rCurrentFrame,
Float32 * prWeights,
UInt32 WeightCount,
bool bInterpolate)
{
if (GetIsManaged())
{
return (GetManagedBSWeights(prWeights, WeightCount, bInterpolate));
}
else
{
return (GetBSWeights(rCurrentFrame, prWeights, WeightCount, bInterpolate));
}
}
//-----------------------------------------------------------------------------
// Name: GetBSWeights
// Object:
// 03-06-19: AMA - Created
//-----------------------------------------------------------------------------
bool STREAM_HANDLE_BLEND_SHAPE_ANIM::GetBSWeights(Float32 rCurrentFrame,
Float32 * prWeights,
UInt32 WeightCount,
bool bInterpolate)
{
int nID;
Float32 rTime;
bool bValidBlock, bLoaded;
STREAMABLE_BLEND_SHAPE_ANIM *pStreamable;
STREAM_BLOCK *pB;
pStreamable = static_cast<STREAMABLE_BLEND_SHAPE_ANIM *>(_StreamableBlendShapeAnimInst.GetCommunicator());
rTime = rCurrentFrame / pStreamable->GetFPS();
bValidBlock = false;
pB = GetCurrentBlock();
if (pB)
{
if (rTime >= pB->GetStartTime() && rTime <= pB->GetEndTime())
{
bValidBlock = true;
}
}
if (bValidBlock == false)
{
nID = pStreamable->GetBlockIndexFromTime(rTime);
pB = pStreamable->QueryBlock(nID, true, bLoaded);
SetCurrentBlock(pB);
}
UInt32 nNbrWeights = (unsigned int)pStreamable->GetNbrWeights();
if (WeightCount > nNbrWeights)
{
WeightCount = nNbrWeights;
}
if ((rCurrentFrame < 0.0f) || (rCurrentFrame >= pStreamable->GetNbrFrames()))
{
memset(prWeights, 0, WeightCount * sizeof(Float32));
}
else
{
BLEND_SHAPE_ANIM_BLOCK *pBSB = static_cast<BLEND_SHAPE_ANIM_BLOCK *>(pB);
int nStartFrame = (int)(pB->GetStartTime() * pStreamable->GetFPS());
Float32 *pContrib;
pContrib = pBSB->GetWeights();
pContrib += ((int)rCurrentFrame - nStartFrame) * nNbrWeights;
if (bInterpolate)
{
Float32 *pContribNext = pContrib + nNbrWeights;
Float32 rInterCoeff = rCurrentFrame - MATH::Floor(rCurrentFrame);
Float32 rInterCoeff2 = 1.0f - rInterCoeff;
for (UInt32 i = 0 ; i < WeightCount ; ++i)
{
prWeights[i] = (rInterCoeff2 * pContrib[i]) + (rInterCoeff * pContribNext[i]);
}
}
else
{
for (UInt32 i = 0 ; i < WeightCount ; ++i)
{
prWeights[i] = pContrib[i];
}
}
}
return (true);
}
//-----------------------------------------------------------------------------
// Name: GetManagedBSWeights
// Object:
// 03-06-19: AMA - Created
//-----------------------------------------------------------------------------
bool STREAM_HANDLE_BLEND_SHAPE_ANIM::GetManagedBSWeights(Float32 * prWeights,
UInt32 WeightCount,
bool bInterpolate)
{
int nID;
Float32 rCurrentTime = GetTheCurrentTime();
#ifdef PLATFORM_PS2
// Fix pour la synchro labiale sur PS2
// (ATTENTION, fonctionne pour fahrenheit car la taille des blocs est supérieur à 200ms
// et le bloc n+1 est toujours chargé en mémoire (n+2 en cours) )
rCurrentTime += 0.2f;
#elif PLATFORM_PC
rCurrentTime += 0.175f;
#endif
STREAMABLE_BLEND_SHAPE_ANIM *pStreamable;
STREAM_BLOCK *pB;
pStreamable = static_cast<STREAMABLE_BLEND_SHAPE_ANIM *>(_StreamableBlendShapeAnimInst.GetCommunicator());
nID = pStreamable->GetBlockIndexFromTime(rCurrentTime);
pB = pStreamable->GetBlock(nID);
if ( pB == NULL )
{
return (false);
}
UInt32 nNbrWeights = (unsigned int)pStreamable->GetNbrWeights();
if (WeightCount > nNbrWeights)
{
WeightCount = nNbrWeights;
}
Float32 rStreamDuration = pStreamable->GetStreamDuration();
if (rCurrentTime >= rStreamDuration)
{
rCurrentTime = rStreamDuration;
}
BLEND_SHAPE_ANIM_BLOCK *pBSB = static_cast<BLEND_SHAPE_ANIM_BLOCK *>(pB);
int nStartFrame = (int)(pB->GetStartTime() * pStreamable->GetFPS());
Float32 *pContrib;
Float32 rCurrentFrame = rCurrentTime * pStreamable->GetFPS();
pContrib = pBSB->GetWeights();
pContrib += ((int)rCurrentFrame - nStartFrame) * nNbrWeights;
if (rCurrentFrame >= pStreamable->GetNbrFrames())
{
bInterpolate = false;
}
if (bInterpolate)
{
Float32 *pContribNext = pContrib + nNbrWeights;
Float32 rInterCoeff = rCurrentFrame - MATH::Floor(rCurrentFrame);
Float32 rInterCoeff2 = 1.0f - rInterCoeff;
for (UInt32 i = 0 ; i < WeightCount ; ++i)
{
prWeights[i] = (rInterCoeff2 * pContrib[i]) + (rInterCoeff * pContribNext[i]);
}
}
else
{
for (UInt32 i = 0 ; i < WeightCount ; ++i)
{
prWeights[i] = pContrib[i];
}
}
return (true);
}
//=============================================================================
// CODE ENDS HERE
//=============================================================================