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();
        }
Exemplo n.º 2
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();
        }