5 #include "modelheaders.h" 6 #include "AnimInstanceBase.h" 11 typedef std::pair<uint32, uint32> AnimRange;
14 extern int globalTime;
22 template <
class T,
class D = T,
class Conv = Identity<T> >
40 std::vector<AnimRange> ranges;
41 std::vector<int> times;
44 std::vector<T> in, out;
46 inline static float Absolute1(
float v){
return fabs(v); };
47 inline static float Absolute1(
double v){
return (
float)abs(v); };
48 inline static float Absolute1(
const Vector3& v){
return fabs(v.x) + fabs(v.y) + fabs(v.z); };
49 inline static float Absolute1(
const Quaternion& v){
return fabs(v.x) + fabs(v.y) + fabs(v.z) + fabs(v.w); };
50 inline static float Absolute1(
const Vector2& v){
return fabs(v.x) + fabs(v.y); };
55 int nSize = (int)data.size();
58 auto firstValue = data[0];
59 for (
int i = 1; i < nSize; ++i)
61 if (data[i] != firstValue)
71 int nSize = (int)data.size();
72 for (
int i = 0; i < nSize; ++i)
82 int nSize = (int)data.size();
83 for (
int i = 0; i < nSize; ++i)
85 if (Absolute1(data[i] - key) > fEpsilon)
94 if (type != INTERPOLATION_NONE || data.size() > 1) {
101 if (globals[seq] == 0)
104 time = globalTime % globals[
seq];
106 range.second = (uint32)(data.size()) - 1;
112 if (range.second > range.first)
113 time = times[range.first] + globalTime % (times[range.second] - times[range.first]);
119 if (anim >= 0 && anim < (
int)ranges.size())
121 range = ranges[anim];
131 if (time >= times[range.second])
133 return data[range.second];
135 else if (range.first != range.second && time > times[range.first])
137 size_t pos = range.first;
155 int nStart = (int)range.first;
156 int nEnd = (
int)range.second - 1;
164 int nMid = (nStart + nEnd) / 2;
165 int startP = (times[nMid]);
166 int endP = (times[nMid + 1]);
168 if (startP <= time && time < endP)
173 else if (time < startP)
177 else if (time >= endP)
184 int t2 = times[pos + 1];
185 float r = (time - t1) / (
float)(t2 - t1);
187 if (type == INTERPOLATION_LINEAR)
188 return interpolate<T>(r, data[pos], data[pos + 1]);
189 else if (type == INTERPOLATION_LINEAR_CROSSFRAME)
194 return interpolate<T>(r, data[pos], data[pos + 1]);
200 return interpolate<T>(r, data[pos], data[pos + 1]);
204 return data[range.first];
231 T
getValue(
int nCurrentAnim,
int currentFrame,
int nBlendingAnim,
int blendingFrame,
float blendingFactor)
233 if (blendingFactor == 0.0f)
235 return getValue(nCurrentAnim, currentFrame);
239 if (blendingFactor == 1.0f)
241 return getValue(nBlendingAnim, blendingFrame);
245 T v1 =
getValue(nCurrentAnim, currentFrame);
246 T v2 =
getValue(nBlendingAnim, blendingFrame);
248 return interpolate<T>(blendingFactor, v1, v2);
256 return (Index.Provider == 0) ?
getValue(Index.nIndex, Index.nCurrentFrame) : getDefaultValue();
262 if (blendingFactor == 0.0f)
268 if (blendingFactor == 1.0f)
277 return interpolate<T>(blendingFactor, v1, v2);
282 static T BlendValues(
const T& currentValue,
const T& blendingValue,
float blendingFactor)
284 if (blendingFactor == 0.0f)
290 if (blendingFactor == 1.0f)
292 return blendingValue;
296 return interpolate<T>(blendingFactor, currentValue, blendingValue);
301 void SetRangeByAnimIndex(
int nAnimIndex,
const AnimRange& range)
303 if ((
int)ranges.size() <= nAnimIndex)
304 ranges.resize(nAnimIndex + 1, range);
306 ranges[nAnimIndex] = range;
308 void AppendKey(
int time_,
const T& data_)
310 times.push_back(time_);
311 data.push_back(data_);
314 void UpdateLastKey(
int time_,
const T& data_)
316 int KeyCount = GetKeyNum();
319 times[KeyCount - 1] = time_;
320 data[KeyCount - 1] = data_;
323 AppendKey(time_, data_);
327 return (
int)data.size();
340 int nKeyCount, nFirstKeyIndex, nLastKeyIndex, i, curtime;
342 nLastKeyIndex = nFirstKeyIndex = c_data.GetKeyNum();
345 c_data.AppendKey(times[0], curkey);
348 T lastlastKey = lastKey;
351 nKeyCount = GetKeyNum();
353 for (i = 1; i < nKeyCount; ++i)
358 T predicatedKey = lastKey * 2 - lastlastKey;
359 T delta = (curkey - predicatedKey);
362 if (Absolute1(delta) >= fEpsilon)
365 if (nLastKeyIndex == nFirstKeyIndex)
368 int nKeyIndex = c_data.GetKeyNum() - 1;
369 int nTime = c_data.times[nKeyIndex];
370 c_data.times[nKeyIndex] = 0;
373 c_data.AppendKey(nTime, lastKey);
377 c_data.AppendKey(curtime, curkey);
378 predicatedKey = curkey;
384 c_data.UpdateLastKey(curtime, predicatedKey);
387 lastlastKey = lastKey;
388 lastKey = predicatedKey;
390 if (nFirstKeyIndex == nLastKeyIndex)
391 c_data.UpdateLastKey(0, lastKey);
392 c_data.SetRangeByAnimIndex(0, AnimRange(nFirstKeyIndex, nLastKeyIndex));
396 times = c_data.times;
398 SetRangeByAnimIndex(0, AnimRange(nFirstKeyIndex, nLastKeyIndex));
403 return (
int)data.size();
410 data.resize(nKeyCount);
411 times.resize(nKeyCount);
417 if (nIndex < (
int)times.size())
418 times[nIndex] = nTime;
421 virtual int GetTime(
int nIndex)
423 return (nIndex < (
int)times.size()) ? times[nIndex] : 0;
void CompressKeyLinear(float fEpsilon)
if multiple adjacent keys can be linearly interpolated and get an error smaller than fEpsilon...
Definition: animated.h:335
bool CheckIsAnimated()
check if all key are equal
Definition: animated.h:53
int * globals
a reference to the global sequence object which is an array of time ranges for global sequences...
Definition: animated.h:38
T getValue(int anim, int time)
this function will return the interpolated animation vector at the specified anim id and frame number...
Definition: animated.h:92
different physics engine has different winding order.
Definition: EventBinding.h:32
int seq
Definition: animated.h:36
Implementation of a Quaternion, i.e.
Definition: ParaQuaternion.h:10
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
Definition: animated.h:23
T getValue(const AnimIndex &Index)
it accept anim index of both local and external animation
Definition: animated.h:254
bool used
whether it is a constant value(not animated).
Definition: animated.h:26
base class for AnimatedVariable.
Definition: IAnimated.h:18
void SetConstantKey(T key)
if all animated values equals to the key, this animation will be set unused
Definition: animated.h:69
void SetConstantKey(T key, float fEpsilon)
if all animated values are very close to a given key, this animation will be set unused ...
Definition: animated.h:80
it presents a given in bone animation providers or parax local model bone animation pools ...
Definition: AnimInstanceBase.h:13
virtual void SetTime(int nIndex, int nTime)
only applied to Animated attribute
Definition: animated.h:415
T getValue(const AnimIndex &CurrentAnim, const AnimIndex &BlendingAnim, float blendingFactor)
it accept anim index of both local and external animation
Definition: animated.h:260
virtual void SetNumKeys(int nKeyCount)
get set the total number of animated keys.
Definition: animated.h:406
virtual int GetNumKeys()
get total number of animated keys.
Definition: animated.h:401
T getValue(int nCurrentAnim, int currentFrame, int nBlendingAnim, int blendingFrame, float blendingFactor)
get value with motion blending with a specified blending frame.
Definition: animated.h:231
int type
interpolation of type Interpolations
Definition: animated.h:30