public FlverBoneInfo(FLVER2.Bone bone, List <FLVER2.Bone> boneList)
            {
                Matrix GetBoneMatrix(SoulsFormats.FLVER2.Bone b)
                {
                    SoulsFormats.FLVER2.Bone parentBone = b;

                    var result = Matrix.Identity;

                    do
                    {
                        result *= Matrix.CreateScale(parentBone.Scale.X, parentBone.Scale.Y, parentBone.Scale.Z);
                        result *= Matrix.CreateRotationX(parentBone.Rotation.X);
                        result *= Matrix.CreateRotationZ(parentBone.Rotation.Z);
                        result *= Matrix.CreateRotationY(parentBone.Rotation.Y);
                        result *= Matrix.CreateTranslation(parentBone.Translation.X, parentBone.Translation.Y, parentBone.Translation.Z);

                        if (parentBone.ParentIndex >= 0)
                        {
                            parentBone = boneList[parentBone.ParentIndex];
                        }
                        else
                        {
                            parentBone = null;
                        }
                    }while (parentBone != null);

                    return(result);
                }

                ReferenceMatrix = GetBoneMatrix(bone);
                Name            = bone.Name;
            }
        Matrix GetParentBoneMatrix(FLVER2 f, FLVER2.Bone bone)
        {
            FLVER2.Bone parent = bone;

            var boneParentMatrix = Matrix.Identity;

            do
            {
                boneParentMatrix *= Matrix.CreateScale(parent.Scale.X, parent.Scale.Y, parent.Scale.Z);
                boneParentMatrix *= Matrix.CreateRotationX(parent.Rotation.X);
                boneParentMatrix *= Matrix.CreateRotationZ(parent.Rotation.Z);
                boneParentMatrix *= Matrix.CreateRotationY(parent.Rotation.Y);

                //boneParentMatrix *= Matrix.CreateRotationY(parent.EulerRadian.Y);
                //boneParentMatrix *= Matrix.CreateRotationZ(parent.EulerRadian.Z);
                //boneParentMatrix *= Matrix.CreateRotationX(parent.EulerRadian.X);
                boneParentMatrix *= Matrix.CreateTranslation(parent.Translation.X, parent.Translation.Y, parent.Translation.Z);
                //boneParentMatrix *= Matrix.CreateScale(parent.Scale);

                if (parent.ParentIndex >= 0)
                {
                    parent = f.Bones[parent.ParentIndex];
                }
                else
                {
                    parent = null;
                }
            }while (parent != null);

            return(boneParentMatrix);
        }
Exemple #3
0
            public FlverBoneInfo(FLVER2.Bone bone, List <FLVER2.Bone> boneList)
            {
                Matrix GetBoneMatrix(SoulsFormats.FLVER2.Bone b)
                {
                    SoulsFormats.FLVER2.Bone parentBone = b;

                    var result = Matrix.Identity;

                    do
                    {
                        result *= Matrix.CreateScale(parentBone.Scale.X, parentBone.Scale.Y, parentBone.Scale.Z);
                        result *= Matrix.CreateRotationX(parentBone.Rotation.X);
                        result *= Matrix.CreateRotationZ(parentBone.Rotation.Z);
                        result *= Matrix.CreateRotationY(parentBone.Rotation.Y);
                        result *= Matrix.CreateTranslation(parentBone.Translation.X, parentBone.Translation.Y, parentBone.Translation.Z);

                        if (parentBone.ParentIndex >= 0)
                        {
                            parentBone = boneList[parentBone.ParentIndex];
                        }
                        else
                        {
                            parentBone = null;
                        }
                    }while (parentBone != null);

                    return(result);
                }

                ReferenceMatrix = GetBoneMatrix(bone);
                Name            = bone.Name;

                if (bone.Unk3C == 0)
                {
                    BonePrim = new DbgPrimWireBone(bone.Name, new Transform(ReferenceMatrix), DBG.COLOR_FLVER_BONE)
                    {
                        Category = DbgPrimCategory.FlverBone,
                    };

                    BoundingBoxPrim = new DbgPrimWireBox(Transform.Default,
                                                         new Vector3(bone.BoundingBoxMin.X, bone.BoundingBoxMin.Y, bone.BoundingBoxMin.Z),
                                                         new Vector3(bone.BoundingBoxMax.X, bone.BoundingBoxMax.Y, bone.BoundingBoxMax.Z),
                                                         DBG.COLOR_FLVER_BONE_BBOX)
                    {
                        Category = DbgPrimCategory.FlverBoneBoundingBox,
                    };
                }
            }
        private void SetBoneBoundingBox(FLVER2 f, FLVER2.Bone b)
        {
            var bb = GetBoundingBox(GetVerticesParentedToBone(f, b).Select(v => new Vector3(v.Position.X, v.Position.Y, v.Position.Z)).ToList());

            if (bb.Max.LengthSquared() != 0 || bb.Min.LengthSquared() != 0)
            {
                var matrix = GetParentBoneMatrix(f, b);
                b.BoundingBoxMin = Vector3.Transform(bb.Min, Matrix.Invert(matrix)).ToNumerics();
                b.BoundingBoxMax = Vector3.Transform(bb.Max, Matrix.Invert(matrix)).ToNumerics();
            }
            else
            {
                b.BoundingBoxMin = new System.Numerics.Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
                b.BoundingBoxMax = new System.Numerics.Vector3(float.MinValue, float.MinValue, float.MinValue);
            }
        }
        private List <FLVER.Vertex> GetVerticesParentedToBone(FLVER2 f, FLVER2.Bone b)
        {
            var result = new List <FLVER.Vertex>();

            foreach (var sm in f.Meshes)
            {
                foreach (var v in sm.Vertices)
                {
                    var bonesReferencedByThisShit = GetAllBonesReferencedByVertex(f, sm, v);
                    if (bonesReferencedByThisShit.Contains(b))
                    {
                        result.Add(v);
                    }
                }
            }
            return(result);
        }