コード例 #1
0
ファイル: CreatingGestures.cs プロジェクト: Buscems/Thesis
    // 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."));
    }
コード例 #2
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);
        }
コード例 #3
0
    public bool LoadDeafaultTrainedData()   //load default gesture suggestions file in Assets/StreamingAssets/
    {
        string trainedData = "gestureSuggestions.dat";
        string trainedDataPath;

#if UNITY_EDITOR
        trainedDataPath = "Assets/StreamingAssets";
#elif UNITY_ANDROID
        var unityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        var activity        = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
        var unityWebRequest = UnityWebRequest.Get($"{Application.streamingAssetsPath}/{trainedData}");
        trainedDataPath = activity.Call <AndroidJavaObject>("getCacheDir").Call <string>("getCanonicalPath");
        unityWebRequest.SendWebRequest();

        while (!unityWebRequest.isDone)
        {
            // wait for file extraction to finish
        }
        if (unityWebRequest.isNetworkError)
        {
            Debug.Log("Load failed. Network must be connected for loading the default data.");
            return(false);
        }
        File.WriteAllBytes($"{trainedDataPath}/{trainedData}", unityWebRequest.downloadHandler.data);
#else
        trainedDataPath = Application.streamingAssetsPath;
#endif
        if (gr.loadFromFile($"{trainedDataPath}/{trainedData}"))
        {
            Debug.Log("Load completed");
            gestureList = new List <Gesture>();
            for (int i = 0; i < gr.numberOfGestures(); i++)
            {
                gestureList.Add(new Gesture(gr.getGestureName(i), gr.getGestureNumberOfSamples(i)));
            }

            return(true);
        }
        else
        {
            Debug.Log("Load failed");
            return(false);
        }
    }
コード例 #4
0
    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();
    }
コード例 #5
0
ファイル: Sample_OneHanded.cs プロジェクト: Buscems/Thesis
    // Initialization:
    void Start()
    {
        // Set the welcome message.
        HUDText      = GameObject.Find("HUDText").GetComponent <Text>();
        HUDText.text = "Welcome to MARUI Gesture Plug-in!\n"
                       + "Press the trigger to draw a gesture. Available gestures:\n"
                       + "1 - a circle/ring (creates a cylinder)\n"
                       + "2 - swipe left/right (rotate object)\n"
                       + "3 - shake (delete object)\n"
                       + "4 - draw a sword from your hip,\nhold it over your head (magic)\n"
                       + "or: press 'A'/'X'/Menu button\nto create new gesture.";

        me = GCHandle.Alloc(this);

        // Load the set of gestures.
        if (LoadGesturesFile == null)
        {
            LoadGesturesFile = "Sample_OneHanded_Gestures.dat";
        }

        // Find the location for the gesture database (.dat) file
#if UNITY_EDITOR
        // When running the scene inside the Unity editor,
        // we can just load the file from the Assets/ folder:
        string GesturesFilePath = "Assets/GestureRecognition";
#elif UNITY_ANDROID
        // On android, the file is in the .apk,
        // so we need to first "download" it to the apps' cache folder.
        AndroidJavaClass  unityPlayer      = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject activity         = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
        string            GesturesFilePath = activity.Call <AndroidJavaObject>("getCacheDir").Call <string>("getCanonicalPath");
        UnityWebRequest   request          = UnityWebRequest.Get(Application.streamingAssetsPath + "/" + LoadGesturesFile);
        request.SendWebRequest();
        while (!request.isDone)
        {
            // wait for file extraction to finish
        }
        if (request.isNetworkError)
        {
            HUDText.text = "Failed to extract sample gesture database file from apk.";
            return;
        }
        File.WriteAllBytes(GesturesFilePath + "/" + LoadGesturesFile, request.downloadHandler.data);
#else
        // This will be the case when exporting a stand-alone PC app.
        // In this case, we can load the gesture database file from the streamingAssets folder.
        string GesturesFilePath = Application.streamingAssetsPath;
#endif
        if (gr.loadFromFile(GesturesFilePath + "/" + LoadGesturesFile) == false)
        {
            HUDText.text = "Failed to load sample gesture database file\n";
            return;
        }

        // Reset the skybox tint color
        RenderSettings.skybox.SetColor("_Tint", new Color(0.5f, 0.5f, 0.5f, 1.0f));

        // Hide unused models in the scene
        GameObject controller_oculus_left     = GameObject.Find("controller_oculus_left");
        GameObject controller_oculus_right    = GameObject.Find("controller_oculus_right");
        GameObject controller_vive_left       = GameObject.Find("controller_vive_left");
        GameObject controller_vive_right      = GameObject.Find("controller_vive_right");
        GameObject controller_microsoft_left  = GameObject.Find("controller_microsoft_left");
        GameObject controller_microsoft_right = GameObject.Find("controller_microsoft_right");
        GameObject controller_dummy_left      = GameObject.Find("controller_dummy_left");
        GameObject controller_dummy_right     = GameObject.Find("controller_dummy_right");

        controller_oculus_left.SetActive(false);
        controller_oculus_right.SetActive(false);
        controller_vive_left.SetActive(false);
        controller_vive_right.SetActive(false);
        controller_microsoft_left.SetActive(false);
        controller_microsoft_right.SetActive(false);
        controller_dummy_left.SetActive(false);
        controller_dummy_right.SetActive(false);

        if (XRDevice.model.Length >= 6 && XRDevice.model.Substring(0, 6) == "Oculus")
        {
            controller_oculus_left.SetActive(true);
            controller_oculus_right.SetActive(true);
        }
        else if (XRDevice.model.Length >= 4 && XRDevice.model.Substring(0, 4) == "Vive")
        {
            controller_vive_left.SetActive(true);
            controller_vive_right.SetActive(true);
        }
        else if (XRDevice.model.Length >= 4 && XRDevice.model.Substring(0, 4) == "DELL")
        {
            controller_microsoft_left.SetActive(true);
            controller_microsoft_right.SetActive(true);
        }
        else //
        {
            controller_dummy_left.SetActive(true);
            controller_dummy_right.SetActive(true);
        }

        GameObject star = GameObject.Find("star");
        star.transform.localScale = new Vector3(0.0f, 0.0f, 0.0f);
        GameObject controller_dummy = GameObject.Find("controller_dummy");
        controller_dummy.transform.localScale = new Vector3(0.0f, 0.0f, 0.0f);
    }
コード例 #6
0
ファイル: Sample_Pixie.cs プロジェクト: DawidSieczka/VrFun
    // Initialization:
    void Start()
    {
        pixie = new Pixie();

        // Set the welcome message.
        HUDText      = GameObject.Find("HUDText").GetComponent <Text>();
        current_step = new Step0_PressTrigger();
        current_step.init(ref gr);

        me = GCHandle.Alloc(this);
        const string LoadGesturesFile = "Sample_Pixie_Gestures.dat";

        // Find the location for the gesture database (.dat) file
#if UNITY_EDITOR
        // When running the scene inside the Unity editor,
        // we can just load the file from the Assets/ folder:
        string gesture_file_path = "Assets/GestureRecognition";
#elif UNITY_ANDROID
        // On android, the file is in the .apk,
        // so we need to first "download" it to the apps' cache folder.
        AndroidJavaClass  unityPlayer       = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject activity          = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
        string            gesture_file_path = activity.Call <AndroidJavaObject>("getCacheDir").Call <string>("getCanonicalPath");
        UnityWebRequest   request           = UnityWebRequest.Get(Application.streamingAssetsPath + "/" + LoadGesturesFile);
        request.SendWebRequest();
        while (!request.isDone)
        {
            // wait for file extraction to finish
        }
        if (request.isNetworkError)
        {
            HUDText.text = "Failed to extract sample gesture database file from apk.\n";
            return;
        }
        File.WriteAllBytes(gesture_file_path + "/" + LoadGesturesFile, request.downloadHandler.data);
#else
        // This will be the case when exporting a stand-alone PC app.
        // In this case, we can load the gesture database file from the streamingAssets folder.
        string gesture_file_path = Application.streamingAssetsPath;
#endif
        int ret = gr.loadFromFile(gesture_file_path + "/" + LoadGesturesFile);
        if (ret != 0)
        {
            HUDText.text = $"Failed to load sample gesture database file ({ret})\n";
            //return;
        }

        // Hide unused models in the scene
        GameObject controller_oculus_left     = GameObject.Find("controller_oculus_left");
        GameObject controller_oculus_right    = GameObject.Find("controller_oculus_right");
        GameObject controller_vive_left       = GameObject.Find("controller_vive_left");
        GameObject controller_vive_right      = GameObject.Find("controller_vive_right");
        GameObject controller_microsoft_left  = GameObject.Find("controller_microsoft_left");
        GameObject controller_microsoft_right = GameObject.Find("controller_microsoft_right");
        GameObject controller_dummy_left      = GameObject.Find("controller_dummy_left");
        GameObject controller_dummy_right     = GameObject.Find("controller_dummy_right");

        controller_oculus_left.SetActive(false);
        controller_oculus_right.SetActive(false);
        controller_vive_left.SetActive(false);
        controller_vive_right.SetActive(false);
        controller_microsoft_left.SetActive(false);
        controller_microsoft_right.SetActive(false);
        controller_dummy_left.SetActive(false);
        controller_dummy_right.SetActive(false);

        var input_devices = new List <UnityEngine.XR.InputDevice>();
        UnityEngine.XR.InputDevices.GetDevices(input_devices);
        String input_device = "";
        foreach (var device in input_devices)
        {
            if (device.characteristics.HasFlag(InputDeviceCharacteristics.HeadMounted))
            {
                input_device = device.name;
                break;
            }
        }

        if (input_device.Length >= 6 && input_device.Substring(0, 6) == "Oculus")
        {
            controller_oculus_left.SetActive(true);
            controller_oculus_right.SetActive(true);
        }
        else if (input_device.Length >= 4 && input_device.Substring(0, 4) == "Vive")
        {
            controller_vive_left.SetActive(true);
            controller_vive_right.SetActive(true);
        }
        else if (input_device.Length >= 4 && input_device.Substring(0, 4) == "DELL")
        {
            controller_microsoft_left.SetActive(true);
            controller_microsoft_right.SetActive(true);
        }
        else //
        {
            controller_dummy_left.SetActive(true);
            controller_dummy_right.SetActive(true);
        }

        GameObject star = GameObject.Find("star");
        star.transform.localScale = new Vector3(0.0f, 0.0f, 0.0f);
    }
コード例 #7
0
    // Initialization:
    void Start()
    {
        me = GCHandle.Alloc(this);

        if (RecognitionInterval == 0)
        {
            RecognitionInterval = 0.1f;
        }
        if (GesturePeriod == 0)
        {
            GesturePeriod = 1.0f;
        }

        // Load the set of gestures.
        if (LoadGesturesFile == null)
        {
            LoadGesturesFile = "Sample_Continuous_Gestures.dat";
        }

        // Find the location for the gesture database (.dat) file
#if UNITY_EDITOR
        // When running the scene inside the Unity editor,
        // we can just load the file from the Assets/ folder:
        string GesturesFilePath = "Assets/GestureRecognition";
#elif UNITY_ANDROID
        // On android, the file is in the .apk,
        // so we need to first "download" it to the apps' cache folder.
        AndroidJavaClass  unityPlayer      = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject activity         = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
        string            GesturesFilePath = activity.Call <AndroidJavaObject>("getCacheDir").Call <string>("getCanonicalPath");
        UnityWebRequest   request          = UnityWebRequest.Get(Application.streamingAssetsPath + "/" + LoadGesturesFile);
        request.SendWebRequest();
        while (!request.isDone)
        {
            // wait for file extraction to finish
        }
        if (request.isNetworkError)
        {
            HUDText.text = "Failed to extract sample gesture database file from apk.";
            return;
        }
        File.WriteAllBytes(GesturesFilePath + "/" + LoadGesturesFile, request.downloadHandler.data);
#else
        // This will be the case when exporting a stand-alone PC app.
        // In this case, we can load the gesture database file from the streamingAssets folder.
        string GesturesFilePath = Application.streamingAssetsPath;
#endif
        int ret = gr.loadFromFile(GesturesFilePath + "/" + LoadGesturesFile);
        if (ret != 0)
        {
            HUDText.text = $"Failed to load sample gesture database file ({ret})\n";
            return;
        }
        gr.contdIdentificationSmoothing = 5;

        // Hide unused models in the scene
        GameObject controller_oculus_left     = GameObject.Find("controller_oculus_left");
        GameObject controller_oculus_right    = GameObject.Find("controller_oculus_right");
        GameObject controller_vive_left       = GameObject.Find("controller_vive_left");
        GameObject controller_vive_right      = GameObject.Find("controller_vive_right");
        GameObject controller_microsoft_left  = GameObject.Find("controller_microsoft_left");
        GameObject controller_microsoft_right = GameObject.Find("controller_microsoft_right");
        GameObject controller_dummy_left      = GameObject.Find("controller_dummy_left");
        GameObject controller_dummy_right     = GameObject.Find("controller_dummy_right");

        controller_oculus_left.SetActive(false);
        controller_oculus_right.SetActive(false);
        controller_vive_left.SetActive(false);
        controller_vive_right.SetActive(false);
        controller_microsoft_left.SetActive(false);
        controller_microsoft_right.SetActive(false);
        controller_dummy_left.SetActive(false);
        controller_dummy_right.SetActive(false);

        var input_devices = new List <UnityEngine.XR.InputDevice>();
        UnityEngine.XR.InputDevices.GetDevices(input_devices);
        String input_device = "";
        foreach (var device in input_devices)
        {
            if (device.characteristics.HasFlag(InputDeviceCharacteristics.HeadMounted))
            {
                input_device = device.name;
                break;
            }
        }

        if (input_device.Length >= 6 && input_device.Substring(0, 6) == "Oculus")
        {
            controller_oculus_left.SetActive(true);
            controller_oculus_right.SetActive(true);
        }
        else if (input_device.Length >= 4 && input_device.Substring(0, 4) == "Vive")
        {
            controller_vive_left.SetActive(true);
            controller_vive_right.SetActive(true);
        }
        else if (input_device.Length >= 4 && input_device.Substring(0, 4) == "DELL")
        {
            controller_microsoft_left.SetActive(true);
            controller_microsoft_right.SetActive(true);
        }
        else //
        {
            controller_dummy_left.SetActive(true);
            controller_dummy_right.SetActive(true);
        }

        GameObject star = GameObject.Find("star");
        star.transform.localScale = new Vector3(0.0f, 0.0f, 0.0f);
        GameObject controller_dummy = GameObject.Find("controller_dummy");
        controller_dummy.transform.localScale = new Vector3(0.0f, 0.0f, 0.0f);


        // Set the welcome message.
        HUDText      = GameObject.Find("HUDText").GetComponent <Text>();
        HUDText.text = "Welcome to MARUI Gesture Plug-in!\n"
                       + "Hold the trigger to draw gestures.\nAvailable gestures:";
        for (int i = 0; i < gr.numberOfGestures(); i++)
        {
            HUDText.text += "\n" + (i + 1) + " : " + gr.getGestureName(i);
        }
        HUDText.text += "\nor: press 'A'/'X'/Menu button\nto create new gesture.";
    }