Exemplo n.º 1
0
        private void ConformAnimationBindPoses(Skeleton skeleton, Skeleton conformToSkeleton)
        {
            foreach (var trackGroup in Root.TrackGroups)
            {
                for (var i = 0; i < trackGroup.TransformTracks.Count; i++)
                {
                    var track = trackGroup.TransformTracks[i];
                    var bone  = skeleton.GetBoneByName(track.Name);
                    if (bone == null)
                    {
                        string msg = String.Format("Animation track references bone '{0}' that cannot be found in the skeleton.", track.Name);
                        throw new ExportException(msg);
                    }

                    var conformingBone = conformToSkeleton.GetBoneByName(track.Name);
                    if (conformingBone == null)
                    {
                        string msg = String.Format("Animation track references bone '{0}' that cannot be found in the conforming skeleton.", track.Name);
                        throw new ExportException(msg);
                    }

                    var keyframes = track.ToKeyframes();
                    keyframes.SwapBindPose(bone.OriginalTransform, conformingBone.Transform.ToMatrix4());
                    var newTrack = TransformTrack.FromKeyframes(keyframes);
                    newTrack.Flags                = track.Flags;
                    newTrack.Name                 = track.Name;
                    newTrack.ParentAnimation      = track.ParentAnimation;
                    trackGroup.TransformTracks[i] = newTrack;
                }
            }
        }
Exemplo n.º 2
0
        private void ConformAnimationBindPoses(Skeleton skeleton, Skeleton conformToSkeleton)
        {
            if (Root.TrackGroups == null)
            {
                return;
            }

            foreach (var trackGroup in Root.TrackGroups)
            {
                for (var i = 0; i < trackGroup.TransformTracks.Count; i++)
                {
                    var track = trackGroup.TransformTracks[i];
                    var bone  = skeleton.GetBoneByName(track.Name);
                    if (bone == null)
                    {
                        //Dummy_Foot -> Dummy_Foot_01
                        bone = skeleton.GetBoneByName(track.Name + "_01");
                    }

                    if (bone == null)
                    {
                        throw new ExportException($"Animation track references bone '{track.Name}' that cannot be found in the skeleton '{skeleton.Name}'.");
                    }

                    var conformingBone = conformToSkeleton.GetBoneByName(bone.Name);
                    if (conformingBone == null)
                    {
                        throw new ExportException($"Animation track references bone '{bone.Name}' that cannot be found in the conforming skeleton '{conformToSkeleton.Name}'.");
                    }

                    var keyframes = track.ToKeyframes();
                    keyframes.SwapBindPose(bone.OriginalTransform, conformingBone.Transform.ToMatrix4());
                    var newTrack = TransformTrack.FromKeyframes(keyframes);
                    newTrack.Flags                = track.Flags;
                    newTrack.Name                 = track.Name;
                    newTrack.ParentAnimation      = track.ParentAnimation;
                    trackGroup.TransformTracks[i] = newTrack;
                }
            }
        }