From 9f0f48e2572bca1e3b269fe3afda24dcb465a746 Mon Sep 17 00:00:00 2001 From: CoudronJerome Date: Sun, 26 Mar 2023 22:44:43 +0200 Subject: [PATCH 1/7] Tested new implementation for models --- .../Interfaces/InterfacesScripts.asmdef | 3 +- Assets/Common/Interfaces/Theme.cs | 5 +++ .../ScriptableObjects/AnimalsTheme.asset | 1 + .../ScriptableObjects/ClothesTheme.asset | 2 + .../ScriptableObjects/FamilyTheme.asset | 2 + .../Common/ScriptableObjects/FoodTheme.asset | 1 + .../Common/ScriptableObjects/HobbyTheme.asset | 2 + .../Common/ScriptableObjects/HouseTheme.asset | 2 + Assets/Courses/Scenes/TemplateCourse.unity | 1 + Assets/Courses/Scripts/TemplateCourse.cs | 7 +++- Assets/Hangman/Scenes/Hangman.unity | 1 + .../Hangman/Scripts/HangmanGameController.cs | 3 ++ Assets/MediaPipeUnity/ScriptableObjects.meta | 8 ++++ .../ScriptableObjects/ModelList.asset | 20 ++++++++++ .../ScriptableObjects/ModelList.asset.meta | 8 ++++ Assets/MediaPipeUnity/Scripts/ModelIndex.cs | 9 +++++ .../MediaPipeUnity/Scripts/ModelIndex.cs.meta | 11 ++++++ Assets/MediaPipeUnity/Scripts/ModelList.cs | 39 +++++++++++++++++++ .../MediaPipeUnity/Scripts/ModelList.cs.meta | 11 ++++++ Assets/MediaPipeUnity/Scripts/ModelTuple.cs | 18 +++++++++ .../MediaPipeUnity/Scripts/ModelTuple.cs.meta | 11 ++++++ .../MediaPipeUnity/Scripts/SignPredictor.cs | 3 ++ Assets/SpellingBee/Scenes/Game.unity | 1 + Assets/SpellingBee/Scripts/GameController.cs | 3 +- 24 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 Assets/MediaPipeUnity/ScriptableObjects.meta create mode 100644 Assets/MediaPipeUnity/ScriptableObjects/ModelList.asset create mode 100644 Assets/MediaPipeUnity/ScriptableObjects/ModelList.asset.meta create mode 100644 Assets/MediaPipeUnity/Scripts/ModelIndex.cs create mode 100644 Assets/MediaPipeUnity/Scripts/ModelIndex.cs.meta create mode 100644 Assets/MediaPipeUnity/Scripts/ModelList.cs create mode 100644 Assets/MediaPipeUnity/Scripts/ModelList.cs.meta create mode 100644 Assets/MediaPipeUnity/Scripts/ModelTuple.cs create mode 100644 Assets/MediaPipeUnity/Scripts/ModelTuple.cs.meta diff --git a/Assets/Common/Interfaces/InterfacesScripts.asmdef b/Assets/Common/Interfaces/InterfacesScripts.asmdef index c6d0301..7d170b5 100644 --- a/Assets/Common/Interfaces/InterfacesScripts.asmdef +++ b/Assets/Common/Interfaces/InterfacesScripts.asmdef @@ -2,7 +2,8 @@ "name": "InterfacesScripts", "rootNamespace": "", "references": [ - "GUID:5c2b5ba89f9e74e418232e154bc5cc7a" + "GUID:5c2b5ba89f9e74e418232e154bc5cc7a", + "GUID:d0b6b39a21908f94fbbd9f2c196a9725" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Common/Interfaces/Theme.cs b/Assets/Common/Interfaces/Theme.cs index 94d7e19..3fa31b5 100644 --- a/Assets/Common/Interfaces/Theme.cs +++ b/Assets/Common/Interfaces/Theme.cs @@ -28,6 +28,11 @@ public class Theme : ScriptableObject /// public NNModel model; + /// + /// The index of the model you want to use + /// + public ModelIndex modelIndex; + /// /// List of all learnable words/letters /// diff --git a/Assets/Common/ScriptableObjects/AnimalsTheme.asset b/Assets/Common/ScriptableObjects/AnimalsTheme.asset index a7817e0..f2e7a3b 100644 --- a/Assets/Common/ScriptableObjects/AnimalsTheme.asset +++ b/Assets/Common/ScriptableObjects/AnimalsTheme.asset @@ -16,6 +16,7 @@ MonoBehaviour: description: Van vis tot leeuw index: 2 model: {fileID: 0} + modelIndex: 1 learnables: - name: Walvis image: {fileID: 21300000, guid: 2b01165a5836ab14593d7a5862bd6793, type: 3} diff --git a/Assets/Common/ScriptableObjects/ClothesTheme.asset b/Assets/Common/ScriptableObjects/ClothesTheme.asset index bcc40cf..db7d5fa 100644 --- a/Assets/Common/ScriptableObjects/ClothesTheme.asset +++ b/Assets/Common/ScriptableObjects/ClothesTheme.asset @@ -15,6 +15,8 @@ MonoBehaviour: title: Kleren en Kleuren description: Van rok tot sok index: 1 + model: {fileID: 0} + modelIndex: 1 learnables: - name: Blauw image: {fileID: 21300000, guid: 182fb89eba9c64041bef31ca35c4bcd8, type: 3} diff --git a/Assets/Common/ScriptableObjects/FamilyTheme.asset b/Assets/Common/ScriptableObjects/FamilyTheme.asset index 9a804ee..e3c8df7 100644 --- a/Assets/Common/ScriptableObjects/FamilyTheme.asset +++ b/Assets/Common/ScriptableObjects/FamilyTheme.asset @@ -15,6 +15,8 @@ MonoBehaviour: title: Familie description: Van generatie tot generatie index: 6 + model: {fileID: 0} + modelIndex: 1 learnables: - name: Broer image: {fileID: 21300000, guid: eecf67266f150f1489717049489cf16d, type: 3} diff --git a/Assets/Common/ScriptableObjects/FoodTheme.asset b/Assets/Common/ScriptableObjects/FoodTheme.asset index 80a80d8..6d70a39 100644 --- a/Assets/Common/ScriptableObjects/FoodTheme.asset +++ b/Assets/Common/ScriptableObjects/FoodTheme.asset @@ -16,6 +16,7 @@ MonoBehaviour: description: Van kers tot pompoen index: 3 model: {fileID: 0} + modelIndex: 1 learnables: - name: Aardappel image: {fileID: 21300000, guid: 2610cdbc24a125f43ada7fed67d8f51b, type: 3} diff --git a/Assets/Common/ScriptableObjects/HobbyTheme.asset b/Assets/Common/ScriptableObjects/HobbyTheme.asset index c17ad1d..393ac5c 100644 --- a/Assets/Common/ScriptableObjects/HobbyTheme.asset +++ b/Assets/Common/ScriptableObjects/HobbyTheme.asset @@ -15,6 +15,8 @@ MonoBehaviour: title: Hobbies description: Van schilderen tot reizen index: 4 + model: {fileID: 0} + modelIndex: 1 learnables: - name: Dansen image: {fileID: 21300000, guid: 6d405f607ae817744b49f921f0611088, type: 3} diff --git a/Assets/Common/ScriptableObjects/HouseTheme.asset b/Assets/Common/ScriptableObjects/HouseTheme.asset index 3e9bf20..65b7f0e 100644 --- a/Assets/Common/ScriptableObjects/HouseTheme.asset +++ b/Assets/Common/ScriptableObjects/HouseTheme.asset @@ -15,6 +15,8 @@ MonoBehaviour: title: Huis beschrijven description: Van zetel tot villa index: 5 + model: {fileID: 0} + modelIndex: 1 learnables: - name: Keuken image: {fileID: 21300000, guid: b17ce5bf59092b847b084d3400e7a1b4, type: 3} diff --git a/Assets/Courses/Scenes/TemplateCourse.unity b/Assets/Courses/Scenes/TemplateCourse.unity index 036592f..b64e582 100644 --- a/Assets/Courses/Scenes/TemplateCourse.unity +++ b/Assets/Courses/Scenes/TemplateCourse.unity @@ -1301,6 +1301,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 043ccd99cf82b3cc9bf2e00956ce2b93, type: 3} m_Name: m_EditorClassIdentifier: + modelList: {fileID: 11400000, guid: 39516e4e6e56f0f4f80647d9c4d8034c, type: 2} model: {fileID: 5022602860645237092, guid: e6d85df707405ad4f97c23b07227ee99, type: 3} modelInfoFile: {fileID: 4900000, guid: fb8b51022bdcd654a9f29c054832a1b5, type: 3} configAsset: {fileID: 4900000, guid: 6288c43cdca97374782dac1ea87aa029, type: 3} diff --git a/Assets/Courses/Scripts/TemplateCourse.cs b/Assets/Courses/Scripts/TemplateCourse.cs index 6e25232..11a75cb 100644 --- a/Assets/Courses/Scripts/TemplateCourse.cs +++ b/Assets/Courses/Scripts/TemplateCourse.cs @@ -128,13 +128,16 @@ public class TemplateCourse : MonoBehaviour { // Setting up course course = courselist.courses[courselist.currentCourseIndex]; - feedback.signPredictor.model = course.theme.model; + //feedback.signPredictor.model = course.theme.model; + feedback.signPredictor.modelList.SetCurrentModel(course.theme.modelIndex); + //feedback.signPredictor.model = feedback.signPredictor.modelList.models[feedback.signPredictor.modelList.currentModelIndex].model; maxWords = course.theme.learnables.Count; // vvv TEMPORARY STUFF vvv feedbackProgressBar.SetActive(course.theme.model != null); previewMessage.SetActive(course.theme.model == null); - feedback.signPredictor.model = previewModel; + // Instead, the NONE-modelIndex points to Fingerspelling, which gives the same result + //feedback.signPredictor.model = previewModel; // ^^^ TEMPORARY STUFF ^^^ // Create entry in current user for keeping track of progress diff --git a/Assets/Hangman/Scenes/Hangman.unity b/Assets/Hangman/Scenes/Hangman.unity index 9209fad..073a6fb 100644 --- a/Assets/Hangman/Scenes/Hangman.unity +++ b/Assets/Hangman/Scenes/Hangman.unity @@ -6245,6 +6245,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 043ccd99cf82b3cc9bf2e00956ce2b93, type: 3} m_Name: m_EditorClassIdentifier: + modelList: {fileID: 11400000, guid: 39516e4e6e56f0f4f80647d9c4d8034c, type: 2} model: {fileID: 5022602860645237092, guid: e6d85df707405ad4f97c23b07227ee99, type: 3} modelInfoFile: {fileID: 4900000, guid: fb8b51022bdcd654a9f29c054832a1b5, type: 3} configAsset: {fileID: 4900000, guid: 6288c43cdca97374782dac1ea87aa029, type: 3} diff --git a/Assets/Hangman/Scripts/HangmanGameController.cs b/Assets/Hangman/Scripts/HangmanGameController.cs index 45f9bec..3b83c67 100644 --- a/Assets/Hangman/Scripts/HangmanGameController.cs +++ b/Assets/Hangman/Scripts/HangmanGameController.cs @@ -241,6 +241,9 @@ public class HangmanGameController : MonoBehaviour } userList.Save(); + // Hangman always uses fingerspelling + feedback.signPredictor.model = feedback.signPredictor.modelList.GetModelByIndex(ModelIndex.FINGERSPELLING); + // Set calllbacks feedback.getSignCallback = () => { diff --git a/Assets/MediaPipeUnity/ScriptableObjects.meta b/Assets/MediaPipeUnity/ScriptableObjects.meta new file mode 100644 index 0000000..256bc92 --- /dev/null +++ b/Assets/MediaPipeUnity/ScriptableObjects.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 438a3ced42dd6fc4ab38e3a16c1e43a7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MediaPipeUnity/ScriptableObjects/ModelList.asset b/Assets/MediaPipeUnity/ScriptableObjects/ModelList.asset new file mode 100644 index 0000000..12d799c --- /dev/null +++ b/Assets/MediaPipeUnity/ScriptableObjects/ModelList.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 78a3f61c93a08c04496c49ffd10b9021, type: 3} + m_Name: ModelList + m_EditorClassIdentifier: + currentModelIndex: 0 + models: + - index: 0 + model: {fileID: 5022602860645237092, guid: e6d85df707405ad4f97c23b07227ee99, type: 3} + - index: 1 + model: {fileID: 5022602860645237092, guid: e6d85df707405ad4f97c23b07227ee99, type: 3} diff --git a/Assets/MediaPipeUnity/ScriptableObjects/ModelList.asset.meta b/Assets/MediaPipeUnity/ScriptableObjects/ModelList.asset.meta new file mode 100644 index 0000000..6b6b05c --- /dev/null +++ b/Assets/MediaPipeUnity/ScriptableObjects/ModelList.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 39516e4e6e56f0f4f80647d9c4d8034c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MediaPipeUnity/Scripts/ModelIndex.cs b/Assets/MediaPipeUnity/Scripts/ModelIndex.cs new file mode 100644 index 0000000..ec15091 --- /dev/null +++ b/Assets/MediaPipeUnity/Scripts/ModelIndex.cs @@ -0,0 +1,9 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum ModelIndex +{ + FINGERSPELLING, + NONE +} diff --git a/Assets/MediaPipeUnity/Scripts/ModelIndex.cs.meta b/Assets/MediaPipeUnity/Scripts/ModelIndex.cs.meta new file mode 100644 index 0000000..2fdf846 --- /dev/null +++ b/Assets/MediaPipeUnity/Scripts/ModelIndex.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6dbd5e1100bc81648b52206df369d0a1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MediaPipeUnity/Scripts/ModelList.cs b/Assets/MediaPipeUnity/Scripts/ModelList.cs new file mode 100644 index 0000000..3a6b759 --- /dev/null +++ b/Assets/MediaPipeUnity/Scripts/ModelList.cs @@ -0,0 +1,39 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Unity.Barracuda; +/// +/// This scriptable will hold tupples of Courseindices and models +/// +[CreateAssetMenu(menuName = "Create new Scriptable/ModelList")] +public class ModelList : ScriptableObject +{ + /// + /// Index of the currently active model + /// + public int currentModelIndex = 0; + + /// + /// A list of all the models + /// + public List models = new List(); + + /// + /// Get a model by modelindex + /// + /// ModelIndex of the model + /// Model associated with this index, null if no model was found + public NNModel GetModelByIndex(ModelIndex modelIndex) + { + return models.Find((m) => m.index == modelIndex).model; + } + + /// + /// Function to find a model-index in the list based on its index + /// + /// + public void SetCurrentModel(ModelIndex index) + { + currentModelIndex = models.FindIndex((m) => m.index == index); + } +} diff --git a/Assets/MediaPipeUnity/Scripts/ModelList.cs.meta b/Assets/MediaPipeUnity/Scripts/ModelList.cs.meta new file mode 100644 index 0000000..e31c7ee --- /dev/null +++ b/Assets/MediaPipeUnity/Scripts/ModelList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 78a3f61c93a08c04496c49ffd10b9021 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MediaPipeUnity/Scripts/ModelTuple.cs b/Assets/MediaPipeUnity/Scripts/ModelTuple.cs new file mode 100644 index 0000000..439e02e --- /dev/null +++ b/Assets/MediaPipeUnity/Scripts/ModelTuple.cs @@ -0,0 +1,18 @@ +using System; +using UnityEngine; +using Unity.Barracuda; +/// +/// Small class to link a model to a courseIndex irrespective of its position in a list +/// +[Serializable] +public class ModelTuple +{ + /// + /// ModelIndex to which the model corresponds + /// + public ModelIndex index; + /// + /// The model itself + /// + public NNModel model; +} diff --git a/Assets/MediaPipeUnity/Scripts/ModelTuple.cs.meta b/Assets/MediaPipeUnity/Scripts/ModelTuple.cs.meta new file mode 100644 index 0000000..ea41afa --- /dev/null +++ b/Assets/MediaPipeUnity/Scripts/ModelTuple.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bce8507dcb30db447b69708ad4f5f962 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs index b1d8338..6815ae3 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs @@ -18,6 +18,9 @@ namespace Mediapipe.Unity.Tutorial { public class SignPredictor : MonoBehaviour { + + public ModelList modelList; + /// /// Reference to the model used in the SignPredictor /// diff --git a/Assets/SpellingBee/Scenes/Game.unity b/Assets/SpellingBee/Scenes/Game.unity index 0f7aabc..274be82 100644 --- a/Assets/SpellingBee/Scenes/Game.unity +++ b/Assets/SpellingBee/Scenes/Game.unity @@ -3900,6 +3900,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 043ccd99cf82b3cc9bf2e00956ce2b93, type: 3} m_Name: m_EditorClassIdentifier: + modelList: {fileID: 11400000, guid: 39516e4e6e56f0f4f80647d9c4d8034c, type: 2} model: {fileID: 5022602860645237092, guid: e6d85df707405ad4f97c23b07227ee99, type: 3} modelInfoFile: {fileID: 4900000, guid: fb8b51022bdcd654a9f29c054832a1b5, type: 3} configAsset: {fileID: 4900000, guid: 6288c43cdca97374782dac1ea87aa029, type: 3} diff --git a/Assets/SpellingBee/Scripts/GameController.cs b/Assets/SpellingBee/Scripts/GameController.cs index 94b5f95..6e22e68 100644 --- a/Assets/SpellingBee/Scripts/GameController.cs +++ b/Assets/SpellingBee/Scripts/GameController.cs @@ -182,7 +182,8 @@ public partial class GameController : MonoBehaviour userList.Save(); currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex]; - feedback.signPredictor.model = currentTheme.model; + //feedback.signPredictor.model = currentTheme.model; + feedback.signPredictor.model = feedback.signPredictor.modelList.GetModelByIndex(currentTheme.modelIndex); words.AddRange(currentTheme.learnables); ShuffleWords(); NextWord(); -- 2.49.1 From 2183397a0fc1d963def640387028169b80bb0a50 Mon Sep 17 00:00:00 2001 From: CoudronJerome Date: Sun, 26 Mar 2023 22:51:02 +0200 Subject: [PATCH 2/7] Succesfully removed model from theme --- Assets/Common/Interfaces/Theme.cs | 5 ----- Assets/Common/Scripts/CommonScripts.asmdef | 3 ++- Assets/Common/Scripts/CourseActivityScreen.cs | 4 ++-- Assets/Courses/Scripts/TemplateCourse.cs | 4 ++-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Assets/Common/Interfaces/Theme.cs b/Assets/Common/Interfaces/Theme.cs index 3fa31b5..9ddf25d 100644 --- a/Assets/Common/Interfaces/Theme.cs +++ b/Assets/Common/Interfaces/Theme.cs @@ -23,11 +23,6 @@ public class Theme : ScriptableObject /// public ThemeIndex index; - /// - /// Reference to the model used in the SignPredictor - /// - public NNModel model; - /// /// The index of the model you want to use /// diff --git a/Assets/Common/Scripts/CommonScripts.asmdef b/Assets/Common/Scripts/CommonScripts.asmdef index 8b1a1ba..8cd1fb2 100644 --- a/Assets/Common/Scripts/CommonScripts.asmdef +++ b/Assets/Common/Scripts/CommonScripts.asmdef @@ -6,7 +6,8 @@ "GUID:63c63e721f65ebb7d871cb9ef49f4752", "GUID:1631ed2680c61245b8211d943c1639a8", "GUID:5c2b5ba89f9e74e418232e154bc5cc7a", - "GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25" + "GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25", + "GUID:d0b6b39a21908f94fbbd9f2c196a9725" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Common/Scripts/CourseActivityScreen.cs b/Assets/Common/Scripts/CourseActivityScreen.cs index ab0cdb4..40302fa 100644 --- a/Assets/Common/Scripts/CourseActivityScreen.cs +++ b/Assets/Common/Scripts/CourseActivityScreen.cs @@ -56,8 +56,8 @@ public class CourseActivityScreen : MonoBehaviour Course course = courseList.courses[index]; // vvv TEMPORARY STUFF vvv - playButton.SetActive(course.theme.model != null); - previewButton.SetActive(course.theme.model == null); + playButton.SetActive(course.theme.modelIndex != ModelIndex.NONE); + previewButton.SetActive(course.theme.modelIndex == ModelIndex.NONE); // ^^^ TEMPORARY STUFF ^^^ title.text = course.title; diff --git a/Assets/Courses/Scripts/TemplateCourse.cs b/Assets/Courses/Scripts/TemplateCourse.cs index 11a75cb..8bc2ad9 100644 --- a/Assets/Courses/Scripts/TemplateCourse.cs +++ b/Assets/Courses/Scripts/TemplateCourse.cs @@ -134,8 +134,8 @@ public class TemplateCourse : MonoBehaviour maxWords = course.theme.learnables.Count; // vvv TEMPORARY STUFF vvv - feedbackProgressBar.SetActive(course.theme.model != null); - previewMessage.SetActive(course.theme.model == null); + feedbackProgressBar.SetActive(course.theme.modelIndex != ModelIndex.NONE); + previewMessage.SetActive(course.theme.modelIndex == ModelIndex.NONE); // Instead, the NONE-modelIndex points to Fingerspelling, which gives the same result //feedback.signPredictor.model = previewModel; // ^^^ TEMPORARY STUFF ^^^ -- 2.49.1 From 78f4d961f71e36841374e4f171d666ede1114f7a Mon Sep 17 00:00:00 2001 From: CoudronJerome Date: Sun, 26 Mar 2023 23:15:09 +0200 Subject: [PATCH 3/7] Made modelChanging internal in SIgnPredictor Made it so that there is a function inside SignPredictor that is used to change its model --- Assets/Courses/Scripts/TemplateCourse.cs | 4 +--- .../Hangman/Scripts/HangmanGameController.cs | 2 +- .../MediaPipeUnity/Scripts/SignPredictor.cs | 19 +++++++++++++------ Assets/SpellingBee/Scripts/GameController.cs | 3 +-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Assets/Courses/Scripts/TemplateCourse.cs b/Assets/Courses/Scripts/TemplateCourse.cs index 8bc2ad9..19b417a 100644 --- a/Assets/Courses/Scripts/TemplateCourse.cs +++ b/Assets/Courses/Scripts/TemplateCourse.cs @@ -128,9 +128,7 @@ public class TemplateCourse : MonoBehaviour { // Setting up course course = courselist.courses[courselist.currentCourseIndex]; - //feedback.signPredictor.model = course.theme.model; - feedback.signPredictor.modelList.SetCurrentModel(course.theme.modelIndex); - //feedback.signPredictor.model = feedback.signPredictor.modelList.models[feedback.signPredictor.modelList.currentModelIndex].model; + feedback.signPredictor.ChangeModel(course.theme.modelIndex); maxWords = course.theme.learnables.Count; // vvv TEMPORARY STUFF vvv diff --git a/Assets/Hangman/Scripts/HangmanGameController.cs b/Assets/Hangman/Scripts/HangmanGameController.cs index 3b83c67..9771fc6 100644 --- a/Assets/Hangman/Scripts/HangmanGameController.cs +++ b/Assets/Hangman/Scripts/HangmanGameController.cs @@ -242,7 +242,7 @@ public class HangmanGameController : MonoBehaviour userList.Save(); // Hangman always uses fingerspelling - feedback.signPredictor.model = feedback.signPredictor.modelList.GetModelByIndex(ModelIndex.FINGERSPELLING); + feedback.signPredictor.ChangeModel(ModelIndex.FINGERSPELLING); // Set calllbacks feedback.getSignCallback = () => diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs index 6815ae3..fb02a82 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs @@ -18,13 +18,10 @@ namespace Mediapipe.Unity.Tutorial { public class SignPredictor : MonoBehaviour { - - public ModelList modelList; - /// - /// Reference to the model used in the SignPredictor + /// ModelList, used to change model using ModelIndex /// - public NNModel model; + public ModelList modelList; /// /// Reference to the model info file @@ -213,12 +210,22 @@ namespace Mediapipe.Unity.Tutorial // check if model exists at path //var model = ModelLoader.Load(Resources.Load("Models/Fingerspelling/model_A-L")); - worker = model.CreateWorker(); + worker = modelList.models[modelList.currentModelIndex].model.CreateWorker(); StartCoroutine(SignRecognitionCoroutine()); StartCoroutine(MediapipeCoroutine()); } + public void ChangeModel(ModelIndex index) + { + this.modelList.SetCurrentModel(index); + // If a worker already existed, we throw it out + worker?.Dispose(); + + // Add a new worker for the new model + worker = modelList.models[modelList.currentModelIndex].model.CreateWorker(); + } + /// /// Coroutine which executes the mediapipe pipeline /// diff --git a/Assets/SpellingBee/Scripts/GameController.cs b/Assets/SpellingBee/Scripts/GameController.cs index 6e22e68..d0605fc 100644 --- a/Assets/SpellingBee/Scripts/GameController.cs +++ b/Assets/SpellingBee/Scripts/GameController.cs @@ -182,8 +182,7 @@ public partial class GameController : MonoBehaviour userList.Save(); currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex]; - //feedback.signPredictor.model = currentTheme.model; - feedback.signPredictor.model = feedback.signPredictor.modelList.GetModelByIndex(currentTheme.modelIndex); + feedback.signPredictor.ChangeModel(currentTheme.modelIndex); words.AddRange(currentTheme.learnables); ShuffleWords(); NextWord(); -- 2.49.1 From be7457236c87875e4bc1b7a7ab7f0303bc2bf6b7 Mon Sep 17 00:00:00 2001 From: CoudronJerome Date: Mon, 27 Mar 2023 10:57:30 +0200 Subject: [PATCH 4/7] Added test-code and moved scripts to correct folders --- .../Interfaces/InterfacesScripts.asmdef | 3 +- .../Interfaces}/ModelIndex.cs | 0 .../Interfaces}/ModelIndex.cs.meta | 0 .../Interfaces}/ModelList.cs | 0 .../Interfaces}/ModelList.cs.meta | 0 .../Interfaces}/ModelTuple.cs | 0 .../Interfaces}/ModelTuple.cs.meta | 0 Assets/Common/Interfaces/Theme.cs | 1 - Assets/Common/Tests/CommonTests.asmdef | 4 +- Assets/Common/Tests/ModelListTest.cs | 77 +++++++++++++++++++ Assets/Common/Tests/ModelListTest.cs.meta | 11 +++ .../Scripts/SignPredictor.asmdef | 3 +- 12 files changed, 94 insertions(+), 5 deletions(-) rename Assets/{MediaPipeUnity/Scripts => Common/Interfaces}/ModelIndex.cs (100%) rename Assets/{MediaPipeUnity/Scripts => Common/Interfaces}/ModelIndex.cs.meta (100%) rename Assets/{MediaPipeUnity/Scripts => Common/Interfaces}/ModelList.cs (100%) rename Assets/{MediaPipeUnity/Scripts => Common/Interfaces}/ModelList.cs.meta (100%) rename Assets/{MediaPipeUnity/Scripts => Common/Interfaces}/ModelTuple.cs (100%) rename Assets/{MediaPipeUnity/Scripts => Common/Interfaces}/ModelTuple.cs.meta (100%) create mode 100644 Assets/Common/Tests/ModelListTest.cs create mode 100644 Assets/Common/Tests/ModelListTest.cs.meta diff --git a/Assets/Common/Interfaces/InterfacesScripts.asmdef b/Assets/Common/Interfaces/InterfacesScripts.asmdef index 7d170b5..c6d0301 100644 --- a/Assets/Common/Interfaces/InterfacesScripts.asmdef +++ b/Assets/Common/Interfaces/InterfacesScripts.asmdef @@ -2,8 +2,7 @@ "name": "InterfacesScripts", "rootNamespace": "", "references": [ - "GUID:5c2b5ba89f9e74e418232e154bc5cc7a", - "GUID:d0b6b39a21908f94fbbd9f2c196a9725" + "GUID:5c2b5ba89f9e74e418232e154bc5cc7a" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/MediaPipeUnity/Scripts/ModelIndex.cs b/Assets/Common/Interfaces/ModelIndex.cs similarity index 100% rename from Assets/MediaPipeUnity/Scripts/ModelIndex.cs rename to Assets/Common/Interfaces/ModelIndex.cs diff --git a/Assets/MediaPipeUnity/Scripts/ModelIndex.cs.meta b/Assets/Common/Interfaces/ModelIndex.cs.meta similarity index 100% rename from Assets/MediaPipeUnity/Scripts/ModelIndex.cs.meta rename to Assets/Common/Interfaces/ModelIndex.cs.meta diff --git a/Assets/MediaPipeUnity/Scripts/ModelList.cs b/Assets/Common/Interfaces/ModelList.cs similarity index 100% rename from Assets/MediaPipeUnity/Scripts/ModelList.cs rename to Assets/Common/Interfaces/ModelList.cs diff --git a/Assets/MediaPipeUnity/Scripts/ModelList.cs.meta b/Assets/Common/Interfaces/ModelList.cs.meta similarity index 100% rename from Assets/MediaPipeUnity/Scripts/ModelList.cs.meta rename to Assets/Common/Interfaces/ModelList.cs.meta diff --git a/Assets/MediaPipeUnity/Scripts/ModelTuple.cs b/Assets/Common/Interfaces/ModelTuple.cs similarity index 100% rename from Assets/MediaPipeUnity/Scripts/ModelTuple.cs rename to Assets/Common/Interfaces/ModelTuple.cs diff --git a/Assets/MediaPipeUnity/Scripts/ModelTuple.cs.meta b/Assets/Common/Interfaces/ModelTuple.cs.meta similarity index 100% rename from Assets/MediaPipeUnity/Scripts/ModelTuple.cs.meta rename to Assets/Common/Interfaces/ModelTuple.cs.meta diff --git a/Assets/Common/Interfaces/Theme.cs b/Assets/Common/Interfaces/Theme.cs index 9ddf25d..838d223 100644 --- a/Assets/Common/Interfaces/Theme.cs +++ b/Assets/Common/Interfaces/Theme.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Unity.Barracuda; using UnityEngine; /// diff --git a/Assets/Common/Tests/CommonTests.asmdef b/Assets/Common/Tests/CommonTests.asmdef index aaa7ab0..7e91147 100644 --- a/Assets/Common/Tests/CommonTests.asmdef +++ b/Assets/Common/Tests/CommonTests.asmdef @@ -5,7 +5,9 @@ "UnityEngine.TestRunner", "UnityEditor.TestRunner", "CommonScripts", - "InterfacesScripts" + "InterfacesScripts", + "Unity.Barracuda", + "SignPredictor" ], "includePlatforms": [ "Editor" diff --git a/Assets/Common/Tests/ModelListTest.cs b/Assets/Common/Tests/ModelListTest.cs new file mode 100644 index 0000000..d28480d --- /dev/null +++ b/Assets/Common/Tests/ModelListTest.cs @@ -0,0 +1,77 @@ +using NUnit.Framework; +using Unity.Barracuda; +using UnityEngine; +/// +/// Test the ModelList class +/// +[TestFixture] +public class ModelListTest +{ + private ModelList modelList; + + /// + /// Setup a ModelList with all possible Models in the enum + /// + [SetUp] + public void Setup_Model() + { + modelList = ScriptableObject.CreateInstance(); + + // Add a Model for each index in the enum + + // Dumb way to access each index in the enum, couldn't find a different way to do it though + foreach (var field in typeof(ModelIndex).GetFields()) + { + if (field.IsLiteral) + { + ModelIndex value = (ModelIndex)field.GetValue(null); + string name = field.Name; + ModelTuple model = new ModelTuple(); + // This is all we will need to distinguish + model.index = value; + + // Insert in front to guarantee that ModelIndex will not line up with listIndex + modelList.models.Insert(0, model); + } + } + } + + /// + /// Check if getModelByIndex returns the NMModel or return null if there is no model + /// + [Test] + public void TestGetModelByIndex() + { + foreach (var field in typeof(ModelIndex).GetFields()) + { + if (field.IsLiteral) + { + ModelIndex value = (ModelIndex)field.GetValue(null); + string name = field.Name; + Assert.IsTrue(modelList.GetModelByIndex(value) is NNModel || modelList.GetModelByIndex(value) is null); + } + } + } + + /// + /// Check if all courses can be correctly set as current via SetCurrentCourse + /// + [Test] + public void TestSetCurrentModel() + { + foreach (var field in typeof(ModelIndex).GetFields()) + { + if (field.IsLiteral) + { + ModelIndex value = (ModelIndex)field.GetValue(null); + string name = field.Name; + modelList.SetCurrentModel(value); + + // Fetch the current course and check if its name is the same as the one we made into the current one + ModelTuple m = modelList.models[modelList.currentModelIndex]; + + Assert.AreEqual(m.index, value); + } + } + } +} diff --git a/Assets/Common/Tests/ModelListTest.cs.meta b/Assets/Common/Tests/ModelListTest.cs.meta new file mode 100644 index 0000000..85cdfd3 --- /dev/null +++ b/Assets/Common/Tests/ModelListTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1313e0cc80244354eb6e2d0c1e891941 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.asmdef b/Assets/MediaPipeUnity/Scripts/SignPredictor.asmdef index cc93292..ba94856 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.asmdef +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.asmdef @@ -6,7 +6,8 @@ "GUID:5c2b5ba89f9e74e418232e154bc5cc7a", "GUID:04c4d86a70aa56c55a78c61f1ab1a56d", "GUID:edc93f477bb73a743a97d6882ed330b3", - "GUID:58e104b97fb3752438ada2902a36dcbf" + "GUID:58e104b97fb3752438ada2902a36dcbf", + "GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25" ], "includePlatforms": [], "excludePlatforms": [], -- 2.49.1 From dfdb2ab10b68659829ebd9893627fab9238fb4d7 Mon Sep 17 00:00:00 2001 From: CoudronJerome Date: Tue, 28 Mar 2023 08:52:02 +0200 Subject: [PATCH 5/7] Updated getter in ModelList and cleaned Assembly --- Assets/Common/Interfaces/ModelList.cs | 4 ++-- Assets/Common/Scripts/CommonScripts.asmdef | 3 +-- Assets/Common/Tests/ModelListTest.cs | 22 +++---------------- .../MediaPipeUnity/Scripts/SignPredictor.cs | 4 ++-- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/Assets/Common/Interfaces/ModelList.cs b/Assets/Common/Interfaces/ModelList.cs index 3a6b759..5f191a8 100644 --- a/Assets/Common/Interfaces/ModelList.cs +++ b/Assets/Common/Interfaces/ModelList.cs @@ -23,9 +23,9 @@ public class ModelList : ScriptableObject /// /// ModelIndex of the model /// Model associated with this index, null if no model was found - public NNModel GetModelByIndex(ModelIndex modelIndex) + public NNModel GetCurrentModel() { - return models.Find((m) => m.index == modelIndex).model; + return models[currentModelIndex].model; } /// diff --git a/Assets/Common/Scripts/CommonScripts.asmdef b/Assets/Common/Scripts/CommonScripts.asmdef index 8cd1fb2..8b1a1ba 100644 --- a/Assets/Common/Scripts/CommonScripts.asmdef +++ b/Assets/Common/Scripts/CommonScripts.asmdef @@ -6,8 +6,7 @@ "GUID:63c63e721f65ebb7d871cb9ef49f4752", "GUID:1631ed2680c61245b8211d943c1639a8", "GUID:5c2b5ba89f9e74e418232e154bc5cc7a", - "GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25", - "GUID:d0b6b39a21908f94fbbd9f2c196a9725" + "GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Common/Tests/ModelListTest.cs b/Assets/Common/Tests/ModelListTest.cs index d28480d..2e975a9 100644 --- a/Assets/Common/Tests/ModelListTest.cs +++ b/Assets/Common/Tests/ModelListTest.cs @@ -37,27 +37,10 @@ public class ModelListTest } /// - /// Check if getModelByIndex returns the NMModel or return null if there is no model + /// Check if all courses can be correctly gotten and set as current via SetCurrentCourse /// [Test] - public void TestGetModelByIndex() - { - foreach (var field in typeof(ModelIndex).GetFields()) - { - if (field.IsLiteral) - { - ModelIndex value = (ModelIndex)field.GetValue(null); - string name = field.Name; - Assert.IsTrue(modelList.GetModelByIndex(value) is NNModel || modelList.GetModelByIndex(value) is null); - } - } - } - - /// - /// Check if all courses can be correctly set as current via SetCurrentCourse - /// - [Test] - public void TestSetCurrentModel() + public void TestGetSetCurrentModel() { foreach (var field in typeof(ModelIndex).GetFields()) { @@ -71,6 +54,7 @@ public class ModelListTest ModelTuple m = modelList.models[modelList.currentModelIndex]; Assert.AreEqual(m.index, value); + Assert.IsTrue(m.model is NNModel || m.model is null); } } } diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs index fb02a82..2ec4263 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs @@ -210,7 +210,7 @@ namespace Mediapipe.Unity.Tutorial // check if model exists at path //var model = ModelLoader.Load(Resources.Load("Models/Fingerspelling/model_A-L")); - worker = modelList.models[modelList.currentModelIndex].model.CreateWorker(); + worker = modelList.GetCurrentModel().CreateWorker(); StartCoroutine(SignRecognitionCoroutine()); StartCoroutine(MediapipeCoroutine()); @@ -223,7 +223,7 @@ namespace Mediapipe.Unity.Tutorial worker?.Dispose(); // Add a new worker for the new model - worker = modelList.models[modelList.currentModelIndex].model.CreateWorker(); + worker = modelList.GetCurrentModel().CreateWorker(); } /// -- 2.49.1 From be8885a508d4d3db9824de5d8e834ac8e704daff Mon Sep 17 00:00:00 2001 From: CoudronJerome Date: Tue, 28 Mar 2023 15:37:17 +0200 Subject: [PATCH 6/7] Implemented MR feedback --- Assets/Common/Interfaces/ModelIndex.cs | 4 ++- Assets/Common/Interfaces/ModelList.cs | 23 ++++++++++++++-- Assets/Common/Interfaces/ModelTuple.cs | 18 ------------- Assets/Common/Interfaces/ModelTuple.cs.meta | 11 -------- Assets/Common/Tests/ModelListTest.cs | 26 +++++++++++++++---- .../MediaPipeUnity/Scripts/SignPredictor.cs | 4 +-- 6 files changed, 47 insertions(+), 39 deletions(-) delete mode 100644 Assets/Common/Interfaces/ModelTuple.cs delete mode 100644 Assets/Common/Interfaces/ModelTuple.cs.meta diff --git a/Assets/Common/Interfaces/ModelIndex.cs b/Assets/Common/Interfaces/ModelIndex.cs index ec15091..594fd39 100644 --- a/Assets/Common/Interfaces/ModelIndex.cs +++ b/Assets/Common/Interfaces/ModelIndex.cs @@ -1,7 +1,9 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; - +/// +/// This enum is used to identify each of the SignLanguage models +/// public enum ModelIndex { FINGERSPELLING, diff --git a/Assets/Common/Interfaces/ModelList.cs b/Assets/Common/Interfaces/ModelList.cs index 5f191a8..98ec086 100644 --- a/Assets/Common/Interfaces/ModelList.cs +++ b/Assets/Common/Interfaces/ModelList.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -8,6 +9,23 @@ using Unity.Barracuda; [CreateAssetMenu(menuName = "Create new Scriptable/ModelList")] public class ModelList : ScriptableObject { + /// + /// Small class to link a model to a courseIndex irrespective of its position in a list + /// + [Serializable] + public class ModelTuple + { + /// + /// ModelIndex to which the model corresponds + /// + public ModelIndex index; + /// + /// The model itself + /// + public NNModel model; + } + + /// /// Index of the currently active model /// @@ -23,9 +41,10 @@ public class ModelList : ScriptableObject /// /// ModelIndex of the model /// Model associated with this index, null if no model was found - public NNModel GetCurrentModel() + public ModelTuple GetCurrentModel() { - return models[currentModelIndex].model; + //if(currentModelIndex < models.Find) + return models.Find(x => x.model == models[currentModelIndex].model); } /// diff --git a/Assets/Common/Interfaces/ModelTuple.cs b/Assets/Common/Interfaces/ModelTuple.cs deleted file mode 100644 index 439e02e..0000000 --- a/Assets/Common/Interfaces/ModelTuple.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using UnityEngine; -using Unity.Barracuda; -/// -/// Small class to link a model to a courseIndex irrespective of its position in a list -/// -[Serializable] -public class ModelTuple -{ - /// - /// ModelIndex to which the model corresponds - /// - public ModelIndex index; - /// - /// The model itself - /// - public NNModel model; -} diff --git a/Assets/Common/Interfaces/ModelTuple.cs.meta b/Assets/Common/Interfaces/ModelTuple.cs.meta deleted file mode 100644 index ea41afa..0000000 --- a/Assets/Common/Interfaces/ModelTuple.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: bce8507dcb30db447b69708ad4f5f962 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Common/Tests/ModelListTest.cs b/Assets/Common/Tests/ModelListTest.cs index 2e975a9..a988913 100644 --- a/Assets/Common/Tests/ModelListTest.cs +++ b/Assets/Common/Tests/ModelListTest.cs @@ -26,7 +26,7 @@ public class ModelListTest { ModelIndex value = (ModelIndex)field.GetValue(null); string name = field.Name; - ModelTuple model = new ModelTuple(); + ModelList.ModelTuple model = new ModelList.ModelTuple(); // This is all we will need to distinguish model.index = value; @@ -36,11 +36,23 @@ public class ModelListTest } } + public void TestGetCurrentModel() + { + System.Random random = new System.Random(); + ModelIndex value = (ModelIndex)random.Next(modelList.models.Count); + modelList.SetCurrentModel(value); + + Assert.AreEqual(value, modelList.GetCurrentModel().index); + + // Check if empty model fails gracefully (returns null) + Assert.IsNull(ScriptableObject.CreateInstance().GetCurrentModel()); + } + /// - /// Check if all courses can be correctly gotten and set as current via SetCurrentCourse + /// Check if all models can be correctly set as current via SetCurrentModel /// [Test] - public void TestGetSetCurrentModel() + public void TestSetCurrentModel() { foreach (var field in typeof(ModelIndex).GetFields()) { @@ -50,12 +62,16 @@ public class ModelListTest string name = field.Name; modelList.SetCurrentModel(value); - // Fetch the current course and check if its name is the same as the one we made into the current one - ModelTuple m = modelList.models[modelList.currentModelIndex]; + // Fetch the current model and check if its name is the same as the one we made into the current one + ModelList.ModelTuple m = modelList.models[modelList.currentModelIndex]; Assert.AreEqual(m.index, value); Assert.IsTrue(m.model is NNModel || m.model is null); } } + ModelList emptyList = ScriptableObject.CreateInstance(); + emptyList.SetCurrentModel(ModelIndex.FINGERSPELLING); + + Assert.IsTrue(emptyList.currentModelIndex == -1); } } diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs index 2ec4263..8beb2dd 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs @@ -210,7 +210,7 @@ namespace Mediapipe.Unity.Tutorial // check if model exists at path //var model = ModelLoader.Load(Resources.Load("Models/Fingerspelling/model_A-L")); - worker = modelList.GetCurrentModel().CreateWorker(); + worker = modelList.GetCurrentModel().model.CreateWorker(); StartCoroutine(SignRecognitionCoroutine()); StartCoroutine(MediapipeCoroutine()); @@ -223,7 +223,7 @@ namespace Mediapipe.Unity.Tutorial worker?.Dispose(); // Add a new worker for the new model - worker = modelList.GetCurrentModel().CreateWorker(); + worker = modelList.GetCurrentModel().model.CreateWorker(); } /// -- 2.49.1 From a44532b94a0a3cdcaac7964d6d874d388ac5ba85 Mon Sep 17 00:00:00 2001 From: CoudronJerome Date: Wed, 29 Mar 2023 19:17:42 +0200 Subject: [PATCH 7/7] Changed GetCurrentModel to return the model instead of the tuple --- Assets/Common/Interfaces/ModelList.cs | 5 ++--- Assets/Common/Tests/ModelListTest.cs | 7 +++++-- Assets/MediaPipeUnity/Scripts/SignPredictor.cs | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Assets/Common/Interfaces/ModelList.cs b/Assets/Common/Interfaces/ModelList.cs index 98ec086..d2a4de9 100644 --- a/Assets/Common/Interfaces/ModelList.cs +++ b/Assets/Common/Interfaces/ModelList.cs @@ -41,10 +41,9 @@ public class ModelList : ScriptableObject /// /// ModelIndex of the model /// Model associated with this index, null if no model was found - public ModelTuple GetCurrentModel() + public NNModel GetCurrentModel() { - //if(currentModelIndex < models.Find) - return models.Find(x => x.model == models[currentModelIndex].model); + return models.Find(x => x.model == models[currentModelIndex].model)?.model; } /// diff --git a/Assets/Common/Tests/ModelListTest.cs b/Assets/Common/Tests/ModelListTest.cs index a988913..8ea900c 100644 --- a/Assets/Common/Tests/ModelListTest.cs +++ b/Assets/Common/Tests/ModelListTest.cs @@ -35,14 +35,17 @@ public class ModelListTest } } } - + /// + /// Check if current model can be correctly gotten as current via GetCurrentModel + /// + [Test] public void TestGetCurrentModel() { System.Random random = new System.Random(); ModelIndex value = (ModelIndex)random.Next(modelList.models.Count); modelList.SetCurrentModel(value); - Assert.AreEqual(value, modelList.GetCurrentModel().index); + Assert.AreEqual(modelList.models[modelList.currentModelIndex].model, modelList.GetCurrentModel()); // Check if empty model fails gracefully (returns null) Assert.IsNull(ScriptableObject.CreateInstance().GetCurrentModel()); diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs index 8beb2dd..2ec4263 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs @@ -210,7 +210,7 @@ namespace Mediapipe.Unity.Tutorial // check if model exists at path //var model = ModelLoader.Load(Resources.Load("Models/Fingerspelling/model_A-L")); - worker = modelList.GetCurrentModel().model.CreateWorker(); + worker = modelList.GetCurrentModel().CreateWorker(); StartCoroutine(SignRecognitionCoroutine()); StartCoroutine(MediapipeCoroutine()); @@ -223,7 +223,7 @@ namespace Mediapipe.Unity.Tutorial worker?.Dispose(); // Add a new worker for the new model - worker = modelList.GetCurrentModel().model.CreateWorker(); + worker = modelList.GetCurrentModel().CreateWorker(); } /// -- 2.49.1