Ejemplo n.º 1
0
        /// <summary>
        /// Once capture is complete, request the OutputProfile to save the animation.
        /// </summary>
        protected void saveAnimation(MocapSession session)
        {
            if (OutputProfile == null)
            {
                Debug.LogWarning("No Output method was found. Animation was not saved");
                return;
            }
            if (MappingProfile == null)
            {
                Debug.LogWarning("No Mapping method was found. Animation was not saved");
                return;
            }
            if (session == null)
            {
                return;
            }

            var animation = new NUIHumanoidAnimation();
            var cache     = new CaptureCache();

            foreach (MocapSessionKeyframe keyframe in session.CaptureData)
            {
                var elapsedTime = keyframe.ElapsedMilliseconds;
                var skeleton    = NUICaptureHelper.GetNUISkeleton(keyframe.Skeleton);

                cache.AddNewFrame(skeleton, elapsedTime);

                // Filter the raw input with enabled filters.
                NUISkeleton filtered = skeleton;
                foreach (MocapFilter filter in preMapFilters)
                {
                    if (filter.Enabled)
                    {
                        filtered = filter.Filter(cache);
                        cache.AddFiltered(filter.Name, filtered);
                    }
                }

                // Convert the input skeleton to the normalized skeleton (Unity)
                NUISkeleton mapped = MappingProfile.MapSkeleton(filtered);
                cache.AddMapped(mapped);

                // Apply any post-mapped filters selected by the user.
                filtered = mapped;
                foreach (MocapFilter filter in postMapFilters)
                {
                    if (filter.Enabled)
                    {
                        filtered = filter.Filter(cache);
                        cache.AddFiltered(filter.Name, filtered);
                    }
                }
                cache.AddResult(filtered);

                filtered.Joints[NUIJointType.SpineBase].Position = skeleton.Joints[NUIJointType.SpineBase].Position;
                animation.AddKeyframe(filtered, keyframe.ElapsedMilliseconds);
            }

            // Save the session
            if (saveSession)
            {
                string newFileName = fileName;
                if (BaseSystem.IO.File.Exists(string.Format(SAVE_DESTINATION_FORMAT, sessionSaveDestination, newFileName)))
                {
                    newFileName = CinemaMocapHelper.GetNewFilename(sessionSaveDestination, fileName, "asset");
                    UnityEngine.Debug.LogWarning(string.Format(NAME_DUPLICATE_ERROR_MSG, fileName, newFileName));
                }

                AssetDatabase.CreateAsset(session, string.Format(SAVE_DESTINATION_FORMAT, sessionSaveDestination, newFileName));
                AssetDatabase.SaveAssets();
            }

            // Save the animation
            OutputProfile.SaveAnimation(animation);
            AssetDatabase.Refresh();
        }
Ejemplo n.º 2
0
        public virtual NUISkeleton Filter(CaptureCache cache)
        {
            NUISkeleton skeleton = cache.CurrentSkeleton;

            return(Filter(skeleton));
        }