Exemplo n.º 1
0
        public override void SaveAnimation(NUIHumanoidAnimation animation)
        {
            // Check if there is capture data
            if (animation == null)
            {
                UnityEngine.Debug.LogWarning("No capture data was found.");
                return;
            }

            // Map captured data to Collada data
            ColladaAnimationData data = GetColladaAnimation(animation);

            // Check filename
            string appendedFileName = string.Format("MoCapHumanoid@{0}", fileName);
            string newFileName      = appendedFileName;

            if (BaseSystem.IO.File.Exists(string.Format(SAVE_DESTINATION_FORMAT, animSaveDestination, newFileName)))
            {
                newFileName = CinemaMocapHelper.GetNewFilename(animSaveDestination, appendedFileName, "dae");
                UnityEngine.Debug.LogWarning(string.Format(NAME_DUPLICATE_ERROR_MSG, appendedFileName, newFileName));
            }

            // Save
            if (transformationType == TransformationType.Matrix)
            {
                ColladaUtility.SaveAnimationData(data, SOURCE_FILE_MATRIX_PATH, string.Format(SAVE_DESTINATION_FORMAT, animSaveDestination, newFileName), true);
            }
            else
            {
                ColladaUtility.SaveAnimationData(data, SOURCE_FILE_PATH, string.Format(SAVE_DESTINATION_FORMAT, animSaveDestination, newFileName), false);
            }
        }
Exemplo n.º 2
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();
        }