Skip to content

Commit

Permalink
Merge pull request #22 from YukihoAA/master
Browse files Browse the repository at this point in the history
Fix save config function
  • Loading branch information
regzo2 authored Sep 4, 2023
2 parents 999d03e + cef0f3c commit 9393e25
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 116 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,6 @@ VRC.Enums*
/Assets
/Assembly-CSharp.csproj
/Assembly-CSharp-Editor.csproj
/Packages
*.csproj
.history
6 changes: 6 additions & 0 deletions .vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}
117 changes: 78 additions & 39 deletions Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,38 @@ public static class OSCmoothAnimationHandler
public static List<OSCmoothParameter> _parameters;
public static bool _writeDefaults;
public static string _animExportDirectory;
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()
{
// Cleanup Animator before applying OSCmooth:
OSCmoothAnimationHandler.RemoveAllOSCmoothFromController();

// 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;
Expand All @@ -68,12 +63,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,
Expand Down Expand Up @@ -101,14 +90,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<ChildMotion> localChildMotion = new List<ChildMotion>();
Expand All @@ -122,13 +104,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
{
Expand All @@ -148,5 +125,67 @@ public static void CreateSmoothAnimationLayer()
basisLocalBlendTree.children = localChildMotion.ToArray();
basisRemoteBlendTree.children = remoteChildMotion.ToArray();
}

public static void CreateBinaryLayer()
{

// Creating new Binary setup.
AnimatorControllerLayer animLayer;

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.
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<ChildMotion> childBinary = new List<ChildMotion>();

// 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();
}

}
}
2 changes: 1 addition & 1 deletion Assets/OSCmooth/Editor/OSCmoothFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
{
Expand Down
25 changes: 25 additions & 0 deletions Assets/OSCmooth/Editor/OSCmoothLayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace OSCTools.OSCmooth.Types
{
[Serializable]
public class OSCmoothLayer : ScriptableObject
{
public List<OSCmoothParameter> parameters;
public OSCmoothParameter configuration;

public OSCmoothLayer()
{
parameters = new List<OSCmoothParameter>();
configuration = new OSCmoothParameter();
}
public OSCmoothLayer(List<OSCmoothParameter> parameters, OSCmoothParameter configuration)
{
this.parameters = parameters;
this.configuration = configuration;
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using UnityEngine;

Expand All @@ -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 = 0;
// Combined parameter for positive and negative
public bool combinedParameter = false;

// for Editor window visibility
public bool isVisible;

Expand All @@ -31,32 +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;
}
}

[Serializable]
public class OSCmoothLayer : ScriptableObject
{
public List<OSCmoothParameter> parameters;
public OSCmoothParameter configuration;

public OSCmoothLayer()
{
parameters = new List<OSCmoothParameter>();
configuration = new OSCmoothParameter();
}
public OSCmoothLayer(List<OSCmoothParameter> parameters, OSCmoothParameter configuration)
{
this.parameters = parameters;
this.configuration = configuration;
}
}
}

}
Loading

0 comments on commit 9393e25

Please sign in to comment.