Beispiel #1
0
        public static void Save(string fileName, SBScene scene, string sourceSkelPath)
        {
            var Skeleton = scene.Skeleton;

            var skelFile = new Skel();

            skelFile.MajorVersion = 1;
            skelFile.MinorVersion = 0;

            List <SkelBoneEntry> BoneEntries        = new List <SkelBoneEntry>();
            List <Matrix4x4>     Transforms         = new List <Matrix4x4>();
            List <Matrix4x4>     InvTransforms      = new List <Matrix4x4>();
            List <Matrix4x4>     WorldTransforms    = new List <Matrix4x4>();
            List <Matrix4x4>     InvWorldTransforms = new List <Matrix4x4>();

            // Attempt to match bone order to an existing SKEL if possible.
            var sortedBones = Skeleton.Bones;

            if (!string.IsNullOrEmpty(sourceSkelPath))
            {
                sortedBones = GetBoneOrderBasedOnReference(Skeleton.Bones, sourceSkelPath);
            }

            short index = 0;

            foreach (var bone in sortedBones)
            {
                var boneEntry = new SkelBoneEntry
                {
                    Name = bone.Name,
                    Type = bone.Type,
                    Id   = index++
                };
                boneEntry.Type     = 1;
                boneEntry.ParentId = -1;
                if (bone.Parent != null)
                {
                    boneEntry.ParentId = (short)Array.IndexOf(sortedBones, bone.Parent);
                }
                BoneEntries.Add(boneEntry);

                Transforms.Add(bone.Transform.ToSsbh());
                InvTransforms.Add(bone.Transform.Inverted().ToSsbh());
                WorldTransforms.Add(bone.WorldTransform.ToSsbh());
                InvWorldTransforms.Add(bone.InvWorldTransform.ToSsbh());
            }

            skelFile.BoneEntries       = BoneEntries.ToArray();
            skelFile.Transform         = Transforms.ToArray();
            skelFile.InvTransform      = InvTransforms.ToArray();
            skelFile.WorldTransform    = WorldTransforms.ToArray();
            skelFile.InvWorldTransform = InvWorldTransforms.ToArray();

            Ssbh.TrySaveSsbhFile(fileName, skelFile);
        }
Beispiel #2
0
        public static void Save(string FileName, SBScene Scene)
        {
            var Skeleton = Scene.Skeleton;

            var skelFile = new Skel();

            skelFile.MajorVersion = 1;
            skelFile.MinorVersion = 0;

            List <SkelBoneEntry> BoneEntries        = new List <SkelBoneEntry>();
            List <SkelMatrix>    Transforms         = new List <SkelMatrix>();
            List <SkelMatrix>    InvTransforms      = new List <SkelMatrix>();
            List <SkelMatrix>    WorldTransforms    = new List <SkelMatrix>();
            List <SkelMatrix>    InvWorldTransforms = new List <SkelMatrix>();

            short index = 0;
            Dictionary <SBBone, short> BoneToIndex = new Dictionary <SBBone, short>();
            var OrderedBones = SortBones(Skeleton.Bones);

            foreach (var bone in OrderedBones)
            {
                BoneToIndex.Add(bone, index);
                var boneentry = new SkelBoneEntry();
                boneentry.Name     = bone.Name;
                boneentry.Type     = bone.Type;
                boneentry.Id       = index++;
                boneentry.Type     = 1;
                boneentry.ParentId = -1;
                if (bone.Parent != null)// && BoneToIndex.ContainsKey(bone.Parent))
                {
                    boneentry.ParentId = (short)OrderedBones.IndexOf(bone.Parent);
                }
                BoneEntries.Add(boneentry);

                Transforms.Add(TKMatrix_to_Skel(bone.Transform));
                InvTransforms.Add(TKMatrix_to_Skel(bone.Transform.Inverted()));
                WorldTransforms.Add(TKMatrix_to_Skel(bone.WorldTransform));
                InvWorldTransforms.Add(TKMatrix_to_Skel(bone.InvWorldTransform));
            }

            skelFile.BoneEntries       = BoneEntries.ToArray();
            skelFile.Transform         = Transforms.ToArray();
            skelFile.InvTransform      = InvTransforms.ToArray();
            skelFile.WorldTransform    = WorldTransforms.ToArray();
            skelFile.InvWorldTransform = InvWorldTransforms.ToArray();

            Ssbh.TrySaveSsbhFile(FileName, skelFile);
        }