Ejemplo n.º 1
0
        public override void LoadEditorPrefs()
        {
            if (EditorPrefs.HasKey(PLAYBACK_INPUT_SESSION_ASSET_PATH_KEY))
            {
                sessionAssetPath = EditorPrefs.GetString(PLAYBACK_INPUT_SESSION_ASSET_PATH_KEY);

                session = (MocapSession)AssetDatabase.LoadAssetAtPath(sessionAssetPath, typeof(MocapSession));
            }
        }
Ejemplo n.º 2
0
        private void beginRecording()
        {
            cache        = new CaptureCache();
            captureState = RecordingState.Recording;
            session      = ScriptableObject.CreateInstance <MocapSession>();

            session.MetaData    = InputProfile.GetSessionMetaData();
            session.CaptureData = new List <MocapSessionKeyframe>();

            startTime = DateTime.Now;
        }
Ejemplo n.º 3
0
        public override void DrawPipelineSettings()
        {
            EditorGUI.BeginDisabledGroup(!InputProfile.IsDeviceOn);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");
            if (GUILayout.Button(new GUIContent("Save"), EditorStyles.miniButton))
            {
                saveSession = false;

                MocapSession session = InputProfile.GetSession();
                saveAnimation(session);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draw the Input settings for session playback.
        /// </summary>
        public override void DrawInputSettings()
        {
            MocapSession temp = EditorGUILayout.ObjectField(new GUIContent("Session"), session, typeof(MocapSession), false) as MocapSession;

            sessionAssetPath = AssetDatabase.GetAssetPath(temp);

            if (temp != session)
            {
                session = temp;
                base.OnInputSkeletonTypeChanged(new EventArgs());
                EditorPrefs.SetString(PLAYBACK_INPUT_SESSION_ASSET_PATH_KEY, sessionAssetPath);
            }

            EditorGUI.BeginDisabledGroup(session == null);

            int lastFrame = session == null ? 0 : session.CaptureData.Count - 1;

            EditorGUILayout.BeginHorizontal();

            int tempFrame = EditorGUILayout.IntField("Frame", frame);


            if (GUILayout.Button("<", EditorStyles.miniButton, GUILayout.Width(25f)))
            {
                tempFrame--;
            }

            if (GUILayout.Button(">", EditorStyles.miniButton, GUILayout.Width(25f)))
            {
                tempFrame++;
            }

            //bounds
            if (tempFrame < 0)
            {
                tempFrame = 0;
            }
            if (tempFrame > lastFrame)
            {
                tempFrame = lastFrame;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");

            // "Start rendering" button
            if (skeletonRendererInstance == null)
            {
                if (GUILayout.Button(new GUIContent("Render Raw Skeleton"), EditorStyles.miniButton))
                {
                    skeletonRendererInstance = GameObject.Find(SKELETON_RENDERER_NAME);

                    if (skeletonRendererInstance == null)
                    {
                        skeletonRendererInstance = new GameObject(SKELETON_RENDERER_NAME);
                        skeletonRendererInstance.AddComponent <SkeletonRenderer>();
                    }

                    skeletonRendererInstance.GetComponent <SkeletonRenderer>().UpdateSkeleton(session.CaptureData[frame].Skeleton, this.InputSkeleton);
                }
            }
            else // "Stop rendering" button
            {
                Color tempColor = GUI.color;
                GUI.color = Color.magenta;
                if (GUILayout.Button(new GUIContent("Stop Rendering"), EditorStyles.miniButton))
                {
                    skeletonRendererInstance = null;
                    UnityEngine.Object.DestroyImmediate(GameObject.Find(SKELETON_RENDERER_NAME));
                }
                GUI.color = tempColor;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            if (session != null && tempFrame != frame)
            {
                frame = tempFrame;

                var data = new FrameSelectedEventArgs(session, frame);
                OnFrameSelected(data);

                skeletonRendererInstance = GameObject.Find(SKELETON_RENDERER_NAME);
                if (skeletonRendererInstance != null)
                {
                    skeletonRendererInstance.GetComponent <SkeletonRenderer>().UpdateSkeleton(session.CaptureData[frame].Skeleton, this.InputSkeleton);
                }
            }

            SaveEditorPrefs();
        }
Ejemplo n.º 5
0
 public FrameSelectedEventArgs(MocapSession session, int frame)
 {
     this.session = session;
     this.frame   = frame;
 }
Ejemplo n.º 6
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.º 7
0
        public override void DrawPipelineSettings()
        {
            int tempDelaySelection = EditorGUILayout.Popup(new GUIContent("Start Delay", "The delay in seconds before recording begins after pressing the record button."), delaySelection, delays);

            if (tempDelaySelection != delaySelection)
            {
                delaySelection = tempDelaySelection;
                EditorPrefs.SetInt(RECORD_START_DELAY_KEY, delaySelection);
            }

            bool isDeveloperModeEnabled = true;

            if (isDeveloperModeEnabled)
            {
                bool tempSaveSession = EditorGUILayout.Toggle(new GUIContent("Save Session", "Saves the raw data of the session in the project folder for later use."), saveSession);

                if (tempSaveSession != saveSession)
                {
                    saveSession = tempSaveSession;
                    EditorPrefs.SetBool(PIPELINE_SAVE_SESSION_KEY, saveSession);
                }

                if (saveSession)
                {
                    // Check if save location has changed from settings window
                    if (sessionSaveDestination != EditorPrefs.GetString(PIPELINE_SAVE_DESTINATION_KEY))
                    {
                        sessionSaveDestination = EditorPrefs.GetString(PIPELINE_SAVE_DESTINATION_KEY);
                        absPath = (Application.dataPath).Replace("Assets", sessionSaveDestination);
                    }

                    string tempFileName = EditorGUILayout.TextField(new GUIContent("Session Filename"), fileName);

                    if (tempFileName != fileName)
                    {
                        fileName = tempFileName;
                        EditorPrefs.SetString(PIPELINE_SAVE_FILENAME_KEY, fileName);
                    }

                    EditorGUILayout.PrefixLabel("Save Location:");

                    EditorGUILayout.BeginHorizontal();

                    EditorGUI.indentLevel++;
                    EditorGUILayout.SelectableLabel(sessionSaveDestination, EditorStyles.textField, GUILayout.Height(16f));
                    EditorGUI.indentLevel--;


                    bool saveDestChanged = false;
                    if (GUILayout.Button(new GUIContent("..."), EditorStyles.miniButton, GUILayout.Width(24f)))
                    {
                        // Ensure the path text field does not have focus, or else we cannot change the contents.
                        GUI.SetNextControlName("");
                        GUI.FocusControl("");

                        string temp = EditorUtility.SaveFolderPanel("Select a folder within your project", sessionSaveDestination, "");

                        // Pressing cancel returns an empty string, don't clear the previous text on cancel.
                        if (temp != string.Empty)
                        {
                            absPath = temp;
                        }

                        saveDestChanged = true;
                    }

                    EditorGUILayout.EndHorizontal();

                    // Display error if path not within project folder
                    if (!absPath.StartsWith(Application.dataPath))
                    {
                        EditorGUILayout.HelpBox("Invalid selection!\nYou must select a location within your project's \"Assets\" folder.", MessageType.Warning);
                        sessionSaveDestination = CinemaMocapHelper.GetRelativeProjectPath(Application.dataPath);
                    }
                    else
                    {
                        sessionSaveDestination = CinemaMocapHelper.GetRelativeProjectPath(absPath);
                    }

                    if (saveDestChanged)
                    {
                        EditorPrefs.SetString(PIPELINE_SAVE_DESTINATION_KEY, sessionSaveDestination);
                    }
                }
            }

            EditorGUI.BeginDisabledGroup(!InputProfile.IsDeviceOn);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");
            if (GUILayout.Button(captureState == RecordingState.NotRecording ? new GUIContent("Record") : new GUIContent("Stop"), EditorStyles.miniButton))
            {
                if (captureState == RecordingState.NotRecording)
                {
                    int delaySeconds = int.Parse(delays[delaySelection].text.Split(' ')[0]);
                    StartRecording(delaySeconds);
                }
                else
                {
                    MocapSession session = StopRecording();
                    saveAnimation(session);
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();
        }