Skip to content

Commit

Permalink
Update to support the new backwards-incompatible VRC open-beta. Layer…
Browse files Browse the repository at this point in the history
… masks continue to be inaccurate.
  • Loading branch information
lyuma committed Jul 24, 2020
1 parent 5717216 commit 104e740
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Editor/LyumaAv3EditorSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using UnityEditor.Animations;
using UnityEditor.Playables;
using UnityEngine.Playables;
using VRC.SDK3.Components;
using VRC.SDK3.Avatars.Components;

[InitializeOnLoadAttribute]
public static class LyumaAv3EditorSupport
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Avatar 3.0 Emulator
**NEW IN v0.5.0**: UPDATED _July 24, 2020_ for the Open Beta with support for VRCExpressionParameters!

Documentation here: https://docs.vrchat.com/v2020.3.2/docs/what-is-avatars-30

This is an emulator for Avatars 3.0 reimplemented in the unity editor on top the the unity [PlayableGraph](https://docs.unity3d.com/Manual/Playables-Graph.html) API, using the [AnimationControllerPlayable](https://docs.unity3d.com/2018.4/Documentation/ScriptReference/Animations.AnimatorControllerPlayable.html) and [AnimationLayerMixerPlayable](https://docs.unity3d.com/2018.4/Documentation/ScriptReference/Animations.AnimationLayerMixerPlayable.html) APIs.

## Features:
Expand Down
3 changes: 2 additions & 1 deletion Scripts/LyumaAv3Emulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */
using UnityEngine;
using System.Collections.Generic;
using VRC.SDK3.Avatars.Components;

public class LyumaAv3Emulator : MonoBehaviour
{
Expand All @@ -30,7 +31,7 @@ public class LyumaAv3Emulator : MonoBehaviour

private void Start()
{
VRC.SDK3.Components.VRCAvatarDescriptor[] avatars = FindObjectsOfType<VRC.SDK3.Components.VRCAvatarDescriptor>();
VRCAvatarDescriptor[] avatars = FindObjectsOfType<VRCAvatarDescriptor>();
Debug.Log("drv len "+avatars.Length);
foreach (var avadesc in avatars)
{
Expand Down
63 changes: 49 additions & 14 deletions Scripts/LyumaAv3Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;
using VRC.SDK3.Components;
using VRC.SDK3.ScriptableObjects;
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Avatars.ScriptableObjects;

[RequireComponent(typeof(Animator))]
public class LyumaAv3Runtime : MonoBehaviour
Expand All @@ -47,7 +47,7 @@ public class LyumaAv3Runtime : MonoBehaviour
AnimationLayerMixerPlayable playableMixer;
PlayableGraph playableGraph;
VRCExpressionsMenu expressionsMenu;
VRCStageParameters stageParameters;
VRCExpressionParameters stageParameters;
int sittingIndex;
int fxIndex;
int actionIndex;
Expand Down Expand Up @@ -95,8 +95,12 @@ public enum GestureIndex {
public VisemeIndex VisemeDD;
private int Viseme;
public GestureIndex GestureLeft;
public int GestureLeftIdx;
private char GestureLeftIdxInt;
[Range(0, 1)] public float GestureLeftWeight;
public GestureIndex GestureRight;
public int GestureRightIdx;
private char GestureRightIdxInt;
[Range(0, 1)] public float GestureRightWeight;
public Vector3 Velocity;
[Range(-1, 1)] public float AngularY;
Expand All @@ -118,14 +122,15 @@ public enum GestureIndex {
public Vector3 ViewPosition;
float AvatarScaleFactor;
public VRCAnimatorTrackingControl.TrackingType trackingHead;
public VRCAnimatorTrackingControl.TrackingType trackingRightFingers;
public VRCAnimatorTrackingControl.TrackingType trackingLeftFingers;
public VRCAnimatorTrackingControl.TrackingType trackingEyes;
public VRCAnimatorTrackingControl.TrackingType trackingLeftFoot;
public VRCAnimatorTrackingControl.TrackingType trackingHip;
public VRCAnimatorTrackingControl.TrackingType trackingRightHand;
public VRCAnimatorTrackingControl.TrackingType trackingLeftHand;
public VRCAnimatorTrackingControl.TrackingType trackingRightHand;
public VRCAnimatorTrackingControl.TrackingType trackingHip;
public VRCAnimatorTrackingControl.TrackingType trackingLeftFoot;
public VRCAnimatorTrackingControl.TrackingType trackingRightFoot;
public VRCAnimatorTrackingControl.TrackingType trackingLeftFingers;
public VRCAnimatorTrackingControl.TrackingType trackingRightFingers;
public VRCAnimatorTrackingControl.TrackingType trackingEyesAndEyelids;
public VRCAnimatorTrackingControl.TrackingType trackingMouthAndJaw;

[Serializable]
public class FloatParam
Expand Down Expand Up @@ -407,6 +412,10 @@ static LyumaAv3Runtime () {
return;
}

if (behaviour.trackingMouth != VRCAnimatorTrackingControl.TrackingType.NoChange)
{
runtime.trackingMouthAndJaw = behaviour.trackingMouth;
}
if (behaviour.trackingHead != VRCAnimatorTrackingControl.TrackingType.NoChange)
{
runtime.trackingHead = behaviour.trackingHead;
Expand All @@ -417,7 +426,7 @@ static LyumaAv3Runtime () {
}
if (behaviour.trackingEyes != VRCAnimatorTrackingControl.TrackingType.NoChange)
{
runtime.trackingEyes = behaviour.trackingEyes;
runtime.trackingEyesAndEyelids = behaviour.trackingEyes;
}
if (behaviour.trackingLeftFingers != VRCAnimatorTrackingControl.TrackingType.NoChange)
{
Expand Down Expand Up @@ -490,7 +499,7 @@ void Awake()
expressionsMenu = avadesc.expressionsMenu;
if (expressionsMenu != null)
{
stageParameters = expressionsMenu.stageParameters;
stageParameters = avadesc.expressionParameters;
}
origAnimatorController = animator.runtimeAnimatorController;
animator.runtimeAnimatorController = null;
Expand Down Expand Up @@ -545,7 +554,7 @@ void Awake()
if (stageParameters != null)
{
int stageId = 0;
foreach (var stageParam in stageParameters.stageParameters)
foreach (var stageParam in stageParameters.parameters)
{
stageId++; // one-indexed
if (stageParam.name == null || stageParam.name.Length == 0) {
Expand Down Expand Up @@ -728,8 +737,12 @@ void Update()
Viseme = VisemeI = AvatarSyncSource.Viseme;
VisemeDD = (VisemeIndex)Viseme;
GestureLeft = AvatarSyncSource.GestureLeft;
GestureLeftIdx = AvatarSyncSource.GestureLeftIdx;
GestureLeftIdxInt = AvatarSyncSource.GestureLeftIdxInt;
GestureLeftWeight = AvatarSyncSource.GestureLeftWeight;
GestureRight = AvatarSyncSource.GestureRight;
GestureRightIdx = AvatarSyncSource.GestureRightIdx;
GestureRightIdxInt = AvatarSyncSource.GestureRightIdxInt;
GestureRightWeight = AvatarSyncSource.GestureRightWeight;
Velocity = AvatarSyncSource.Velocity;
AngularY = AvatarSyncSource.AngularY;
Expand Down Expand Up @@ -763,6 +776,24 @@ void Update()
Viseme = (int)VisemeDD;
VisemeI = Viseme;
}
if (GestureLeftIdx != GestureLeftIdxInt) {
GestureLeft = (GestureIndex)GestureLeftIdx;
GestureLeftIdx = (int)GestureLeft;
GestureLeftIdxInt = (char)GestureLeftIdx;
}
if ((int)GestureLeft != (int)GestureLeftIdxInt) {
GestureLeftIdx = (int)GestureLeft;
GestureLeftIdxInt = (char)GestureLeftIdx;
}
if (GestureRightIdx != GestureRightIdxInt) {
GestureRight = (GestureIndex)GestureRightIdx;
GestureRightIdx = (int)GestureRight;
GestureRightIdxInt = (char)GestureRightIdx;
}
if ((int)GestureRight != (int)GestureRightIdxInt) {
GestureRightIdx = (int)GestureRight;
GestureRightIdxInt = (char)GestureRightIdx;
}
IsLocal = AvatarSyncSource == this;
int whichcontroller = 0;
foreach (AnimatorControllerPlayable playable in playables)
Expand Down Expand Up @@ -825,7 +856,9 @@ void Update()
if (parameterIndices.TryGetValue("GestureLeft", out paramid))
{
if (paramterInts.TryGetValue(paramid, out iparam) && iparam != playable.GetInteger(paramid)) {
GestureLeft = (GestureIndex)playable.GetInteger(paramid);
GestureLeftIdx = playable.GetInteger(paramid);
GestureLeftIdxInt = (char)GestureLeftIdx;
GestureLeft = (GestureIndex)GestureLeftIdx;
}
playable.SetInteger(paramid, (int)GestureLeft);
paramterInts[paramid] = (int)GestureLeft;
Expand All @@ -841,7 +874,9 @@ void Update()
if (parameterIndices.TryGetValue("GestureRight", out paramid))
{
if (paramterInts.TryGetValue(paramid, out iparam) && iparam != playable.GetInteger(paramid)) {
GestureRight = (GestureIndex)playable.GetInteger(paramid);
GestureRightIdx = playable.GetInteger(paramid);
GestureRightIdxInt = (char)GestureRightIdx;
GestureRight = (GestureIndex)GestureRightIdx;
}
playable.SetInteger(paramid, (int)GestureRight);
paramterInts[paramid] = (int)GestureRight;
Expand Down

0 comments on commit 104e740

Please sign in to comment.