Skip to content

Commit

Permalink
Allow visualization of different Animator layers by selecting Animato…
Browse files Browse the repository at this point in the history
…r To Debug. Also, fix some issues for syncing of local parameters used by multiple playables.
  • Loading branch information
lyuma committed Jul 29, 2020
1 parent 0c99d73 commit 2bc8f26
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 61 deletions.
12 changes: 12 additions & 0 deletions AvatarMasks/EmptyController.controller
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: EmptyController
serializedVersion: 5
m_AnimatorParameters: []
m_AnimatorLayers: []
8 changes: 8 additions & 0 deletions AvatarMasks/EmptyController.controller.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion Editor/LyumaAv3EditorSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static class LyumaAv3EditorSupport
{VRCAvatarDescriptor.AnimLayerType.Gesture, "vrc_HandsOnly"},
};


static void InitDefaults() {
foreach (var kv in animLayerToDefaultFile) {
if (kv.Value == null) {
Expand Down Expand Up @@ -94,6 +93,34 @@ static void InitDefaults() {
LyumaAv3Runtime.animLayerToDefaultAvaMask[kv.Key] = mask;
}
}
foreach (string guid in AssetDatabase.FindAssets("EmptyController")) {
LyumaAv3Emulator.EmptyController = AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(AssetDatabase.GUIDToAssetPath(guid));
}

LyumaAv3Runtime.updateSelectionDelegate = (go) => {
if (go == null && LyumaAv3Emulator.emulatorInstance != null) {
Debug.Log("Resetting selected object: " + LyumaAv3Emulator.emulatorInstance);
go = LyumaAv3Emulator.emulatorInstance.gameObject;
}
Debug.Log("Setting selected object: " + go);
Selection.SetActiveObjectWithContext(go, go);
// Highlighter.Highlight("Inspector", "Animator To Debug");
};

LyumaAv3Runtime.addRuntimeDelegate = (runtime) => {
GameObject go = runtime.gameObject;
try {
if (PrefabUtility.IsPartOfAnyPrefab(go)) {
PrefabUtility.UnpackPrefabInstance(go, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);
}
} catch (System.Exception) {}
int moveUpCalls = go.GetComponents<Component>().Length - 2;
if (!PrefabUtility.IsPartOfAnyPrefab(go.GetComponents<Component>()[1])) {
for (int i = 0; i < moveUpCalls; i++) {
UnityEditorInternal.ComponentUtility.MoveComponentUp(runtime);
}
}
};
}

// register an event handler when the class is initialized
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is an emulator for Avatars 3.0 reimplemented in the unity editor on top the
* Should emulate most features of Avatar3.
* Test non-local syncing by duplicating or clicking the "Create Non Local Clone" checkbox.
* Supports viewing and editing float and int paramters. Alt-click the ▶Floats and ▶Ints headers at the bottom.
* Supports live viewing of animator controller state. To use, click the avatar in the scene, then in project view, click the correct animator controller. This will be your own if overriding; or it will be one of the defaults in VRCSDK/Examples3/Animation/Controllers. If you did this right, the Animator window should "Auto Live Link" the controller state and allow you to observe what is happening.
* Supports live viewing and editing within unity's Animator window! Use the "Animator To Debug" dropdown to select which layer is visualized in the Animator window.
* Shows Tracking/Animation in the inspector.

## Not implemented/todo:
Expand All @@ -26,25 +26,19 @@ This will add an object to your scene: you can always remove it if you don't wan

To emulate walking and movement, click the avatar and scroll down the inspector to the bottom section with Lyuma Av3 Runtime component. Here you can change stuff.

It also supports live interacting with the animator controller. To use this, first click your avatar (even if it was already selected), and then open up Windows -> Animation -> Animator ; and find the locomotion or base controller from project. If you customize it, pick your customized version... otherwise, go to VRCSDK3/Examples3/Animation/Controllers and click `vrc_AvatarV3LocomotionLayer` (or whichever controller you want to debug). You can also change parameters from inside the controller, for example moving the red dot in the 2D Blend Tree for Standing. Crouch/Prone by changing the Upright slider; or test Sitting or AFK.
It also supports live interacting with the animator controller. To use this, first click your avatar (even if it was already selected), and then open up Windows -> Animation -> Animator ; and pick the controller using "Animator To Debug" dropdown. You can also change parameters from inside the controller, for example moving the red dot in the 2D Blend Tree for Standing. Crouch/Prone by changing the Upright slider; or test Sitting or AFK.

If you wish to emulate walking, you can also do this by opening up the Locmotion controller with your avatar selected, and going to the Standing blendtree and dragging around the red dot.
If you wish to emulate walking, you can also do this by selecting Base layer, opening up the Locmotion controller with your avatar selected, and going to the Standing blendtree and dragging around the red dot.

## NOTE: about viewing animator state from layers other than Base/locomotion:
Only the Base layer will show parameters and layer weights in the unity Animator window. Other layers will show 0's for everything and every layer will have weight 0.
The avatar should behave correctly when "Animator to Debug" is set to Base. When you pick another layer, for example FX, the *output* of the animator may differ slightly. For example, Direct BlendTrees with non-zero initial outputs may produce different results. Also, the whole playable weight may be forced to 1 on the debugged animator.

You can still edit parameter values, just they show 0 when you finish editing. Additionally, while it is ok to open Blend Trees in the *inspector*, opening a BlendTree in the animation editor (such as double-clicking on it) will force the input values to 0. I believe this to be a Unity bug.

A workaround is don't double-click blendtrees while playing, or if you want to test the state machine, you can put your FX layer into the base slot temporarily to test it, and tick reset Avatar in the emulator component. Another tool is the "PlayableGraph Visualizer" which can be found in the unity Package Manager (Advanced -> Show preview packages). It is hard to use, but does a good job of visualizing clip, layer, and playable weights.
Another useful tool is the "PlayableGraph Visualizer" which can be found in the unity Package Manager (Advanced -> Show preview packages). It is hard to use, but does a good job of visualizing clip, layer, and playable weights.

## Inputing custom stage params:

For testing your own controls, alt-click the Floats and Ints sections at the bottom of the Lyuma Av3 Runtime script to expand them all, and change the values from there. Unfortunately the expressions menu is not emulated yet: you must change the values directly.

## Other known issues:

As mentioned above, a Unity bug prevents you from double-clicking blendtrees in the Animator window, or from *observing* parameter values or layer weights in the Animator window.

The `proxy_` animations included in the SDK are incomplete. Unless you override them, do not expect your avatar to have a full walking cycle, and it is normal for backflip (VRCEmote=6) to stop halfway.

Avoid changing parameter values too quickly (for example click-dragging on the inspector row): it can cause the avatar to glitch out.
12 changes: 12 additions & 0 deletions Scripts/LyumaAv3Emulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,26 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using System.Collections.Generic;
using VRC.SDK3.Avatars.Components;

[RequireComponent(typeof(Animator))]
public class LyumaAv3Emulator : MonoBehaviour
{
public bool RestartEmulator;
private bool RestartingEmulator;
public bool CreateNonLocalClone;

static public LyumaAv3Emulator emulatorInstance;
static public RuntimeAnimatorController EmptyController;

public List<LyumaAv3Runtime> runtimes = new List<LyumaAv3Runtime>();

private void Awake()
{
Animator animator = gameObject.GetOrAddComponent<Animator>();
animator.enabled = false;
animator.runtimeAnimatorController = EmptyController;
emulatorInstance = this;
}

private void Start()
{
VRCAvatarDescriptor[] avatars = FindObjectsOfType<VRCAvatarDescriptor>();
Expand Down
Loading

0 comments on commit 2bc8f26

Please sign in to comment.