Exemplo n.º 1
0
        private static List <NodeBuilder> CreateBonesRecursive(CSkelMeshBone bone, NodeBuilder parent, List <CSkelMeshBone> skeleton, int index)
        {
            var res = new List <NodeBuilder>();

            var bonePos = SwapYZ(bone.Position * 0.01f);
            var boneRot = SwapYZ(bone.Orientation);
            var node    = parent.CreateNode(bone.Name.ToString())
                          .WithLocalRotation(boneRot.ToQuaternion())
                          .WithLocalTranslation(bonePos);

            res.Add(node);

            var numBones = skeleton.Count;

            for (int j = 0; j < numBones; j++)
            {
                if (index == j)
                {
                    continue;
                }
                var bone2 = skeleton[j];
                if (bone2.ParentIndex == index)
                {
                    res.AddRange(CreateBonesRecursive(bone2, node, skeleton, j));
                }
            }
            return(res);
        }
Exemplo n.º 2
0
        public static bool TryConvert(this USkeleton originalSkeleton, out List <CSkelMeshBone> bones)
        {
            bones = new List <CSkelMeshBone>();
            for (var i = 0; i < originalSkeleton.ReferenceSkeleton.FinalRefBoneInfo.Length; i++)
            {
                var skeletalMeshBone = new CSkelMeshBone
                {
                    Name        = originalSkeleton.ReferenceSkeleton.FinalRefBoneInfo[i].Name,
                    ParentIndex = originalSkeleton.ReferenceSkeleton.FinalRefBoneInfo[i].ParentIndex,
                    Position    = originalSkeleton.ReferenceSkeleton.FinalRefBonePose[i].Translation,
                    Orientation = originalSkeleton.ReferenceSkeleton.FinalRefBonePose[i].Rotation,
                };

                if (i >= 1) // fix skeleton; all bones but 0
                {
                    skeletalMeshBone.Orientation.Conjugate();
                }

                bones.Add(skeletalMeshBone);
            }
            return(true);
        }