Beispiel #1
0
        public BoneNode[] BuildBoneHierarchy([NotNull] PmxModel pmx)
        {
            var boneList     = new List <BoneNode>();
            var pmxBones     = pmx.Bones;
            var pmxBoneCount = pmxBones.Length;

            var boneNameMapInversion = _boneNameMapInversion;

            for (var i = 0; i < pmxBoneCount; i++)
            {
                var pmxBone = pmxBones[i];
                var parent  = pmxBone.ParentIndex >= 0 ? boneList[pmxBone.ParentIndex] : null;

                boneNameMapInversion.TryGetValue(pmx.Name, out var mltdBoneName);

                var path = mltdBoneName ?? pmxBone.Name;

                Vector3 t;

                if (parent != null)
                {
                    t = pmxBone.InitialPosition - parent.InitialPosition;
                }
                else
                {
                    t = pmxBone.InitialPosition;
                }

                var bone = new BoneNode(parent, i, path, t, Quaternion.Identity);

                boneList.Add(bone);
            }

            foreach (var bone in boneList)
            {
                var level  = 0;
                var parent = bone.Parent;

                while (parent != null)
                {
                    ++level;
                    parent = parent.Parent;
                }

                bone.Level = level;
            }

            foreach (var bone in boneList)
            {
                bone.Initialize();
            }

            return(boneList.ToArray());
        }
Beispiel #2
0
        public IReadOnlyList <BoneNode> BuildBoneHierarchy([NotNull] PmxModel pmx)
        {
            var boneList = new List <BoneNode>();

            for (var i = 0; i < pmx.Bones.Count; i++)
            {
                var pmxBone = pmx.Bones[i];
                var parent  = pmxBone.ParentIndex >= 0 ? boneList[pmxBone.ParentIndex] : null;

                var mltdBoneName = _boneNameMap.SingleOrDefault(kv => kv.Value == pmx.Name).Key;
                var path         = mltdBoneName ?? pmxBone.Name;

                Vector3 t;

                if (parent != null)
                {
                    t = pmxBone.InitialPosition - parent.InitialPosition;
                }
                else
                {
                    t = pmxBone.InitialPosition;
                }

                var bone = new BoneNode(parent, i, path, t, Quaternion.Identity);

                boneList.Add(bone);
            }

            foreach (var bone in boneList)
            {
                var level  = 0;
                var parent = bone.Parent;

                while (parent != null)
                {
                    ++level;
                    parent = parent.Parent;
                }

                bone.Level = level;
            }

            foreach (var bone in boneList)
            {
                bone.Initialize();
            }

            return(boneList);
        }
Beispiel #3
0
        public static IReadOnlyList <BoneNode> BuildBoneHierachy([NotNull] PrettyAvatar avatar, [NotNull] PrettyMesh mesh)
        {
            var boneList = new List <BoneNode>();

            for (var i = 0; i < avatar.AvatarSkeleton.Nodes.Length; i++)
            {
                var n = avatar.AvatarSkeleton.Nodes[i];

                var parent   = n.ParentIndex >= 0 ? boneList[n.ParentIndex] : null;
                var boneId   = avatar.AvatarSkeleton.NodeIDs[i];
                var bonePath = avatar.BoneNamesMap[boneId];

                var boneIndex = avatar.AvatarSkeleton.NodeIDs.FindIndex(boneId);

                if (boneIndex < 0)
                {
                    throw new IndexOutOfRangeException();
                }

                var initialPose = avatar.AvatarSkeletonPose.Transforms[boneIndex];

                var bone = new BoneNode(parent, i, bonePath, initialPose.LocalPosition.ToOpenTK(), initialPose.LocalRotation.ToOpenTK());

                boneList.Add(bone);
            }

            foreach (var bone in boneList)
            {
                bone.Initialize();
            }

#if DEBUG
            Debug.Print("Model bones:");

            for (var i = 0; i < boneList.Count; i++)
            {
                var bone = boneList[i];
                Debug.Print("[{0}]: {1}", i, bone.ToString());
            }
#endif

            return(boneList);
        }