diff --git a/CodeWalker.Core/GameFiles/Resources/Drawable.cs b/CodeWalker.Core/GameFiles/Resources/Drawable.cs index 4a4377c..bcf20f5 100644 --- a/CodeWalker.Core/GameFiles/Resources/Drawable.cs +++ b/CodeWalker.Core/GameFiles/Resources/Drawable.cs @@ -916,6 +916,7 @@ namespace CodeWalker.GameFiles public Dictionary BonesMap { get; set; }//for convienience finding bones by tag + public Bone[] BonesSorted { get; set; } //sometimes bones aren't in parent>child order in the files! (eg player chars) public Matrix3_s[] BoneTransforms; //for rendering @@ -1116,10 +1117,12 @@ namespace CodeWalker.GameFiles BonesMap = new Dictionary(); if (Bones?.Items != null) { + var bonesSorted = new List(); for (int i = 0; i < Bones.Items.Length; i++) { var bone = Bones.Items[i]; BonesMap[bone.Tag] = bone; + bonesSorted.Add(bone); bone.UpdateAnimTransform(); bone.AbsTransform = bone.AnimTransform; @@ -1128,6 +1131,8 @@ namespace CodeWalker.GameFiles bone.UpdateSkinTransform(); bone.TransformUnk = (i < (Transformations?.Length ?? 0)) ? Transformations[i].Column4 : Vector4.Zero;//still dont know what this is } + bonesSorted.Sort((a, b) => a.Index.CompareTo(b.Index)); + BonesSorted = bonesSorted.ToArray(); } } @@ -2241,7 +2246,7 @@ namespace CodeWalker.GameFiles } ////AnimTransform = Matrix.AffineTransformation(1.0f, AnimRotation, AnimTranslation);//(local transform) - + //var pos = AnimTranslation; //var ori = AnimRotation; //var sca = AnimScale; diff --git a/CodeWalker/Rendering/Renderable.cs b/CodeWalker/Rendering/Renderable.cs index bd6a3bc..abcfb13 100644 --- a/CodeWalker/Rendering/Renderable.cs +++ b/CodeWalker/Rendering/Renderable.cs @@ -516,7 +516,7 @@ namespace CodeWalker.Rendering var dwbl = this.Key; var skel = Skeleton; - var bones = skel?.Bones?.Items; + var bones = skel?.BonesSorted;//.Bones?.Items;// if (bones == null) { return; } diff --git a/CodeWalker/Rendering/Renderer.cs b/CodeWalker/Rendering/Renderer.cs index ef7759f..22fc904 100644 --- a/CodeWalker/Rendering/Renderer.cs +++ b/CodeWalker/Rendering/Renderer.cs @@ -3551,6 +3551,7 @@ namespace CodeWalker.Rendering dskel.BonesMap[srcbone.Tag] = srcbone; } } + dskel.BonesSorted = skel.BonesSorted;//this is pretty hacky. TODO: try and fix all this! animate only the frag skeleton! } } }