private void CreateNodeGraph(List <Node> nodes, STBone bone, bool isSibling = false) { int currentIndex = nodes.Count; //Add a node to represent our node hiearchy //Bones have no shape/draw references. Indices are always the last count used. nodes.Add(new Node() { NodeIndex = (ushort)currentIndex, ChildIndex = bone.Children.Count > 0 ? (ushort)1 : (ushort)0, }); for (int i = 0; i < bone.Children.Count; i++) { //Check the child if there is a sibling next to it //Sibling indices are used for parenting. //These will chain together multiple nodes that have the same parenting //Check if there is children that go after the current child bool sibling = i < bone.Children.Count - 1; CreateNodeGraph(nodes, bone.Children[i], sibling); } int siblingStart = 0; if (isSibling) //Set a sibling index relative to our current index { siblingStart = nodes.Count - currentIndex; } nodes[currentIndex].SiblingIndex = (ushort)siblingStart; }
public void FillSkeleton(SuperBMDLib.BMD.INF1 INF1, STSkeleton skeleton, List <SuperBMDLib.Rigging.Bone> flatSkeleton) { for (int i = 1; i < INF1.FlatNodes.Count; i++) { SuperBMDLib.Scenegraph.SceneNode curNode = INF1.FlatNodes[i]; if (curNode.Type == SuperBMDLib.Scenegraph.Enums.NodeType.Joint) { var Bone = flatSkeleton[curNode.Index]; var stBone = new STBone(skeleton); stBone.Text = Bone.Name; stBone.FromTransform(Bone.TransformationMatrix); if (Bone.Parent != null) { stBone.parentIndex = flatSkeleton.IndexOf(Bone.Parent); } else { stBone.parentIndex = -1; } skeleton.bones.Add(stBone); } } }
private TreeNode SetBoneNode(Node Node, TreeNode parentNode) { if (Node.IsBone) { STBone boneNode = new STBone(Skeleton); boneNode.RotationType = STBone.BoneRotationType.Euler; boneNode.Checked = true; boneNode.Text = Node.Name; boneNode.position = new float[3]; boneNode.scale = new float[3]; boneNode.rotation = new float[4]; boneNode.position[0] = Node.Translation.X; boneNode.position[1] = Node.Translation.Y; boneNode.position[2] = Node.Translation.Z; boneNode.rotation[0] = Node.Rotation.X; boneNode.rotation[1] = Node.Rotation.Y; boneNode.rotation[2] = Node.Rotation.Z; boneNode.scale[0] = Node.Scale.X; boneNode.scale[1] = Node.Scale.Y; boneNode.scale[2] = Node.Scale.Z; if (Node.IsBone) { Skeleton.bones.Add(boneNode); } parentNode.Nodes.Add(boneNode); return(boneNode); } return(new TreeNode(Node.Name)); }
private static STBone LoadBoneHiearchy(node daeNode, STGenericModel model, STBone boneParent, ref Matrix4 parentTransform) { STBone bone = new STBone(model.Skeleton, daeNode.name); model.Skeleton.Bones.Add(bone); var transform = DaeUtility.GetMatrix(daeNode.Items) * parentTransform; bone.Position = transform.ExtractTranslation(); bone.Scale = transform.ExtractScale(); bone.Rotation = transform.ExtractRotation(); bone.Parent = boneParent; Console.WriteLine("NODE " + bone.Name + " " + bone.Transform); //Reset the parent transform for children. We only need to apply the parent root transform parentTransform = Matrix4.Identity; if (daeNode.node1 != null) { foreach (node child in daeNode.node1) { bone.Children.Add(LoadBoneHiearchy(child, model, bone, ref parentTransform)); } } return(bone); }
private void ParseKeyTrack(STBone bone, BoneAnimGroup group) { float value = group.Track.GetFrameValue(this.Frame); bool isVisible = value != 0; bone.Visible = isVisible; }
public void Save(string FileName) { StringBuilder o = new StringBuilder(); o.AppendLine("version 1"); if (Bones != null) { o.AppendLine("nodes"); for (int i = 0; i < Bones.bones.Count; i++) { o.AppendLine(" " + i + " \"" + Bones.bones[i].Text + "\" " + Bones.bones[i].parentIndex); } o.AppendLine("end"); o.AppendLine("skeleton"); o.AppendLine("time 0"); for (int i = 0; i < Bones.bones.Count; i++) { STBone b = Bones.bones[i]; o.AppendFormat("{0} {1} {2} {3} {4} {5} {6}\n", i, b.position[0], b.position[1], b.position[2], b.rotation[0], b.rotation[1], b.rotation[2]); } o.AppendLine("end"); } File.WriteAllText(FileName, o.ToString()); }
public void Save(string FileName) { var culture = new CultureInfo("en-US"); StringBuilder o = new StringBuilder(); o.AppendLine("version 1"); if (Bones != null) { o.AppendLine("nodes"); for (int i = 0; i < Bones.bones.Count; i++) { o.AppendLine(" " + i + " \"" + Bones.bones[i].Text + "\" " + Bones.bones[i].parentIndex); } o.AppendLine("end"); o.AppendLine("skeleton"); o.AppendLine("time 0"); for (int i = 0; i < Bones.bones.Count; i++) { STBone b = Bones.bones[i]; o.AppendFormat(culture, "{0} {1} {2} {3} {4} {5} {6}\n", i, b.Position.X, b.Position.Y, b.Position.Z, b.EulerRotation.X, b.EulerRotation.Y, b.EulerRotation.Z); } o.AppendLine("end"); } File.WriteAllText(FileName, o.ToString()); }
private BonePoint FromBone(STBone bone) { return(new BonePoint(this, ColorUtility.ToVector4(Color.Yellow), bone.Position, bone.EulerRotation, bone.Scale) { Bone = bone }); }
private void GetBoneTransform(STBone bn) { posXUD.Value = (decimal)bn.position[0]; posYUD.Value = (decimal)bn.position[1]; posZUD.Value = (decimal)bn.position[2]; RotXUD.Value = (decimal)bn.rotation[0]; RotYUD.Value = (decimal)bn.rotation[1]; RotZUD.Value = (decimal)bn.rotation[2]; RotWUD.Value = (decimal)bn.rotation[3]; ScaXUD.Value = (decimal)bn.scale[0]; ScaYUD.Value = (decimal)bn.scale[1]; ScaZUD.Value = (decimal)bn.scale[2]; }
public G1MS(FileReader reader, bool isParent = true) { uint pos = (uint)reader.Position - 12; uint boneOffset = reader.ReadUInt32() + pos; ushort conditionNumber = reader.ReadUInt16(); if (isParent && conditionNumber == 0) { } ushort unknown = reader.ReadUInt16(); ushort numBones = reader.ReadUInt16(); ushort numBoneIndices = reader.ReadUInt16(); BoneIndices = reader.ReadInt16s((int)numBoneIndices); BoneIndexList = new ushort[numBones]; for (ushort i = 0; i < BoneIndices?.Length; i++) { if (BoneIndices[i] != -1) { BoneIndexList[BoneIndices[i]] = i; } } reader.SeekBegin(boneOffset); for (int i = 0; i < numBones; i++) { var scale = reader.ReadVec3(); int parentIndex = reader.ReadInt32(); var quat = reader.ReadQuaternion(true); var position = reader.ReadVec3(); reader.ReadSingle(); // if ((parentIndex & 0x80000000) > 0 && parentIndex != -1) // parentIndex = parentIndex & 0x7FFFFFFF; STBone genericBone = new STBone(GenericSkeleton); genericBone.Text = $"Bone {BoneIndexList[i]}"; genericBone.Rotation = quat; genericBone.Scale = scale; genericBone.Position = position; genericBone.parentIndex = parentIndex; GenericSkeleton.bones.Add(genericBone); } GenericSkeleton.reset(); GenericSkeleton.update(); }
/// <summary> /// Generates a baked skeleton based on the first frame of the animation. /// </summary> /// <returns></returns> public STSkeleton CreateBakedSkeleton(int skeletonIndex) { var skel = Skeletons.FirstOrDefault(); if (skeletonIndex < Skeletons.Count) { skel = Skeletons[skeletonIndex]; } if (skel == null) { return(new STSkeleton()); } var target = Animations[0]; STSkeleton skeleton = new STSkeleton(); for (int i = 0; i < skel.GlobalIndexList.Count; i++) { var boneAnim = target.BoneGroups[i]; float posX = boneAnim.TranslateX.GetBaseValue(); float posY = boneAnim.TranslateY.GetBaseValue(); float posZ = boneAnim.TranslateZ.GetBaseValue(); float rotX = boneAnim.RotateX.GetBaseValue(); float rotY = boneAnim.RotateY.GetBaseValue(); float rotZ = boneAnim.RotateZ.GetBaseValue(); float scaleX = boneAnim.ScaleX.GetBaseValue(true); float scaleY = boneAnim.ScaleY.GetBaseValue(true); float scaleZ = boneAnim.ScaleZ.GetBaseValue(true); STBone bone = new STBone(skeleton); bone.ParentIndex = skel.GlobalIndexList[i].ParentIndex; bone.Name = $"Bone{i}"; //Multiply by 1024 (hardcoded scale value) bone.Position = new Vector3(posX, posY, posZ) * 1024.0f; bone.EulerRotation = new Vector3(rotX, rotY, rotZ); bone.Scale = new Vector3(scaleX, scaleY, scaleZ); skeleton.Bones.Add(bone); } skeleton.Reset(); skeleton.Update(); return(skeleton); }
public static void Save(STSkeletonAnimation anim, String Fname) { System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; STSkeleton Skeleton = anim.GetActiveSkeleton(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Fname)) { file.WriteLine("version 1"); file.WriteLine("nodes"); foreach (STBone b in Skeleton.bones) { file.WriteLine(Skeleton.bones.IndexOf(b) + " \"" + b.Text + "\" " + b.parentIndex); } file.WriteLine("end"); file.WriteLine("skeleton"); anim.SetFrame(0); for (int i = 0; i <= anim.FrameCount; i++) { anim.SetFrame(i); anim.NextFrame(); file.WriteLine($"time {i}"); foreach (var sb in anim.AnimGroups) { STBone b = Skeleton.GetBone(sb.Name); if (b == null) { continue; } Vector3 eul = STMath.ToEulerAngles(b.rot); Vector3 scale = b.GetScale(); Vector3 translate = b.GetPosition(); file.WriteLine($"{ Skeleton.bones.IndexOf(b)} {translate.X} {translate.Y} {translate.Z} {eul.X} {eul.Y} {eul.Z}"); } } file.WriteLine("end"); file.Close(); } }
private STVertex ToVertex(STBone node, ShapeBatch.VertexGroup group) { Vector3 positon = group.Position; Vector3 normal = group.Normal; positon = Vector3.TransformPosition(positon, node.Transform); // normal = Vector3.TransformNormal(normal, node.Transform); return(new STVertex() { Position = positon, Normal = normal, TexCoords = new Vector2[1] { group.Texcoord }, }); }
public static Matrix4x4 CalculateTransformMatrix(STBone bone) { var trans = Matrix4x4.CreateTranslation(new Vector3(bone.Position.X, bone.Position.Y, bone.Position.Z)); var scale = Matrix4x4.CreateScale(new Vector3(bone.Scale.X, bone.Scale.Y, bone.Scale.Z)); Matrix4x4 quat = Matrix4x4.Identity; if (bone.RotationType == STBone.BoneRotationType.Euler) { quat = Matrix4x4.CreateFromQuaternion(QuatFromEular(bone.EulerRotation.X, bone.EulerRotation.Y, bone.EulerRotation.Z)); } else { quat = Matrix4x4.CreateFromQuaternion(QuatFromQuat(bone.Rotation.X, bone.Rotation.Y, bone.Rotation.Z, bone.Rotation.W)); } return(Matrix4x4.Multiply(quat, trans)); }
public static Matrix4x4 CalculateTransformMatrix(STBone bone) { var trans = Matrix4x4.CreateTranslation(new Vector3(bone.position[0], bone.position[1], bone.position[2])); var scale = Matrix4x4.CreateScale(new Vector3(bone.scale[0], bone.scale[1], bone.scale[2])); Matrix4x4 quat = Matrix4x4.Identity; if (bone.RotationType == STBone.BoneRotationType.Euler) { quat = Matrix4x4.CreateFromQuaternion(QuatFromEular(bone.rotation[0], bone.rotation[1], bone.rotation[2])); } else { quat = Matrix4x4.CreateFromQuaternion(QuatFromQuat(bone.rotation[0], bone.rotation[1], bone.rotation[2], bone.rotation[3])); } return(Matrix4x4.Multiply(quat, trans)); }
public static void SaveAnimation(string FileName, Animation anim, STSkeleton skeleton) { anim.SetFrame(anim.FrameCount - 1); //from last frame for (int f = 0; f < anim.FrameCount; ++f) //go through each frame with nextFrame { anim.NextFrame(skeleton); } anim.NextFrame(skeleton); //go on first frame SEAnim seAnim = new SEAnim(); seAnim.Looping = anim.CanLoop; seAnim.AnimType = AnimationType.Absolute; //Reset active animation to 0 anim.SetFrame(0); for (int frame = 0; frame < anim.FrameCount; frame++) { anim.NextFrame(skeleton, false, true); foreach (Animation.KeyNode boneAnim in anim.Bones) { if (boneAnim.HasKeyedFrames(frame)) { 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, 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); } } } seAnim.Write(FileName); }
public static void Save(Animation anim, STSkeleton Skeleton, String Fname) { System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Fname)) { file.WriteLine("version 1"); file.WriteLine("nodes"); foreach (STBone b in Skeleton.bones) { file.WriteLine(Skeleton.bones.IndexOf(b) + " \"" + b.Text + "\" " + b.parentIndex); } file.WriteLine("end"); file.WriteLine("skeleton"); anim.SetFrame(0); for (int i = 0; i <= anim.FrameCount; i++) { anim.NextFrame(Skeleton, false, true); file.WriteLine($"time {i}"); foreach (Animation.KeyNode sb in anim.Bones) { STBone b = Skeleton.GetBone(sb.Text); if (b == null) { continue; } Vector3 eul = STMath.ToEulerAngles(b.rot); Vector3 scale = b.GetScale(); Vector3 translate = b.GetPosition(); file.WriteLine($"{ Skeleton.bones.IndexOf(b)} {translate.X} {translate.Y} {translate.Z} {eul.X} {eul.Y} {eul.Z}"); } } file.WriteLine("end"); file.Close(); } }
private void CreateBones(STBone bone) { Bone bn = new Bone(); bn.BillboardIndex = (ushort)bone.BillboardIndex; bn.Flags = BoneFlags.Visible; bn.FlagsRotation = BoneFlagsRotation.EulerXYZ; bn.FlagsTransform = BoneFlagsTransform.None; bn.FlagsTransformCumulative = BoneFlagsTransformCumulative.None; bn.Name = bone.Text; bn.RigidMatrixIndex = 0; bn.Rotation = new Syroot.Maths.Vector4F(bone.rotation[0], bone.rotation[1], bone.rotation[2], bone.rotation[3]); bn.Position = new Syroot.Maths.Vector3F(bone.position[0], bone.position[1], bone.position[2]); bn.Scale = new Syroot.Maths.Vector3F(bone.scale[0], bone.scale[1], bone.scale[2]); bn.UserData = new List <UserData>(); bn.UserDataDict = new ResDict(); }
public GenericSkeletonRenderer(STSkeleton skeleton) : base(Color.Yellow, Color.Yellow, Color.Yellow) { Skeleton = skeleton; var points = new RenderablePathPoint[skeleton.Bones.Count]; for (int i = 0; i < skeleton.Bones.Count; i++) { STBone bone = skeleton.Bones[i]; points[i] = FromBone(bone); } for (int i = 0; i < skeleton.Bones.Count; i++) { if (skeleton.Bones[i].ParentIndex != -1) { points[skeleton.Bones[i].ParentIndex].AddChild(points[i]); } } PathPoints = points.ToList(); }
public static void SaveAnimation(string FileName, Animation anim, STSkeleton skeleton) { SEAnim seAnim = new SEAnim(); //Reset active animation to 0 anim.SetFrame(0); for (int frame = 0; frame < anim.FrameCount; frame++) { anim.NextFrame(skeleton); //Reset it when it reaches the total frame count if (anim.Frame >= anim.FrameCount) { anim.Frame = 0; } 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, 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); } //Add frames to the playing animation anim.Frame += 1f; } seAnim.Write(FileName); }
public static Matrices CalculateInverseMatrix(STBone bone) { var matrices = new Matrices(); //Get parent transform for a smooth matrix if (bone.Parent != null && bone.Parent is STBone) { matrices.transform *= CalculateInverseMatrix((STBone)bone.Parent).transform; } else { matrices.transform = Matrix4x4.Identity; } //Now calculate the matrix with TK matrices var trans = Matrix4x4.CreateTranslation(new Vector3(bone.position[0], bone.position[1], bone.position[2])); var scale = Matrix4x4.CreateScale(new Vector3(bone.scale[0], bone.scale[1], bone.scale[2])); Matrix4x4 quat = Matrix4x4.Identity; if (bone.RotationType == STBone.BoneRotationType.Euler) { quat = Matrix4x4.CreateFromQuaternion(QuatFromEular(bone.rotation[0], bone.rotation[1], bone.rotation[2])); } else { quat = Matrix4x4.CreateFromQuaternion(QuatFromQuat(bone.rotation[0], bone.rotation[1], bone.rotation[2], bone.rotation[3])); } matrices.transform = Matrix4x4.Multiply(Matrix4x4.Multiply(quat, trans), matrices.transform); Matrix4x4 Inverse; Matrix4x4.Invert(matrices.transform, out Inverse); matrices.inverse = Inverse; return(matrices); }
public void CloneBaseInstance(STBone genericBone) { Text = genericBone.Text; Position = new OpenTK.Vector3( genericBone.Position.X, genericBone.Position.Y, genericBone.Position.Z); EulerRotation = new OpenTK.Vector3( genericBone.EulerRotation.X, genericBone.EulerRotation.Y, genericBone.EulerRotation.Z); Scale = new OpenTK.Vector3( genericBone.Scale.X, genericBone.Scale.Y, genericBone.Scale.Z); RotationType = genericBone.RotationType; parentIndex = genericBone.parentIndex; RigidMatrixIndex = genericBone.RigidMatrixIndex; SmoothMatrixIndex = genericBone.SmoothMatrixIndex; }
private static STBone LoadBoneHiearchy(node daeNode, STGenericModel model, STBone boneParent, ref Matrix4 parentTransform) { STBone bone = new STBone(model.Skeleton, daeNode.name); model.Skeleton.Bones.Add(bone); bone.Transform = DaeUtility.GetMatrix(daeNode.Items) * parentTransform; bone.Parent = boneParent; Console.WriteLine("NODE " + bone.Name + " " + bone.Transform); parentTransform = Matrix4.Identity; if (daeNode.node1 != null) { foreach (node child in daeNode.node1) { bone.Children.Add(LoadBoneHiearchy(child, model, bone, ref parentTransform)); } } return(bone); }
public static void Save(STSkeletonAnimation anim, string FileName) { STSkeleton skeleton = anim.GetActiveSkeleton(); SEAnim seAnim = new SEAnim(); seAnim.Looping = anim.Loop; seAnim.AnimType = AnimationType.Absolute; anim.SetFrame(0); for (int frame = 0; frame < anim.FrameCount; frame++) { anim.SetFrame(frame); anim.NextFrame(); foreach (STAnimGroup boneAnim in anim.AnimGroups) { if (boneAnim.GetTracks().Any(x => x.HasKeys)) { STBone bone = skeleton.GetBone(boneAnim.Name); if (bone == null) { continue; } Vector3 position = bone.GetPosition(); Quaternion rotation = bone.GetRotation(); Vector3 scale = bone.GetScale(); seAnim.AddTranslationKey(boneAnim.Name, frame, position.X, position.Y, position.Z); seAnim.AddRotationKey(boneAnim.Name, frame, rotation.X, rotation.Y, rotation.Z, rotation.W); seAnim.AddScaleKey(boneAnim.Name, frame, scale.X, scale.Y, scale.Z); } } } seAnim.Write(FileName); }
private TreeNode SetBoneNode(Node Node, TreeNode parentNode) { if (Node.IsBone) { STBone boneNode = new STBone(Skeleton); boneNode.RotationType = STBone.BoneRotationType.Euler; boneNode.Checked = true; boneNode.Text = Node.Name; boneNode.Position = Node.Translation; boneNode.EulerRotation = Node.Rotation; boneNode.Scale = Node.Scale; if (Node.IsBone) { Skeleton.bones.Add(boneNode); } parentNode.Nodes.Add(boneNode); return(boneNode); } return(new TreeNode(Node.Name)); }
public void CloneBaseInstance(STBone genericBone) { Text = genericBone.Text; position = new float[3]; rotation = new float[4]; scale = new float[3]; position[0] = genericBone.position[0]; position[1] = genericBone.position[1]; position[2] = genericBone.position[2]; rotation[0] = genericBone.rotation[0]; rotation[1] = genericBone.rotation[1]; rotation[2] = genericBone.rotation[2]; rotation[3] = genericBone.rotation[3]; scale[0] = genericBone.scale[0]; scale[1] = genericBone.scale[1]; scale[2] = genericBone.scale[2]; RotationType = genericBone.RotationType; parentIndex = genericBone.parentIndex; RigidMatrixIndex = genericBone.RigidMatrixIndex; SmoothMatrixIndex = genericBone.SmoothMatrixIndex; }
private void GetBoneTransform(STBone bn) { posXUD.Value = (decimal)bn.Position.X; posYUD.Value = (decimal)bn.Position.Y; posZUD.Value = (decimal)bn.Position.Z; if (bn.RotationType == STBone.BoneRotationType.Quaternion) { RotXUD.Value = (decimal)bn.Rotation.X; RotYUD.Value = (decimal)bn.Rotation.Y; RotZUD.Value = (decimal)bn.Rotation.Z; RotWUD.Value = (decimal)bn.Rotation.W; } else { RotXUD.Value = (decimal)bn.EulerRotation.X; RotYUD.Value = (decimal)bn.EulerRotation.Y; RotZUD.Value = (decimal)bn.EulerRotation.Z; RotWUD.Value = (decimal)1.0f; } ScaXUD.Value = (decimal)bn.Scale.X; ScaYUD.Value = (decimal)bn.Scale.Y; ScaZUD.Value = (decimal)bn.Scale.Z; }
public void Save(string FileName) { System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; StringBuilder o = new StringBuilder(); o.AppendLine("version 1"); if (Bones != null) { o.AppendLine("nodes"); for (int i = 0; i < Bones.bones.Count; i++) { o.AppendLine(" " + i + " \"" + Bones.bones[i].Text + "\" " + Bones.bones[i].parentIndex); } o.AppendLine("end"); o.AppendLine("skeleton"); o.AppendLine("time 0"); for (int i = 0; i < Bones.bones.Count; i++) { STBone b = Bones.bones[i]; o.AppendFormat("{0} {1} {2} {3} {4} {5} {6}\n", i, b.Position.X, b.Position.Y, b.Position.Z, b.EulerRotation.X, b.EulerRotation.Y, b.EulerRotation.Z); } o.AppendLine("end"); } File.WriteAllText(FileName, o.ToString()); }
public static Matrices CalculateInverseMatrix(STBone bone) { var matrices = new Matrices(); //Get parent transform for a smooth matrix if (bone.Parent != null && bone.Parent is STBone) { matrices.transform *= CalculateInverseMatrix((STBone)bone.Parent).transform; } else { matrices.transform = Matrix4x4.Identity; } matrices.transform = Matrix4x4.Multiply(CalculateTransformMatrix(bone), matrices.transform); Matrix4x4 Inverse; Matrix4x4.Invert(matrices.transform, out Inverse); matrices.inverse = Inverse; return(matrices); }
public void SetKeyFromBone(float frame, STBone bone) { Vector3 rot = ANIM.quattoeul(bone.rot); if (rot.X != bone.rotation[0] || rot.Y != bone.rotation[1] || rot.Z != bone.rotation[2]) { XROT.GetKeyFrame(frame).Value = bone.rot.X; YROT.GetKeyFrame(frame).Value = bone.rot.Y; ZROT.GetKeyFrame(frame).Value = bone.rot.Z; WROT.GetKeyFrame(frame).Value = bone.rot.W; } if (bone.pos.X != bone.position[0] || bone.pos.Y != bone.position[1] || bone.pos.Z != bone.position[2]) { XPOS.GetKeyFrame(frame).Value = bone.pos.X; YPOS.GetKeyFrame(frame).Value = bone.pos.Y; ZPOS.GetKeyFrame(frame).Value = bone.pos.Z; } if (bone.sca.X != bone.scale[0] || bone.sca.Y != bone.scale[1] || bone.sca.Z != bone.scale[2]) { XSCA.GetKeyFrame(frame).Value = bone.sca.X; YSCA.GetKeyFrame(frame).Value = bone.sca.Y; ZSCA.GetKeyFrame(frame).Value = bone.sca.Z; } }