1
0
mirror of synced 2024-12-01 02:27:22 +01:00

More progress on seanim importing

This commit is contained in:
KillzXGaming 2019-05-26 11:32:12 -04:00
parent d73c607f15
commit 9b0883150a
7 changed files with 88 additions and 0 deletions

Binary file not shown.

View File

@ -9,6 +9,86 @@ namespace Switch_Toolbox.Library.Animations
{
Animation anim = new Animation();
var seanim = SEAnim.Read(FileName);
anim.FrameCount = seanim.FrameCount;
anim.CanLoop = seanim.Looping;
foreach (var bone in seanim.Bones)
{
var boneAnim = new Animation.KeyNode(bone);
anim.Bones.Add(boneAnim);
if (seanim.AnimationPositionKeys.ContainsKey(bone))
{
var translationKeys = seanim.AnimationPositionKeys[bone];
foreach (SEAnimFrame animFrame in translationKeys)
{
boneAnim.XPOS.Keys.Add(new Animation.KeyFrame()
{
Value = (float)((SELib.Utilities.Vector3)animFrame.Data).X,
Frame = animFrame.Frame,
});
boneAnim.YPOS.Keys.Add(new Animation.KeyFrame()
{
Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Y,
Frame = animFrame.Frame,
});
boneAnim.ZPOS.Keys.Add(new Animation.KeyFrame()
{
Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Z,
Frame = animFrame.Frame,
});
}
}
if (seanim.AnimationRotationKeys.ContainsKey(bone))
{
var rotationnKeys = seanim.AnimationRotationKeys[bone];
foreach (SEAnimFrame animFrame in rotationnKeys)
{
boneAnim.XROT.Keys.Add(new Animation.KeyFrame()
{
Value = (float)((SELib.Utilities.Vector3)animFrame.Data).X,
Frame = animFrame.Frame,
});
boneAnim.YROT.Keys.Add(new Animation.KeyFrame()
{
Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Y,
Frame = animFrame.Frame,
});
boneAnim.ZROT.Keys.Add(new Animation.KeyFrame()
{
Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Z,
Frame = animFrame.Frame,
});
}
}
if (seanim.AnimationScaleKeys.ContainsKey(bone))
{
var scaleKeys = seanim.AnimationRotationKeys[bone];
foreach (SEAnimFrame animFrame in scaleKeys)
{
var quat = ((SELib.Utilities.Quaternion)animFrame.Data);
var euler = STMath.ToEulerAngles(quat.X, quat.Y, quat.Z, quat.W);
boneAnim.XSCA.Keys.Add(new Animation.KeyFrame()
{
Value = euler.X,
Frame = animFrame.Frame,
});
boneAnim.YSCA.Keys.Add(new Animation.KeyFrame()
{
Value = euler.Y,
Frame = animFrame.Frame,
});
boneAnim.ZSCA.Keys.Add(new Animation.KeyFrame()
{
Value = euler.Z,
Frame = animFrame.Frame,
});
}
}
}
return anim;
}

View File

@ -40,6 +40,14 @@ namespace Switch_Toolbox.Library
//From https://github.com/Ploaj/SSBHLib/blob/e37b0d83cd088090f7802be19b1d05ec998f2b6a/CrossMod/Tools/CrossMath.cs#L42
//Seems to give good results
public static Vector3 ToEulerAngles(double X, double Y, double Z, double W) {
return ToEulerAngles(new Quaternion((float)X, (float)Y, (float)Z, (float)W));
}
public static Vector3 ToEulerAngles(float X, float Y, float Z, float W) {
return ToEulerAngles(new Quaternion(X, Y, Z, W));
}
public static Vector3 ToEulerAngles(Quaternion q)
{
Matrix4 mat = Matrix4.CreateFromQuaternion(q);