Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (FindObjectOfType <NuitrackManager>(true) == null)
            {
                NuitrackSDKGUI.NuitrackNotExistMessage();
            }

            SensorSpace sensorSpace = serializedObject.targetObject as SensorSpace;
            Canvas      canvas      = viewCanvasProperty.objectReferenceValue as Canvas;

            if (canvas != null)
            {
                if (canvas.renderMode == RenderMode.WorldSpace || canvas.renderMode == RenderMode.ScreenSpaceOverlay)
                {
                    string message = string.Format("The canvas rendering mode is specified: {0}.\nIt is recommended to use: {1}",
                                                   canvas.renderMode, RenderMode.ScreenSpaceCamera);

                    string buttonLabel = string.Format("Switch to {0}", RenderMode.ScreenSpaceCamera);

                    UnityAction fixAction = delegate { FixCanvasRenderMode(canvas, sensorSpace); };

                    NuitrackSDKGUI.DrawMessage(message, LogType.Warning, fixAction, buttonLabel);
                }
            }
            else
            {
                string message = "View Canvas is not set. The screen size will be used to align the camera's fov.";
                NuitrackSDKGUI.DrawMessage(message, LogType.Log);
            }
        }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(m_FrameMode);
            serializedObject.ApplyModifiedProperties();
            EditorGUILayout.Space();

            base.OnInspectorGUI();

            if (FindObjectOfType <NuitrackManager>(true) == null)
            {
                NuitrackSDKGUI.NuitrackNotExistMessage();
            }

            if (nuitrackAspectRatioFitter.aspectMode != AspectRatioFitter.AspectMode.FitInParent)
            {
                UnityAction fixAspectMode = delegate { FixAspectMode(m_AspectMode); };

                string message = string.Format("Aspect Mode is set to {0}." +
                                               "The frame from the sensor may not be displayed correctly." +
                                               "\nRecommended: Fit In Parent.",
                                               nuitrackAspectRatioFitter.aspectMode);

                NuitrackSDKGUI.DrawMessage(message, LogType.Warning, fixAspectMode, "Fix");
            }

            serializedObject.ApplyModifiedProperties();
        }
        void DrawConfiguration()
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Configuration", EditorStyles.boldLabel);

            SerializedProperty runInBackground = serializedObject.FindProperty("runInBackground");

            EditorGUILayout.PropertyField(runInBackground);
            serializedObject.ApplyModifiedProperties();

            NuitrackSDKGUI.PropertyWithHelpButton(
                serializedObject,
                "wifiConnect",
                "https://github.com/3DiVi/nuitrack-sdk/blob/master/doc/TVico_User_Guide.md#wireless-case",
                "Only skeleton. PC, Unity Editor, MacOS and IOS");


            NuitrackSDKGUI.PropertyWithHelpButton(
                serializedObject,
                "useNuitrackAi",
                "https://github.com/3DiVi/nuitrack-sdk/blob/master/doc/Nuitrack_AI.md",
                "ONLY PC! Nuitrack AI is the new version of Nuitrack skeleton tracking middleware");

            NuitrackSDKGUI.PropertyWithHelpButton(
                serializedObject,
                "useFaceTracking",
                "https://github.com/3DiVi/nuitrack-sdk/blob/master/doc/Unity_Face_Tracking.md",
                "Track and get information about faces with Nuitrack (position, angle of rotation, box, emotions, age, gender)");
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.objectReferenceValue == null)
            {
                position = NuitrackSDKGUI.WithRightButton(position, delegate { CreateNewPose(property); }, "Toolbar Plus", "Create a new pose and add it to the list");
            }
            else
            {
                position = NuitrackSDKGUI.WithRightButton(position, delegate { ViewPose(property); }, "animationvisibilitytoggleon", "View pose");
            }

            EditorGUI.PropertyField(position, property, label);
        }
Ejemplo n.º 5
0
        void DrawRuntimePosesMatching()
        {
            ShowRuntimePoseMatching = EditorGUILayout.BeginFoldoutHeaderGroup(ShowRuntimePoseMatching, "Runtime matches of poses");

            if (ShowRuntimePoseMatching)
            {
                if (EditorApplication.isPlaying)
                {
                    if (PoseDetector.CountPoses > 0)
                    {
                        using (new VerticalGroup(EditorStyles.helpBox))
                        {
                            foreach (NuitrackPose pose in PoseDetector)
                            {
                                using (new VerticalGroup())
                                {
                                    EditorGUILayout.LabelField(pose.name, EditorStyles.boldLabel);

                                    using (new VerticalGroup(EditorStyles.helpBox))
                                    {
                                        if (PoseDetector.Matches[pose].Count > 0)
                                        {
                                            foreach (KeyValuePair <int, float> poseMatch in PoseDetector.Matches[pose])
                                            {
                                                DrawUserPoseMatch(string.Format("User id: {0}", poseMatch.Key), poseMatch.Value);
                                            }
                                        }
                                        else
                                        {
                                            DrawUserPoseMatch("User not found", 0);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        NuitrackSDKGUI.DrawMessage("Not a single pose is set", LogType.Log);
                    }

                    Repaint();
                }
                else
                {
                    NuitrackSDKGUI.DrawMessage("Play the scene to see the matching poses for the users", LogType.Log);
                }
            }

            EditorGUILayout.EndFoldoutHeaderGroup();
        }
        void DrawRecordFileGUI()
        {
            EditorGUILayout.LabelField("Advanced", EditorStyles.boldLabel);

            SerializedProperty useFileRecordProp = serializedObject.FindProperty("useFileRecord");

            EditorGUILayout.PropertyField(useFileRecordProp, new GUIContent("Use record file"));
            serializedObject.ApplyModifiedProperties();

            if (useFileRecordProp.boolValue)
            {
                SerializedProperty pathProperty = serializedObject.FindProperty("pathToFileRecord");

                pathProperty.stringValue = NuitrackSDKGUI.OpenFileField(pathProperty.stringValue, "Bag or oni file", "bag", "oni");

                serializedObject.ApplyModifiedProperties();
            }
        }
        void DrawPoseGUI()
        {
            GUIStyle contentStyle = new GUIStyle(GUIStyle.none)
            {
                margin = new RectOffset(20, 0, 2, 2)
            };
            GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout)
            {
                fontStyle = FontStyle.Bold
            };

            List <nuitrack.JointType> jointsMask = NuitrackPoseWrapper.JointsMask;

            using (new VerticalGroup(contentStyle))
            {
                GUIContent relativeButtonContent = new GUIContent("Relative mode", "In relative mode, the rotation of the trunk will not affect the correspondence of the pose");
                poseWrapper.RelativeMode = EditorGUILayout.Toggle(relativeButtonContent, poseWrapper.RelativeMode);

                List <nuitrack.JointType> activeJoints = jointsMask.Where(k => poseWrapper[k].IsActive).ToList();
                skeletonMapper.Draw(activeJoints);

                if (skeletonPoseView != null)
                {
                    skeletonPoseView.DrawGUIInspector();
                }

                if (SelectedJoint != nuitrack.JointType.None)
                {
                    NuitrackSDKGUI.DrawMessage("You can disable the selected joint by clicking on it.", LogType.Log);
                }

                EditorGUILayout.Space();
                openAdvanced = GUILayout.Toggle(openAdvanced, "Advanced settings", foldoutStyle);

                if (openAdvanced)
                {
                    using (new VerticalGroup(contentStyle))
                        DrawPoseAdvanced();
                }

                EditorGUILayout.Space();
            }
        }
Ejemplo n.º 8
0
        public override void OnInspectorGUI()
        {
            if (NuitrackManager == null)
            {
                NuitrackSDKGUI.NuitrackNotExistMessage();
                EditorGUILayout.Space();
            }

            DrawDefaultInspector();
            EditorGUILayout.Space();

            listView.DoLayoutList();
            serializedObject.ApplyModifiedProperties();

            EditorGUILayout.Space();
            DrawRuntimePosesMatching();
            EditorGUILayout.Space();

            DrawRuntimeWizard();
        }
        void DrawAutomapTools(IEnumerable <JointType> activeJoints)
        {
            bool disableClearbutton = activeJoints.Count() == 0;

            using (new VerticalGroup(EditorStyles.helpBox))
            {
                string text = disableClearbutton ?
                              "Click \"Automap\" to quickly configure the avatar" :
                              "To make the avatar exactly repeat your movements, put the avatar in the T-pose";

                GUIContent gUIContent = new GUIContent(text, NuitrackSDKGUI.GetMessageIcon(LogType.Log));
                EditorGUILayout.LabelField(gUIContent, EditorStyles.wordWrappedLabel);

                using (new HorizontalGroup())
                {
                    using (new GUIColor(disableClearbutton ? firstAutomapColor : GUI.color))
                        if (GUILayout.Button(autoMapping))
                        {
                            AutoMapping();
                        }

                    EditorGUI.BeginDisabledGroup(disableClearbutton);

                    if (GUILayout.Button(enforceTPose))
                    {
                        SetToTPose();
                    }

                    if (GUILayout.Button(clearMapping))
                    {
                        if (EditorUtility.DisplayDialog("Skeleton map", "Do you really want to clear the skeleton map?", "Yes", "No"))
                        {
                            Clear();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Draw a GUI in the inspector.
        /// Use this in method OnInspectorGUI of your custom editors.
        /// </summary>
        public void DrawInspectorGUI()
        {
            EditorGUILayout.LabelField("Skeleton display mode", EditorStyles.boldLabel);

            switch (CurrentViewMode)
            {
            case ViewMode.ModelBones:
                string modelBonesMessage = SelectedJoint == nuitrack.JointType.None ?
                                           "Select the joint on the avatar, and then specify the joint on the model in order to set the match." :
                                           "Specify the joint on the model in order to set the match. \nClick \"Deselect\" for cancels selection.";

                NuitrackSDKGUI.DrawMessage(modelBonesMessage, LogType.Log);

                break;

            case ViewMode.AssignedBones:
                string assignedBonesMessage = "The mode displays the specified joints of the skeleton. You can blow out the joints on the model.";
                NuitrackSDKGUI.DrawMessage(assignedBonesMessage, LogType.Log);
                break;
            }

            CurrentViewMode = (ViewMode)GUILayout.Toolbar((int)CurrentViewMode, skeletonModeGuiContent);
        }
        void DrawFramePreview()
        {
            float pointScale = 0.025f;
            float lineScale  = 0.01f;

            ShowPreview = EditorGUILayout.BeginFoldoutHeaderGroup(ShowPreview, "Frame viewer");

            if (ShowPreview)
            {
                if (!EditorApplication.isPlaying)
                {
                    NuitrackSDKGUI.DrawMessage("RGB and depth frames will be displayed run time.", LogType.Log);
                }
                else
                {
                    if (rgbCache == null)
                    {
                        rgbCache = new TextureCache();
                    }

                    if (depthCache == null)
                    {
                        depthCache = new TextureCache();
                    }

                    List <Vector2> pointCoord = new List <Vector2>();

                    rgbTexture   = NuitrackManager.ColorFrame.ToRenderTexture(rgbCache);
                    depthTexture = NuitrackManager.DepthFrame.ToRenderTexture(textureCache: depthCache);

                    Rect rgbRect = NuitrackSDKGUI.DrawFrame(rgbTexture, "RGB frame");

                    Texture pointTexture = EditorGUIUtility.IconContent("sv_icon_dot0_pix16_gizmo").image;

                    float lineSize = rgbRect.size.magnitude * lineScale;

                    foreach (UserData user in NuitrackManager.Users)
                    {
                        if (user.Skeleton != null)
                        {
                            Color userColor = FrameUtils.SegmentToTexture.GetColorByID(user.ID);

                            foreach (nuitrack.JointType jointType in System.Enum.GetValues(typeof(nuitrack.JointType)))
                            {
                                nuitrack.JointType parentJointType = jointType.GetParent();

                                UserData.SkeletonData.Joint joint = user.Skeleton.GetJoint(jointType);

                                if (joint.Confidence > 0.1f)
                                {
                                    Vector2 startPoint = new Vector2(rgbRect.x + rgbRect.width * joint.Proj.x, rgbRect.y + rgbRect.height * (1 - joint.Proj.y));

                                    pointCoord.Add(startPoint);

                                    if (jointType.GetParent() != nuitrack.JointType.None)
                                    {
                                        UserData.SkeletonData.Joint parentJoint = user.Skeleton.GetJoint(parentJointType);

                                        if (parentJoint.Confidence > 0.1f)
                                        {
                                            Vector2 endPoint = new Vector2(rgbRect.x + rgbRect.width * parentJoint.Proj.x, rgbRect.y + rgbRect.height * (1 - parentJoint.Proj.y));
                                            Handles.DrawBezier(startPoint, endPoint, startPoint, endPoint, userColor, null, lineSize);
                                        }
                                    }
                                }
                            }

                            float pointSize = rgbRect.size.magnitude * pointScale;

                            foreach (Vector3 point in pointCoord)
                            {
                                Rect rect = new Rect(point.x - pointSize / 2, point.y - pointSize / 2, pointSize, pointSize);
                                GUI.DrawTexture(rect, pointTexture, ScaleMode.ScaleToFit);
                            }
                        }
                    }

                    NuitrackSDKGUI.DrawFrame(depthTexture, "Depth frame");

                    Repaint();
                }
            }
            EditorGUILayout.EndFoldoutHeaderGroup();
        }
        void DrawPoseAdvanced()
        {
            List <nuitrack.JointType> jointsMask = NuitrackPoseWrapper.JointsMask;

            foreach (KeyValuePair <AvatarMaskBodyPart, SkeletonStyles.GUIBodyPart> bodyPartItem in SkeletonStyles.BodyParts)
            {
                AvatarMaskBodyPart         bodyPart    = bodyPartItem.Key;
                SkeletonStyles.GUIBodyPart guiBodyPart = bodyPartItem.Value;

                bool drawBodyPart = guiBodyPart.guiJoint.Any(x => jointsMask.Contains(x.JointType));

                if (drawBodyPart)
                {
                    EditorGUILayout.LabelField(guiBodyPart.Lable, EditorStyles.boldLabel);

                    foreach (SkeletonStyles.GUIJoint guiJoint in guiBodyPart.guiJoint)
                    {
                        nuitrack.JointType jointType = guiJoint.JointType;

                        if (jointsMask.Contains(jointType))
                        {
                            NuitrackPoseWrapper.JointWrapper jointWrapper = poseWrapper[jointType];

                            using (new GUIColor(jointWrapper.IsActive ? GUI.color : Color.gray))
                            {
                                GUIStyle contentStyle = new GUIStyle(EditorStyles.helpBox)
                                {
                                    margin = new RectOffset(20, 0, 2, 2)
                                };
                                Color selectColor = SelectedJoint == jointType ? colorTheme.mainColor : GUI.color;

                                using (new VerticalGroup(contentStyle, null, selectColor))
                                {
                                    string displayName = NuitrackSDKGUI.GetUnityDisplayBoneName(jointType.ToUnityBones(), bodyPart);

                                    if (!jointWrapper.IsActive)
                                    {
                                        displayName += " (disabled)";
                                    }

                                    bool isActive = EditorGUILayout.ToggleLeft(displayName, jointWrapper.IsActive, EditorStyles.boldLabel);

                                    if (isActive != jointWrapper.IsActive)
                                    {
                                        if (jointWrapper.IsActive && jointType == SelectedJoint)
                                        {
                                            SelectedJoint = nuitrack.JointType.None;
                                        }

                                        jointWrapper.IsActive = isActive;
                                    }

                                    if (isActive)
                                    {
                                        //jointWrapper.Orientation = Quaternion.Euler(EditorGUILayout.Vector3Field("", jointWrapper.Orientation.eulerAngles));
                                        jointWrapper.Tolerance = EditorGUILayout.Slider("Tolerance", jointWrapper.Tolerance, 0.1f, 0.98f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        void DrawRuntimeWizard()
        {
            GUIContent wizardLabel = new GUIContent("Save runtime pose wizard", EditorGUIUtility.IconContent("AvatarSelector").image);

            ShowRuntimePoseWizard = EditorGUILayout.BeginFoldoutHeaderGroup(ShowRuntimePoseWizard, wizardLabel);

            if (ShowRuntimePoseWizard)
            {
                if (NuitrackManager == null)
                {
                    UnityAction fixNuitrack = delegate { NuitrackMenu.AddNuitrackToScene(); };
                    NuitrackSDKGUI.DrawMessage("The wizard requires NuitrackScripts on the scene.", LogType.Error, fixNuitrack, "Fix");

                    Selection.activeObject = target;
                }
                else
                {
                    if (!EditorApplication.isPlaying)
                    {
                        using (new VerticalGroup(EditorStyles.helpBox))
                            EditorGUILayout.LabelField("1) Play \n2) Stand in a pose \n3) Save pose", EditorStyles.wordWrappedLabel);

                        EditorGUILayout.Space();
                        SaveFolder = NuitrackSDKGUI.OpenFolderField(SaveFolder, "Save pose folder", true, DefaultPath);

                        GUIContent playScene = new GUIContent("Play", EditorGUIUtility.IconContent("PlayButton").image);

                        EditorGUILayout.Space();
                        if (GUILayout.Button(playScene))
                        {
                            EditorApplication.isPlaying = true;
                        }
                    }
                    else
                    {
                        UserData user = NuitrackManager.Users.Current;

                        bool disable = user == null || user.Skeleton == null;

                        Texture icon            = disable ? NuitrackSDKGUI.GetMessageIcon(LogType.Warning) : null;
                        Color   backgroundColor = disable ? Color.yellow : Color.green;

                        string message = "After saving a pose, playback will stop and the saved pose will open";

                        if (disable)
                        {
                            message = string.Format("{0}\n{1}", "The user was not found. Stand in front of the sensor to save a pose.", message);
                        }

                        GUIContent  messageGUI = new GUIContent(message, icon);
                        UnityAction savePose   = delegate { SaveRuntimePose(user.Skeleton); };

                        GUIContent iconAvatar = new GUIContent("Save runtime pose", EditorGUIUtility.IconContent("SaveAs").image);

                        EditorGUI.BeginDisabledGroup(disable);
                        NuitrackSDKGUI.DrawMessage(messageGUI, backgroundColor, savePose, iconAvatar);
                        EditorGUI.EndDisabledGroup();

                        Repaint();

                        if (rgbCache == null)
                        {
                            rgbCache = new TextureCache();
                        }

                        rgbTexture = NuitrackManager.ColorFrame.ToRenderTexture(rgbCache);

                        NuitrackSDKGUI.DrawFrame(rgbTexture, "RGB Preview");
                    }
                }
            }
            EditorGUILayout.EndFoldoutHeaderGroup();
        }