Nebula
Loading...
Searching...
No Matches
animjobutil.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
10#include "math/float4.h"
11#include "math/quaternion.h"
13#include "characters/characterjointmask.h"
14
15namespace CoreAnimation
16{
17
18using namespace Math;
19
20//------------------------------------------------------------------------------
24inline void
26 int numCurves,
27 const float4& velocityScale,
28 const float4* src0SamplePtr,
29 float4* outSamplePtr,
30 uchar* outSampleCounts)
31{
32 float4 f0;
33 int i;
34 for (i = 0; i < numCurves; i++)
35 {
36 const AnimCurve& curve = curves[i];
37 if (!curve.IsActive())
38 {
39 // an inactive curve, set sample count to 0
40 outSampleCounts[i] = 0;
41 }
42 else
43 {
44 // curve is active, set sample count to 1
45 outSampleCounts[i] = 1;
46
47 if (curve.IsStatic())
48 {
49 f0 = curve.GetStaticKey();
50 }
51 else
52 {
53 f0.load((scalar*)src0SamplePtr);
54 src0SamplePtr++;
55 }
56
57 // if a velocity curve, multiply the velocity scale
58 // (this is necessary if time factor is != 1)
59 if (curve.GetCurveType() == CurveType::Velocity)
60 {
61 f0 = float4::multiply(f0, velocityScale);
62 }
63 f0.store((scalar*)outSamplePtr);
64 }
65 outSamplePtr++;
66 }
67}
68
69//------------------------------------------------------------------------------
73inline void
75 int numCurves,
76 float sampleWeight,
77 const float4& velocityScale,
78 const float4* src0SamplePtr,
79 const float4* src1SamplePtr,
80 float4* outSamplePtr,
81 uchar* outSampleCounts)
82{
83 float4 f0, f1, fDst;
84 quaternion q0, q1, qDst;
85 int i;
86 for (i = 0; i < numCurves; i++)
87 {
88 const AnimCurve& curve = curves[i];
89 if (!curve.IsActive())
90 {
91 // an inactive curve, set sample count to 0
92 outSampleCounts[i] = 0;
93 }
94 else
95 {
96 CurveType::Code curveType = curve.GetCurveType();
97
98 // curve is active, set sample count to 1
99 outSampleCounts[i] = 1;
100
101 if (curve.IsStatic())
102 {
103 // a static curve, just copy the curve's static key as output
104 f0 = curve.GetStaticKey();
105 if (CurveType::Velocity == curveType)
106 {
107 f0 = float4::multiply(f0, velocityScale);
108 }
109 f0.store((scalar*)outSamplePtr);
110 }
111 else
112 {
113 if (curve.GetCurveType() == CurveType::Rotation)
114 {
115 q0.load((scalar*)src0SamplePtr);
116 q1.load((scalar*)src1SamplePtr);
117 qDst = quaternion::slerp(q0, q1, sampleWeight);
118 qDst.store((scalar*)outSamplePtr);
119 }
120 else
121 {
122 f0.load((scalar*)src0SamplePtr);
123 f1.load((scalar*)src1SamplePtr);
124 fDst = float4::lerp(f0, f1, sampleWeight);
125 if (CurveType::Velocity == curveType)
126 {
127 fDst = float4::multiply(fDst, velocityScale);
128 }
129 fDst.store((scalar*)outSamplePtr);
130 }
131 src0SamplePtr++;
132 src1SamplePtr++;
133 }
134 }
135 outSamplePtr++;
136 }
137}
138
139//------------------------------------------------------------------------------
152inline void
154 int numCurves,
155 const Characters::CharacterJointMask* mask,
156 float mixWeight,
157 const float4* src0SamplePtr,
158 const float4* src1SamplePtr,
159 const uchar* src0SampleCounts,
160 const uchar* src1SampleCounts,
161 float4* outSamplePtr,
162 uchar* outSampleCounts)
163{
164 float4 f0, f1, fDst;
165 quaternion q0, q1, qDst;
166 int i;
167 for (i = 0; i < numCurves; i++)
168 {
169 const AnimCurve& curve = curves[i];
170 uchar src0Count = src0SampleCounts[i];
171 uchar src1Count = src1SampleCounts[i];
172
173 // update dst sample counts
174 outSampleCounts[i] = src0Count + src1Count;
175
176 if ((src0Count > 0) && (src1Count > 0))
177 {
178 float maskWeight = 1;
179
180 // we have 4 curves per joint
181 if (mask != 0) maskWeight = mask->GetWeight(i/4);
182
183 // both samples valid, perform normal mixing
184 if (curve.GetCurveType() == CurveType::Rotation)
185 {
186 q0.load((scalar*)src0SamplePtr);
187 q1.load((scalar*)src1SamplePtr);
188 qDst = quaternion::slerp(q0, q1, mixWeight * maskWeight);
189 qDst.store((scalar*)outSamplePtr);
190 }
191 else
192 {
193 f0.load((scalar*)src0SamplePtr);
194 f1.load((scalar*)src1SamplePtr);
195 fDst = float4::lerp(f0, f1, mixWeight * maskWeight);
196 fDst.store((scalar*)outSamplePtr);
197 }
198 }
199 else if (src0Count > 0)
200 {
201 // only "left" sample is valid
202 f0.load((scalar*)src0SamplePtr);
203 f0.store((scalar*)outSamplePtr);
204 }
205 else if (src1Count > 0)
206 {
207 // only "right" sample is valid
208 f1.load((scalar*)src1SamplePtr);
209 f1.store((scalar*)outSamplePtr);
210 }
211 else
212 {
213 // neither the left nor the right sample is valid,
214 // sample key is undefined
215 }
216
217 // update pointers
218 src0SamplePtr++;
219 src1SamplePtr++;
220 outSamplePtr++;
221 }
222}
223
224} // namespace CoreAnimation
An animation curve describes a set of animation keys in an AnimKeyBuffer.
Definition animcurve.h:28
Code
animation curve types, keep this order!
Definition curvetype.h:25
@ Rotation
Definition curvetype.h:27
@ Velocity
Definition curvetype.h:30
An animation resource holds a set of animations from a loaded NAX file.
Definition charactercontext.h:40
void AnimJobUtilSampleStep(const AnimCurve *curves, int numCurves, const float4 &velocityScale, const float4 *src0SamplePtr, float4 *outSamplePtr, uchar *outSampleCounts)
Sampler for "step" interpolation type.
Definition animjobutil.h:25
void AnimJobUtilSampleLinear(const AnimCurve *curves, int numCurves, float sampleWeight, const float4 &velocityScale, const float4 *src0SamplePtr, const float4 *src1SamplePtr, float4 *outSamplePtr, uchar *outSampleCounts)
Sampler for "linear" interpolation type.
Definition animjobutil.h:74
void AnimJobUtilMix(const AnimCurve *curves, int numCurves, const Characters::CharacterJointMask *mask, float mixWeight, const float4 *src0SamplePtr, const float4 *src1SamplePtr, const uchar *src0SampleCounts, const uchar *src1SampleCounts, float4 *outSamplePtr, uchar *outSampleCounts)
Mixes 2 source sample buffers into a destination sample buffer using a single lerp-value between 0....
Definition animjobutil.h:153
Different curves.
Definition angularpfeedbackloop.h:17
float scalar
Definition scalar.h:45
Definition scalar.h:76
unsigned char uchar
Definition types.h:33