Esempio n. 1
0
    /// <summary>
    /// Draw the Window's contents
    /// </summary>
	protected void OnGUI()
    {
        if (workingResolution == null)
        {
            workingResolution = ResolutionData.FromZigResolution(kinectCaptureResolution);
        }
        float aspectRatio = workingResolution.Width / workingResolution.Height;
        float textureWidth = (base.position.width - (UI_SPACING * 3)) / 2;
        float textureHeight = textureWidth * aspectRatio;
        float newDesiredTilt = desiredTilt;

        if (isNUIOn && ZigEditorInput.Instance.ReaderInited)
        {
            if (viewerType == NUIViewerType.DepthViewer)
            {
                GUI.DrawTexture(new Rect(UI_SPACING, UI_SPACING, textureWidth, textureHeight), depthViewer.Texture);
            }
            else if (viewerType == NUIViewerType.ImageViewer)
            {
                GUI.DrawTexture(new Rect(UI_SPACING, UI_SPACING, textureWidth, textureHeight), imageViewer.Texture);
            }
            //else if (viewerType == NUIViewerType.DepthAndImageViewer)
            //{
            //    GUI.DrawTexture(new Rect(UI_SPACING, UI_SPACING, textureWidth, textureHeight), mixedViewer.Texture);
            //}
            if (captureState == RecordingState.PreRecording)
            {
                int timeLeft = (int)(((delaySeconds * 1000) - stopwatch.ElapsedMilliseconds)/1000) + 1;
                GUIStyle countdownFont = new GUIStyle(EditorStyles.label);
                countdownFont.fontSize = (int)(textureHeight/6);
                countdownFont.normal.textColor = Color.white;
                Vector2 size = countdownFont.CalcSize(new GUIContent(timeLeft.ToString()));
                GUI.Label(new Rect(textureWidth - (size.x), textureHeight - size.y, size.x, size.y), timeLeft.ToString(), countdownFont);
            }
            if (captureState == RecordingState.Recording)
            {
                GUI.DrawTexture(new Rect((textureWidth) - recordingImage.width, (UI_SPACING + textureHeight) - recordingImage.height, recordingImage.width, recordingImage.height), recordingImage);
            }
            GUI.DrawTexture(new Rect((UI_SPACING * 2) + textureWidth, UI_SPACING, textureWidth, textureHeight), radarLogo);
            usersRadar.Render(ZigEditorInput.Instance, new Rect((UI_SPACING * 2) + textureWidth, UI_SPACING, textureWidth, textureHeight));
        }
        else if (mocapLogo != null && workingResolution != null)
        {
            // Draw place holders
            GUI.DrawTexture(new Rect(UI_SPACING, UI_SPACING, textureWidth, textureHeight), mocapLogo);
            GUI.DrawTexture(new Rect((UI_SPACING * 2) + textureWidth, UI_SPACING, textureWidth, textureHeight), radarLogo);
        }

        float panelHeight = base.position.height - textureHeight - (UI_SPACING * 3);
        if (panelHeight > 5)
        {
            GUILayout.BeginArea(new Rect(UI_SPACING, textureHeight + (UI_SPACING * 2), textureWidth, panelHeight), string.Empty, "box");
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent(DEVICE_TRACKING));
                bool toggleOn = false;
                Color temp = GUI.color;
                if (isNUIOn)
                {
                    GUI.color = Color.green;
                    toggleOn = GUILayout.Toggle(isNUIOn, ON, EditorStyles.miniButton);
                }
                else
                {
                    GUI.color = Color.red;
                    toggleOn = GUILayout.Toggle(isNUIOn, OFF, EditorStyles.miniButton);
                }
                GUI.color = temp;
                EditorGUILayout.EndHorizontal();

                if (toggleOn && !isNUIOn)
                {
                    turnOnNUIDevice();
                }
                else if (!toggleOn && isNUIOn)
                {
                    turnOffNUIDevice();
                }
                
                viewerType = (NUIViewerType)EditorGUILayout.EnumPopup(new GUIContent(VIEWER), viewerType);
                
                List<GUIContent> resolutions = new List<GUIContent>();
                foreach(string name in Enum.GetNames(typeof(ZigResolution)))
                {
                    resolutions.Add(new GUIContent(name.Replace('_',' ')));
                }
                kinectCaptureResolution = (ZigResolution)EditorGUILayout.Popup(new GUIContent(KINECT_RESOLUTION), (int)kinectCaptureResolution, resolutions.ToArray());
                
                SmoothingOptions newSmoothingOptions = (SmoothingOptions)EditorGUILayout.EnumPopup(new GUIContent(SMOOTHING_OPTIONS), smoothingOptions);
                if (newSmoothingOptions != smoothingOptions)
                {
                    smoothingOptions = newSmoothingOptions;
                    if (smoothingOptions == SmoothingOptions.None)
                    {
                        settings.KinectSDKSpecific.SmoothingParameters.SetNoSmoothing();
                    }
                    else if(smoothingOptions == SmoothingOptions.Light)
                    {
                        settings.KinectSDKSpecific.SmoothingParameters.SetLightSmoothing();
                    }
                    else if (smoothingOptions == SmoothingOptions.Moderate)
                    {
                        settings.KinectSDKSpecific.SmoothingParameters.SetModerateSmoothing();
                    }
                    else if (smoothingOptions == SmoothingOptions.Heavy)
                    {
                        settings.KinectSDKSpecific.SmoothingParameters.Smoothing = 0.6f;
                        settings.KinectSDKSpecific.SmoothingParameters.Correction = 0.4f;
                        settings.KinectSDKSpecific.SmoothingParameters.Prediction = 0.6f;
                        settings.KinectSDKSpecific.SmoothingParameters.JitterRadius = 0.15f;
                        settings.KinectSDKSpecific.SmoothingParameters.MaxDeviationRadius = 0.10f;
                        //settings.KinectSDKSpecific.SmoothingParameters.SetHeavySmoothing();
                    }
                    ZigEditorInput.Instance.SetSmoothingParameters((smoothingOptions != SmoothingOptions.None), settings.KinectSDKSpecific.SmoothingParameters);
                }
                viewNodes = EditorGUILayout.Toggle(JOINT_VIEW, viewNodes);
                
                EditorGUI.BeginDisabledGroup(!isNUIOn);
                newDesiredTilt = EditorGUILayout.IntSlider(new GUIContent(DEVICE_TILT), (int)desiredTilt, -27, 27);
                EditorGUI.EndDisabledGroup();

                workingResolution = ResolutionData.FromZigResolution(kinectCaptureResolution);
            }
            GUILayout.EndArea();

            GUILayout.BeginArea(new Rect((UI_SPACING * 2) + textureWidth, textureHeight + (UI_SPACING * 2), textureWidth, panelHeight), String.Empty, "box");
            {
                fileName = EditorGUILayout.TextField(new GUIContent("Filename"), fileName);

                /*
                isFilterFoldout = EditorGUILayout.Foldout(isFilterFoldout, new GUIContent("Filters"));
                if (isFilterFoldout)
                {
                    EditorGUI.indentLevel = 1;
                    EditorGUILayout.Toggle(new GUIContent("Smooth"), false);
                    EditorGUILayout.Toggle(new GUIContent("Mirror"), false);
                    EditorGUILayout.Toggle(new GUIContent("Correct Sensor Tilt"), false);
                    EditorGUILayout.Toggle(new GUIContent("Correct Sensor Offset"), false);
                    EditorGUI.indentLevel = 0;
                }

                GUILayout.Space(UI_SPACING);*/
                //recordingStart = (RecordingStart)EditorGUILayout.EnumPopup(new GUIContent("Start On"), recordingStart);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent("Model Preview"));
                if (GUILayout.Button("Generate"))
                {
                    createModelPreview();
                }
                EditorGUILayout.EndHorizontal();

                delaySelection = EditorGUILayout.Popup(new GUIContent("Start Delay"), delaySelection, delays);

                isAdvancedExposed = EditorGUILayout.Foldout(isAdvancedExposed, new GUIContent("Advanced"));
                if (isAdvancedExposed)
                {
                    transformationType = (TransformationType)EditorGUILayout.EnumPopup(new GUIContent("Transformation Type"), transformationType);
                }

                GUILayout.Space(UI_SPACING);
                EditorGUI.BeginDisabledGroup(!isNUIOn);
                if (GUILayout.Button(captureState == RecordingState.NotRecording ? new GUIContent("Record") : new GUIContent("Stop")))
                {
                    if (captureState == RecordingState.NotRecording)
                    {
                        BeginPreRecording();
                    }
                    else
                    {
                        StopRecording();
                    }
                }
                EditorGUI.EndDisabledGroup();
            }
            GUILayout.EndArea();
        }
        GUI.skin = null;

        if (newDesiredTilt != desiredTilt)
        {
            desiredTilt = newDesiredTilt;
            NuiWrapper.NuiCameraElevationSetAngle((long)desiredTilt);
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Draw the Window's contents
    /// </summary>
    protected void OnGUI()
    {
        if (workingResolution == null)
        {
            workingResolution = ResolutionData.FromZigResolution(kinectCaptureResolution);
        }
        float aspectRatio    = workingResolution.Width / workingResolution.Height;
        float textureWidth   = (base.position.width - (UI_SPACING * 3)) / 2;
        float textureHeight  = textureWidth * aspectRatio;
        float newDesiredTilt = desiredTilt;

        if (isNUIOn && ZigEditorInput.Instance.ReaderInited)
        {
            if (viewerType == NUIViewerType.DepthViewer)
            {
                GUI.DrawTexture(new Rect(UI_SPACING, UI_SPACING, textureWidth, textureHeight), depthViewer.Texture);
            }
            else if (viewerType == NUIViewerType.ImageViewer)
            {
                GUI.DrawTexture(new Rect(UI_SPACING, UI_SPACING, textureWidth, textureHeight), imageViewer.Texture);
            }
            //else if (viewerType == NUIViewerType.DepthAndImageViewer)
            //{
            //    GUI.DrawTexture(new Rect(UI_SPACING, UI_SPACING, textureWidth, textureHeight), mixedViewer.Texture);
            //}
            if (captureState == RecordingState.PreRecording)
            {
                int      timeLeft      = (int)(((delaySeconds * 1000) - stopwatch.ElapsedMilliseconds) / 1000) + 1;
                GUIStyle countdownFont = new GUIStyle(EditorStyles.label);
                countdownFont.fontSize         = (int)(textureHeight / 6);
                countdownFont.normal.textColor = Color.white;
                Vector2 size = countdownFont.CalcSize(new GUIContent(timeLeft.ToString()));
                GUI.Label(new Rect(textureWidth - (size.x), textureHeight - size.y, size.x, size.y), timeLeft.ToString(), countdownFont);
            }
            if (captureState == RecordingState.Recording)
            {
                GUI.DrawTexture(new Rect((textureWidth) - recordingImage.width, (UI_SPACING + textureHeight) - recordingImage.height, recordingImage.width, recordingImage.height), recordingImage);
            }
            GUI.DrawTexture(new Rect((UI_SPACING * 2) + textureWidth, UI_SPACING, textureWidth, textureHeight), radarLogo);
            usersRadar.Render(ZigEditorInput.Instance, new Rect((UI_SPACING * 2) + textureWidth, UI_SPACING, textureWidth, textureHeight));
        }
        else if (mocapLogo != null && workingResolution != null)
        {
            // Draw place holders
            GUI.DrawTexture(new Rect(UI_SPACING, UI_SPACING, textureWidth, textureHeight), mocapLogo);
            GUI.DrawTexture(new Rect((UI_SPACING * 2) + textureWidth, UI_SPACING, textureWidth, textureHeight), radarLogo);
        }

        float panelHeight = base.position.height - textureHeight - (UI_SPACING * 3);

        if (panelHeight > 5)
        {
            GUILayout.BeginArea(new Rect(UI_SPACING, textureHeight + (UI_SPACING * 2), textureWidth, panelHeight), string.Empty, "box");
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent(DEVICE_TRACKING));
                bool  toggleOn = false;
                Color temp     = GUI.color;
                if (isNUIOn)
                {
                    GUI.color = Color.green;
                    toggleOn  = GUILayout.Toggle(isNUIOn, ON, EditorStyles.miniButton);
                }
                else
                {
                    GUI.color = Color.red;
                    toggleOn  = GUILayout.Toggle(isNUIOn, OFF, EditorStyles.miniButton);
                }
                GUI.color = temp;
                EditorGUILayout.EndHorizontal();

                if (toggleOn && !isNUIOn)
                {
                    turnOnNUIDevice();
                }
                else if (!toggleOn && isNUIOn)
                {
                    turnOffNUIDevice();
                }

                viewerType = (NUIViewerType)EditorGUILayout.EnumPopup(new GUIContent(VIEWER), viewerType);

                List <GUIContent> resolutions = new List <GUIContent>();
                foreach (string name in Enum.GetNames(typeof(ZigResolution)))
                {
                    resolutions.Add(new GUIContent(name.Replace('_', ' ')));
                }
                kinectCaptureResolution = (ZigResolution)EditorGUILayout.Popup(new GUIContent(KINECT_RESOLUTION), (int)kinectCaptureResolution, resolutions.ToArray());

                SmoothingOptions newSmoothingOptions = (SmoothingOptions)EditorGUILayout.EnumPopup(new GUIContent(SMOOTHING_OPTIONS), smoothingOptions);
                if (newSmoothingOptions != smoothingOptions)
                {
                    smoothingOptions = newSmoothingOptions;
                    if (smoothingOptions == SmoothingOptions.None)
                    {
                        settings.KinectSDKSpecific.SmoothingParameters.SetNoSmoothing();
                    }
                    else if (smoothingOptions == SmoothingOptions.Light)
                    {
                        settings.KinectSDKSpecific.SmoothingParameters.SetLightSmoothing();
                    }
                    else if (smoothingOptions == SmoothingOptions.Moderate)
                    {
                        settings.KinectSDKSpecific.SmoothingParameters.SetModerateSmoothing();
                    }
                    else if (smoothingOptions == SmoothingOptions.Heavy)
                    {
                        settings.KinectSDKSpecific.SmoothingParameters.Smoothing          = 0.6f;
                        settings.KinectSDKSpecific.SmoothingParameters.Correction         = 0.4f;
                        settings.KinectSDKSpecific.SmoothingParameters.Prediction         = 0.6f;
                        settings.KinectSDKSpecific.SmoothingParameters.JitterRadius       = 0.15f;
                        settings.KinectSDKSpecific.SmoothingParameters.MaxDeviationRadius = 0.10f;
                        //settings.KinectSDKSpecific.SmoothingParameters.SetHeavySmoothing();
                    }
                    ZigEditorInput.Instance.SetSmoothingParameters((smoothingOptions != SmoothingOptions.None), settings.KinectSDKSpecific.SmoothingParameters);
                }
                viewNodes = EditorGUILayout.Toggle(JOINT_VIEW, viewNodes);

                EditorGUI.BeginDisabledGroup(!isNUIOn);
                newDesiredTilt = EditorGUILayout.IntSlider(new GUIContent(DEVICE_TILT), (int)desiredTilt, -27, 27);
                EditorGUI.EndDisabledGroup();

                workingResolution = ResolutionData.FromZigResolution(kinectCaptureResolution);
            }
            GUILayout.EndArea();

            GUILayout.BeginArea(new Rect((UI_SPACING * 2) + textureWidth, textureHeight + (UI_SPACING * 2), textureWidth, panelHeight), String.Empty, "box");
            {
                fileName = EditorGUILayout.TextField(new GUIContent("Filename"), fileName);

                /*
                 * isFilterFoldout = EditorGUILayout.Foldout(isFilterFoldout, new GUIContent("Filters"));
                 * if (isFilterFoldout)
                 * {
                 *  EditorGUI.indentLevel = 1;
                 *  EditorGUILayout.Toggle(new GUIContent("Smooth"), false);
                 *  EditorGUILayout.Toggle(new GUIContent("Mirror"), false);
                 *  EditorGUILayout.Toggle(new GUIContent("Correct Sensor Tilt"), false);
                 *  EditorGUILayout.Toggle(new GUIContent("Correct Sensor Offset"), false);
                 *  EditorGUI.indentLevel = 0;
                 * }
                 *
                 * GUILayout.Space(UI_SPACING);*/
                //recordingStart = (RecordingStart)EditorGUILayout.EnumPopup(new GUIContent("Start On"), recordingStart);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent("Model Preview"));
                if (GUILayout.Button("Generate"))
                {
                    createModelPreview();
                }
                EditorGUILayout.EndHorizontal();

                delaySelection = EditorGUILayout.Popup(new GUIContent("Start Delay"), delaySelection, delays);

                isAdvancedExposed = EditorGUILayout.Foldout(isAdvancedExposed, new GUIContent("Advanced"));
                if (isAdvancedExposed)
                {
                    transformationType = (TransformationType)EditorGUILayout.EnumPopup(new GUIContent("Transformation Type"), transformationType);
                }

                GUILayout.Space(UI_SPACING);
                EditorGUI.BeginDisabledGroup(!isNUIOn);
                if (GUILayout.Button(captureState == RecordingState.NotRecording ? new GUIContent("Record") : new GUIContent("Stop")))
                {
                    if (captureState == RecordingState.NotRecording)
                    {
                        BeginPreRecording();
                    }
                    else
                    {
                        StopRecording();
                    }
                }
                EditorGUI.EndDisabledGroup();
            }
            GUILayout.EndArea();
        }
        GUI.skin = null;

        if (newDesiredTilt != desiredTilt)
        {
            desiredTilt = newDesiredTilt;
            NuiWrapper.NuiCameraElevationSetAngle((long)desiredTilt);
        }
    }