1
0
mirror of synced 2025-01-19 01:14:08 +01:00

Add option to configure the rotation of the bones manually

This commit is contained in:
KillzXGaming 2019-05-25 14:27:39 -04:00
parent 60fd66a27d
commit e720214b5e
9 changed files with 148 additions and 81 deletions

Binary file not shown.

View File

@ -513,18 +513,30 @@ namespace BrawlboxHelper
if (entry.UseModelScale)
boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
var FirstFrame = entry.GetAnimFrame(0);
float xRadian = FirstFrame.Rotation._x * Deg2Rad;
float yRadian = FirstFrame.Rotation._y * Deg2Rad;
float zRadian = FirstFrame.Rotation._z * Deg2Rad;
var baseData = new BoneAnimData();
baseData.Translate = new Vector3F(FirstFrame.Translation._x, FirstFrame.Translation._y, FirstFrame.Translation._z);
baseData.Rotate = new Vector4F(xRadian, yRadian, zRadian, 1);
baseData.Scale = new Vector3F(FirstFrame.Scale._x, FirstFrame.Scale._y, FirstFrame.Scale._z);
baseData.Flags = 0;
boneAnim.BaseData = baseData;
var FirstFrame = entry.GetAnimFrame(0);
if (FirstFrame.HasKeys)
{
float xRadian = FirstFrame.Rotation._x * Deg2Rad;
float yRadian = FirstFrame.Rotation._y * Deg2Rad;
float zRadian = FirstFrame.Rotation._z * Deg2Rad;
baseData.Translate = new Vector3F(FirstFrame.Translation._x, FirstFrame.Translation._y, FirstFrame.Translation._z);
baseData.Rotate = new Vector4F(xRadian, yRadian, zRadian, 1);
baseData.Scale = new Vector3F(FirstFrame.Scale._x, FirstFrame.Scale._y, FirstFrame.Scale._z);
baseData.Flags = 0;
boneAnim.BaseData = baseData;
}
else
{
baseData.Translate = new Vector3F(0,0,0);
baseData.Rotate = new Vector4F(0, 0, 0, 1);
baseData.Scale = new Vector3F(1, 1, 1);
baseData.Flags = 0;
boneAnim.BaseData = baseData;
}
boneAnim.FlagsBase |= BoneAnimFlagsBase.Translate;
boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
@ -642,61 +654,31 @@ namespace BrawlboxHelper
List<float> Frames = new List<float>();
List<float> Keys = new List<float>();
CHRAnimationFrame ain, aout;
for (int frame = 0; frame < entry.FrameCount; frame++)
{
//Max of 4 values. Cubic using 4, linear using 2, and step using 1
float[] KeyValues = new float[4];
//Set the main values to the curve based on offset for encoding later
var AnimFrame = entry.GetAnimFrame(frame);
if (AnimFrame.hasTx && AnimOffset == 0x10)
if ((ain = entry.GetAnimFrame(frame)).HasKeys)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Translation._x);
}
if (AnimFrame.hasTy && AnimOffset == 0x14)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Translation._y);
}
if (AnimFrame.hasTz && AnimOffset == 0x18)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Translation._z);
}
if (AnimFrame.hasRx && AnimOffset == 0x20)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Rotation._x * Deg2Rad);
}
if (AnimFrame.hasRy && AnimOffset == 0x24)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Rotation._y * Deg2Rad);
}
if (AnimFrame.hasRz && AnimOffset == 0x28)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Rotation._z * Deg2Rad);
}
if (AnimFrame.hasSx && AnimOffset == 0x04)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Scale._x);
}
if (AnimFrame.hasSy && AnimOffset == 0x08)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Scale._y);
}
if (AnimFrame.hasSz && AnimOffset == 0x0C)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Scale._z);
aout = entry.GetAnimFrame(frame, true);
FillKeyList(aout, frame, curve.AnimDataOffset, Frames, Keys);
Console.WriteLine(aout);
if (!ain.Equals(aout))
{
FillKeyList(aout, frame, curve.AnimDataOffset, Frames, Keys);
}
}
}
Console.WriteLine($"AnimOffset {AnimOffset} Keys {Keys.Count}");
if (Frames.Count <= 0)
return null;
// Console.WriteLine($"AnimOffset {AnimOffset} Keys {Keys.Count}");
//Max value in frames is our end frame
curve.EndFrame = Frames.Max();
@ -755,6 +737,55 @@ namespace BrawlboxHelper
return curve;
}
private static void FillKeyList(CHRAnimationFrame AnimFrame, int frame, uint AnimOffset, List<float> Frames, List<float> Keys)
{
if (AnimFrame.hasTx && AnimOffset == 0x10)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Translation._x);
}
if (AnimFrame.hasTy && AnimOffset == 0x14)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Translation._y);
}
if (AnimFrame.hasTz && AnimOffset == 0x18)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Translation._z);
}
if (AnimFrame.hasRx && AnimOffset == 0x20)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Rotation._x * Deg2Rad);
}
if (AnimFrame.hasRy && AnimOffset == 0x24)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Rotation._y * Deg2Rad);
}
if (AnimFrame.hasRz && AnimOffset == 0x28)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Rotation._z * Deg2Rad);
}
if (AnimFrame.hasSx && AnimOffset == 0x04)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Scale._x);
}
if (AnimFrame.hasSy && AnimOffset == 0x08)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Scale._y);
}
if (AnimFrame.hasSz && AnimOffset == 0x0C)
{
Frames.Add(frame);
Keys.Add(AnimFrame.Scale._z);
}
}
private static ushort[] SetIndices(SkeletalAnim fska)
{
List<ushort> indces = new List<ushort>();

View File

@ -15,7 +15,8 @@ namespace Switch_Toolbox.Library
public class AssimpData
{
public bool UseTransformMatrix = true;
public bool RotateSkeleton90Y = false;
public bool RotateSkeleton = false;
public float RotateSkeletonAmount = 90;
public Scene scene;
@ -42,7 +43,8 @@ namespace Switch_Toolbox.Library
if (settings.ShowDialog() == DialogResult.OK)
{
UseTransformMatrix = settings.UseNodeTransform;
RotateSkeleton90Y = settings.RotateSkeleton90Y;
RotateSkeleton = settings.RotateSkeleton;
RotateSkeletonAmount = settings.RotateSkeletonAmount;
AssimpContext Importer = new AssimpContext();
@ -262,9 +264,6 @@ namespace Switch_Toolbox.Library
}
private void BuildSkeletonNodes(Node node, List<string> boneNames, STSkeleton skeleton, ref Matrix4x4 rootTransform)
{
if (RotateSkeleton90Y)
BoneRotation = 90;
Matrix4x4 trafo = node.Transform;
Matrix4x4 world = trafo * rootTransform;
Matrix4 worldTK = AssimpHelper.TKMatrix(world);
@ -301,8 +300,6 @@ namespace Switch_Toolbox.Library
}
}
public int BoneRotation = 0;
private List<Node> tempBoneNodes = new List<Node>();
private void CreateByNode(Node node, STSkeleton skeleton, string ParentArmatureName,
short SmoothIndex, short RigidIndex, bool IsRoot, ref Assimp.Matrix4x4 rootTransform)
@ -341,7 +338,11 @@ namespace Switch_Toolbox.Library
if (IsRoot)
{
bone.parentIndex = -1;
transformMat = AssimpHelper.TKMatrix(world * Matrix4x4.FromRotationX(MathHelper.DegreesToRadians(BoneRotation)));
if (RotateSkeleton)
transformMat = AssimpHelper.TKMatrix(world * Matrix4x4.FromRotationX(MathHelper.DegreesToRadians(RotateSkeletonAmount)));
else
transformMat = AssimpHelper.TKMatrix(world);
}
else
{

View File

@ -41,14 +41,17 @@
this.useNodeTransform = new Switch_Toolbox.Library.Forms.STCheckBox();
this.stButton1 = new Switch_Toolbox.Library.Forms.STButton();
this.stButton2 = new Switch_Toolbox.Library.Forms.STButton();
this.rotateBonesY90 = new Switch_Toolbox.Library.Forms.STCheckBox();
this.rotateBones = new Switch_Toolbox.Library.Forms.STCheckBox();
this.rotateBonesUD = new System.Windows.Forms.NumericUpDown();
this.contentContainer.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.rotateBonesUD)).BeginInit();
this.SuspendLayout();
//
// contentContainer
//
this.contentContainer.Controls.Add(this.rotateBonesY90);
this.contentContainer.Controls.Add(this.rotateBonesUD);
this.contentContainer.Controls.Add(this.rotateBones);
this.contentContainer.Controls.Add(this.stButton2);
this.contentContainer.Controls.Add(this.stButton1);
this.contentContainer.Controls.Add(this.useNodeTransform);
@ -76,7 +79,8 @@
this.contentContainer.Controls.SetChildIndex(this.useNodeTransform, 0);
this.contentContainer.Controls.SetChildIndex(this.stButton1, 0);
this.contentContainer.Controls.SetChildIndex(this.stButton2, 0);
this.contentContainer.Controls.SetChildIndex(this.rotateBonesY90, 0);
this.contentContainer.Controls.SetChildIndex(this.rotateBones, 0);
this.contentContainer.Controls.SetChildIndex(this.rotateBonesUD, 0);
//
// generateNormalsChk
//
@ -246,17 +250,39 @@
this.stButton2.Text = "Ok";
this.stButton2.UseVisualStyleBackColor = false;
//
// rotateBonesY90
// rotateBones
//
this.rotateBonesY90.AutoSize = true;
this.rotateBonesY90.ForeColor = System.Drawing.Color.White;
this.rotateBonesY90.Location = new System.Drawing.Point(9, 31);
this.rotateBonesY90.Name = "rotateBonesY90";
this.rotateBonesY90.Size = new System.Drawing.Size(116, 17);
this.rotateBonesY90.TabIndex = 14;
this.rotateBonesY90.Text = "Rotate Bones 90 Y";
this.rotateBonesY90.UseVisualStyleBackColor = true;
this.rotateBonesY90.CheckedChanged += new System.EventHandler(this.rotateBonesY90_CheckedChanged);
this.rotateBones.AutoSize = true;
this.rotateBones.ForeColor = System.Drawing.Color.White;
this.rotateBones.Location = new System.Drawing.Point(9, 31);
this.rotateBones.Name = "rotateBones";
this.rotateBones.Size = new System.Drawing.Size(105, 17);
this.rotateBones.TabIndex = 14;
this.rotateBones.Text = "Rotate Bones by";
this.rotateBones.UseVisualStyleBackColor = true;
this.rotateBones.CheckedChanged += new System.EventHandler(this.rotateBonesY90_CheckedChanged);
//
// rotateBonesUD
//
this.rotateBonesUD.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.rotateBonesUD.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.rotateBonesUD.Enabled = false;
this.rotateBonesUD.ForeColor = System.Drawing.Color.White;
this.rotateBonesUD.Location = new System.Drawing.Point(120, 33);
this.rotateBonesUD.Maximum = new decimal(new int[] {
360,
0,
0,
0});
this.rotateBonesUD.Name = "rotateBonesUD";
this.rotateBonesUD.Size = new System.Drawing.Size(120, 16);
this.rotateBonesUD.TabIndex = 15;
this.rotateBonesUD.Value = new decimal(new int[] {
90,
0,
0,
0});
this.rotateBonesUD.ValueChanged += new System.EventHandler(this.rotateBonesUD_ValueChanged);
//
// Assimp_Settings
//
@ -269,6 +295,7 @@
this.contentContainer.ResumeLayout(false);
this.contentContainer.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.rotateBonesUD)).EndInit();
this.ResumeLayout(false);
}
@ -288,6 +315,7 @@
private STCheckBox useNodeTransform;
private STButton stButton2;
private STButton stButton1;
private STCheckBox rotateBonesY90;
private STCheckBox rotateBones;
private System.Windows.Forms.NumericUpDown rotateBonesUD;
}
}

View File

@ -15,7 +15,8 @@ namespace Switch_Toolbox.Library.Forms
{
public uint SkinLimitMax = 4;
public bool UseNodeTransform = true;
public bool RotateSkeleton90Y = false;
public bool RotateSkeleton = false;
public float RotateSkeletonAmount = 90;
public Assimp_Settings()
{
@ -24,7 +25,8 @@ namespace Switch_Toolbox.Library.Forms
public PostProcessSteps GetFlags()
{
RotateSkeleton90Y = rotateBonesY90.Checked;
RotateSkeleton = rotateBones.Checked;
RotateSkeletonAmount = (float)rotateBonesUD.Value;
UseNodeTransform = useNodeTransform.Checked;
@ -60,7 +62,12 @@ namespace Switch_Toolbox.Library.Forms
private void rotateBonesY90_CheckedChanged(object sender, EventArgs e)
{
RotateSkeleton90Y = rotateBonesY90.Checked;
RotateSkeleton = rotateBones.Checked;
}
private void rotateBonesUD_ValueChanged(object sender, EventArgs e)
{
RotateSkeletonAmount = (float)rotateBonesUD.Value;
}
}
}