From 1f3bf301660c8ccc52ee622ac52cb91b6744fe67 Mon Sep 17 00:00:00 2001 From: Emiliana <38952746+emilianavt@users.noreply.github.com> Date: Tue, 11 Feb 2020 09:55:31 +0100 Subject: [PATCH] There's now an example on how to apply detected expressions to a VRM model. --- Examples/OpenSeeVRMExpression.cs | 53 ++++++++++++++++++++++++++++++++ Unity/OpenSeeLauncher.cs | 2 +- Unity/Plugins/SVMModel.cs | 2 +- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 Examples/OpenSeeVRMExpression.cs diff --git a/Examples/OpenSeeVRMExpression.cs b/Examples/OpenSeeVRMExpression.cs new file mode 100644 index 0000000..fc625ba --- /dev/null +++ b/Examples/OpenSeeVRMExpression.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; +using UnityEngine; +using VRM; + +namespace OpenSee { + +public class OpenSeeVRMExpression : MonoBehaviour +{ + public OpenSeeExpression openSeeExpression; + public VRMBlendShapeProxy vrmBlendShapeProxy; + public string expressionNeutral = "neutral"; + public string expressionFun = "smile"; + public string expressionSorrow = "sad"; + public string expressionAngry = "angry"; + public string expressionJoy = "shocked"; + + private BlendShapeKey lastKey; + private string lastExpression = ""; + + void Start() + { + } + + void Update() + { + if (openSeeExpression == null || vrmBlendShapeProxy == null) { + return; + } + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Neutral), 0f); + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Fun), 0f); + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Sorrow), 0f); + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Angry), 0f); + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Joy), 0f); + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Blink_R), 0f); + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Blink_L), 0f); + if (openSeeExpression.expression == expressionFun) { + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Fun), 1f); + return; + } else if (openSeeExpression.expression == expressionSorrow) { + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Sorrow), 1f); + return; + } else if (openSeeExpression.expression == expressionAngry) { + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Angry), 1f); + return; + } else if (openSeeExpression.expression == expressionJoy) { + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Joy), 1f); + return; + } + vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Neutral), 1f); + } +} + +} \ No newline at end of file diff --git a/Unity/OpenSeeLauncher.cs b/Unity/OpenSeeLauncher.cs index b0d4abe..50034c8 100644 --- a/Unity/OpenSeeLauncher.cs +++ b/Unity/OpenSeeLauncher.cs @@ -29,7 +29,7 @@ public class OpenSeeLauncher : MonoBehaviour { [Tooltip("The path, where the .onnx model files can be found")] public string modelPath = "models\\"; [Tooltip("Additional options that should be passed to the face tracker.")] - public string[] commandlineOptions = new string[] { "--silent", "1", "--max-threads", "2", "--model", "1" }; + public List commandlineOptions = new List(new string[] { "--silent", "1", "--max-threads", "2", "--model", "3" }); [Header("Runtime information")] [Tooltip("This field shows if the tracker is currently alive.")] public bool trackerAlive = false; diff --git a/Unity/Plugins/SVMModel.cs b/Unity/Plugins/SVMModel.cs index 7ad3ad3..9beb8d1 100644 --- a/Unity/Plugins/SVMModel.cs +++ b/Unity/Plugins/SVMModel.cs @@ -143,7 +143,7 @@ public class SVMModel { maxClasses = max + 1; this.cols = cols; - model = trainModel(features, labels, rows, cols, 32f); + model = trainModel(features, labels, rows, cols, 12f); haveModel = true; return true;