From cda24777c551e013a66a62aa2364c222b5634d16 Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Sun, 19 Mar 2023 17:51:05 -0500 Subject: [PATCH 01/17] Add Binary Creation UI --- .gitignore | 2 + .vsconfig | 6 +++ Assets/OSCmooth/Editor/OSCmoothFilters.cs | 2 +- Assets/OSCmooth/Editor/OSCmoothType.cs | 9 ++++- Assets/OSCmooth/Editor/OSCmoothWindow.cs | 48 +++++++++++++++++++++-- 5 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 .vsconfig diff --git a/.gitignore b/.gitignore index bd07a94..fc9ac58 100644 --- a/.gitignore +++ b/.gitignore @@ -396,3 +396,5 @@ VRC.Enums* /Assets /Assembly-CSharp.csproj /Assembly-CSharp-Editor.csproj +/Packages +*.csproj \ No newline at end of file diff --git a/.vsconfig b/.vsconfig new file mode 100644 index 0000000..d70cd98 --- /dev/null +++ b/.vsconfig @@ -0,0 +1,6 @@ +{ + "version": "1.0", + "components": [ + "Microsoft.VisualStudio.Workload.ManagedGame" + ] +} diff --git a/Assets/OSCmooth/Editor/OSCmoothFilters.cs b/Assets/OSCmooth/Editor/OSCmoothFilters.cs index 5c3500f..240f5fb 100644 --- a/Assets/OSCmooth/Editor/OSCmoothFilters.cs +++ b/Assets/OSCmooth/Editor/OSCmoothFilters.cs @@ -10,7 +10,7 @@ public static class OSCmoothFilters { public static readonly string[] BlackList = { - "OSCm/", "IsLocal", "Smooth", "Proxy", "Proxy/", "_Float", "_Normalizer", "_FTI", "OSCm_BlendSet", "BlendSet", "Blend" + "OSCm/", "IsLocal", "Smooth", "Proxy", "Proxy/", "_Float", "_Normalizer", "_FTI", "OSCm_BlendSet", "BlendSet", "Blend", "Binary" }; public static readonly string[] AllLayerNames = { diff --git a/Assets/OSCmooth/Editor/OSCmoothType.cs b/Assets/OSCmooth/Editor/OSCmoothType.cs index 474eb56..78bd1bb 100644 --- a/Assets/OSCmooth/Editor/OSCmoothType.cs +++ b/Assets/OSCmooth/Editor/OSCmoothType.cs @@ -23,6 +23,11 @@ public class OSCmoothParameter // WARNING. Please be considerate with this setting. public bool convertToProxy = true; + // Resolution of parameters for binaries and disable binary + public int binarySizeSelection = 3; + // Combined parameter for positive and negative + public bool combinedParameter = false; + // for Editor window visibility public bool isVisible; @@ -31,13 +36,15 @@ public OSCmoothParameter(string paramName) { this.paramName = paramName; } - public OSCmoothParameter(string paramName, float localSmoothness, float remoteSmoothness, bool convertToProxy, bool flipInputOutput) + public OSCmoothParameter(string paramName, float localSmoothness, float remoteSmoothness, bool convertToProxy, bool flipInputOutput, int binarySizeSelection, bool combinedParameter) { this.paramName = paramName; this.localSmoothness = localSmoothness; this.remoteSmoothness = remoteSmoothness; this.convertToProxy = convertToProxy; this.flipInputOutput = flipInputOutput; + this.binarySizeSelection = binarySizeSelection; + this.combinedParameter = combinedParameter; } } diff --git a/Assets/OSCmooth/Editor/OSCmoothWindow.cs b/Assets/OSCmooth/Editor/OSCmoothWindow.cs index ea291f0..6dcd070 100644 --- a/Assets/OSCmooth/Editor/OSCmoothWindow.cs +++ b/Assets/OSCmooth/Editor/OSCmoothWindow.cs @@ -22,9 +22,14 @@ public class OSCmoothWindow : EditorWindow private bool _showParameters = true; private bool _showGlobalConfiguration = false; - private bool _writeDefaults = false; + private bool _writeDefaults = true; private Vector2 paramMenuScroll; + readonly public string[] binarySizeOptions = new string[] + { + "OFF","2","4","8","16","32" + }; + //readonly private string[] _humanoidLayers = { "Base", "Additive", "Gesture", "Action", "FX" }; [MenuItem("Tools/OSCmooth")] @@ -163,7 +168,9 @@ void DrawGUI() localSmoothness = _basisConfigurationParameter.localSmoothness, remoteSmoothness = _basisConfigurationParameter.remoteSmoothness, flipInputOutput = _basisConfigurationParameter.flipInputOutput, - convertToProxy = _basisConfigurationParameter.convertToProxy + convertToProxy = _basisConfigurationParameter.convertToProxy, + binarySizeSelection = _basisConfigurationParameter.binarySizeSelection, + combinedParameter = _basisConfigurationParameter.combinedParameter }); } } @@ -254,7 +261,9 @@ void DrawGUI() localSmoothness = _basisConfigurationParameter.localSmoothness, remoteSmoothness = _basisConfigurationParameter.remoteSmoothness, flipInputOutput = _basisConfigurationParameter.flipInputOutput, - convertToProxy = _basisConfigurationParameter.convertToProxy + convertToProxy = _basisConfigurationParameter.convertToProxy, + binarySizeSelection = _basisConfigurationParameter.binarySizeSelection, + combinedParameter = _basisConfigurationParameter.combinedParameter }; _parameterAsset.parameters.Add(param); @@ -343,6 +352,8 @@ public void DrawParameterConfiguration(OSCmoothParameter parameter, bool removab float remoteSmoothness = parameter.remoteSmoothness; bool convertToProxy = parameter.convertToProxy; bool flipIO = parameter.flipInputOutput; + int binarySizeSelection = parameter.binarySizeSelection; + bool combinedParameter = parameter.combinedParameter; EditorGUI.BeginChangeCheck(); { @@ -389,6 +400,35 @@ public void DrawParameterConfiguration(OSCmoothParameter parameter, bool removab ), flipIO ); + + binarySizeSelection = EditorGUILayout.Popup + ( + new GUIContent + ( + "Binary Resolution", + "How many steps a Binary Parameter can make. Higher values are more accurate, " + + "while lower values are more economic for parameter space. Recommended to use a " + + "Resolution of 16 or less for more space savings." + ), + binarySizeSelection, + binarySizeOptions + ); + + + combinedParameter = EditorGUILayout.Toggle + ( + new GUIContent + ( + "Combined Parameter", + "Does this parameter go from positive to negative? " + + "This option will add an extra bool to keep track of the " + + "positive/negative of the parameter." + ), + combinedParameter + ); + + + } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_parameterAsset, "Change Parameter Values"); @@ -396,6 +436,8 @@ public void DrawParameterConfiguration(OSCmoothParameter parameter, bool removab parameter.remoteSmoothness = remoteSmoothness; parameter.convertToProxy = convertToProxy; parameter.flipInputOutput = flipIO; + parameter.binarySizeSelection = binarySizeSelection; + parameter.combinedParameter = combinedParameter; } EditorGUILayout.BeginHorizontal(); From b38d3fa58f71c807e5d231c60446f25a9a1b6645 Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Sun, 19 Mar 2023 17:56:28 -0500 Subject: [PATCH 02/17] Hide save config as it is not functional at this time --- Assets/OSCmooth/Editor/OSCmoothWindow.cs | 85 ++++++++++++------------ 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothWindow.cs b/Assets/OSCmooth/Editor/OSCmoothWindow.cs index 6dcd070..03b10e7 100644 --- a/Assets/OSCmooth/Editor/OSCmoothWindow.cs +++ b/Assets/OSCmooth/Editor/OSCmoothWindow.cs @@ -46,6 +46,7 @@ private void OnGUI() { DrawGUI(); } + void DrawGUI() { _avDescriptor = (VRCAvatarDescriptor)EditorGUILayout.ObjectField @@ -85,48 +86,48 @@ void DrawGUI() layers.ToArray() ); - EditorGUILayout.Space(10f); - - _parameterAsset = (OSCmoothLayer)EditorGUILayout.ObjectField - ( - new GUIContent - ( - "Config", - "A preset configuration that stores Parameter Configuration data. " + - "This is intended for saving configurations for use later or sharing." - ), - _parameterAsset, - typeof(OSCmoothLayer), - false - ); - - if (_parameterAsset == null) - _parameterAsset = ScriptableObject.CreateInstance(); - - if (_basisConfigurationParameter == null) - _basisConfigurationParameter = new OSCmoothParameter(); - - EditorGUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - - if (GUILayout.Button - ( - new GUIContent - ( - "Save Config", - "Saves Parameter configuration into a JSON readable text file." - ), - GUILayout.MaxWidth((float)Screen.width - 159f) - )) - { - if (AssetDatabase.GetAssetPath(_parameterAsset) == string.Empty) - AssetDatabase.CreateAsset(_parameterAsset, EditorUtility.SaveFilePanelInProject("Save OSCmooth Configuration", "OSCmoothConfig", "asset", "")); - - EditorUtility.SetDirty(_parameterAsset); - AssetDatabase.SaveAssets(); - } - - EditorGUILayout.EndHorizontal(); + //EditorGUILayout.Space(10f); + + //_parameterAsset = (OSCmoothLayer)EditorGUILayout.ObjectField + //( + // new GUIContent + // ( + // "Config", + // "A preset configuration that stores Parameter Configuration data. " + + // "This is intended for saving configurations for use later or sharing." + // ), + // _parameterAsset, + // typeof(OSCmoothLayer), + // false + //); + + //if (_parameterAsset == null) + // _parameterAsset = ScriptableObject.CreateInstance(); + + //if (_basisConfigurationParameter == null) + // _basisConfigurationParameter = new OSCmoothParameter(); + + //EditorGUILayout.BeginHorizontal(); + //GUILayout.FlexibleSpace(); + + //if (GUILayout.Button + //( + // new GUIContent + // ( + // "Save Config", + // "Saves Parameter configuration into a JSON readable text file." + // ), + // GUILayout.MaxWidth((float)Screen.width - 159f) + //)) + //{ + // if (AssetDatabase.GetAssetPath(_parameterAsset) == string.Empty) + // AssetDatabase.CreateAsset(_parameterAsset, EditorUtility.SaveFilePanelInProject("Save OSCmooth Configuration", "OSCmoothConfig", "asset", "")); + + // EditorUtility.SetDirty(_parameterAsset); + // AssetDatabase.SaveAssets(); + //} + + //EditorGUILayout.EndHorizontal(); _writeDefaults = EditorGUILayout.Toggle ( From d55f06b0dee90f07fbff1e8bb417ba355342a7fc Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Tue, 21 Mar 2023 18:01:03 -0500 Subject: [PATCH 03/17] Remove WD OFF option; Add BinaryLayerGenerator Removed the write defaults off option as blend trees machines can remain write default on while other layers are on. Problem with leaving write default off is you have to normalize all the animations which is messy and you cannot touch anything in the blend trees without breaking everything. Added binary layer generator that is 20% performance gain to traditional binary parameter layers, stuffing into direct blend tree organizes everything into one layer, the binary layer uses type casting of bool parameters to floats. --- .../Editor/OSCmoothAnimationHandler.cs | 113 +++++++++----- Assets/OSCmooth/Editor/OSCmoothFilters.cs | 2 +- Assets/OSCmooth/Editor/OSCmoothType.cs | 2 +- Assets/OSCmooth/Editor/OSCmoothUtil.cs | 138 +++++++++++++++++- Assets/OSCmooth/Editor/OSCmoothWindow.cs | 33 ++--- 5 files changed, 222 insertions(+), 66 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs index 9b05f65..088da60 100644 --- a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs +++ b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs @@ -15,6 +15,7 @@ public static class OSCmoothAnimationHandler public static List _parameters; public static bool _writeDefaults; public static string _animExportDirectory; + public static string _binaryExportDirectory; public static void RemoveAllOSCmoothFromController() { @@ -22,6 +23,74 @@ public static void RemoveAllOSCmoothFromController() AnimUtil.RemoveExtendedParametersInController("OSCm", _animatorController); AnimUtil.RemoveContainingLayersInController("OSCm", _animatorController); } + + public static void RemoveAllBinaryFromController() + { + AnimUtil.RevertStateMachineParameters(_animatorController); + AnimUtil.RemoveExtendedParametersInController("Binary", _animatorController); + AnimUtil.RemoveContainingLayersInController("Binary", _animatorController); + } + + public static void CreateBinaryLayer() + { + // Cleannup Animator before apply Binaries + OSCmoothAnimationHandler.RemoveAllBinaryFromController(); + + // Creating new Binary setup. + AnimatorControllerLayer animLayer; + + animLayer = AnimUtil.CreateAnimLayerInController("_Binary_Parameters_Gen", _animatorController); + + // Creating a Direct BlendTree that will hold all of the binary decode driver animations. This is to effectively create a 'sublayer' + // system within the Direct BlendTree to tidy up the animator base layers from bloating up visually. + AnimatorState[] state = new AnimatorState[1]; + + + state[0] = animLayer.stateMachine.AddState("Binary_Parameters_Blendtree", new Vector3(30, 170, 0)); + state[0].writeDefaultValues = true; + + // Creating BlendTree objects to better customize them in the AC Editor + + var binaryTreeRoot = new BlendTree() + { + blendType = BlendTreeType.Direct, + hideFlags = HideFlags.HideInHierarchy, + name = "Binary_Root", + useAutomaticThresholds = false + + }; + + // Stuffing the BlendTrees into their designated state. Also stuffing them so that they + // retain serialization. + state[0].motion = binaryTreeRoot; + AssetDatabase.AddObjectToAsset(binaryTreeRoot, AssetDatabase.GetAssetPath(animLayer.stateMachine)); + + // Creating a '1Set' parameter that holds a value of one at all times for the Direct BlendTree + + ParameterUtil.CheckAndCreateParameter("OSCm/BlendSet", _animatorController, AnimatorControllerParameterType.Float, 1f); + + + List childBinary = new List(); + + // Go through each parameter and create each child to eventually stuff into the Direct BlendTrees. + foreach (OSCmoothParameter p in _parameters) + { + + var decodeBinary = AnimUtil.CreateBinaryBlendTree(_animatorController, animLayer.stateMachine, p.paramName, _binaryExportDirectory, p.binarySizeSelection); + + + childBinary.Add(new ChildMotion + { + directBlendParameter = "OSCm/BlendSet", + motion = decodeBinary, + timeScale = 1 + }); + + } + + binaryTreeRoot.children = childBinary.ToArray(); + } + public static void CreateSmoothAnimationLayer() { // Cleanup Animator before applying OSCmooth: @@ -30,28 +99,18 @@ public static void CreateSmoothAnimationLayer() // Creating new OSCmooth setup. AnimatorControllerLayer animLayer; - if (_writeDefaults) - animLayer = AnimUtil.CreateAnimLayerInController("_OSCmooth_Smoothing_WD_Gen", _animatorController); - else animLayer = AnimUtil.CreateAnimLayerInController("_OSCmooth_Smoothing_Gen", _animatorController); + animLayer = AnimUtil.CreateAnimLayerInController("_OSCmooth_Smoothing_Gen", _animatorController); // Creating a Direct BlendTree that will hold all of the smooth driver animations. This is to effectively create a 'sublayer' // system within the Direct BlendTree to tidy up the animator base layers from bloating up visually. AnimatorState[] state = new AnimatorState[2]; - if (_writeDefaults) - { - state[0] = animLayer.stateMachine.AddState("OSCmooth_Local_WD", new Vector3(30, 170, 0)); - state[1] = animLayer.stateMachine.AddState("OSCmooth_Net_WD", new Vector3(30, 170 + 60, 0)); - } - else - { - state[0] = animLayer.stateMachine.AddState("OSCmooth_Local", new Vector3(30, 170, 0)); - state[1] = animLayer.stateMachine.AddState("OSCmooth_Net", new Vector3(30, 170 + 60, 0)); - } + state[0] = animLayer.stateMachine.AddState("OSCmooth_Local", new Vector3(30, 170, 0)); + state[1] = animLayer.stateMachine.AddState("OSCmooth_Net", new Vector3(30, 170 + 60, 0)); - state[0].writeDefaultValues = _writeDefaults; - state[1].writeDefaultValues = _writeDefaults; + state[0].writeDefaultValues = true; + state[1].writeDefaultValues = true; var toRemoteState = state[0].AddTransition(state[1]); toRemoteState.duration = 0; @@ -68,12 +127,6 @@ public static void CreateSmoothAnimationLayer() var nameLocalWD = "OSCm_Local"; var nameRemoteWD = "OSCm_Remote"; - if (_writeDefaults) - { - nameLocalWD = "OSCm_Local_WD"; - nameRemoteWD = "OSCm_Remote_WD"; - } - var basisLocalBlendTree = new BlendTree() { blendType = BlendTreeType.Direct, @@ -101,14 +154,7 @@ public static void CreateSmoothAnimationLayer() // Creating a '1Set' parameter that holds a value of one at all times for the Direct BlendTree - if (_writeDefaults) - { - ParameterUtil.CheckAndCreateParameter("OSCm/BlendSet", _animatorController, AnimatorControllerParameterType.Float, 1f); - } - else - { - ParameterUtil.CheckAndCreateParameter("OSCm/BlendSet", _animatorController, AnimatorControllerParameterType.Float, 1f / (float)_parameters.Count); - } + ParameterUtil.CheckAndCreateParameter("OSCm/BlendSet", _animatorController, AnimatorControllerParameterType.Float, 1f); List localChildMotion = new List(); @@ -122,13 +168,8 @@ public static void CreateSmoothAnimationLayer() AnimUtil.RenameAllStateMachineInstancesOfBlendParameter(_animatorController, p.paramName, "OSCm/Proxy/" + p.paramName); } - var motionLocal = AnimUtil.CreateSmoothingBlendTree(_animatorController, animLayer.stateMachine, p.localSmoothness, p.paramName, p.flipInputOutput, (float)_parameters.Count, _animExportDirectory, "OSCm/Local/", "Smoother", "OSCm/Proxy/", "Proxy"); - var motionRemote = AnimUtil.CreateSmoothingBlendTree(_animatorController, animLayer.stateMachine, p.remoteSmoothness, p.paramName, p.flipInputOutput, (float)_parameters.Count, _animExportDirectory, "OSCm/Remote/", "SmootherRemote", "OSCm/Proxy/", "Proxy"); - if (_writeDefaults) - { - motionLocal = AnimUtil.CreateSmoothingBlendTree(_animatorController, animLayer.stateMachine, p.localSmoothness, p.paramName, p.flipInputOutput, 1f, _animExportDirectory, "OSCm/Local/", "SmootherWD", "OSCm/Proxy/", "Proxy"); - motionRemote = AnimUtil.CreateSmoothingBlendTree(_animatorController, animLayer.stateMachine, p.remoteSmoothness, p.paramName, p.flipInputOutput, 1f, _animExportDirectory, "OSCm/Remote/", "SmootherRemoteWD", "OSCm/Proxy/", "Proxy"); - } + var motionLocal = AnimUtil.CreateSmoothingBlendTree(_animatorController, animLayer.stateMachine, p.localSmoothness, p.paramName, p.flipInputOutput, 1f, _animExportDirectory, "OSCm/Local/", "SmootherWD", "OSCm/Proxy/", "Proxy"); + var motionRemote = AnimUtil.CreateSmoothingBlendTree(_animatorController, animLayer.stateMachine, p.remoteSmoothness, p.paramName, p.flipInputOutput, 1f, _animExportDirectory, "OSCm/Remote/", "SmootherRemoteWD", "OSCm/Proxy/", "Proxy"); localChildMotion.Add(new ChildMotion { diff --git a/Assets/OSCmooth/Editor/OSCmoothFilters.cs b/Assets/OSCmooth/Editor/OSCmoothFilters.cs index 240f5fb..b6fd124 100644 --- a/Assets/OSCmooth/Editor/OSCmoothFilters.cs +++ b/Assets/OSCmooth/Editor/OSCmoothFilters.cs @@ -10,7 +10,7 @@ public static class OSCmoothFilters { public static readonly string[] BlackList = { - "OSCm/", "IsLocal", "Smooth", "Proxy", "Proxy/", "_Float", "_Normalizer", "_FTI", "OSCm_BlendSet", "BlendSet", "Blend", "Binary" + "OSCm/", "IsLocal", "Smooth", "Proxy", "Proxy/", "_Float", "_Normalizer", "_FTI", "OSCm_BlendSet", "BlendSet", "Blend", "Binary/" }; public static readonly string[] AllLayerNames = { diff --git a/Assets/OSCmooth/Editor/OSCmoothType.cs b/Assets/OSCmooth/Editor/OSCmoothType.cs index 78bd1bb..6a4e1cb 100644 --- a/Assets/OSCmooth/Editor/OSCmoothType.cs +++ b/Assets/OSCmooth/Editor/OSCmoothType.cs @@ -24,7 +24,7 @@ public class OSCmoothParameter public bool convertToProxy = true; // Resolution of parameters for binaries and disable binary - public int binarySizeSelection = 3; + public int binarySizeSelection = 0; // Combined parameter for positive and negative public bool combinedParameter = false; diff --git a/Assets/OSCmooth/Editor/OSCmoothUtil.cs b/Assets/OSCmooth/Editor/OSCmoothUtil.cs index 2038244..d83f780 100644 --- a/Assets/OSCmooth/Editor/OSCmoothUtil.cs +++ b/Assets/OSCmooth/Editor/OSCmoothUtil.cs @@ -28,7 +28,7 @@ public static string NameNoSymbol(string name) public static void CleanAnimatorBlendTreeBloat(AnimatorController animatorController, string filter) { - Object[] animatorAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(animatorController)); + Object[] animatorAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(animatorController)); foreach (Object asset in animatorAssets) { @@ -41,6 +41,7 @@ public static void CleanAnimatorBlendTreeBloat(AnimatorController animatorContro } } } + public static void RenameAllStateMachineInstancesOfBlendParameter(AnimatorController animatorController, string initParameter, string newParameter) { Object[] animatorAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(animatorController)); @@ -49,7 +50,7 @@ public static void RenameAllStateMachineInstancesOfBlendParameter(AnimatorContro { if (asset?.GetType() == typeof(BlendTree)) { - if(((BlendTree)asset).blendParameter == initParameter) + if (((BlendTree)asset).blendParameter == initParameter) ((BlendTree)asset).blendParameter = newParameter; if (((BlendTree)asset).blendParameterY == initParameter) @@ -131,7 +132,7 @@ public static void RevertStateMachineParameters(AnimatorController animatorContr foreach (var oscmParam in OSCmoothFilters.ParameterExtensions) { - foreach (var stateParam in stateParams) + foreach (var stateParam in stateParams) { if (stateParam.Contains(oscmParam)) { @@ -151,7 +152,7 @@ public static void RemoveExtendedParametersInController(string name, AnimatorCon continue; } i++; - } + } } public static void RemoveContainingLayersInController(string name, AnimatorController animatorController) @@ -188,7 +189,7 @@ public static AnimatorControllerLayer CreateAnimLayerInController(string layerNa defaultWeight = 1f }; - CleanAnimatorBlendTreeBloat(animatorController, "OSCm_"); + CleanAnimatorBlendTreeBloat(animatorController, "OSCm_"); // Store Layer into Animator Controller, as creating a Layer object is not serialized unless we store it inside an asset. if (AssetDatabase.GetAssetPath(animatorController) != string.Empty) @@ -215,7 +216,7 @@ public static AnimationClip[] CreateFloatSmootherAnimation(AnimatorController an long id; AssetDatabase.TryGetGUIDAndLocalFileIdentifier(animatorController, out animatorGUID, out id); - + AnimationClip _animationClipInit = new AnimationClip(); AnimationClip _animationClipFinal = new AnimationClip(); @@ -261,7 +262,7 @@ public static AnimationClip[] CreateFloatSmootherAnimation(AnimatorController an AssetDatabase.SaveAssets(); } - return new AnimationClip[]{ _animationClipInit, _animationClipFinal }; + return new AnimationClip[] { _animationClipInit, _animationClipFinal }; } private static void SaveAnimationAsset(ref AnimationClip clip, string name, string directory) @@ -302,7 +303,7 @@ public static BlendTree CreateSmoothingBlendTree(AnimatorController animatorCont { blendType = BlendTreeType.Simple1D, hideFlags = HideFlags.HideInHierarchy, - blendParameter = driveBase ? paramName: proxyPrefix + paramName, + blendParameter = driveBase ? paramName : proxyPrefix + paramName, name = "OSCm_Driver", useAutomaticThresholds = false }; @@ -327,5 +328,126 @@ public static BlendTree CreateSmoothingBlendTree(AnimatorController animatorCont return rootTree; } + + public static BlendTree CreateBinaryBlendTree(AnimatorController animatorController, AnimatorStateMachine stateMachine, string paramName, string directory, int binarySizeSelection) + { + + //Create Direct Blendtree Root to for each binary parameter + BlendTree decodeBinaryRoot = new BlendTree + { + blendType = BlendTreeType.Direct, + hideFlags = HideFlags.HideInHierarchy, + name = "Binary_" + paramName + "_Root", + useAutomaticThresholds = false + }; + + List childBinaryPositiveDecode = new List(); + + // Go through binary steps and create each child to eventually stuff into the Direct BlendTrees. + for (int i = 0; i < binarySizeSelection; i++) + { + // Create each binary step decode layer. This using type casting of bools to float. Parameters will be bools but will be floats in the animator. + // This is way to take typically transition type binaries and stuff them inside direct blendtree to reduce the visual overhead with using binaries in layers. + // There is 20% performance gain by stuffing into direct blend trees. + var decodeBinary = CreateBinaryDecode(animatorController, stateMachine, paramName, directory, i, binarySizeSelection); + + childBinaryPositiveDecode.Add(new ChildMotion + { + directBlendParameter = "OSCm/BlendSet", + motion = decodeBinary, + timeScale = 1 + }); + + } + + decodeBinaryRoot.children = childBinaryPositiveDecode.ToArray(); + + AssetDatabase.AddObjectToAsset(decodeBinaryRoot, AssetDatabase.GetAssetPath(animatorController)); + + AssetDatabase.SaveAssets(); + + return decodeBinaryRoot; + } + + public static AnimationClip[] CreateBinaryAnimation(AnimatorController animatorController, string paramName, string directory, float weight = 1) + { + string animatorGUID; + long id; + + AssetDatabase.TryGetGUIDAndLocalFileIdentifier(animatorController, out animatorGUID, out id); + + AnimationClip _animationClipInit = new AnimationClip(); + AnimationClip _animationClipFinal = new AnimationClip(); + + AnimationCurve _curvesInit = new AnimationCurve(new Keyframe(0.0f, 0.0f)); + AnimationCurve _curvesFinal = new AnimationCurve(new Keyframe(0.0f, weight)); + + _animationClipInit.SetCurve("", typeof(Animator), paramName, _curvesInit); + _animationClipFinal.SetCurve("", typeof(Animator), paramName, _curvesFinal); + + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + + string[] guid = (AssetDatabase.FindAssets(NameNoSymbol(paramName) + "False.anim")); + + if (guid.Length == 0) + { + AssetDatabase.CreateAsset(_animationClipInit, directory + NameNoSymbol(paramName) + "_False_" + animatorGUID + ".anim"); + AssetDatabase.SaveAssets(); + } + + else + { + AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(guid[0])); + AssetDatabase.CreateAsset(_animationClipInit, directory + NameNoSymbol(paramName) + "_False_" + animatorGUID + ".anim"); + AssetDatabase.SaveAssets(); + } + + guid = (AssetDatabase.FindAssets(NameNoSymbol(paramName) + "_True.anim")); + + if (guid.Length == 0) + { + AssetDatabase.CreateAsset(_animationClipFinal, directory + NameNoSymbol(paramName) + "_True_" + animatorGUID + ".anim"); + AssetDatabase.SaveAssets(); + } + + else + { + + AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(guid[0])); + AssetDatabase.CreateAsset(_animationClipFinal, "Assets/Binary/Generated/Binary/" + NameNoSymbol(paramName) + "_True_" + animatorGUID + ".anim"); + AssetDatabase.SaveAssets(); + } + + return new AnimationClip[] { _animationClipInit, _animationClipFinal }; + } + + public static BlendTree CreateBinaryDecode(AnimatorController animatorController, AnimatorStateMachine stateMachine, string paramName, string directory, int binaryPow, int binarySize) + { + + ParameterUtil.CheckAndCreateParameter(paramName + Mathf.Pow(2,binaryPow).ToString(), animatorController, AnimatorControllerParameterType.Float); + + BlendTree decodeBinary = new BlendTree + { + blendType = BlendTreeType.Simple1D, + hideFlags = HideFlags.HideInHierarchy, + blendParameter = paramName + Mathf.Pow(2, binaryPow).ToString(), + name = "Binary_" + paramName + "_Decode_" + Mathf.Pow(2, binaryPow).ToString(), + useAutomaticThresholds = false + }; + + // Create Decode anims and weight per binary + AnimationClip[] decodeAnims = AnimUtil.CreateBinaryAnimation(animatorController, paramName, directory, 0.5f * Mathf.Pow(2, binaryPow + 1) / (Mathf.Pow(2, binarySize) - 1f)); + decodeBinary.AddChild(decodeAnims[0], 0f); + decodeBinary.AddChild(decodeAnims[1], 1f); + + AssetDatabase.AddObjectToAsset(decodeBinary, AssetDatabase.GetAssetPath(animatorController)); + + return decodeBinary; + + } + } } \ No newline at end of file diff --git a/Assets/OSCmooth/Editor/OSCmoothWindow.cs b/Assets/OSCmooth/Editor/OSCmoothWindow.cs index 03b10e7..393683a 100644 --- a/Assets/OSCmooth/Editor/OSCmoothWindow.cs +++ b/Assets/OSCmooth/Editor/OSCmoothWindow.cs @@ -22,7 +22,6 @@ public class OSCmoothWindow : EditorWindow private bool _showParameters = true; private bool _showGlobalConfiguration = false; - private bool _writeDefaults = true; private Vector2 paramMenuScroll; readonly public string[] binarySizeOptions = new string[] @@ -101,11 +100,11 @@ void DrawGUI() // false //); - //if (_parameterAsset == null) - // _parameterAsset = ScriptableObject.CreateInstance(); + if (_parameterAsset == null) + _parameterAsset = ScriptableObject.CreateInstance(); - //if (_basisConfigurationParameter == null) - // _basisConfigurationParameter = new OSCmoothParameter(); + if (_basisConfigurationParameter == null) + _basisConfigurationParameter = new OSCmoothParameter(); //EditorGUILayout.BeginHorizontal(); //GUILayout.FlexibleSpace(); @@ -127,17 +126,6 @@ void DrawGUI() // AssetDatabase.SaveAssets(); //} - //EditorGUILayout.EndHorizontal(); - - _writeDefaults = EditorGUILayout.Toggle - ( - new GUIContent - ( - "Write Defaults", - "Sets whether the generated OSCmooth layer will have write defaults on or off. Set true for WD on, false for WD off" - ), - _writeDefaults - ); _animatorController = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(_avDescriptor.baseAnimationLayers[_layerSelect].animatorController)); @@ -293,10 +281,11 @@ void DrawGUI() OSCmoothAnimationHandler._animatorController = _animatorController; OSCmoothAnimationHandler._parameters = _parameterAsset.parameters; - OSCmoothAnimationHandler._writeDefaults = _writeDefaults; - OSCmoothAnimationHandler._animExportDirectory = "Assets/OSCmooth/Generated/Anims/" + "Animator_" + animatorGUID + "/"; + OSCmoothAnimationHandler._animExportDirectory = "Assets/OSCmooth/Generated/Smooth/" + "Animator_" + animatorGUID + "/"; + OSCmoothAnimationHandler._binaryExportDirectory = "Assets/OSCmooth/Generated/Binary/" + "Animator_" + animatorGUID + "/"; Undo.RecordObject(OSCmoothAnimationHandler._animatorController, "Apply OSCmooth to Layer"); + OSCmoothAnimationHandler.CreateBinaryLayer(); OSCmoothAnimationHandler.CreateSmoothAnimationLayer(); } @@ -321,10 +310,14 @@ void DrawGUI() OSCmoothAnimationHandler._parameters = _parameterAsset.parameters; Undo.RecordObject(OSCmoothAnimationHandler._animatorController, "Revert OSCmooth in Layer"); + OSCmoothAnimationHandler.RemoveAllBinaryFromController(); OSCmoothAnimationHandler.RemoveAllOSCmoothFromController(); - FileUtil.DeleteFileOrDirectory("Assets/OSCmooth/Generated/Anims/" + "Animator_" + animatorGUID); - FileUtil.DeleteFileOrDirectory("Assets/OSCmooth/Generated/Anims/" + "Animator_" + animatorGUID + ".meta"); + FileUtil.DeleteFileOrDirectory("Assets/OSCmooth/Generated/Smooth/" + "Animator_" + animatorGUID); + FileUtil.DeleteFileOrDirectory("Assets/OSCmooth/Generated/Smooth/" + "Animator_" + animatorGUID + ".meta"); + FileUtil.DeleteFileOrDirectory("Assets/OSCmooth/Generated/Binary/" + "Animator_" + animatorGUID); + FileUtil.DeleteFileOrDirectory("Assets/OSCmooth/Generated/Binary/" + "Animator_" + animatorGUID + ".meta"); + AssetDatabase.Refresh(); } From c9b9f2577125e286288140468f75d6ee56d1012d Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Tue, 21 Mar 2023 20:25:04 -0500 Subject: [PATCH 04/17] Add combined component to binary parameter generation --- .../Editor/OSCmoothAnimationHandler.cs | 2 +- Assets/OSCmooth/Editor/OSCmoothUtil.cs | 90 ++++++++++++++++--- 2 files changed, 77 insertions(+), 15 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs index 088da60..56f2f89 100644 --- a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs +++ b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs @@ -76,7 +76,7 @@ public static void CreateBinaryLayer() foreach (OSCmoothParameter p in _parameters) { - var decodeBinary = AnimUtil.CreateBinaryBlendTree(_animatorController, animLayer.stateMachine, p.paramName, _binaryExportDirectory, p.binarySizeSelection); + var decodeBinary = AnimUtil.CreateBinaryBlendTree(_animatorController, animLayer.stateMachine, p.paramName, _binaryExportDirectory, p.binarySizeSelection, p.combinedParameter); childBinary.Add(new ChildMotion diff --git a/Assets/OSCmooth/Editor/OSCmoothUtil.cs b/Assets/OSCmooth/Editor/OSCmoothUtil.cs index d83f780..0485972 100644 --- a/Assets/OSCmooth/Editor/OSCmoothUtil.cs +++ b/Assets/OSCmooth/Editor/OSCmoothUtil.cs @@ -329,39 +329,102 @@ public static BlendTree CreateSmoothingBlendTree(AnimatorController animatorCont return rootTree; } - public static BlendTree CreateBinaryBlendTree(AnimatorController animatorController, AnimatorStateMachine stateMachine, string paramName, string directory, int binarySizeSelection) + public static BlendTree CreateBinaryBlendTree(AnimatorController animatorController, AnimatorStateMachine stateMachine, string paramName, string directory, int binarySizeSelection, bool combinedParameter) { + // Create each binary step decode layer. This using type casting of bools to float. Parameters will be bools but will be floats in the animator. + // This is way to take typically transition type binaries and stuff them inside direct blendtree to reduce the visual overhead with using binaries in layers. + // There is 20% performance gain by stuffing into direct blend trees. + + + //Create Root to for each binary parameter + var blendRootPara = "OSCm/BlendSet"; + if (combinedParameter) + { + ParameterUtil.CheckAndCreateParameter(paramName + "Negative", animatorController, AnimatorControllerParameterType.Float); + blendRootPara = paramName + "Negative"; + } - //Create Direct Blendtree Root to for each binary parameter BlendTree decodeBinaryRoot = new BlendTree { - blendType = BlendTreeType.Direct, + blendType = BlendTreeType.Simple1D, hideFlags = HideFlags.HideInHierarchy, + blendParameter = blendRootPara, name = "Binary_" + paramName + "_Root", useAutomaticThresholds = false }; + + BlendTree decodeBinaryPositiveTree = new BlendTree + { + blendType = BlendTreeType.Direct, + hideFlags = HideFlags.HideInHierarchy, + name = "Binary_" + paramName + "_Positive", + useAutomaticThresholds = false + }; + + + BlendTree decodeBinaryNegativeTree = new BlendTree + { + blendType = BlendTreeType.Direct, + hideFlags = HideFlags.HideInHierarchy, + name = "Binary_" + paramName + "_Negative", + useAutomaticThresholds = false + }; + + List childBinaryPositiveDecode = new List(); + List childBinaryNegativeDecode = new List(); + + + // Go through binary steps and create each child to eventually stuff into the Direct BlendTrees. - // Go through binary steps and create each child to eventually stuff into the Direct BlendTrees. for (int i = 0; i < binarySizeSelection; i++) { - // Create each binary step decode layer. This using type casting of bools to float. Parameters will be bools but will be floats in the animator. - // This is way to take typically transition type binaries and stuff them inside direct blendtree to reduce the visual overhead with using binaries in layers. - // There is 20% performance gain by stuffing into direct blend trees. - var decodeBinary = CreateBinaryDecode(animatorController, stateMachine, paramName, directory, i, binarySizeSelection); + + var decodeBinaryPositive = CreateBinaryDecode(animatorController, stateMachine, paramName, directory, i, binarySizeSelection, false); childBinaryPositiveDecode.Add(new ChildMotion { directBlendParameter = "OSCm/BlendSet", - motion = decodeBinary, + motion = decodeBinaryPositive, timeScale = 1 }); } - decodeBinaryRoot.children = childBinaryPositiveDecode.ToArray(); + if (combinedParameter) + { + for (int i = 0; i < binarySizeSelection; i++) + { + + var decodeBinaryNegative = CreateBinaryDecode(animatorController, stateMachine, paramName, directory, i, binarySizeSelection, true); + + childBinaryNegativeDecode.Add(new ChildMotion + { + directBlendParameter = "OSCm/BlendSet", + motion = decodeBinaryNegative, + timeScale = 1 + }); + + } + + } + + + decodeBinaryPositiveTree.children = childBinaryPositiveDecode.ToArray(); + decodeBinaryNegativeTree.children = childBinaryNegativeDecode.ToArray(); + + + decodeBinaryRoot.AddChild(decodeBinaryPositiveTree, 0f); + if (combinedParameter) + { + decodeBinaryRoot.AddChild(decodeBinaryNegativeTree, 1f); + } + + + AssetDatabase.AddObjectToAsset(decodeBinaryPositiveTree, AssetDatabase.GetAssetPath(animatorController)); + AssetDatabase.AddObjectToAsset(decodeBinaryNegativeTree, AssetDatabase.GetAssetPath(animatorController)); AssetDatabase.AddObjectToAsset(decodeBinaryRoot, AssetDatabase.GetAssetPath(animatorController)); AssetDatabase.SaveAssets(); @@ -424,10 +487,10 @@ public static AnimationClip[] CreateBinaryAnimation(AnimatorController animatorC return new AnimationClip[] { _animationClipInit, _animationClipFinal }; } - public static BlendTree CreateBinaryDecode(AnimatorController animatorController, AnimatorStateMachine stateMachine, string paramName, string directory, int binaryPow, int binarySize) + public static BlendTree CreateBinaryDecode(AnimatorController animatorController, AnimatorStateMachine stateMachine, string paramName, string directory, int binaryPow, int binarySize, bool negative) { - ParameterUtil.CheckAndCreateParameter(paramName + Mathf.Pow(2,binaryPow).ToString(), animatorController, AnimatorControllerParameterType.Float); + ParameterUtil.CheckAndCreateParameter(paramName + Mathf.Pow(2, binaryPow).ToString(), animatorController, AnimatorControllerParameterType.Float); BlendTree decodeBinary = new BlendTree { @@ -439,7 +502,7 @@ public static BlendTree CreateBinaryDecode(AnimatorController animatorController }; // Create Decode anims and weight per binary - AnimationClip[] decodeAnims = AnimUtil.CreateBinaryAnimation(animatorController, paramName, directory, 0.5f * Mathf.Pow(2, binaryPow + 1) / (Mathf.Pow(2, binarySize) - 1f)); + AnimationClip[] decodeAnims = AnimUtil.CreateBinaryAnimation(animatorController, paramName, directory, (negative ? -0.5f : 0.5f) * Mathf.Pow(2, binaryPow + 1) / (Mathf.Pow(2, binarySize) - 1f)); decodeBinary.AddChild(decodeAnims[0], 0f); decodeBinary.AddChild(decodeAnims[1], 1f); @@ -448,6 +511,5 @@ public static BlendTree CreateBinaryDecode(AnimatorController animatorController return decodeBinary; } - } } \ No newline at end of file From 635d42418b5694bc2f6d9ccb73f7864af2d35a62 Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Wed, 22 Mar 2023 16:09:26 -0500 Subject: [PATCH 05/17] Move Function and Fix OFF Switch --- .../Editor/OSCmoothAnimationHandler.cs | 126 +++++++++--------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs index 56f2f89..ac0e338 100644 --- a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs +++ b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs @@ -30,67 +30,7 @@ public static void RemoveAllBinaryFromController() AnimUtil.RemoveExtendedParametersInController("Binary", _animatorController); AnimUtil.RemoveContainingLayersInController("Binary", _animatorController); } - - public static void CreateBinaryLayer() - { - // Cleannup Animator before apply Binaries - OSCmoothAnimationHandler.RemoveAllBinaryFromController(); - - // Creating new Binary setup. - AnimatorControllerLayer animLayer; - - animLayer = AnimUtil.CreateAnimLayerInController("_Binary_Parameters_Gen", _animatorController); - - // Creating a Direct BlendTree that will hold all of the binary decode driver animations. This is to effectively create a 'sublayer' - // system within the Direct BlendTree to tidy up the animator base layers from bloating up visually. - AnimatorState[] state = new AnimatorState[1]; - - - state[0] = animLayer.stateMachine.AddState("Binary_Parameters_Blendtree", new Vector3(30, 170, 0)); - state[0].writeDefaultValues = true; - - // Creating BlendTree objects to better customize them in the AC Editor - - var binaryTreeRoot = new BlendTree() - { - blendType = BlendTreeType.Direct, - hideFlags = HideFlags.HideInHierarchy, - name = "Binary_Root", - useAutomaticThresholds = false - - }; - - // Stuffing the BlendTrees into their designated state. Also stuffing them so that they - // retain serialization. - state[0].motion = binaryTreeRoot; - AssetDatabase.AddObjectToAsset(binaryTreeRoot, AssetDatabase.GetAssetPath(animLayer.stateMachine)); - - // Creating a '1Set' parameter that holds a value of one at all times for the Direct BlendTree - - ParameterUtil.CheckAndCreateParameter("OSCm/BlendSet", _animatorController, AnimatorControllerParameterType.Float, 1f); - - - List childBinary = new List(); - - // Go through each parameter and create each child to eventually stuff into the Direct BlendTrees. - foreach (OSCmoothParameter p in _parameters) - { - - var decodeBinary = AnimUtil.CreateBinaryBlendTree(_animatorController, animLayer.stateMachine, p.paramName, _binaryExportDirectory, p.binarySizeSelection, p.combinedParameter); - - - childBinary.Add(new ChildMotion - { - directBlendParameter = "OSCm/BlendSet", - motion = decodeBinary, - timeScale = 1 - }); - - } - - binaryTreeRoot.children = childBinary.ToArray(); - } - + public static void CreateSmoothAnimationLayer() { // Cleanup Animator before applying OSCmooth: @@ -189,5 +129,69 @@ public static void CreateSmoothAnimationLayer() basisLocalBlendTree.children = localChildMotion.ToArray(); basisRemoteBlendTree.children = remoteChildMotion.ToArray(); } + + public static void CreateBinaryLayer() + { + // Cleannup Animator before apply Binaries + OSCmoothAnimationHandler.RemoveAllBinaryFromController(); + + // Creating new Binary setup. + AnimatorControllerLayer animLayer; + + animLayer = AnimUtil.CreateAnimLayerInController("_Binary_Parameters_Gen", _animatorController); + + // Creating a Direct BlendTree that will hold all of the binary decode driver animations. This is to effectively create a 'sublayer' + // system within the Direct BlendTree to tidy up the animator base layers from bloating up visually. + AnimatorState[] state = new AnimatorState[1]; + + + state[0] = animLayer.stateMachine.AddState("Binary_Parameters_Blendtree", new Vector3(30, 170, 0)); + state[0].writeDefaultValues = true; + + // Creating BlendTree objects to better customize them in the AC Editor + + var binaryTreeRoot = new BlendTree() + { + blendType = BlendTreeType.Direct, + hideFlags = HideFlags.HideInHierarchy, + name = "Binary_Root", + useAutomaticThresholds = false + + }; + + // Stuffing the BlendTrees into their designated state. Also stuffing them so that they + // retain serialization. + state[0].motion = binaryTreeRoot; + AssetDatabase.AddObjectToAsset(binaryTreeRoot, AssetDatabase.GetAssetPath(animLayer.stateMachine)); + + // Creating a '1Set' parameter that holds a value of one at all times for the Direct BlendTree + + ParameterUtil.CheckAndCreateParameter("OSCm/BlendSet", _animatorController, AnimatorControllerParameterType.Float, 1f); + + + List childBinary = new List(); + + // Go through each parameter and create each child to eventually stuff into the Direct BlendTrees. + foreach (OSCmoothParameter p in _parameters) + { + + var decodeBinary = AnimUtil.CreateBinaryBlendTree(_animatorController, animLayer.stateMachine, p.paramName, _binaryExportDirectory, p.binarySizeSelection, p.combinedParameter); + + if(p.binarySizeSelection != 0) + { + childBinary.Add(new ChildMotion + { + directBlendParameter = "OSCm/BlendSet", + motion = decodeBinary, + timeScale = 1 + }); + } + + + } + + binaryTreeRoot.children = childBinary.ToArray(); + } + } } \ No newline at end of file From 677b53dea43e11c6edc787edbdc1d859f683c43d Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Wed, 22 Mar 2023 17:30:25 -0500 Subject: [PATCH 06/17] Fix Overwriting Animations --- Assets/OSCmooth/Editor/OSCmoothUtil.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothUtil.cs b/Assets/OSCmooth/Editor/OSCmoothUtil.cs index 0485972..69ecb6e 100644 --- a/Assets/OSCmooth/Editor/OSCmoothUtil.cs +++ b/Assets/OSCmooth/Editor/OSCmoothUtil.cs @@ -432,7 +432,7 @@ public static BlendTree CreateBinaryBlendTree(AnimatorController animatorControl return decodeBinaryRoot; } - public static AnimationClip[] CreateBinaryAnimation(AnimatorController animatorController, string paramName, string directory, float weight = 1) + public static AnimationClip[] CreateBinaryAnimation(AnimatorController animatorController, string paramName, string directory, float weight = 1, int step = 1) { string animatorGUID; long id; @@ -453,26 +453,27 @@ public static AnimationClip[] CreateBinaryAnimation(AnimatorController animatorC Directory.CreateDirectory(directory); } - string[] guid = (AssetDatabase.FindAssets(NameNoSymbol(paramName) + "False.anim")); + string[] guid = (AssetDatabase.FindAssets(NameNoSymbol(paramName) + "_FALSE_" + step.ToString() + "_" + (weight < 0 ? "Negative_" : "Positive_") + animatorGUID + ".anim")); if (guid.Length == 0) { - AssetDatabase.CreateAsset(_animationClipInit, directory + NameNoSymbol(paramName) + "_False_" + animatorGUID + ".anim"); + AssetDatabase.CreateAsset(_animationClipInit, directory + NameNoSymbol(paramName) + "_False_" + step.ToString() + "_" + (weight < 0 ? "Negative_" : "Positive_") + animatorGUID + ".anim"); AssetDatabase.SaveAssets(); } else { AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(guid[0])); - AssetDatabase.CreateAsset(_animationClipInit, directory + NameNoSymbol(paramName) + "_False_" + animatorGUID + ".anim"); + AssetDatabase.CreateAsset(_animationClipInit, directory + NameNoSymbol(paramName) + "_False_" + step.ToString() + "_" + (weight < 0 ? "Negative_" : "Positive_") + animatorGUID + ".anim"); AssetDatabase.SaveAssets(); + } - guid = (AssetDatabase.FindAssets(NameNoSymbol(paramName) + "_True.anim")); + guid = (AssetDatabase.FindAssets(NameNoSymbol(paramName) + "_True_" + step.ToString() + (weight < 0 ? "Negative_" : "Positive_") + animatorGUID + ".anim")); if (guid.Length == 0) { - AssetDatabase.CreateAsset(_animationClipFinal, directory + NameNoSymbol(paramName) + "_True_" + animatorGUID + ".anim"); + AssetDatabase.CreateAsset(_animationClipFinal, directory + NameNoSymbol(paramName) + "_True_" + step.ToString() + "_" + (weight < 0 ? "Negative_" : "Positive_") + animatorGUID + ".anim"); AssetDatabase.SaveAssets(); } @@ -502,7 +503,7 @@ public static BlendTree CreateBinaryDecode(AnimatorController animatorController }; // Create Decode anims and weight per binary - AnimationClip[] decodeAnims = AnimUtil.CreateBinaryAnimation(animatorController, paramName, directory, (negative ? -0.5f : 0.5f) * Mathf.Pow(2, binaryPow + 1) / (Mathf.Pow(2, binarySize) - 1f)); + AnimationClip[] decodeAnims = AnimUtil.CreateBinaryAnimation(animatorController, paramName, directory, (negative ? -0.5f : 0.5f) * Mathf.Pow(2, binaryPow + 1) / (Mathf.Pow(2, binarySize) - 1f), binaryPow); decodeBinary.AddChild(decodeAnims[0], 0f); decodeBinary.AddChild(decodeAnims[1], 1f); From 7f4fc756e4264ce9996fd8ce05fcb40a39d00ed2 Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Wed, 22 Mar 2023 17:39:44 -0500 Subject: [PATCH 07/17] Update UI with more options of binaries --- Assets/OSCmooth/Editor/OSCmoothWindow.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothWindow.cs b/Assets/OSCmooth/Editor/OSCmoothWindow.cs index 393683a..c15eb48 100644 --- a/Assets/OSCmooth/Editor/OSCmoothWindow.cs +++ b/Assets/OSCmooth/Editor/OSCmoothWindow.cs @@ -26,7 +26,7 @@ public class OSCmoothWindow : EditorWindow readonly public string[] binarySizeOptions = new string[] { - "OFF","2","4","8","16","32" + "OFF","2 (1 Bit)","4 (2 Bit)","8 (3 Bit)","16 (4 Bit)","32 (5 Bit)", "64 (6 Bit)", "128 (7 Bit)" }; //readonly private string[] _humanoidLayers = { "Base", "Additive", "Gesture", "Action", "FX" }; @@ -340,7 +340,7 @@ public void DrawParameterConfiguration(OSCmoothParameter parameter, bool removab ); EditorGUI.indentLevel = 3; - EditorGUIUtility.labelWidth = 200; + EditorGUIUtility.labelWidth = 220; float localSmoothness = parameter.localSmoothness; float remoteSmoothness = parameter.remoteSmoothness; @@ -413,7 +413,7 @@ public void DrawParameterConfiguration(OSCmoothParameter parameter, bool removab ( new GUIContent ( - "Combined Parameter", + "Combined Parameter (+1 Bit)", "Does this parameter go from positive to negative? " + "This option will add an extra bool to keep track of the " + "positive/negative of the parameter." From 54d91af527ca94c495c337b5648d8f0a92f3381d Mon Sep 17 00:00:00 2001 From: Adjerry91 <58948489+Adjerry91@users.noreply.github.com> Date: Wed, 22 Mar 2023 18:33:05 -0500 Subject: [PATCH 08/17] Changes animator cleanup --- Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs | 10 ++-------- Assets/OSCmooth/Editor/OSCmoothUtil.cs | 1 - Assets/OSCmooth/Editor/OSCmoothWindow.cs | 3 +++ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs index ac0e338..ac8ec05 100644 --- a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs +++ b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs @@ -26,15 +26,11 @@ public static void RemoveAllOSCmoothFromController() public static void RemoveAllBinaryFromController() { - AnimUtil.RevertStateMachineParameters(_animatorController); - AnimUtil.RemoveExtendedParametersInController("Binary", _animatorController); - AnimUtil.RemoveContainingLayersInController("Binary", _animatorController); + } public static void CreateSmoothAnimationLayer() { - // Cleanup Animator before applying OSCmooth: - OSCmoothAnimationHandler.RemoveAllOSCmoothFromController(); // Creating new OSCmooth setup. AnimatorControllerLayer animLayer; @@ -132,13 +128,11 @@ public static void CreateSmoothAnimationLayer() public static void CreateBinaryLayer() { - // Cleannup Animator before apply Binaries - OSCmoothAnimationHandler.RemoveAllBinaryFromController(); // Creating new Binary setup. AnimatorControllerLayer animLayer; - animLayer = AnimUtil.CreateAnimLayerInController("_Binary_Parameters_Gen", _animatorController); + animLayer = AnimUtil.CreateAnimLayerInController("_OSCmooth_Binary_Gen", _animatorController); // Creating a Direct BlendTree that will hold all of the binary decode driver animations. This is to effectively create a 'sublayer' // system within the Direct BlendTree to tidy up the animator base layers from bloating up visually. diff --git a/Assets/OSCmooth/Editor/OSCmoothUtil.cs b/Assets/OSCmooth/Editor/OSCmoothUtil.cs index 69ecb6e..37da809 100644 --- a/Assets/OSCmooth/Editor/OSCmoothUtil.cs +++ b/Assets/OSCmooth/Editor/OSCmoothUtil.cs @@ -189,7 +189,6 @@ public static AnimatorControllerLayer CreateAnimLayerInController(string layerNa defaultWeight = 1f }; - CleanAnimatorBlendTreeBloat(animatorController, "OSCm_"); // Store Layer into Animator Controller, as creating a Layer object is not serialized unless we store it inside an asset. if (AssetDatabase.GetAssetPath(animatorController) != string.Empty) diff --git a/Assets/OSCmooth/Editor/OSCmoothWindow.cs b/Assets/OSCmooth/Editor/OSCmoothWindow.cs index c15eb48..509fc95 100644 --- a/Assets/OSCmooth/Editor/OSCmoothWindow.cs +++ b/Assets/OSCmooth/Editor/OSCmoothWindow.cs @@ -285,6 +285,9 @@ void DrawGUI() OSCmoothAnimationHandler._binaryExportDirectory = "Assets/OSCmooth/Generated/Binary/" + "Animator_" + animatorGUID + "/"; Undo.RecordObject(OSCmoothAnimationHandler._animatorController, "Apply OSCmooth to Layer"); + + OSCmoothAnimationHandler.RemoveAllBinaryFromController(); + OSCmoothAnimationHandler.RemoveAllOSCmoothFromController(); OSCmoothAnimationHandler.CreateBinaryLayer(); OSCmoothAnimationHandler.CreateSmoothAnimationLayer(); } From a9167c1686f843c4cf6820554e71369dd9a92a9a Mon Sep 17 00:00:00 2001 From: InconsolableCellist <23345188+InconsolableCellist@users.noreply.github.com> Date: Wed, 3 May 2023 13:55:33 -0600 Subject: [PATCH 09/17] Fixing issue where directories weren't created with when /v2/ was in the paramName --- Assets/OSCmooth/Editor/OSCmoothUtil.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Assets/OSCmooth/Editor/OSCmoothUtil.cs b/Assets/OSCmooth/Editor/OSCmoothUtil.cs index 2038244..ae15199 100644 --- a/Assets/OSCmooth/Editor/OSCmoothUtil.cs +++ b/Assets/OSCmooth/Editor/OSCmoothUtil.cs @@ -229,6 +229,22 @@ public static AnimationClip[] CreateFloatSmootherAnimation(AnimatorController an { Directory.CreateDirectory(directory); } + + // Create paths for v2/ params + string[] paramNameSplit = paramName.Split('/'); + if (paramNameSplit.Length > 1) + { + string nestedDirectory = directory; + for (int i = 0; i < paramNameSplit.Length - 1; i++) + { + nestedDirectory += paramNameSplit[i] + "/"; + if (!Directory.Exists(nestedDirectory)) + { + Directory.CreateDirectory(nestedDirectory); + } + } + } + string[] guid = (AssetDatabase.FindAssets(NameNoSymbol(paramName) + "-1" + "Smoother.anim")); From 3612f1f3cfd76c55273c6ad8bdd97d6a17b0ae84 Mon Sep 17 00:00:00 2001 From: Yuki <20253131+YukihoAA@users.noreply.github.com> Date: Sun, 27 Aug 2023 10:06:36 +0900 Subject: [PATCH 10/17] Enable Save Function --- Assets/OSCmooth/Editor/OSCmoothWindow.cs | 66 ++++++++++++------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothWindow.cs b/Assets/OSCmooth/Editor/OSCmoothWindow.cs index 509fc95..2b9260b 100644 --- a/Assets/OSCmooth/Editor/OSCmoothWindow.cs +++ b/Assets/OSCmooth/Editor/OSCmoothWindow.cs @@ -85,20 +85,20 @@ void DrawGUI() layers.ToArray() ); - //EditorGUILayout.Space(10f); - - //_parameterAsset = (OSCmoothLayer)EditorGUILayout.ObjectField - //( - // new GUIContent - // ( - // "Config", - // "A preset configuration that stores Parameter Configuration data. " + - // "This is intended for saving configurations for use later or sharing." - // ), - // _parameterAsset, - // typeof(OSCmoothLayer), - // false - //); + EditorGUILayout.Space(10f); + + _parameterAsset = (OSCmoothLayer)EditorGUILayout.ObjectField + ( + new GUIContent + ( + "Config", + "A preset configuration that stores Parameter Configuration data. " + + "This is intended for saving configurations for use later or sharing." + ), + _parameterAsset, + typeof(OSCmoothLayer), + false + ); if (_parameterAsset == null) _parameterAsset = ScriptableObject.CreateInstance(); @@ -106,25 +106,25 @@ void DrawGUI() if (_basisConfigurationParameter == null) _basisConfigurationParameter = new OSCmoothParameter(); - //EditorGUILayout.BeginHorizontal(); - //GUILayout.FlexibleSpace(); - - //if (GUILayout.Button - //( - // new GUIContent - // ( - // "Save Config", - // "Saves Parameter configuration into a JSON readable text file." - // ), - // GUILayout.MaxWidth((float)Screen.width - 159f) - //)) - //{ - // if (AssetDatabase.GetAssetPath(_parameterAsset) == string.Empty) - // AssetDatabase.CreateAsset(_parameterAsset, EditorUtility.SaveFilePanelInProject("Save OSCmooth Configuration", "OSCmoothConfig", "asset", "")); - - // EditorUtility.SetDirty(_parameterAsset); - // AssetDatabase.SaveAssets(); - //} + EditorGUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + + if (GUILayout.Button + ( + new GUIContent + ( + "Save Config", + "Saves Parameter configuration into a JSON readable text file." + ), + GUILayout.MaxWidth((float)Screen.width - 159f) + )) + { + if (AssetDatabase.GetAssetPath(_parameterAsset) == string.Empty) + AssetDatabase.CreateAsset(_parameterAsset, EditorUtility.SaveFilePanelInProject("Save OSCmooth Configuration", "OSCmoothConfig", "asset", "")); + + EditorUtility.SetDirty(_parameterAsset); + AssetDatabase.SaveAssets(); + } _animatorController = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(_avDescriptor.baseAnimationLayers[_layerSelect].animatorController)); From e140c888fde899f26883c112310c6e8cad44cad4 Mon Sep 17 00:00:00 2001 From: Yuki <20253131+YukihoAA@users.noreply.github.com> Date: Sun, 27 Aug 2023 10:08:23 +0900 Subject: [PATCH 11/17] Format Codes. formated by bleak --- .../Editor/OSCmoothAnimationHandler.cs | 16 ++++----- Assets/OSCmooth/Editor/OSCmoothType.cs | 2 +- Assets/OSCmooth/Editor/OSCmoothWindow.cs | 34 +++++++++++-------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs index ac8ec05..0d851b0 100644 --- a/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs +++ b/Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs @@ -18,17 +18,17 @@ public static class OSCmoothAnimationHandler public static string _binaryExportDirectory; public static void RemoveAllOSCmoothFromController() - { + { AnimUtil.RevertStateMachineParameters(_animatorController); AnimUtil.RemoveExtendedParametersInController("OSCm", _animatorController); AnimUtil.RemoveContainingLayersInController("OSCm", _animatorController); } - + public static void RemoveAllBinaryFromController() { - + } - + public static void CreateSmoothAnimationLayer() { @@ -105,7 +105,7 @@ public static void CreateSmoothAnimationLayer() } var motionLocal = AnimUtil.CreateSmoothingBlendTree(_animatorController, animLayer.stateMachine, p.localSmoothness, p.paramName, p.flipInputOutput, 1f, _animExportDirectory, "OSCm/Local/", "SmootherWD", "OSCm/Proxy/", "Proxy"); - var motionRemote = AnimUtil.CreateSmoothingBlendTree(_animatorController, animLayer.stateMachine, p.remoteSmoothness, p.paramName, p.flipInputOutput, 1f, _animExportDirectory, "OSCm/Remote/", "SmootherRemoteWD", "OSCm/Proxy/", "Proxy"); + var motionRemote = AnimUtil.CreateSmoothingBlendTree(_animatorController, animLayer.stateMachine, p.remoteSmoothness, p.paramName, p.flipInputOutput, 1f, _animExportDirectory, "OSCm/Remote/", "SmootherRemoteWD", "OSCm/Proxy/", "Proxy"); localChildMotion.Add(new ChildMotion { @@ -125,7 +125,7 @@ public static void CreateSmoothAnimationLayer() basisLocalBlendTree.children = localChildMotion.ToArray(); basisRemoteBlendTree.children = remoteChildMotion.ToArray(); } - + public static void CreateBinaryLayer() { @@ -171,7 +171,7 @@ public static void CreateBinaryLayer() var decodeBinary = AnimUtil.CreateBinaryBlendTree(_animatorController, animLayer.stateMachine, p.paramName, _binaryExportDirectory, p.binarySizeSelection, p.combinedParameter); - if(p.binarySizeSelection != 0) + if (p.binarySizeSelection != 0) { childBinary.Add(new ChildMotion { @@ -180,7 +180,7 @@ public static void CreateBinaryLayer() timeScale = 1 }); } - + } diff --git a/Assets/OSCmooth/Editor/OSCmoothType.cs b/Assets/OSCmooth/Editor/OSCmoothType.cs index 6a4e1cb..50a8587 100644 --- a/Assets/OSCmooth/Editor/OSCmoothType.cs +++ b/Assets/OSCmooth/Editor/OSCmoothType.cs @@ -54,7 +54,7 @@ public class OSCmoothLayer : ScriptableObject public List parameters; public OSCmoothParameter configuration; - public OSCmoothLayer() + public OSCmoothLayer() { parameters = new List(); configuration = new OSCmoothParameter(); diff --git a/Assets/OSCmooth/Editor/OSCmoothWindow.cs b/Assets/OSCmooth/Editor/OSCmoothWindow.cs index 2b9260b..a3309e0 100644 --- a/Assets/OSCmooth/Editor/OSCmoothWindow.cs +++ b/Assets/OSCmooth/Editor/OSCmoothWindow.cs @@ -41,13 +41,13 @@ public static void ShowWindow() window.Show(); } - private void OnGUI() + private void OnGUI() { DrawGUI(); } - - void DrawGUI() - { + + void DrawGUI() + { _avDescriptor = (VRCAvatarDescriptor)EditorGUILayout.ObjectField ( new GUIContent @@ -71,7 +71,7 @@ void DrawGUI() // Making sure the selector never goes beyond the length of the selection if (_layerSelect > layers.Count) _layerSelect = layers.Count - 1; - + _layerSelect = EditorGUILayout.Popup ( new GUIContent @@ -181,8 +181,10 @@ void DrawGUI() EditorGUI.indentLevel = 0; _showParameters = EditorGUILayout.Foldout(_showParameters, "Parameter Configuration"); - if (_parameterAsset.parameters != null && _parameterAsset.parameters.Count() > 0) { - if (GUILayout.Button("Remove All")) { + if (_parameterAsset.parameters != null && _parameterAsset.parameters.Count() > 0) + { + if (GUILayout.Button("Remove All")) + { Undo.RecordObject(_parameterAsset, "Remove All Parameters"); _parameterAsset.parameters = new List(); return; @@ -193,7 +195,7 @@ void DrawGUI() paramMenuScroll = EditorGUILayout.BeginScrollView(paramMenuScroll); if (_showParameters && _parameterAsset != null) - { + { foreach (OSCmoothParameter parameter in _parameterAsset.parameters) { if (parameter == null) @@ -202,7 +204,8 @@ void DrawGUI() EditorGUI.indentLevel = 0; using (new EditorGUILayout.HorizontalScope()) { - if (GUILayout.Button(parameter.isVisible ? "v" : ">", GUILayout.Width(20))) { + if (GUILayout.Button(parameter.isVisible ? "v" : ">", GUILayout.Width(20))) + { Undo.RecordObject(_parameterAsset, "Set Parameter Visible"); parameter.isVisible = !parameter.isVisible; } @@ -210,14 +213,15 @@ void DrawGUI() EditorGUI.BeginChangeCheck(); string paramName = parameter.paramName; paramName = EditorGUILayout.TextField(paramName); - if (EditorGUI.EndChangeCheck() && parameter != null) { + if (EditorGUI.EndChangeCheck() && parameter != null) + { Undo.RecordObject(_parameterAsset, "Change Parameter Name"); parameter.paramName = paramName; return; } GUI.color = Color.red; - if (GUILayout.Button("X", GUILayout.Width(40))) + if (GUILayout.Button("X", GUILayout.Width(40))) { Undo.RecordObject(_parameterAsset, "Remove Parameter"); _parameterAsset.parameters.Remove(parameter); @@ -227,7 +231,8 @@ void DrawGUI() GUI.color = Color.white; } EditorGUI.indentLevel = 2; - if (parameter.isVisible) { + if (parameter.isVisible) + { DrawParameterConfiguration(parameter); } } @@ -423,11 +428,12 @@ public void DrawParameterConfiguration(OSCmoothParameter parameter, bool removab ), combinedParameter ); - + } - if (EditorGUI.EndChangeCheck()) { + if (EditorGUI.EndChangeCheck()) + { Undo.RecordObject(_parameterAsset, "Change Parameter Values"); parameter.localSmoothness = localSmoothness; parameter.remoteSmoothness = remoteSmoothness; From e8153308dc9ab6321abbb8df61b203ff2755aef7 Mon Sep 17 00:00:00 2001 From: Yuki <20253131+YukihoAA@users.noreply.github.com> Date: Sun, 27 Aug 2023 11:16:08 +0900 Subject: [PATCH 12/17] Delete OSCmoothType.cs --- Assets/OSCmooth/Editor/OSCmoothType.cs | 69 -------------------------- 1 file changed, 69 deletions(-) delete mode 100644 Assets/OSCmooth/Editor/OSCmoothType.cs diff --git a/Assets/OSCmooth/Editor/OSCmoothType.cs b/Assets/OSCmooth/Editor/OSCmoothType.cs deleted file mode 100644 index 50a8587..0000000 --- a/Assets/OSCmooth/Editor/OSCmoothType.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace OSCTools.OSCmooth.Types -{ - [Serializable] - public class OSCmoothParameter - { - - // for Animation creation purposes: - public float localSmoothness = 0.1f; - public float remoteSmoothness = 0.7f; - public string paramName = "NewParam"; - - // This setting sets the output to controll the - // base parameter. This is useful if an OSC app - // doesn't need to directly control the base parameter, - // such as VRCFaceTracking binary parameters. - public bool flipInputOutput = false; - - // This will convert all instances of the base parameter to the proxy in every blend tree. - // WARNING. Please be considerate with this setting. - public bool convertToProxy = true; - - // Resolution of parameters for binaries and disable binary - public int binarySizeSelection = 0; - // Combined parameter for positive and negative - public bool combinedParameter = false; - - // for Editor window visibility - public bool isVisible; - - public OSCmoothParameter() { } - public OSCmoothParameter(string paramName) - { - this.paramName = paramName; - } - public OSCmoothParameter(string paramName, float localSmoothness, float remoteSmoothness, bool convertToProxy, bool flipInputOutput, int binarySizeSelection, bool combinedParameter) - { - this.paramName = paramName; - this.localSmoothness = localSmoothness; - this.remoteSmoothness = remoteSmoothness; - this.convertToProxy = convertToProxy; - this.flipInputOutput = flipInputOutput; - this.binarySizeSelection = binarySizeSelection; - this.combinedParameter = combinedParameter; - } - } - - [Serializable] - public class OSCmoothLayer : ScriptableObject - { - public List parameters; - public OSCmoothParameter configuration; - - public OSCmoothLayer() - { - parameters = new List(); - configuration = new OSCmoothParameter(); - } - public OSCmoothLayer(List parameters, OSCmoothParameter configuration) - { - this.parameters = parameters; - this.configuration = configuration; - } - } -} - From 5e9f8c73245de5993adf8676cf7b21eb262d2774 Mon Sep 17 00:00:00 2001 From: Yuki <20253131+YukihoAA@users.noreply.github.com> Date: Sun, 27 Aug 2023 11:19:55 +0900 Subject: [PATCH 13/17] Add OSCmoothLayer,Params --- .gitignore | 4 +- Assets/OSCmooth/Editor/OSCmoothLayer.cs | 25 +++++++++++ Assets/OSCmooth/Editor/OSCmoothParameter.cs | 50 +++++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 Assets/OSCmooth/Editor/OSCmoothLayer.cs create mode 100644 Assets/OSCmooth/Editor/OSCmoothParameter.cs diff --git a/.gitignore b/.gitignore index fc9ac58..b60f12c 100644 --- a/.gitignore +++ b/.gitignore @@ -393,8 +393,8 @@ VRC.Enums* /Assets/Scenes/SampleScene.unity /Assets/Scenes /Assets/OSCmooth/Generated/Anims/Animator_354a5319244b7d64ca734626cd690e47 -/Assets /Assembly-CSharp.csproj /Assembly-CSharp-Editor.csproj /Packages -*.csproj \ No newline at end of file +*.csproj +.history \ No newline at end of file diff --git a/Assets/OSCmooth/Editor/OSCmoothLayer.cs b/Assets/OSCmooth/Editor/OSCmoothLayer.cs new file mode 100644 index 0000000..80b969f --- /dev/null +++ b/Assets/OSCmooth/Editor/OSCmoothLayer.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace OSCTools.OSCmooth.Types +{ + [Serializable] + public class OSCmoothLayer : ScriptableObject + { + public List parameters; + public OSCmoothParameter configuration; + + public OSCmoothLayer() + { + parameters = new List(); + configuration = new OSCmoothParameter(); + } + public OSCmoothLayer(List parameters, OSCmoothParameter configuration) + { + this.parameters = parameters; + this.configuration = configuration; + } + } +} + diff --git a/Assets/OSCmooth/Editor/OSCmoothParameter.cs b/Assets/OSCmooth/Editor/OSCmoothParameter.cs new file mode 100644 index 0000000..e040519 --- /dev/null +++ b/Assets/OSCmooth/Editor/OSCmoothParameter.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace OSCTools.OSCmooth.Types +{ + [Serializable] + public class OSCmoothParameter + { + + // for Animation creation purposes: + public float localSmoothness = 0.1f; + public float remoteSmoothness = 0.7f; + public string paramName = "NewParam"; + + // This setting sets the output to controll the + // base parameter. This is useful if an OSC app + // doesn't need to directly control the base parameter, + // such as VRCFaceTracking binary parameters. + public bool flipInputOutput = false; + + // This will convert all instances of the base parameter to the proxy in every blend tree. + // WARNING. Please be considerate with this setting. + public bool convertToProxy = true; + + // Resolution of parameters for binaries and disable binary + public int binarySizeSelection = 0; + // Combined parameter for positive and negative + public bool combinedParameter = false; + + // for Editor window visibility + public bool isVisible; + + public OSCmoothParameter() { } + public OSCmoothParameter(string paramName) + { + this.paramName = paramName; + } + public OSCmoothParameter(string paramName, float localSmoothness, float remoteSmoothness, bool convertToProxy, bool flipInputOutput, int binarySizeSelection, bool combinedParameter) + { + this.paramName = paramName; + this.localSmoothness = localSmoothness; + this.remoteSmoothness = remoteSmoothness; + this.convertToProxy = convertToProxy; + this.flipInputOutput = flipInputOutput; + this.binarySizeSelection = binarySizeSelection; + this.combinedParameter = combinedParameter; + } + } +} \ No newline at end of file From 1e4a91691895c595b095a7dea2cb2b92aff2407e Mon Sep 17 00:00:00 2001 From: Yuki <20253131+YukihoAA@users.noreply.github.com> Date: Sun, 27 Aug 2023 11:20:08 +0900 Subject: [PATCH 14/17] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b60f12c..a97bd77 100644 --- a/.gitignore +++ b/.gitignore @@ -393,6 +393,7 @@ VRC.Enums* /Assets/Scenes/SampleScene.unity /Assets/Scenes /Assets/OSCmooth/Generated/Anims/Animator_354a5319244b7d64ca734626cd690e47 +/Assets /Assembly-CSharp.csproj /Assembly-CSharp-Editor.csproj /Packages From 32190f809bb0f3f749988b1648c99202e2d55865 Mon Sep 17 00:00:00 2001 From: Yuki <20253131+YukihoAA@users.noreply.github.com> Date: Sun, 27 Aug 2023 11:35:27 +0900 Subject: [PATCH 15/17] Fix mooth Panel --- Assets/OSCmooth/Editor/OSCmoothWindow.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Assets/OSCmooth/Editor/OSCmoothWindow.cs b/Assets/OSCmooth/Editor/OSCmoothWindow.cs index a3309e0..f4f5f97 100644 --- a/Assets/OSCmooth/Editor/OSCmoothWindow.cs +++ b/Assets/OSCmooth/Editor/OSCmoothWindow.cs @@ -126,6 +126,7 @@ void DrawGUI() AssetDatabase.SaveAssets(); } + EditorGUILayout.EndHorizontal(); _animatorController = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(_avDescriptor.baseAnimationLayers[_layerSelect].animatorController)); From a7016b841e89c2872643f8b4884e660eaf32d512 Mon Sep 17 00:00:00 2001 From: Yuki <20253131+YukihoAA@users.noreply.github.com> Date: Sun, 27 Aug 2023 12:13:07 +0900 Subject: [PATCH 16/17] Revert "Merge branch 'pr/20'" This reverts commit ea0f32cc4bc0f87c1cc2ffe7ae6e8c3b917c4af8, reversing changes made to e140c888fde899f26883c112310c6e8cad44cad4. --- Assets/OSCmooth/Editor/OSCmoothUtil.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Assets/OSCmooth/Editor/OSCmoothUtil.cs b/Assets/OSCmooth/Editor/OSCmoothUtil.cs index 768074f..37da809 100644 --- a/Assets/OSCmooth/Editor/OSCmoothUtil.cs +++ b/Assets/OSCmooth/Editor/OSCmoothUtil.cs @@ -229,22 +229,6 @@ public static AnimationClip[] CreateFloatSmootherAnimation(AnimatorController an { Directory.CreateDirectory(directory); } - - // Create paths for v2/ params - string[] paramNameSplit = paramName.Split('/'); - if (paramNameSplit.Length > 1) - { - string nestedDirectory = directory; - for (int i = 0; i < paramNameSplit.Length - 1; i++) - { - nestedDirectory += paramNameSplit[i] + "/"; - if (!Directory.Exists(nestedDirectory)) - { - Directory.CreateDirectory(nestedDirectory); - } - } - } - string[] guid = (AssetDatabase.FindAssets(NameNoSymbol(paramName) + "-1" + "Smoother.anim")); From cef0f3c98cd91f7128ac26623a17418b51abee21 Mon Sep 17 00:00:00 2001 From: Yuki <20253131+YukihoAA@users.noreply.github.com> Date: Sun, 27 Aug 2023 12:57:16 +0900 Subject: [PATCH 17/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86404d2..2ce3a3a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# OSCmooth +# OSCmooth [![Github Releases](https://img.shields.io/github/downloads/YukihoAA/OSCmooth/total.svg)](https://github.com/YukihoAA/OSCmooth/releases) > Create smoothed out animations that mimics IK Sync on avatars for OSC controlled parameters for VRChat. https://user-images.githubusercontent.com/74634856/183157866-37a20b11-20b5-4cfe-a356-e2acfea23a68.mp4