Improved animations game replication and performance

This commit is contained in:
dexy 2022-01-28 06:25:41 +11:00
parent 73402373e3
commit bc14a1fd22
3 changed files with 31 additions and 12 deletions

View File

@ -922,7 +922,7 @@ namespace CodeWalker.GameFiles
var aseq = seq.Sequences[boneIndex];
var q0 = aseq.EvaluateQuaternion(f0);
var q1 = aseq.EvaluateQuaternion(f1);
var q = interpolate ? Quaternion.Slerp(q0, q1, frame.Alpha1) : q0;
var q = interpolate ? QuaternionExtension.FastLerp(q0, q1, frame.Alpha1) : q0;
return q;
}

View File

@ -2233,19 +2233,27 @@ namespace CodeWalker.GameFiles
public void UpdateAnimTransform()
{
//AnimTransform = Matrix.AffineTransformation(1.0f, AnimRotation, AnimTranslation);//(local transform)
var pos = AnimTranslation;
var ori = AnimRotation;
var sca = AnimScale;
var pbone = Parent;
while (pbone != null)
AnimTransform = Matrix.AffineTransformation(1.0f, AnimRotation, AnimTranslation);
AnimTransform.ScaleVector *= AnimScale;
if (Parent != null)
{
pos = pbone.AnimRotation.Multiply(pos /** pbone.AnimScale*/) + pbone.AnimTranslation;
ori = pbone.AnimRotation * ori;
pbone = pbone.Parent;
AnimTransform = AnimTransform * Parent.AnimTransform;
}
AnimTransform = Matrix.AffineTransformation(1.0f, ori, pos);//(global transform)
AnimTransform.ScaleVector *= sca;
////AnimTransform = Matrix.AffineTransformation(1.0f, AnimRotation, AnimTranslation);//(local transform)
//var pos = AnimTranslation;
//var ori = AnimRotation;
//var sca = AnimScale;
//var pbone = Parent;
//while (pbone != null)
//{
// pos = pbone.AnimRotation.Multiply(pos /** pbone.AnimScale*/) + pbone.AnimTranslation;
// ori = pbone.AnimRotation * ori;
// pbone = pbone.Parent;
//}
//AnimTransform = Matrix.AffineTransformation(1.0f, ori, pos);//(global transform)
//AnimTransform.ScaleVector *= sca;
}
public void UpdateSkinTransform()
{

View File

@ -67,6 +67,17 @@ namespace CodeWalker
return new Vector4(q.X, q.Y, q.Z, q.W);
}
public static Quaternion FastLerp(Quaternion a, Quaternion b, float v)
{
var r = new Quaternion();
var vi = 1.0f - v;
r.X = vi * a.X + v * b.X;
r.Y = vi * a.Y + v * b.Y;
r.Z = vi * a.Z + v * b.Z;
r.W = vi * a.W + v * b.W;
r.Normalize();
return r;
}
}