Exemple #1
0
        public override void dragStop(ref GestureRecognition gr, ref Pixie pixie)
        {
            int gesture_id = gr.endStroke(ref similarity, ref pos, ref scale, ref dir0, ref dir1, ref dir2);

            if (gesture_id == gestureid_flip)
            {
                pixie.triggerFlip(pos, dir0);
                this.num_commands_issued += 1;
                Sample_Pixie.HUDText.text = "That's your new gesture. Nice!\nTry it a few more times.\n(" + this.num_commands_issued + "/4)";
            }
            else if (gesture_id == gestureid_spin)
            {
                pixie.triggerSpin(pos);
                Sample_Pixie.HUDText.text = "That's a 'spin' gesture. Nice!\nTry a few more times.\n(" + this.num_commands_issued + "/4)";
            }
            else if (gesture_id == gestureid_go)
            {
                pixie.triggerGo(pos + (dir0 * 6.0f * (float)scale));
                Sample_Pixie.HUDText.text = "That's a 'go there' gesture. Nice!\nTry a few more times.\n(" + this.num_commands_issued + "/4)";
            }
            else if (gesture_id == gestureid_come)
            {
                pixie.triggerCome(pos);
                Sample_Pixie.HUDText.text = "That's a 'come here' gesture. Nice!\nTry a few more times.\n(" + this.num_commands_issued + "/4)";
            }
            if (this.num_commands_issued >= 4)
            {
                this.completed            = true;
                Sample_Pixie.HUDText.text = "";
            }
        }
Exemple #2
0
        public override void dragStop(ref GestureRecognition gr, ref Pixie pixie)
        {
            int gesture_id = gr.endStroke(ref similarity, ref pos, ref scale, ref dir0, ref dir1, ref dir2);

            if (gesture_id == gestureid_peekaboo)
            {
                pixie.triggerPeekaboo();
                Sample_Pixie.HUDText.text = "That's your new gesture. Awesome!\nFeel try to try out any gesture.";
            }
            else if (gesture_id == gestureid_flip)
            {
                pixie.triggerFlip(pos, dir0);
                Sample_Pixie.HUDText.text = "That's your previous gesture. Cool!\nFeel try to try out any gesture.";
            }
            else if (gesture_id == gestureid_spin)
            {
                pixie.triggerSpin(pos);
                Sample_Pixie.HUDText.text = "That's a 'spin' gesture. Nice!\nFeel try to try out any gesture.";
            }
            else if (gesture_id == gestureid_go)
            {
                pixie.triggerGo(pos + (dir0 * 6.0f * (float)scale));
                Sample_Pixie.HUDText.text = "That's a 'go there' gesture. Splended!\nMake it larger to send the pixie further away.";
            }
            else if (gesture_id == gestureid_come)
            {
                pixie.triggerCome(pos);
                Sample_Pixie.HUDText.text = "That's a 'come here' gesture. Not bad!\nFeel try to try out any gesture.";
            }
        }
Exemple #3
0
        /// <summary>
        /// Inicializa reconocimiento de gestos
        /// </summary>
        private void Start()
        {
            //Inicialización gestos de la mano.
            gestureRecognition = new GestureRecognition();

            //Carga los gestos de un archivo de base de datos de gestos
            string gesturesFilePath = "Assets/GestureRecognition";

            if (gestureRecognition.loadFromFile(gesturesFilePath + "/" + LoadGesturesFile) == false)
            {
                Debug.LogError("Error cargando gestos");
                return;
            }
            gestureRecognition.contdIdentificationSmoothing = 5;

            //Imprime los gestos disponibles
            for (int i = 0; i < gestureRecognition.numberOfGestures(); i++)
            {
                Debug.Log("\n" + (i + 1) + " : " + gestureRecognition.getGestureName(i));
            }

            //Empieza detección de gestos
            gestureRecognition.contdIdentificationPeriod = (int)(this.GesturePeriod * 1000.0f); // to milliseconds
            Vector3    headsetPos      = Camera.main.gameObject.transform.position;
            Quaternion headsetRotation = Camera.main.gameObject.transform.rotation;

            gestureRecognition.startStroke(headsetPos, headsetRotation);
        }
Exemple #4
0
    // Start is called before the first frame update
    void Start()
    {
        // Set the welcome message.
        HUDText      = GameObject.Find("HUDText").GetComponent <TextMeshProUGUI>();
        HUDText.text = "Welcome to Spell-Smith\n"
                       + "You can cast spells by drawing shapes,\n"
                       + "Draw a circle for fireballs, lightning bolt for a lightning bolt, and a square for a shield\n"
                       + "";

        me = GCHandle.Alloc(this);

        gr = new GestureRecognition();

        gr.setTrainingUpdateCallback(CreatingGestures.trainingUpdateCallback);
        gr.setTrainingUpdateCallbackMetadata((IntPtr)me);
        gr.setTrainingFinishCallback(CreatingGestures.trainingFinishCallback);
        gr.setTrainingFinishCallbackMetadata((IntPtr)me);

        bool success = gr.loadFromFile(file_load_gestures);

        if (!success)
        {
            HUDText.text = "Failed";
        }
        //Debug.Log((success ? "Gesture file loaded successfully" : "[ERROR] Failed to load gesture file."));
    }
        public GesturesForm(GesturesForm gesturesForm, GestureRecognition.Logic.Enums.GestureFormOption option, GestureRecognition.UnistrokeRecognizer.Logic.Enums.RecognizeMode recognizeMethod)
        {
            InitializeComponent();

            this._gesturesForm = gesturesForm;
            this._gestureOption = option;
            this._recognizeMethods = recognizeMethod;
            this.SquareButton.Visible = false;

            BuildSkeletonSave.Visible = false;

            graphics = this.CreateGraphics();

            this.DoubleBuffered = true;

            switch (option)
            {
                case GestureRecognition.Logic.Enums.GestureFormOption.Record:
                    {
                        InitRecording();
                    } break;
                case GestureRecognition.Logic.Enums.GestureFormOption.Load:
                    {
                        InitLoading();
                    } break;
                case GestureRecognition.Logic.Enums.GestureFormOption.Recognize:
                    {
                        InitRecognizing();
                    } break;
                case GestureRecognition.Logic.Enums.GestureFormOption.SquareRecognizer:
                    {
                        InitSquareRecognizing();
                    }break;
            }
        }
Exemple #6
0
 private void ResetGesturesButton_Click(object sender, EventArgs e)
 {
     Logging.LogOtherEvent("Reset Gestures");
     training = true;
     GestureRecognition.Reset();
     training = false;
     UpdateGestureList();
 }
Exemple #7
0
        public void UpdateGestureCount()
        {
            if (InvokeRequired)
            {
                Invoke(new MethodInvoker(UpdateGestureCount)); return;
            }

            GestureCountLabel.Text = GestureRecognition.GetNumExamples() + " gesture examples (" + GestureRecognition.GetNumClasses() + " classes)";
        }
Exemple #8
0
    private void DragStop(ref GestureRecognition gr)
    {
        var gesture         = (InteractionMachine.Gesture)gr.endStroke(ref similarity, ref pos, ref scale, ref dir0, ref dir1, ref dir2);
        var cameraTransform = Camera.main.transform;

        if (gesture != InteractionMachine.Gesture.None)
        {
            subs.ForEach(i => i.Notify(gesture, cameraTransform.position, cameraTransform.forward));
        }
    }
Exemple #9
0
        public override void dragStop(ref GestureRecognition gr, ref Pixie pixie)
        {
            this.completed            = true;
            Sample_Pixie.HUDText.text = "";
            // reparent the text to be static in front
            Transform hud_text_transform = GameObject.Find("Canvas").transform;

            hud_text_transform.SetParent(GameObject.Find("XR Rig").transform, true);
            hud_text_transform.rotation.SetLookRotation(GameObject.Find("Main Camera").transform.position - hud_text_transform.position);
        }
Exemple #10
0
        public MainWindow()
        {
            InitializeComponent();
            //var gestures = new RandomGesturesProvider();
            var gestures = new GestureRecognition();

            gestures.ScrollRight += GesturesScrollRight;
            gestures.ScrollLeft  += GesturesScrollLeft;
            gestures.ScrollUp    += GesturesScrollUp;
            gestures.ScrollDown  += GesturesScrollDown;
        }
Exemple #11
0
        public override void dragStop(ref GestureRecognition gr, ref Pixie pixie)
        {
            int gesture_id = gr.endStroke(ref similarity, ref pos, ref scale, ref dir0, ref dir1, ref dir2);

            if (gesture_id == gestureid_go)
            {
                pixie.triggerGo(pos + (dir0 * 6.0f * (float)scale));
                this.completed            = true;
                Sample_Pixie.HUDText.text = "";
            }
        }
Exemple #12
0
        private void SaveProfileButton_Click(object sender, EventArgs e)
        {
            bool overwrite = false;

            if (profileName != null)
            {
                DialogResult result = MessageBox.Show("Would you like to overwrite the existing profile named \"" + profileName + "\"", "Overwrite Existing Profile?", MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else if (result == DialogResult.Yes)
                {
                    overwrite = true;
                    Directory.Delete(Path.Combine("savedProfiles", profileName), true);
                }
            }

            if (!overwrite)
            {
                PromptDialog dialog = new PromptDialog("Enter Profile Name", "Save");
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    if (Directory.Exists(Path.Combine("savedProfiles", dialog.Value)))
                    {
                        if (MessageBox.Show("A profile with that name already exists. Would you like to overwrite it?", "Confirm overwrite profile", MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        {
                            return;
                        }
                        Directory.Delete(Path.Combine("savedProfiles", dialog.Value), true);
                    }

                    profileName = dialog.Value;
                }
            }

            Task.Factory.StartNew(() =>
            {
                Localization.Instance.Save(profileName);
                Logging.LogOtherEvent("Save Location Profile");

                if (Properties.Settings.Default.IncludeGesturesInProfile)
                {
                    GestureRecognition.Save(profileName);
                    Logging.LogOtherEvent("Save Gesture Profile");
                }

                Debug.WriteLine("Finished Saving");

                IsSaved = true;
            });
        }
Exemple #13
0
        public override void init(ref GestureRecognition gr)
        {
            this.completed            = false;
            Sample_Pixie.HUDText.text = "Let's try it again!\nInvent a new gesture and do it 20 times.\n(0/20)";
            int record_gesture_id = gr.createGesture("Peekaboo");

            // record_gesture_id should be gestureid_peekaboo
            if (record_gesture_id != gestureid_peekaboo)
            {
                Sample_Pixie.HUDText.text = "[ERROR: FAILED TO CREATE NEW GESTURE]";
            }
            this.recorded_samples = 0;
        }
Exemple #14
0
        public override void init(ref GestureRecognition gr)
        {
            this.completed            = false;
            Sample_Pixie.HUDText.text = "Now teach your pixie something new!\nInvent a new gesture and do it 20 times.\n(0/20)";
            this.recorded_samples     = 0;
            int record_gesture_id = gr.createGesture("Flip");

            // record_gesture_id should be gestureid_peekaboo
            if (record_gesture_id != gestureid_flip)
            {
                Sample_Pixie.HUDText.text = "[ERROR: FAILED TO CREATE NEW GESTURE]";
            }
        }
Exemple #15
0
        private void LoadProfileButton_Click(object sender, EventArgs e)
        {
            List <string> profiles = new List <string>();

            foreach (string dir in Directory.GetDirectories("savedProfiles"))
            {
                profiles.Add((new DirectoryInfo(dir)).Name);
            }
            if (profiles.Contains("default"))
            {
                profiles.Remove("default");
            }
            if (profiles.Count == 0)
            {
                MessageBox.Show("Error: no saved profiles!");
                return;
            }
            SelectFromListDialog dialog = new SelectFromListDialog("Select Saved Profile", "Load", profiles);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                profileName = dialog.SelectedItem;

                training = true;

                Task.Factory.StartNew(() =>
                {
                    if (Properties.Settings.Default.OverwriteExistingSamples)
                    {
                        Localization.Instance.Reset();
                    }
                    Localization.Instance.Load(dialog.SelectedItem);
                    Logging.LogOtherEvent("Load Location Profile: " + dialog.SelectedItem);

                    //if (Properties.Settings.Default.IncludeGesturesInProfile)
                    {
                        if (Properties.Settings.Default.OverwriteExistingSamples)
                        {
                            GestureRecognition.Reset();
                        }
                        GestureRecognition.Load(dialog.SelectedItem, enableSingleTap: Properties.Settings.Default.EnableSingleTap, enableSwipeDown: Properties.Settings.Default.EnableSwipeDown, isDefault: true);
                        Logging.LogOtherEvent("Load Gesture Profile: " + dialog.SelectedItem);
                    }
                    training = false;

                    UpdateLists();

                    IsSaved = true;
                });
            }
        }
Exemple #16
0
        private void SaveGestureSVMButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.InitialDirectory = Path.GetFullPath("savedProfiles");
            dialog.DefaultExt       = ".svm";
            dialog.Filter           = "SVM Files|*.svm";
            dialog.OverwritePrompt  = true;
            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                GestureRecognition.SaveClassifier(dialog.FileName);
                Logging.LogOtherEvent("Save Gesture SVM: " + dialog.FileName);
            }
        }
Exemple #17
0
        private static void Main(string[] args)
        {
            var gestures = new GestureRecognition();

            //var gestures = new RandomGesturesProvider();
            gestures.ZoomIn      += GesturesZoomIn;
            gestures.ZoomOut     += GesturesZoomOut;
            gestures.ScrollLeft  += GesturesScrollLeft;
            gestures.ScrollRight += GesturesScrollRight;
            gestures.ScrollDown  += GesturesScrollDown;
            gestures.ScrollUp    += GesturesScrollUp;

            Console.ReadLine();
        }
Exemple #18
0
        public override void dragStop(ref GestureRecognition gr, ref Pixie pixie)
        {
            int gesture_id = gr.endStroke(ref similarity, ref pos, ref scale, ref dir0, ref dir1, ref dir2);

            if (gesture_id == gestureid_peekaboo)
            {
                recorded_samples         += 1;
                Sample_Pixie.HUDText.text = "Let's try it again!\nInvent a new gesture and do it 20 times.\n(" + recorded_samples + "/20)";
            }
            if (recorded_samples >= 20)
            {
                this.completed = true;
                gr.startTraining();
                Sample_Pixie.HUDText.text = "Please wait while your pixie is learning the new gesture...";
            }
        }
Exemple #19
0
        public override void dragStop(ref GestureRecognition gr, ref Pixie pixie)
        {
            int gesture_id = gr.endStroke(ref similarity, ref pos, ref scale, ref dir0, ref dir1, ref dir2);

            if (gesture_id == gestureid_spin)
            {
                pixie.triggerSpin(pos);
                this.num_commands_issued += 1;
                Sample_Pixie.HUDText.text = "Great!\nTry it again!\nMake a twirl (whirling) gesture\nto make the pixie spin. (" + this.num_commands_issued + "/3)";
            }
            if (this.num_commands_issued >= 3)
            {
                this.completed            = true;
                Sample_Pixie.HUDText.text = "";
            }
        }
        /// <summary>
        /// Sets the screen up (UI components, multimedia content, etc.)
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            idroids = ResourceManager.CreateImage("Droids");
            iRethink = ResourceManager.CreateImage("Rethink");
            iwato = ResourceManager.CreateImage("Wato");

            // TODO: Replace these comments with your own poetry, and enjoy!
            lblText = new Label("Please try a gesture");
            AddComponent(lblText, 20, Preferences.Height / 8);

            recognizer = new GestureRecognition();
            recognizer.LoadGestureSet("Gestures.gs");
            recognizer.GestureRecognizerEvent -= recognizer_GestureRecognizerEvent;
            recognizer.GestureRecognizerEvent += recognizer_GestureRecognizerEvent;
        }
Exemple #21
0
 public override void init(ref GestureRecognition gr)
 {
     this.completed            = false;
     this.num_commands_issued  = 0;
     Sample_Pixie.HUDText.text = "Learning finished! Try out your new gesture.";
 }
Exemple #22
0
 public override void init(ref GestureRecognition gr)
 {
     this.completed            = false;
     Sample_Pixie.HUDText.text = "Learning finished! Try out any of the gestures.";
 }
Exemple #23
0
 public override void dragStart(ref GestureRecognition gr, Vector3 hmd_p, Quaternion hmd_q)
 {
     gr.startStroke(hmd_p, hmd_q, gestureid_peekaboo);
 }
Exemple #24
0
 public override void init(ref GestureRecognition gr)
 {
     this.completed            = false;
     Sample_Pixie.HUDText.text = "Welcome to MiVRy\nPress the trigger button on your controller to start";
 }
Exemple #25
0
 public abstract void dragStop(ref GestureRecognition gr, ref Pixie pixie);
Exemple #26
0
 public override void dragContd(ref GestureRecognition gr, Vector3 controller_p, Quaternion controller_q)
 {
     // nothing to do
 }
Exemple #27
0
 public override void init(ref GestureRecognition gr)
 {
     this.completed            = false;
     Sample_Pixie.HUDText.text = "Make a 'come here' gesture\nto call the pixie close to you.";
 }
Exemple #28
0
 public override void init(ref GestureRecognition gr)
 {
     this.completed            = false;
     this.num_commands_issued  = 0;
     Sample_Pixie.HUDText.text = "Make a twirl (whirling) gesture\nto make the pixie spin.";
 }
Exemple #29
0
 public override void init(ref GestureRecognition gr)
 {
     this.completed            = false;
     Sample_Pixie.HUDText.text = "Good!\nTry calling and sending the pixie away a few times.";
     this.num_commands_issued  = 0;
 }
Exemple #30
0
 public override void init(ref GestureRecognition gr)
 {
     this.completed            = false;
     Sample_Pixie.HUDText.text = "Nice!\n Now make a throwing gesture\nto send the pixie away";
 }
    public override void OnInspectorGUI()
    {
        // DrawDefaultInspector();

        serializedObject.Update();

        GestureManager gm = (GestureManager)target;

        EditorGUILayout.BeginVertical(GUI.skin.box);
        EditorGUILayout.LabelField("NUMBER OF GESTURE PARTS:");
        gm.numberOfParts = EditorGUILayout.IntField("Number of parts", gm.numberOfParts);
        EditorGUILayout.LabelField(" ", "1 for one-handed,");
        EditorGUILayout.LabelField(" ", "2 for two-handed or two sequential gestures,");
        EditorGUILayout.LabelField(" ", "3 for three sequential gestures, ...");
        if (GUILayout.Button("Update"))
        {
            if (gm.numberOfParts <= 0)
            {
                return;
            }
            if (gm.numberOfParts == 1)
            {
                gm.gc = null;
                if (gm.gr == null)
                {
                    gm.gr = new GestureRecognition();
                }
                gm.gr.setTrainingUpdateCallback(GestureManager.trainingUpdateCallback);
                gm.gr.setTrainingUpdateCallbackMetadata((IntPtr)gm.me);
                gm.gr.setTrainingFinishCallback(GestureManager.trainingFinishCallback);
                gm.gr.setTrainingFinishCallbackMetadata((IntPtr)gm.me);
            }
            else
            {
                gm.gr = null;
                if (gm.gc == null || gm.gc.numberOfParts() != gm.numberOfParts)
                {
                    gm.gc = new GestureCombinations(gm.numberOfParts);
                }
                gm.gc.setTrainingUpdateCallback(GestureManager.trainingUpdateCallback);
                gm.gc.setTrainingUpdateCallbackMetadata((IntPtr)gm.me);
                gm.gc.setTrainingFinishCallback(GestureManager.trainingFinishCallback);
                gm.gc.setTrainingFinishCallbackMetadata((IntPtr)gm.me);
            }
        }
        EditorGUILayout.EndVertical();

        if (gm.gc != null)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.LabelField("HAND/PART MAPPING:", "(which hand performs which part)");
            int      num_parts  = gm.gc.numberOfParts();
            string[] part_names = new string[num_parts];
            for (int i = 0; i < num_parts; i++)
            {
                part_names[i] = "part (or side) " + i.ToString();
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Left hand:");
            gm.lefthand_combination_part = EditorGUILayout.Popup(gm.lefthand_combination_part, part_names);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Right hand:");
            gm.righthand_combination_part = EditorGUILayout.Popup(gm.righthand_combination_part, part_names);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }

        // Gesture file management
        if (gm.gr == null && gm.gc == null)
        {
            serializedObject.ApplyModifiedProperties();
            return;
        }

        EditorGUILayout.Space();
        EditorGUILayout.BeginVertical(GUI.skin.box);
        EditorGUILayout.LabelField("GESTURE FILES:");
        if (gm.gr != null)
        {
            gm.file_load_gestures = EditorGUILayout.TextField("Load gestures file:", gm.file_load_gestures);
            if (GUILayout.Button("Load Gestures from File"))
            {
                int ret = gm.gr.loadFromFile(gm.file_load_gestures);
                Debug.Log((ret == 0 ? "Gesture file loaded successfully" : $"[ERROR] Failed to load gesture file ({ret})."));
            }
            gm.file_save_gestures = EditorGUILayout.TextField("Save gestures file:", gm.file_save_gestures);
            if (GUILayout.Button("Save Gestures to File"))
            {
                int ret = gm.gr.saveToFile(gm.file_save_gestures);
                Debug.Log((ret == 0 ? "Gesture file saved successfully" : $"[ERROR] Failed to save gesture file ({ret})."));
            }
        }
        else if (gm.gc != null)
        {
            gm.file_load_combinations = EditorGUILayout.TextField("Load GestureCombinations File: ", gm.file_load_combinations);
            if (GUILayout.Button("Load GestureCombinations File"))
            {
                int ret = gm.gc.loadFromFile(gm.file_load_combinations);
                Debug.Log((ret == 0 ? "Gesture file loaded successfully" : $"[ERROR] Failed to load gesture file ({ret})."));
            }
            gm.file_save_combinations = EditorGUILayout.TextField("Save GestureCombinations File: ", gm.file_save_combinations);
            if (GUILayout.Button("Save GestureCombinations File"))
            {
                int ret = gm.gc.saveToFile(gm.file_save_combinations);
                Debug.Log((ret == 0 ? "Gesture file saved successfully" : $"[ERROR] Failed to save gesture file ({ret})."));
            }
            EditorGUILayout.LabelField("(optional) Import single-handed gesture file:");
            gm.file_load_subgestures   = EditorGUILayout.TextField("Import SubGestures File:", gm.file_load_subgestures);
            gm.file_load_subgestures_i = EditorGUILayout.IntField("^ ... for subgesture #", gm.file_load_subgestures_i);
            if (GUILayout.Button("Import SubGesture File"))
            {
                int ret = gm.gc.loadGestureFromFile(gm.file_load_subgestures_i, gm.file_load_subgestures);
                Debug.Log((ret == 0 ? "Gesture file imported successfully" : $"[ERROR] Failed to import gesture file ({ret})."));
            }
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();
        EditorGUILayout.BeginVertical(GUI.skin.box);
        EditorGUILayout.LabelField("ROTATIONAL FRAME OF REFERENCE:");
        string[] framesOfReference = { "Head", "World" };
        if (gm.gr != null)
        {
            gm.gr.frameOfReferenceYaw         = (GestureRecognition.FrameOfReference)EditorGUILayout.Popup("Yaw (left/right)", (int)gm.gr.frameOfReferenceYaw, framesOfReference);
            gm.gr.frameOfReferenceUpDownPitch = (GestureRecognition.FrameOfReference)EditorGUILayout.Popup("Pitch (up/down)", (int)gm.gr.frameOfReferenceUpDownPitch, framesOfReference);
            gm.gr.frameOfReferenceRollTilt    = (GestureRecognition.FrameOfReference)EditorGUILayout.Popup("Tilt (roll)", (int)gm.gr.frameOfReferenceRollTilt, framesOfReference);
        }
        else if (gm.gc != null)
        {
            gm.gc.frameOfReferenceYaw         = (GestureCombinations.FrameOfReference)EditorGUILayout.Popup("Yaw (left/right)", (int)gm.gc.frameOfReferenceYaw, framesOfReference);
            gm.gc.frameOfReferenceUpDownPitch = (GestureCombinations.FrameOfReference)EditorGUILayout.Popup("Pitch (up/down)", (int)gm.gc.frameOfReferenceUpDownPitch, framesOfReference);
            gm.gc.frameOfReferenceRollTilt    = (GestureCombinations.FrameOfReference)EditorGUILayout.Popup("Tilt (roll)", (int)gm.gc.frameOfReferenceRollTilt, framesOfReference);
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();
        EditorGUILayout.BeginVertical(GUI.skin.box);
        EditorGUILayout.LabelField("GESTURES:");
        if (gm.gr != null)
        {
            int num_gestures = gm.gr.numberOfGestures();
            for (int i = 0; i < num_gestures; i++)
            {
                string gesture_name    = gm.gr.getGestureName(i);
                int    gesture_samples = gm.gr.getGestureNumberOfSamples(i);
                GUILayout.BeginHorizontal();
                string new_gesture_name = EditorGUILayout.TextField(gesture_name);
                if (gesture_name != new_gesture_name)
                {
                    bool success = gm.gr.setGestureName(i, new_gesture_name);
                    if (!success)
                    {
                        Debug.Log("[ERROR] Failed to rename gesture.");
                    }
                }
                EditorGUILayout.LabelField(gesture_samples.ToString() + " samples", GUILayout.Width(70));
                if (GUILayout.Button("Delete Last Sample"))
                {
                    bool success = gm.gr.deleteGestureSample(i, gesture_samples - 1);
                    if (!success)
                    {
                        Debug.Log("[ERROR] Failed to delete gesture sample.");
                    }
                }
                if (GUILayout.Button("Delete All Samples"))
                {
                    bool success = gm.gr.deleteAllGestureSamples(i);
                    if (!success)
                    {
                        Debug.Log("[ERROR] Failed to delete gesture samples.");
                    }
                }
                if (GUILayout.Button("Delete Gesture"))
                {
                    bool success = gm.gr.deleteGesture(i);
                    if (!success)
                    {
                        Debug.Log("[ERROR] Failed to delete gesture.");
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal();
            gm.create_gesture_name = EditorGUILayout.TextField(gm.create_gesture_name);
            if (GUILayout.Button("Create new gesture"))
            {
                int gesture_id = gm.gr.createGesture(gm.create_gesture_name);
                if (gesture_id < 0)
                {
                    Debug.Log("[ERROR] Failed to create gesture.");
                }
                gm.create_gesture_name = "(new gesture name)";
            }
            GUILayout.EndHorizontal();
            gm.file_load_gestures = EditorGUILayout.TextField("Import gestures:", gm.file_load_gestures);
            if (GUILayout.Button("Import Gestures from File"))
            {
                GestureRecognition importGR = new GestureRecognition();
                int ret = importGR.loadFromFile(gm.file_load_gestures);
                if (ret != 0)
                {
                    Debug.Log($"[ERROR] Failed to load gesture file ({ret}).");
                }
                else if (gm.gr.importGestures(importGR))
                {
                    Debug.Log("Gesture file imported successfully");
                }
                else
                {
                    Debug.Log("[ERROR] Failed to import gesture file.");
                }
            }
        }
        else if (gm.gc != null)
        {
            int num_combinations = gm.gc.numberOfGestureCombinations();
            int num_parts        = gm.gc.numberOfParts();
            for (int combination_id = 0; combination_id < num_combinations; combination_id++)
            {
                string combination_name = gm.gc.getGestureCombinationName(combination_id);
                GUILayout.BeginHorizontal();
                string new_combination_name = EditorGUILayout.TextField(combination_name);
                if (combination_name != new_combination_name)
                {
                    bool success = gm.gc.setGestureCombinationName(combination_id, new_combination_name);
                    if (!success)
                    {
                        Debug.Log("[ERROR] Failed to rename GestureCombination.");
                    }
                }
                if (GUILayout.Button("Delete"))
                {
                    bool success = gm.gc.deleteGestureCombination(combination_id);
                    if (!success)
                    {
                        Debug.Log("[ERROR] Failed to delete gesture.");
                    }
                }
                GUILayout.EndHorizontal();
                for (int i = 0; i < num_parts; i++)
                {
                    int      num_gestures  = gm.gc.numberOfGestures(i);
                    string[] gesture_names = new string[num_gestures + 1];
                    gesture_names[0] = "[NONE]";
                    for (int k = 0; k < num_gestures; k++)
                    {
                        gesture_names[k + 1] = gm.gc.getGestureName(i, k);
                    }
                    int connected_gesture_id = gm.gc.getCombinationPartGesture(combination_id, i);
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Subgesture for part/side " + i);
                    int new_connected_gesture_id = EditorGUILayout.Popup(connected_gesture_id + 1, gesture_names) - 1;
                    GUILayout.EndHorizontal();
                    if (new_connected_gesture_id != connected_gesture_id)
                    {
                        bool success = gm.gc.setCombinationPartGesture(combination_id, i, new_connected_gesture_id);
                        if (!success)
                        {
                            Debug.Log("[ERROR] Failed to change GestureCombination.");
                        }
                    }
                }
            }
            GUILayout.BeginHorizontal();
            gm.create_combination_name = EditorGUILayout.TextField(gm.create_combination_name);
            if (GUILayout.Button("Create new Gesture Combination"))
            {
                int gesture_id = gm.gc.createGestureCombination(gm.create_combination_name);
                if (gesture_id < 0)
                {
                    Debug.Log("[ERROR] Failed to create Gesture Combination.");
                }
                gm.create_combination_name = "(new Gesture Combination name)";
            }
            GUILayout.EndHorizontal();

            for (int part = 0; part < num_parts; part++)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Combination Part/Side:", part.ToString());
                int num_gestures = gm.gc.numberOfGestures(part);
                for (int i = 0; i < num_gestures; i++)
                {
                    string gesture_name    = gm.gc.getGestureName(part, i);
                    int    gesture_samples = gm.gc.getGestureNumberOfSamples(part, i);
                    GUILayout.BeginHorizontal();
                    string new_gesture_name = EditorGUILayout.TextField(gesture_name);
                    if (gesture_name != new_gesture_name)
                    {
                        bool success = gm.gc.setGestureName(part, i, new_gesture_name);
                        if (!success)
                        {
                            Debug.Log("[ERROR] Failed to rename gesture.");
                        }
                    }
                    EditorGUILayout.LabelField(gesture_samples.ToString() + " samples", GUILayout.Width(70));
                    if (GUILayout.Button("Delete Last Sample"))
                    {
                        bool success = gm.gc.deleteGestureSample(part, i, gesture_samples - 1);
                        if (!success)
                        {
                            Debug.Log("[ERROR] Failed to delete gesture sample.");
                        }
                    }
                    if (GUILayout.Button("Delete All Samples"))
                    {
                        bool success = gm.gc.deleteAllGestureSamples(part, i);
                        if (!success)
                        {
                            Debug.Log("[ERROR] Failed to delete gesture samples.");
                        }
                    }
                    if (GUILayout.Button("Delete"))
                    {
                        bool success = gm.gc.deleteGesture(part, i);
                        if (!success)
                        {
                            Debug.Log("[ERROR] Failed to delete gesture.");
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                GUILayout.BeginHorizontal();
                if (gm.create_gesture_names == null || gm.create_gesture_names.Length < num_parts)
                {
                    gm.create_gesture_names = new string[num_parts];
                    for (int i = 0; i < num_parts; i++)
                    {
                        gm.create_gesture_names[i] = "(new gesture name)";
                    }
                }
                gm.create_gesture_names[part] = EditorGUILayout.TextField(gm.create_gesture_names[part]);
                if (GUILayout.Button("Add new gesture"))
                {
                    int gesture_id = gm.gc.createGesture(part, gm.create_gesture_names[part]);
                    if (gesture_id < 0)
                    {
                        Debug.Log("[ERROR] Failed to create gesture.");
                    }
                    gm.create_gesture_names[part] = "(new gesture name)";
                }
                GUILayout.EndHorizontal();
            }
            // copy gestures
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Copy gestures:");
            string[] part_names = new string[num_parts];
            for (int i = 0; i < num_parts; i++)
            {
                part_names[i] = i.ToString();
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("From (part/side):");
            gm.copy_gesture_from_part = EditorGUILayout.Popup(gm.copy_gesture_from_part, part_names);
            EditorGUILayout.EndHorizontal();

            int      copy_gestures_from_num  = gm.gc.numberOfGestures(gm.copy_gesture_from_part);
            string[] copy_gesture_from_names = new string[copy_gestures_from_num];
            for (int i = 0; i < copy_gestures_from_num; i++)
            {
                copy_gesture_from_names[i] = gm.gc.getGestureName(gm.copy_gesture_from_part, i);
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Gesture to copy:");
            gm.copy_gesture_from_id = EditorGUILayout.Popup(gm.copy_gesture_from_id, copy_gesture_from_names);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("To (part/side):");
            gm.copy_gesture_to_part = EditorGUILayout.Popup(gm.copy_gesture_to_part, part_names);
            EditorGUILayout.EndHorizontal();

            int      copy_gestures_to_num  = gm.gc.numberOfGestures(gm.copy_gesture_to_part);
            string[] copy_gesture_to_names = new string[copy_gestures_to_num + 1];
            copy_gesture_to_names[0] = "[NEW GESTURE]";
            for (int i = 0; i < copy_gestures_to_num; i++)
            {
                copy_gesture_to_names[i + 1] = gm.gc.getGestureName(gm.copy_gesture_to_part, i);
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Copy into:");
            gm.copy_gesture_to_id = EditorGUILayout.Popup(gm.copy_gesture_to_id, copy_gesture_to_names);
            EditorGUILayout.EndHorizontal();

            gm.copy_gesture_mirror = EditorGUILayout.Toggle("Mirror left/right", gm.copy_gesture_mirror);
            gm.copy_gesture_rotate = EditorGUILayout.Toggle("Rotate 180 degrees", gm.copy_gesture_rotate);

            if (GUILayout.Button("Copy"))
            {
                int new_gesture = gm.gc.copyGesture(gm.copy_gesture_from_part, gm.copy_gesture_from_id, gm.copy_gesture_to_part, gm.copy_gesture_to_id - 1, gm.copy_gesture_mirror ^ gm.copy_gesture_rotate, false, gm.copy_gesture_rotate);
                if (new_gesture < 0)
                {
                    Debug.Log("[ERROR] Failed to copy gesture.");
                }
            }

            //EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndVertical();


        EditorGUILayout.Space();
        EditorGUILayout.BeginVertical(GUI.skin.box);
        EditorGUILayout.LabelField("RECORD GESTURE SAMPLES:");
        if (gm.gr != null)
        {
            int      num_gestures  = gm.gr.numberOfGestures();
            string[] gesture_names = new string[num_gestures + 1];
            gesture_names[0] = "[Testing, not recording]";
            for (int i = 0; i < num_gestures; i++)
            {
                gesture_names[i + 1] = gm.gr.getGestureName(i);
            }
            gm.record_gesture_id = EditorGUILayout.Popup(gm.record_gesture_id + 1, gesture_names) - 1;
        }
        else if (gm.gc != null)
        {
            int      num_combinations  = gm.gc.numberOfGestureCombinations();
            string[] combination_names = new string[num_combinations + 1];
            combination_names[0] = "[Testing, not recording]";
            for (int i = 0; i < num_combinations; i++)
            {
                combination_names[i + 1] = gm.gc.getGestureCombinationName(i);
            }
            gm.record_combination_id = EditorGUILayout.Popup(gm.record_combination_id + 1, combination_names) - 1;
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();
        EditorGUILayout.BeginVertical(GUI.skin.box);
        EditorGUILayout.LabelField("START/STOP TRAINING:");
        if (gm.gr != null)
        {
            EditorGUILayout.LabelField("Performance:", (gm.gr.recognitionScore() * 100.0).ToString() + "%");
            EditorGUILayout.LabelField("Currently training:", (gm.gr.isTraining() ? "yes" : "no"));
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Start training"))
            {
                gm.training_started = gm.gr.startTraining();
                Debug.Log((gm.training_started ? "Training successfully started" : "[ERROR] Failed to start training."));
            }
            if (GUILayout.Button("Stop training"))
            {
                gm.gr.stopTraining();
            }
            GUILayout.EndHorizontal();
        }
        else if (gm.gc != null)
        {
            EditorGUILayout.LabelField("Performance:", (gm.gc.recognitionScore() * 100.0).ToString() + "%");
            EditorGUILayout.LabelField("Currently training:", (gm.gc.isTraining() ? "yes" : "no"));
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Start training"))
            {
                gm.training_started = gm.gc.startTraining();
                Debug.Log((gm.training_started ? "Training successfully started" : "[ERROR] Failed to start training."));
            }
            if (GUILayout.Button("Stop training"))
            {
                gm.gc.stopTraining();
            }
            GUILayout.EndHorizontal();
        }

        EditorGUILayout.EndVertical();
        serializedObject.ApplyModifiedProperties();
    }
Exemple #32
0
 public override void dragStart(ref GestureRecognition gr, Vector3 hmd_p, Quaternion hmd_q)
 {
     // nothing to do
 }