Animations now playing sequences correctly

This commit is contained in:
dexy 2019-11-08 22:55:39 +11:00
parent d60234469a
commit 87092996f8
2 changed files with 53 additions and 132 deletions

View File

@ -804,13 +804,6 @@ namespace CodeWalker.GameFiles
public AnimSequence[] Sequences { get; set; } public AnimSequence[] Sequences { get; set; }
// //Original testing parsed data
//public SequencePart1[] FrameData { get; set; }
//public ushort[] Part2 { get; set; }
//public int Part2Count { get; set; }
//public int Part2Offset { get; set; }
//public static Dictionary<ushort, int> SeqDict = new Dictionary<ushort, int>();
class AnimChannelListItem class AnimChannelListItem
{ {
@ -845,77 +838,6 @@ namespace CodeWalker.GameFiles
this.Data = reader.ReadBytes((int)DataLength); this.Data = reader.ReadBytes((int)DataLength);
#region //old dexyfex testing code
/*
if (Unused_08h != 0)
{ }
if (Unused_14h != 0)
{ }
if (UnkLength != (DataLength + 32)) //sometimes this is true
{ }
if ((FrameLength % 4) > 0)
{ }
int offset = (int)FrameOffset;
if (FrameLength > 0)
{
FrameData = new SequencePart1[NumFrames];
for (int i = 0; i < NumFrames; i++)
{
var sp = new SequencePart1();
sp.Init(Data, offset, FrameLength);
FrameData[i] = sp;
offset += FrameLength;
}
}
else if (NumFrames != 0)
{ }
int brem = (int)DataLength - offset;
int p2cnt = brem / 2;
if (p2cnt > 0)
{
Part2Offset = offset;
Part2Count = p2cnt;
Part2 = new ushort[p2cnt];
for (int i = 0; i < p2cnt; i++)
{
Part2[i] = BitConverter.ToUInt16(Data, offset);
offset += 2;
}
}
else
{ }
if (offset != DataLength)
{ } //no hits here!
//if (SeqDict.ContainsKey(Unknown_1Ah)) SeqDict[Unknown_1Ah]++;
//else SeqDict[Unknown_1Ah] = 1;
if ((Unknown_1Ah != 0) && (Unknown_1Ah > FrameOffset))
{ }
if ((Unknown_1Ch != 0) && (Unknown_1Ch > FrameOffset))
{ }
switch (ChunkSize)
{
case 64: //0x40
case 255: //0xFF
break;
default://no hits
break;
}
switch (Unknown_1Fh_Type)
{
case 0:
case 17: //0x11
case 20: //0x14
case 21: //0x15
case 49: //0x31
case 52: //0x34
case 53: //0x35
break;
default: //no hits
break;
}
*/
#endregion
int Part2Offset = 0;//replacement calculation from old dexyfex parsing code int Part2Offset = 0;//replacement calculation from old dexyfex parsing code
int offset = (int)FrameOffset + (FrameLength * NumFrames); int offset = (int)FrameOffset + (FrameLength * NumFrames);

View File

@ -430,11 +430,9 @@ namespace CodeWalker.Rendering
var clipanimlist = cme.Clip as ClipAnimationList; var clipanimlist = cme.Clip as ClipAnimationList;
if (clipanimlist?.Animations != null) if (clipanimlist?.Animations != null)
{ {
//float t = clipanimlist.GetPlaybackTime(CurrentAnimTime);
foreach (var canim in clipanimlist.Animations) foreach (var canim in clipanimlist.Animations)
{ {
if (canim?.Animation == null) continue; if (canim?.Animation == null) continue;
//UpdateAnim(canim.Animation, t*canim.Rate + canim.StartTime);
UpdateAnim(canim.Animation, canim.GetPlaybackTime(CurrentAnimTime)); UpdateAnim(canim.Animation, canim.GetPlaybackTime(CurrentAnimTime));
} }
} }
@ -458,7 +456,7 @@ namespace CodeWalker.Rendering
var curPos = (t/duration) * nframes; var curPos = (t/duration) * nframes;
var frame0 = ((ushort)curPos) % frames; var frame0 = ((ushort)curPos) % frames;
var frame1 = (frame0 + 1) % frames; var frame1 = (frame0 + 1);// % frames;
var falpha = (float)(curPos - Math.Floor(curPos)); var falpha = (float)(curPos - Math.Floor(curPos));
var ialpha = 1.0f - falpha; var ialpha = 1.0f - falpha;
@ -482,45 +480,46 @@ namespace CodeWalker.Rendering
if (bone == null) if (bone == null)
{ continue; } { continue; }
var sfl = anim.SequenceFrameLimit;
var s = frame0 / sfl;
int f0 = frame0 % sfl;
int f1 = f0 + 1;
for (int s = 0; s < anim.Sequences.data_items.Length; s++) var seq = anim.Sequences.data_items[s];
var aseq = seq.Sequences[i];
switch (track)
{ {
var seq = anim.Sequences.data_items[s]; case 0: //bone position
var aseq = seq.Sequences[i]; v0 = aseq.EvaluateVector(f0);
switch (track) v1 = aseq.EvaluateVector(f1);
{ v = interpolate ? (v0 * ialpha) + (v1 * falpha) : v0;
case 0: //bone position bone.AnimTranslation = v.XYZ();
v0 = aseq.EvaluateVector(frame0); break;
v1 = aseq.EvaluateVector(frame1); case 1: //bone orientation
v = interpolate ? (v0 * ialpha) + (v1 * falpha) : v0; q0 = new Quaternion(aseq.EvaluateVector(f0));
bone.AnimTranslation = v.XYZ(); q1 = new Quaternion(aseq.EvaluateVector(f1));
break; q = interpolate ? Quaternion.Slerp(q0, q1, falpha) : q0;
case 1: //bone orientation bone.AnimRotation = q;
q0 = new Quaternion(aseq.EvaluateVector(frame0)); break;
q1 = new Quaternion(aseq.EvaluateVector(frame1)); case 2: //scale?
q = interpolate ? Quaternion.Slerp(q0, q1, falpha) : q0; break;
bone.AnimRotation = q; case 5://vector3...
break; //v0 = aseq.EvaluateVector(f0);
case 2: //scale? //v1 = aseq.EvaluateVector(f1);
break; //v = interpolate ? (v0 * ialpha) + (v1 * falpha) : v0;
case 5://vector3... //bone.AnimScale = v.XYZ();
//v0 = aseq.EvaluateVector(frame0); break;
//v1 = aseq.EvaluateVector(frame1); case 6://quaternion...
//v = interpolate ? (v0 * ialpha) + (v1 * falpha) : v0; break;
//bone.AnimScale = v.XYZ(); case 134://single float?
break; case 136:
case 6://quaternion... case 137:
break; case 138:
case 134://single float? case 139:
case 136: case 140:
case 137: break;
case 138: default:
case 139: break;
case 140:
break;
default:
break;
}
} }
} }
@ -562,11 +561,9 @@ namespace CodeWalker.Rendering
var clipanimlist = cme.Clip as ClipAnimationList; var clipanimlist = cme.Clip as ClipAnimationList;
if (clipanimlist?.Animations != null) if (clipanimlist?.Animations != null)
{ {
//float t = clipanimlist.GetPlaybackTime(CurrentAnimTime);
foreach (var canim in clipanimlist.Animations) foreach (var canim in clipanimlist.Animations)
{ {
if (canim?.Animation == null) continue; if (canim?.Animation == null) continue;
//UpdateAnimUV(canim.Animation, t * canim.Rate + canim.StartTime, rgeom);
UpdateAnimUV(canim.Animation, canim.GetPlaybackTime(CurrentAnimTime), rgeom); UpdateAnimUV(canim.Animation, canim.GetPlaybackTime(CurrentAnimTime), rgeom);
} }
} }
@ -590,7 +587,7 @@ namespace CodeWalker.Rendering
var curPos = (t / duration) * nframes; var curPos = (t / duration) * nframes;
var frame0 = ((ushort)curPos) % frames; var frame0 = ((ushort)curPos) % frames;
var frame1 = (frame0 + 1) % frames; var frame1 = (frame0 + 1);// % frames;
var falpha = (float)(curPos - Math.Floor(curPos)); var falpha = (float)(curPos - Math.Floor(curPos));
var ialpha = 1.0f - falpha; var ialpha = 1.0f - falpha;
@ -605,18 +602,20 @@ namespace CodeWalker.Rendering
if ((track != 17) && (track != 18)) if ((track != 17) && (track != 18))
{ continue; }//17 and 18 would be UV0 and UV1 { continue; }//17 and 18 would be UV0 and UV1
for (int s = 0; s < anim.Sequences.data_items.Length; s++) var sfl = anim.SequenceFrameLimit;
var s = frame0 / sfl;
int f0 = frame0 % sfl;
int f1 = f0 + 1;
var seq = anim.Sequences.data_items[s];
var aseq = seq.Sequences[i];
var v0 = aseq.EvaluateVector(f0);
var v1 = aseq.EvaluateVector(f1);
var v = interpolate ? (v0 * ialpha) + (v1 * falpha) : v0;
switch (track)
{ {
var seq = anim.Sequences.data_items[s]; case 17: globalAnimUV0 = v; break; //could be overwriting values here...
var aseq = seq.Sequences[i]; case 18: globalAnimUV1 = v; break;
var v0 = aseq.EvaluateVector(frame0);
var v1 = aseq.EvaluateVector(frame1);
var v = interpolate ? (v0 * ialpha) + (v1 * falpha) : v0;
switch (track)
{
case 17: globalAnimUV0 = v; break; //could be overwriting values here...
case 18: globalAnimUV1 = v; break;
}
} }
} }