Some adjustments for animations

This commit is contained in:
KillzXGaming 2019-05-17 21:09:24 -04:00
parent 7f582adbaf
commit b759a293fe
11 changed files with 22 additions and 37 deletions

Binary file not shown.

View file

@ -18,20 +18,6 @@ namespace Bfres.Structs
public int[] Node_Array;
public fsklNode node;
public List<Matrix4> GetInverseMatrices()
{
List<Matrix4> matrices = new List<Matrix4>();
foreach (var bn in bones)
{
Console.WriteLine(bn.Text);
Console.WriteLine(bn.CalculateSmoothMatrix());
matrices.Add(bn.CalculateSmoothMatrix());
}
return matrices;
}
public void CalculateIndices()
{
if (node.SkeletonU != null)

View file

@ -221,6 +221,8 @@ namespace Bfres.Structs
Nodes.Clear();
Bones.Clear();
CanLoop = ska.FlagsAnimSettings.HasFlag(SkeletalAnimFlags.Looping);
for (int i = 0; i < ska.BoneAnims.Count; i++)
{
var bn = ska.BoneAnims[i];
@ -283,6 +285,8 @@ namespace Bfres.Structs
Nodes.Clear();
Bones.Clear();
CanLoop = ska.FlagsAnimSettings.HasFlag(ResU.SkeletalAnimFlags.Looping);
foreach (ResU.BoneAnim bn in ska.BoneAnims)
{
BoneAnimNode bone = new BoneAnimNode(bn.Name, false);

View file

@ -23,6 +23,8 @@ namespace Switch_Toolbox.Library.Animations
public class Animation : STGenericWrapper
{
public bool CanLoop { get; set; }
//Use to load data when clicked on. Can potentially speed up load times
public virtual void OpenAnimationData() { }
@ -144,6 +146,15 @@ namespace Switch_Toolbox.Library.Animations
return pos;
}
public Matrix4 Transform(float Frame)
{
Matrix4 Translaton = Matrix4.CreateTranslation(GetPosition(Frame));
Matrix4 Rotation = Matrix4.CreateFromQuaternion(GetRotation(Frame));
Matrix4 Scale = Matrix4.CreateScale(GetScale(Frame));
return (Scale * Rotation * Translaton);
}
public Quaternion GetRotation(float frame)
{
Quaternion rot = new Quaternion();
@ -504,7 +515,6 @@ namespace Switch_Toolbox.Library.Animations
if (Frame == 0 && !isChild)
skeleton.reset();
foreach (object child in Children)
{
if (child is Animation)
@ -517,7 +527,6 @@ namespace Switch_Toolbox.Library.Animations
bool Updated = false; // no need to update skeleton of animations that didn't change
foreach (KeyNode node in Bones)
{
// Get Skeleton Node
STBone b = null;
b = skeleton.GetBone(node.Text);

View file

@ -8,6 +8,7 @@ namespace Switch_Toolbox.Library.Animations
public static void SaveAnimation(string FileName, Animation anim, STSkeleton skeleton)
{
SEAnim seAnim = new SEAnim();
seAnim.Looping = anim.CanLoop;
//Reset active animation to 0
anim.SetFrame(0);
@ -18,16 +19,15 @@ namespace Switch_Toolbox.Library.Animations
foreach (Animation.KeyNode boneAnim in anim.Bones)
{
STBone bone = skeleton.GetBone(boneAnim.Text);
if (bone == null) continue;
Vector3 position = bone.GetPosition();
Quaternion rotation = bone.GetRotation();
Vector3 scale = bone.GetScale();
seAnim.AddTranslationKey(boneAnim.Text, frame, bone.pos.X, bone.pos.Y, bone.pos.Z);
seAnim.AddRotationKey(boneAnim.Text, frame, bone.rot.X, bone.rot.Y, bone.rot.Z, bone.rot.W);
//seAnim.AddScaleKey(boneAnim.Text, frame, scale.X, scale.Y, scale.Z);
seAnim.AddTranslationKey(boneAnim.Text, frame, position.X, position.Y, position.Z);
seAnim.AddRotationKey(boneAnim.Text, frame, rotation.X, rotation.Y, rotation.Z, rotation.W);
seAnim.AddScaleKey(boneAnim.Text, frame, scale.X, scale.Y, scale.Z);
}
}

View file

@ -161,21 +161,7 @@ namespace Switch_Toolbox.Library
SelectedImageKey = "bone";
}
public Matrix4 CalculateSmoothMatrix()
{
Matrix4 mat4 = new Matrix4();
return Transform * invert;
}
public Matrix4 CalculateRigidMatrix()
{
Matrix4 mat4 = new Matrix4();
return mat4;
}
public void Render()
public void RenderLegacy()
{
if (!Runtime.OpenTKInitialized || !Runtime.renderBones)
return;

View file

@ -92,7 +92,7 @@ namespace Switch_Toolbox.Library
foreach (STBone bn in bones)
{
bn.Render();
bn.RenderLegacy();
}
}
@ -103,7 +103,7 @@ namespace Switch_Toolbox.Library
foreach (STBone bn in bones)
{
bn.Render();
bn.RenderLegacy();
}
}