I am reverse engineering a video games animation files and have run into a brick wall. The animation sets are structured as follows:
For each animation set:
- Animation Set Name: Attack
- Number of Bones: 22
- Duration: 1.03333
and subsequently for each bone in the set:
- Bone Name: Pelvis
- Bone ID: 0
- Key Interval: 0.0333333
- Keys: 31
and then the following data is broken up into 7 channels (Position[x,y,z]
and Rotation quaternion[x,y,z,w]
):
Position[x,y,z] are either Constant or Original Values and I have no trouble here.
But the Rotation quaternion[x,y,z,w] channels are interpreted as Splines with N Segments and N Coefficients and I'm having trouble figuring out exactly how I would evaluate the Splines into data I can punch into a 3D program.
I know that each channel's spline is plotted as Y and X would equal normalized time (0 to 1).
This Q+A ( Evaluating Polynomial coefficients ) seems to be what I need:
A polynomial of degree n with coefficient a0, a1, a2, a3........an is the function
p(x)= a0+a1*x+a2*x^2+a3*x^3+.....+an*x^n
and written as Python code:
def poly(lst, x):
n, tmp = 0, 0
for a in lst:
tmp = tmp + (a * (x**n))
n += 1
return tmp
But I'm not sure I'm doing it right when i put lst
as the coefficients for each segment and x = Duration / Keys
.
Here is the first animation set's 'Rot.x' channel and its Segments and Coefficients:
Segments = 3
Segment 1
- Coeff1: 0.0198117
- Coeff2: 0.00826611
- Coeff3: 0.0521381
- Coeff4: -0.00210184
Segment 2
- Coeff1: -0.181324
- Coeff2: 1.09073
- Coeff3: -1.77627
- Coeff4: 0.920407
Segment 3
- Coeff1: -0.0335189
- Coeff2: 0.265863
- Coeff3: -0.359457
- Coeff4: 0.147228
The way I'm looking at this is each segment is 1/3 of the duration (1.03333) and furthermore each segments coefficients are to be evaluated over 1/3 of the number of keys (31), but the output using the above poly(lst, x)
function for
- segment 1 = from 0.019 to 4.90 to -7.15
- segment 2 = from -0.18 to 20985.41
- segment 3 = from -0.03 to 3296.11
Obviously I'm doing something wrong since the output is way too high.
Any help would greatly be appreciated!