Skip to content

Commit fd8e15b

Browse files
sohailshafiiWkfacebook-github-bot
authored andcommitted
feat(samples): Adds menu to toggle animation on retargeted character
Summary: Adds a menu to allow playing a custom animation on the retargeted character. This will show people how to modify the retargeting mask to ignore joints that an animation will play on. The animated character has an `AnimatorController` that will need to activate the animation clip in the first place, and the `CustomAnimToggle` also accesses the controller. Reviewed By: andkim-meta Differential Revision: D48755430 fbshipit-source-id: edf9d8c2fc77af5cec133c5a17810440a4452c1d
1 parent fe410bf commit fd8e15b

17 files changed

+2913
-5
lines changed

Runtime/Scripts/Tooltips.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,4 +1394,22 @@ public static class BlendHandConstraintsTooltips
13941394
public const string MaxWeight =
13951395
"Max constraint weight.";
13961396
}
1397+
1398+
public static class CustomAnimToggleTooltips
1399+
{
1400+
public const string AnimClip =
1401+
"Animation clip to play.";
1402+
public const string CustomMask =
1403+
"Mask to apply.";
1404+
public const string RetargetingConstraints =
1405+
"Retargeting constraints to fix based on animation state.";
1406+
public const string Animators =
1407+
"Animators to control.";
1408+
public const string CustomAnimEnabled =
1409+
"True if animation is enabled, false is not.";
1410+
public const string WorldText =
1411+
"Text to update to based on animation state.";
1412+
public const string AnimParamName =
1413+
"Animator parameter name.";
1414+
}
13971415
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
using Oculus.Movement.AnimationRigging;
4+
using UnityEngine;
5+
using UnityEngine.Assertions;
6+
7+
namespace Oculus.Movement.UI
8+
{
9+
/// <summary>
10+
/// A simple script that allows toggling an animation on and off.
11+
/// </summary>
12+
public class CustomAnimToggle : MonoBehaviour
13+
{
14+
/// <summary>
15+
/// Animation clip to play.
16+
/// </summary>
17+
[SerializeField]
18+
private AnimationClip _animClip;
19+
/// <summary>
20+
/// Mask to apply.
21+
/// </summary>
22+
[SerializeField]
23+
private AvatarMask _customMask;
24+
/// <summary>
25+
/// Retargeting constraints to fix based on animation state.
26+
/// </summary>
27+
[SerializeField]
28+
private RetargetingAnimationConstraint[] _retargetingConstraints;
29+
/// <summary>
30+
/// Animators to control.
31+
/// </summary>
32+
[SerializeField]
33+
private Animator[] _animators;
34+
/// <summary>
35+
/// True if animation is enabled, false is not.
36+
/// </summary>
37+
[SerializeField]
38+
private bool _customAnimEnabled = false;
39+
/// <summary>
40+
/// Text to update to based on animation state.
41+
/// </summary>
42+
[SerializeField]
43+
private TMPro.TextMeshPro _worldText;
44+
/// <summary>
45+
/// Animator parameter name.
46+
/// </summary>
47+
[SerializeField]
48+
private string _animParamName = "Wave";
49+
50+
private const string _ANIM_OFF_TEXT = "Anim off";
51+
private const string _ANIM_ON_TEXT = "Anim on";
52+
53+
private void Awake()
54+
{
55+
Assert.IsNotNull(_animClip);
56+
Assert.IsNotNull(_customMask);
57+
Assert.IsTrue(_retargetingConstraints != null && _retargetingConstraints.Length > 0);
58+
Assert.IsTrue(_animators != null && _animators.Length > 0);
59+
Assert.IsNotNull(_worldText);
60+
}
61+
62+
private void Start()
63+
{
64+
EnforceAnimState();
65+
}
66+
67+
private void Update()
68+
{
69+
// since the animation rig set up might reboot due to calibration
70+
// keep setting parameter to the proper value.
71+
foreach (var animator in _animators)
72+
{
73+
animator.SetBool(_animParamName, _customAnimEnabled);
74+
}
75+
}
76+
77+
public void SwapAnimState()
78+
{
79+
_customAnimEnabled = !_customAnimEnabled;
80+
EnforceAnimState();
81+
}
82+
83+
private void EnforceAnimState()
84+
{
85+
foreach (var retargetConstraint in _retargetingConstraints)
86+
{
87+
retargetConstraint.data.AvatarMaskComp =
88+
_customAnimEnabled ? _customMask : null;
89+
}
90+
foreach (var animator in _animators)
91+
{
92+
animator.SetBool(_animParamName, _customAnimEnabled);
93+
}
94+
_worldText.text = _customAnimEnabled ?
95+
_ANIM_ON_TEXT : _ANIM_OFF_TEXT;
96+
}
97+
}
98+
}

Runtime/Scripts/UI/CustomAnimToggle.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples/Animations/AnimationControllers.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1107 &-2645630912117078639
4+
AnimatorStateMachine:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 1
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: Base Layer
11+
m_ChildStates: []
12+
m_ChildStateMachines: []
13+
m_AnyStateTransitions: []
14+
m_EntryTransitions: []
15+
m_StateMachineTransitions: {}
16+
m_StateMachineBehaviours: []
17+
m_AnyStatePosition: {x: 50, y: 20, z: 0}
18+
m_EntryPosition: {x: 50, y: 60, z: 0}
19+
m_ExitPosition: {x: 800, y: 120, z: 0}
20+
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
21+
m_DefaultState: {fileID: 0}
22+
--- !u!1101 &-1932229821684974742
23+
AnimatorStateTransition:
24+
m_ObjectHideFlags: 1
25+
m_CorrespondingSourceObject: {fileID: 0}
26+
m_PrefabInstance: {fileID: 0}
27+
m_PrefabAsset: {fileID: 0}
28+
m_Name:
29+
m_Conditions:
30+
- m_ConditionMode: 2
31+
m_ConditionEvent: Wave
32+
m_EventTreshold: 0
33+
m_DstStateMachine: {fileID: 0}
34+
m_DstState: {fileID: 7133807363423554656}
35+
m_Solo: 0
36+
m_Mute: 0
37+
m_IsExit: 0
38+
serializedVersion: 3
39+
m_TransitionDuration: 0.25
40+
m_TransitionOffset: 0
41+
m_ExitTime: 0.53125
42+
m_HasExitTime: 0
43+
m_HasFixedDuration: 0
44+
m_InterruptionSource: 0
45+
m_OrderedInterruption: 1
46+
m_CanTransitionToSelf: 1
47+
--- !u!1107 &-1366296532757319655
48+
AnimatorStateMachine:
49+
serializedVersion: 6
50+
m_ObjectHideFlags: 1
51+
m_CorrespondingSourceObject: {fileID: 0}
52+
m_PrefabInstance: {fileID: 0}
53+
m_PrefabAsset: {fileID: 0}
54+
m_Name: WaveAnimation
55+
m_ChildStates:
56+
- serializedVersion: 1
57+
m_State: {fileID: 7133807363423554656}
58+
m_Position: {x: 40, y: 220, z: 0}
59+
- serializedVersion: 1
60+
m_State: {fileID: 5976499542520269038}
61+
m_Position: {x: 310, y: 10, z: 0}
62+
m_ChildStateMachines: []
63+
m_AnyStateTransitions:
64+
- {fileID: 6667832075500730961}
65+
m_EntryTransitions: []
66+
m_StateMachineTransitions: {}
67+
m_StateMachineBehaviours: []
68+
m_AnyStatePosition: {x: 50, y: 20, z: 0}
69+
m_EntryPosition: {x: 50, y: 120, z: 0}
70+
m_ExitPosition: {x: 800, y: 120, z: 0}
71+
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
72+
m_DefaultState: {fileID: 7133807363423554656}
73+
--- !u!91 &9100000
74+
AnimatorController:
75+
m_ObjectHideFlags: 0
76+
m_CorrespondingSourceObject: {fileID: 0}
77+
m_PrefabInstance: {fileID: 0}
78+
m_PrefabAsset: {fileID: 0}
79+
m_Name: WaveAnimController
80+
serializedVersion: 5
81+
m_AnimatorParameters:
82+
- m_Name: Wave
83+
m_Type: 4
84+
m_DefaultFloat: 0
85+
m_DefaultInt: 0
86+
m_DefaultBool: 0
87+
m_Controller: {fileID: 9100000}
88+
m_AnimatorLayers:
89+
- serializedVersion: 5
90+
m_Name: Base Layer
91+
m_StateMachine: {fileID: -2645630912117078639}
92+
m_Mask: {fileID: 0}
93+
m_Motions: []
94+
m_Behaviours: []
95+
m_BlendingMode: 0
96+
m_SyncedLayerIndex: -1
97+
m_DefaultWeight: 0
98+
m_IKPass: 0
99+
m_SyncedLayerAffectsTiming: 0
100+
m_Controller: {fileID: 9100000}
101+
- serializedVersion: 5
102+
m_Name: WaveAnimation
103+
m_StateMachine: {fileID: -1366296532757319655}
104+
m_Mask: {fileID: 31900000, guid: 4aa24b5561f462548a428cc9c9786a61, type: 2}
105+
m_Motions: []
106+
m_Behaviours: []
107+
m_BlendingMode: 0
108+
m_SyncedLayerIndex: -1
109+
m_DefaultWeight: 1
110+
m_IKPass: 0
111+
m_SyncedLayerAffectsTiming: 0
112+
m_Controller: {fileID: 9100000}
113+
--- !u!1102 &5976499542520269038
114+
AnimatorState:
115+
serializedVersion: 6
116+
m_ObjectHideFlags: 1
117+
m_CorrespondingSourceObject: {fileID: 0}
118+
m_PrefabInstance: {fileID: 0}
119+
m_PrefabAsset: {fileID: 0}
120+
m_Name: Wave
121+
m_Speed: 1
122+
m_CycleOffset: 0
123+
m_Transitions:
124+
- {fileID: -1932229821684974742}
125+
m_StateMachineBehaviours: []
126+
m_Position: {x: 50, y: 50, z: 0}
127+
m_IKOnFeet: 0
128+
m_WriteDefaultValues: 1
129+
m_Mirror: 0
130+
m_SpeedParameterActive: 0
131+
m_MirrorParameterActive: 0
132+
m_CycleOffsetParameterActive: 0
133+
m_TimeParameterActive: 0
134+
m_Motion: {fileID: -203655887218126122, guid: 240510be9aff67c4c82bd2ec6500a06d, type: 3}
135+
m_Tag:
136+
m_SpeedParameter:
137+
m_MirrorParameter:
138+
m_CycleOffsetParameter:
139+
m_TimeParameter:
140+
--- !u!1101 &6667832075500730961
141+
AnimatorStateTransition:
142+
m_ObjectHideFlags: 1
143+
m_CorrespondingSourceObject: {fileID: 0}
144+
m_PrefabInstance: {fileID: 0}
145+
m_PrefabAsset: {fileID: 0}
146+
m_Name:
147+
m_Conditions:
148+
- m_ConditionMode: 1
149+
m_ConditionEvent: Wave
150+
m_EventTreshold: 0
151+
m_DstStateMachine: {fileID: 0}
152+
m_DstState: {fileID: 5976499542520269038}
153+
m_Solo: 0
154+
m_Mute: 0
155+
m_IsExit: 0
156+
serializedVersion: 3
157+
m_TransitionDuration: 0.25
158+
m_TransitionOffset: 0
159+
m_ExitTime: 0.75
160+
m_HasExitTime: 0
161+
m_HasFixedDuration: 0
162+
m_InterruptionSource: 0
163+
m_OrderedInterruption: 1
164+
m_CanTransitionToSelf: 0
165+
--- !u!1102 &7133807363423554656
166+
AnimatorState:
167+
serializedVersion: 6
168+
m_ObjectHideFlags: 1
169+
m_CorrespondingSourceObject: {fileID: 0}
170+
m_PrefabInstance: {fileID: 0}
171+
m_PrefabAsset: {fileID: 0}
172+
m_Name: Default
173+
m_Speed: 1
174+
m_CycleOffset: 0
175+
m_Transitions: []
176+
m_StateMachineBehaviours: []
177+
m_Position: {x: 50, y: 50, z: 0}
178+
m_IKOnFeet: 0
179+
m_WriteDefaultValues: 1
180+
m_Mirror: 0
181+
m_SpeedParameterActive: 0
182+
m_MirrorParameterActive: 0
183+
m_CycleOffsetParameterActive: 0
184+
m_TimeParameterActive: 0
185+
m_Motion: {fileID: 0}
186+
m_Tag:
187+
m_SpeedParameter:
188+
m_MirrorParameter:
189+
m_CycleOffsetParameter:
190+
m_TimeParameter:

Samples/Animations/AnimationControllers/WaveAnimController.controller.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!319 &31900000
4+
AvatarMask:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_Name: ExcludeRightArm
10+
m_Mask: 01000000010000000100000001000000010000000100000000000000010000000000000001000000010000000100000000000000
11+
m_Elements: []

Samples/Animations/Masks/ExcludeRightArm.mask.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!319 &31900000
4+
AvatarMask:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_Name: JustRightArm
10+
m_Mask: 00000000000000000000000000000000000000000000000001000000000000000100000000000000000000000000000001000000
11+
m_Elements: []

Samples/Animations/Masks/JustRightArm.mask.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)