Skip to content

Commit ced2f45

Browse files
author
Lukas Tönne
authored
Fix broken gesture event actions raised by SimulatedGestureHand. (#4024)
The Awake function was never called (controllers are not MonoBehaviours). There doesn't seem to be a good non-ctor init function, so use lazy init. The currentPosition update was also redundant and broke the manipulation/ navigation events. Added logging in the GestureTester example component for completeness.
1 parent aebbe50 commit ced2f45

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

Assets/MixedRealityToolkit.Examples/Demos/HandTracking/Script/GestureTester.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public void OnGestureUpdated(InputEventData eventData)
5858

5959
public void OnGestureUpdated(InputEventData<Vector3> eventData)
6060
{
61+
Debug.Log($"OnGestureUpdated [{Time.frameCount}]: {eventData.MixedRealityInputAction.Description}");
62+
6163
var action = eventData.MixedRealityInputAction.Description;
6264
if (action == "Manipulate Action")
6365
{
@@ -83,6 +85,8 @@ public void OnGestureCompleted(InputEventData eventData)
8385

8486
public void OnGestureCompleted(InputEventData<Vector3> eventData)
8587
{
88+
Debug.Log($"OnGestureCompleted [{Time.frameCount}]: {eventData.MixedRealityInputAction.Description}");
89+
8690
var action = eventData.MixedRealityInputAction.Description;
8791
if (action == "Manipulate Action")
8892
{

Assets/MixedRealityToolkit.Services/InputSimulation/SimulatedGestureHand.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class SimulatedGestureHand : SimulatedHand
1313
{
1414
public override HandSimulationMode SimulationMode => HandSimulationMode.Gestures;
1515

16+
private bool initializedFromProfile = false;
1617
private MixedRealityInputAction holdAction = MixedRealityInputAction.None;
1718
private MixedRealityInputAction navigationAction = MixedRealityInputAction.None;
1819
private MixedRealityInputAction manipulationAction = MixedRealityInputAction.None;
@@ -25,7 +26,6 @@ public class SimulatedGestureHand : SimulatedHand
2526
private bool holdInProgress = false;
2627
private Vector3 currentRailsUsed = Vector3.one;
2728
private Vector3 currentPosition = Vector3.zero;
28-
private Vector3 lastPosition = Vector3.zero;
2929
private Vector3 cumulativeDelta = Vector3.zero;
3030
private MixedRealityPose currentGripPose = MixedRealityPose.ZeroIdentity;
3131

@@ -50,8 +50,16 @@ public SimulatedGestureHand(
5050
{
5151
}
5252

53-
void Awake()
54-
{
53+
/// Lazy-init settings based on profile.
54+
/// This cannot happen in the constructor because the profile may not exist yet.
55+
private void EnsureProfileSettings()
56+
{
57+
if (initializedFromProfile)
58+
{
59+
return;
60+
}
61+
initializedFromProfile = true;
62+
5563
var gestureProfile = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.GesturesProfile;
5664
if (gestureProfile != null)
5765
{
@@ -100,9 +108,13 @@ public override void SetupDefaultInteractions(Handedness controllerHandedness)
100108

101109
protected override void UpdateInteractions(SimulatedHandData handData)
102110
{
103-
lastPosition = currentPosition;
111+
EnsureProfileSettings();
112+
113+
Vector3 lastPosition = currentPosition;
104114
currentPosition = jointPositions[(int)TrackedHandJoint.IndexTip];
115+
cumulativeDelta += currentPosition - lastPosition;
105116
currentGripPose.Position = currentPosition;
117+
106118
if (lastPosition != currentPosition)
107119
{
108120
MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, currentPosition);
@@ -143,12 +155,6 @@ protected override void UpdateInteractions(SimulatedHandData handData)
143155
}
144156
else if (Interactions[i].BoolData)
145157
{
146-
// For convenience of simulating in Unity Editor, make the ray use the index
147-
// finger position instead of knuckle, since the index finger doesn't move when we press.
148-
Vector3 newPosition = jointPositions[(int)TrackedHandJoint.IndexTip];
149-
cumulativeDelta += newPosition - currentPosition;
150-
currentPosition = newPosition;
151-
152158
if (!manipulationInProgress)
153159
{
154160
if (cumulativeDelta.magnitude > manipulationStartThreshold)

0 commit comments

Comments
 (0)