From f41898f77456bcca97774631d47dc89087c7ef94 Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Mon, 28 Nov 2022 18:12:12 -0600 Subject: [PATCH 1/2] Fix create parameter switch --- .gitignore | 1 + .../Editor/BinaryParameterScript.cs | 1 + .../Editor/BinaryParameterWindow.cs | 86 +++++++++++++++---- .../Editor/ParameterGenerator.cs | 33 +++++++ 4 files changed, 103 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 498816d..f5d7a2e 100644 --- a/.gitignore +++ b/.gitignore @@ -416,3 +416,4 @@ FodyWeavers.xsd /.vsconfig /Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/Test.controller /Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/AllParams.asset +/Export \ No newline at end of file diff --git a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterScript.cs b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterScript.cs index 3f12f0a..0b993f6 100644 --- a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterScript.cs +++ b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterScript.cs @@ -367,6 +367,7 @@ private static void CreateUniformBinaryStatesInMachine(string name, int binarySi } } + // implement next update pls private static void CreateBranchingBinaryStatesInMachine(string name, int binarySize, AnimatorStateMachine stateMachine, AnimationClip initClip, AnimationClip finalClip, bool writeDefaults, float duration, bool nextStateInterrupt, float min, float max, AnimationClip finalNegativeClip = null, float minNeg = 0, float maxNeg = 0) { // Skips creating the negative & positive branch diff --git a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterWindow.cs b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterWindow.cs index 6b725c1..dbec15f 100644 --- a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterWindow.cs +++ b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterWindow.cs @@ -405,7 +405,37 @@ private void OnGUI() "set animations, transitions, and parameters that handle the specified Binary Parameter." ))) { - if (ParameterTools.AddVRCParameter(_avDescriptor, GenerateBinaryParams(_baseParamName, _binarySize, _isCombined)) | !_createParametersInDescriptor) + if (_createParametersInDescriptor) + { + if (ParameterTools.AddVRCParameter(_avDescriptor, GenerateBinaryParams(_baseParamName, _binarySize, _isCombined))) + { + + if (_tab == 0 && !_smooth) + { + ParameterTools.CheckAndCreateParameter(_baseParamName, _animatorController, 1); + + _binaryStateMachine.initClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName, 0f); + _binaryStateMachine.finalClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName, 1f); + } + else if (_tab == 0) + { + ParameterTools.CheckAndCreateParameter(_baseParamName, _animatorController, 1); + + _binaryStateMachine.CreateSmoothingLayer(_smoothness); + + _binaryStateMachine.initClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName + "Proxy", 0f); + _binaryStateMachine.finalClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName + "Proxy", 1f); + } + if (ParameterTools.AddVRCParameter(_avDescriptor, GenerateBinaryParams(_baseParamName, _binarySize, _isCombined))) + { + ParameterTools.RemoveVRCParameter(_avDescriptor, _baseParamName); + _binaryStateMachine.CreateBinaryLayer(); + } + else + EditorGUILayout.HelpBox("Parameters can not fit, or Expressions Parameters do not exist.", MessageType.Warning); + } + } + else { if (_tab == 0 && !_smooth) { @@ -423,13 +453,7 @@ private void OnGUI() _binaryStateMachine.initClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName + "Proxy", 0f); _binaryStateMachine.finalClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName + "Proxy", 1f); } - if (ParameterTools.AddVRCParameter(_avDescriptor, GenerateBinaryParams(_baseParamName, _binarySize, _isCombined))) - { - ParameterTools.RemoveVRCParameter(_avDescriptor, _baseParamName); - _binaryStateMachine.CreateBinaryLayer(); - } - else - EditorGUILayout.HelpBox("Parameters can not fit, or Expressions Parameters do not exist.", MessageType.Warning); + _binaryStateMachine.CreateBinaryLayer(); } } } @@ -442,15 +466,43 @@ private void OnGUI() "set animations, transitions, and parameters that handle the specified Combined Binary Parameter." ))) { - if (ParameterTools.AddVRCParameter(_avDescriptor, GenerateBinaryParams(_baseParamName, _binarySize, _isCombined)) | !_createParametersInDescriptor) + if(_createParametersInDescriptor) { - if (_tab == 0 && !_smooth) + if (ParameterTools.AddVRCParameter(_avDescriptor, GenerateBinaryParams(_baseParamName, _binarySize, _isCombined))) { - ParameterTools.RemoveVRCParameter(_avDescriptor, new VRCExpressionParameters.Parameter + if (_tab == 0 && !_smooth) + { + ParameterTools.RemoveVRCParameter(_avDescriptor, new VRCExpressionParameters.Parameter + { + name = _baseParamName, + valueType = VRCExpressionParameters.ValueType.Float + }); + ParameterTools.CheckAndCreateParameter(_baseParamName, _animatorController, 1); + + _binaryStateMachine.initClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName, 0f); + _binaryStateMachine.finalClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName, 1f); + _binaryStateMachine.finalNegativeClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName, -1f); + } + else if (_tab == 0) { - name = _baseParamName, - valueType = VRCExpressionParameters.ValueType.Float - }); + ParameterTools.RemoveVRCParameter(_avDescriptor, _baseParamName); + ParameterTools.CheckAndCreateParameter(_baseParamName, _animatorController, 1); + + _binaryStateMachine.CreateSmoothingLayer(_smoothness); + _binaryStateMachine.initClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName + "Proxy", 0f); + _binaryStateMachine.finalClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName + "Proxy", 1f); + _binaryStateMachine.finalNegativeClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName + "Proxy", -1f); + } + _binaryStateMachine.CreateCombinedBinaryLayer(); + } + else + EditorGUILayout.HelpBox("Parameters can not fit, or Expressions Parameters do not exist.", MessageType.Warning); + } + else + { + if (_tab == 0 && !_smooth) + { + ParameterTools.CheckAndCreateParameter(_baseParamName, _animatorController, 1); _binaryStateMachine.initClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName, 0f); @@ -458,8 +510,7 @@ private void OnGUI() _binaryStateMachine.finalNegativeClip = BinaryParameterFloatDriver.CreateFloatDriverAnimation(_baseParamName, -1f); } else if (_tab == 0) - { - ParameterTools.RemoveVRCParameter(_avDescriptor, _baseParamName); + { ParameterTools.CheckAndCreateParameter(_baseParamName, _animatorController, 1); _binaryStateMachine.CreateSmoothingLayer(_smoothness); @@ -469,8 +520,7 @@ private void OnGUI() } _binaryStateMachine.CreateCombinedBinaryLayer(); } - else - EditorGUILayout.HelpBox("Parameters can not fit, or Expressions Parameters do not exist.", MessageType.Warning); + } EditorGUILayout.HelpBox("Parameters (" + _avDescriptor.expressionParameters.CalcTotalCost() + "/" + VRCExpressionParameters.MAX_PARAMETER_COST + "):" + GenerateParamNames(_baseParamName, _binarySize, _isCombined), MessageType.None); diff --git a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/ParameterGenerator.cs b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/ParameterGenerator.cs index 59a8e81..90f20d0 100644 --- a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/ParameterGenerator.cs +++ b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/ParameterGenerator.cs @@ -132,6 +132,39 @@ public static bool RemoveVRCParameter(VRCAvatarDescriptor avatarDescriptor, VRCE return true; } + public static bool RemoveVRCParameter(VRCAvatarDescriptor avatarDescriptor, string parameter) + { + // Make sure Parameters aren't null + if (avatarDescriptor.expressionParameters == null) + { + Debug.Log("ExpressionsParameters not found!"); + return false; + } + + // Instantiate and Save to Database + VRCExpressionParameters newParameters = avatarDescriptor.expressionParameters; + string assetPath = AssetDatabase.GetAssetPath(avatarDescriptor.expressionParameters); + if (assetPath != String.Empty) + { + AssetDatabase.RemoveObjectFromAsset(avatarDescriptor.expressionParameters); + AssetDatabase.CreateAsset(newParameters, assetPath); + avatarDescriptor.expressionParameters = newParameters; + } + + // Check and see if parameter exists + if (newParameters.FindParameter(parameter) != null) + { + // Remove the parameters with listed keyword + List betterParametersBecauseItsAListInstead = + newParameters.parameters.ToList(); + foreach (VRCExpressionParameters.Parameter p in betterParametersBecauseItsAListInstead) + if (p.name.Contains(parameter)) + betterParametersBecauseItsAListInstead.Remove(p); + newParameters.parameters = betterParametersBecauseItsAListInstead.ToArray(); + } + return true; + } + public static AnimatorControllerParameter CheckAndCreateParameter(string paramName, AnimatorController animatorController, int type, double defaultVal = 0) { AnimatorControllerParameter param = new AnimatorControllerParameter(); From 47105b2ad9339423b392d9a5551909b5db87fca0 Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Wed, 8 Feb 2023 20:04:51 -0600 Subject: [PATCH 2/2] Remove symbols Remove symbols being used in naming of blend tree assets, layers and animations to make Unified Expressions work. Using "/" character for the names will break animation naming mapping. --- .../Editor/BinaryParameterFloatDriver.cs | 29 ++++++++++--- .../Editor/BinaryParameterScript.cs | 43 +++++++++++++------ 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterFloatDriver.cs b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterFloatDriver.cs index 2bc72a6..730d541 100644 --- a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterFloatDriver.cs +++ b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterFloatDriver.cs @@ -22,11 +22,11 @@ public static AnimationClip CreateFloatDriverAnimation(string baseParamName, flo Directory.CreateDirectory("Assets/VRCFaceTracking/Generated/Anims/"); } - string[] guid = (AssetDatabase.FindAssets(baseParamName + parameterValue + "Float")); + string[] guid = (AssetDatabase.FindAssets(NameNoSymbol(baseParamName) + parameterValue + "Float")); if (guid.Length == 0) { - AssetDatabase.CreateAsset(_animationClip, "Assets/VRCFaceTracking/Generated/Anims/" + baseParamName + parameterValue + "Float.anim"); + AssetDatabase.CreateAsset(_animationClip, "Assets/VRCFaceTracking/Generated/Anims/" + NameNoSymbol(baseParamName) + parameterValue + "Float.anim"); AssetDatabase.SaveAssets(); } @@ -51,11 +51,11 @@ public static AnimationClip CreateFloatDriverAnimation(string baseParamName, str Directory.CreateDirectory("Assets/VRCFaceTracking/Generated/Anims/"); } - string[] guid = (AssetDatabase.FindAssets(animName)); + string[] guid = (AssetDatabase.FindAssets(NameNoSymbol(animName))); if (guid.Length == 0) { - AssetDatabase.CreateAsset(_animationClip, "Assets/VRCFaceTracking/Generated/Anims/" + animName + ".anim"); + AssetDatabase.CreateAsset(_animationClip, "Assets/VRCFaceTracking/Generated/Anims/" + NameNoSymbol(animName) + ".anim"); AssetDatabase.SaveAssets(); } @@ -83,11 +83,11 @@ public static AnimationClip[] CreateFloatSmootherAnimation(string baseParamName, Directory.CreateDirectory("Assets/VRCFaceTracking/Generated/Anims/"); } - string[] guid = (AssetDatabase.FindAssets(baseParamName + initThreshold + "Smoother.anim")); + string[] guid = (AssetDatabase.FindAssets(NameNoSymbol(baseParamName) + initThreshold + "Smoother.anim")); if (guid.Length == 0) { - AssetDatabase.CreateAsset(_animationClip1, "Assets/VRCFaceTracking/Generated/Anims/"+ baseParamName + initThreshold + "Smoother.anim"); + AssetDatabase.CreateAsset(_animationClip1, "Assets/VRCFaceTracking/Generated/Anims/" + NameNoSymbol(baseParamName) + initThreshold + "Smoother.anim"); AssetDatabase.SaveAssets(); } @@ -100,7 +100,7 @@ public static AnimationClip[] CreateFloatSmootherAnimation(string baseParamName, if (guid.Length == 0) { - AssetDatabase.CreateAsset(_animationClip2, "Assets/VRCFaceTracking/Generated/Anims/" + baseParamName + finalThreshold + "Smoother.anim"); + AssetDatabase.CreateAsset(_animationClip2, "Assets/VRCFaceTracking/Generated/Anims/" + NameNoSymbol(baseParamName) + finalThreshold + "Smoother.anim"); AssetDatabase.SaveAssets(); } @@ -111,5 +111,20 @@ public static AnimationClip[] CreateFloatSmootherAnimation(string baseParamName, return new AnimationClip[] { _animationClip1, _animationClip2 }; } + + public static string NameNoSymbol(string name) + { + string nameNoSym = ""; + + for (int j = 0; j < name.Length; j++) + { + if (name[j] != '/') + { + nameNoSym += name[j]; + } + + } + return nameNoSym; + } } } diff --git a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterScript.cs b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterScript.cs index 0b993f6..1152108 100644 --- a/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterScript.cs +++ b/Assets/VRCFaceTracking/Tools/Binary Parameter Tool/Editor/BinaryParameterScript.cs @@ -60,7 +60,7 @@ public void CreateBinaryLayer() // Clear out existing ...Binary layers to make-way for an updated one for (int i = 0; i < animatorController.layers.Length; i++) - if (animatorController.layers[i].name == baseParamName + " Binary") + if (animatorController.layers[i].name == NameNoSymbol(baseParamName) + " Binary") { animatorController.RemoveLayer(i); } @@ -68,7 +68,7 @@ public void CreateBinaryLayer() // Creating a layer object since the default weight can not be assigned after creation. AnimatorControllerLayer layer = new AnimatorControllerLayer { - name = baseParamName + " Binary", + name = NameNoSymbol(baseParamName) + " Binary", stateMachine = new AnimatorStateMachine { hideFlags = HideFlags.HideInHierarchy @@ -108,7 +108,7 @@ public void CreateCombinedBinaryLayer() // Clear out existing ...Binary layers to make-way for an updated one for (int i = 0; i < animatorController.layers.Length; i++) - if (animatorController.layers[i].name == baseParamName + " Binary") + if (animatorController.layers[i].name == NameNoSymbol(baseParamName) + " Binary") { animatorController.RemoveLayer(i); } @@ -116,7 +116,7 @@ public void CreateCombinedBinaryLayer() // Creating a layer object since the default weight can not be assigned after creation. AnimatorControllerLayer layer = new AnimatorControllerLayer { - name = baseParamName + " Binary", + name = NameNoSymbol(baseParamName) + " Binary", stateMachine = new AnimatorStateMachine { hideFlags = HideFlags.HideInHierarchy @@ -187,7 +187,7 @@ private static void CreateCombinedUniformBinaryStatesInMachine(string name, int AnimatorState[] states = new AnimatorState[binarySteps]; - stateMachine.name = name + " Binary State Machine"; + stateMachine.name = NameNoSymbol(name) + " Binary State Machine"; stateMachine.anyStatePosition = new Vector3(20, 0, 0); stateMachine.entryPosition = new Vector3 ( @@ -228,7 +228,7 @@ private static void CreateCombinedUniformBinaryStatesInMachine(string name, int // Creating all the binary states and transitions for (int i = 1; i < binarySteps; i++) { - states[i] = stateMachine.AddState(name + i * negativeCount, new Vector3 + states[i] = stateMachine.AddState(NameNoSymbol(name) + i * negativeCount, new Vector3 ( stateMachine.anyStatePosition.x - 20 - Mathf.Sin(((float)i / binarySteps) * Mathf.PI * (-1) * negativeCount) * (200 + binarySteps * 8), stateMachine.anyStatePosition.y - 5 - Mathf.Cos(((float)i / binarySteps) * Mathf.PI) * (100 + binarySteps * 4), @@ -263,7 +263,7 @@ private static void CreateCombinedUniformBinaryStatesInMachine(string name, int blendType = BlendTreeType.Simple1D, hideFlags = HideFlags.HideInHierarchy, blendParameter = "BinaryBlend", - name = name + (i * negativeCount), + name = NameNoSymbol(name) + (i * negativeCount), useAutomaticThresholds = false }; @@ -308,7 +308,7 @@ private static void CreateUniformBinaryStatesInMachine(string name, int binarySi for (int i = 0; i < binarySteps; i++) { - stateMachine.name = name + " Binary State Machine"; + stateMachine.name = NameNoSymbol(name) + " Binary State Machine"; stateMachine.anyStatePosition = new Vector3(20, 0, 0); stateMachine.entryPosition = new Vector3 ( @@ -318,7 +318,7 @@ private static void CreateUniformBinaryStatesInMachine(string name, int binarySi ); - states[i] = stateMachine.AddState(name + i, new Vector3 + states[i] = stateMachine.AddState(NameNoSymbol(name) + i, new Vector3 ( stateMachine.anyStatePosition.x - 20 - Mathf.Sin((i / (float)binarySteps) * Mathf.PI * 2f) * (200 + binarySteps * 8), stateMachine.anyStatePosition.y - 5 - Mathf.Cos((i / (float)binarySteps) * Mathf.PI * 2f) * (100 + binarySteps * 4), @@ -349,7 +349,7 @@ private static void CreateUniformBinaryStatesInMachine(string name, int binarySi blendType = BlendTreeType.Simple1D, hideFlags = HideFlags.HideInHierarchy, blendParameter = "BinaryBlend", - name = name + i, + name = NameNoSymbol(name) + i, useAutomaticThresholds = false, }; @@ -381,7 +381,7 @@ private static void CreateBranchingBinaryStatesInMachine(string name, int binary int minSteps = (int)((min + .05) * binarySteps); int maxSteps = (int)((max - .05) * binarySteps); - stateMachine.name = name + " Binary State Machine"; + stateMachine.name = NameNoSymbol(name) + " Binary State Machine"; stateMachine.entryPosition = new Vector3(0, 20, 0); stateMachine.anyStatePosition = new Vector3 ( @@ -418,7 +418,7 @@ private static void CreateBranchingBinaryStatesInMachine(string name, int binary blendType = BlendTreeType.Simple1D, hideFlags = HideFlags.HideInHierarchy, blendParameter = "BinaryBlend", - name = name + i, + name = NameNoSymbol(name) + i, useAutomaticThresholds = false, }; @@ -500,7 +500,7 @@ public void CreateSmoothingLayer(float smoothness) // Clear out existing ...Binary layers to make-way for an updated one for (int i = 0; i < animatorController.layers.Length; i++) - if (animatorController.layers[i].name == baseParamName + " Float Smoother") + if (animatorController.layers[i].name == NameNoSymbol(baseParamName) + " Float Smoother") { animatorController.RemoveLayer(i); } @@ -508,7 +508,7 @@ public void CreateSmoothingLayer(float smoothness) // Creates an animation layer AnimatorControllerLayer layer = new AnimatorControllerLayer { - name = baseParamName + " Float Smoother", + name = NameNoSymbol(baseParamName) + " Float Smoother", stateMachine = new AnimatorStateMachine { hideFlags = HideFlags.HideInHierarchy @@ -572,5 +572,20 @@ public void CreateSmoothingLayer(float smoothness) state.motion = rootTree; } + public static string NameNoSymbol(string name) + { + string nameNoSym = ""; + + for (int j = 0; j < name.Length; j++) + { + if (name[j] != '/') + { + nameNoSym += name[j]; + } + + } + return nameNoSym; + } + } }