-
Notifications
You must be signed in to change notification settings - Fork 161
Fixed for issue 940: HandConstraint hand tracking events not being fired (OnFirstHandDetected/OnHandActivate/OnLastHandLost/OnHandDeactivate) when SolverHandler TrackedHand is set to Right or Left #956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
keveleigh
merged 7 commits into
MixedRealityToolkit:main
from
MaxPalmer-UH:bug/OnHandLost_OnHandDeactivated_Not_Invoked
Jul 21, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4448752
Fixed for issue 940, andConstraint hand tracking events not being fir…
MaxPalmer-UH 7ad02c6
Merge branch 'main' into bug/OnHandLost_OnHandDeactivated_Not_Invoked
keveleigh cbc62f8
Create HandConstraintTests
keveleigh 7c9e8a5
Properly handle Handedness.None in GetControllerNode
keveleigh b5cee0f
Ensure we set CurrentTrackedHandedness to Handedness.None if the hand…
keveleigh 32520a7
Update doc
keveleigh df2d6f1
Merge branch 'main' into bug/OnHandLost_OnHandDeactivated_Not_Invoked
keveleigh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
org.mixedrealitytoolkit.spatialmanipulation/Tests/Runtime/HandConstraintTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| // Copyright (c) Mixed Reality Toolkit Contributors | ||
| // Licensed under the BSD 3-Clause | ||
|
|
||
| // Disable "missing XML comment" warning for tests. While nice to have, this documentation is not required. | ||
| #pragma warning disable CS1591 | ||
|
|
||
| using MixedReality.Toolkit.Core.Tests; | ||
| using MixedReality.Toolkit.Input.Tests; | ||
| using NUnit.Framework; | ||
| using System.Collections; | ||
| using UnityEngine; | ||
| using UnityEngine.TestTools; | ||
|
|
||
| namespace MixedReality.Toolkit.SpatialManipulation.Runtime.Tests | ||
| { | ||
| /// <summary> | ||
| /// Tests for <see cref="HandConstraint"/>. | ||
| /// </summary> | ||
| public class HandConstraintTests : BaseRuntimeInputTests | ||
| { | ||
| /// <summary> | ||
| /// This checks if the HandConstraint events properly fire when the tracked handedness is set to a single hand. | ||
| /// </summary> | ||
| [UnityTest] | ||
| public IEnumerator HandConstraintEventsOneHanded() | ||
| { | ||
| // Disable gaze interactions for this unit test; | ||
| InputTestUtilities.DisableGazeInteractor(); | ||
|
|
||
| // Set up GameObject with a SolverHandler | ||
| GameObject testObject = GameObject.CreatePrimitive(PrimitiveType.Cube); | ||
| SolverHandler solverHandler = testObject.AddComponent<SolverHandler>(); | ||
|
|
||
| // Set it to track interactors | ||
| solverHandler.TrackedHandedness = Handedness.Right; | ||
| solverHandler.TrackedTargetType = TrackedObjectType.HandJoint; | ||
| solverHandler.TrackedHandJoint = TrackedHandJoint.Palm; | ||
|
|
||
| // Set up GameObject with a HandConstraint | ||
| HandConstraint handConstraint = testObject.AddComponent<HandConstraint>(); | ||
|
|
||
| bool onFirstHandDetected = false; | ||
| bool onHandActivate = false; | ||
| bool onHandDeactivate = false; | ||
| bool onLastHandLost = false; | ||
|
|
||
| handConstraint.OnFirstHandDetected.AddListener(() => onFirstHandDetected = true); | ||
| handConstraint.OnHandActivate.AddListener(() => onHandActivate = true); | ||
| handConstraint.OnHandDeactivate.AddListener(() => onHandDeactivate = true); | ||
| handConstraint.OnLastHandLost.AddListener(() => onLastHandLost = true); | ||
|
|
||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| TestHand rightHand = new TestHand(Handedness.Right); | ||
|
|
||
| yield return rightHand.Show(InputTestUtilities.InFrontOfUser(0.5f)); | ||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| // Check if corresponding events were sent | ||
| Assert.IsTrue(onFirstHandDetected, "OnFirstHandDetected wasn't successfully sent."); | ||
| Assert.IsTrue(onHandActivate, "OnHandActivate wasn't successfully sent."); | ||
|
|
||
| yield return rightHand.Hide(); | ||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| // Check if corresponding events were sent | ||
| Assert.IsTrue(onHandDeactivate, "OnHandDeactivate wasn't successfully sent."); | ||
| Assert.IsTrue(onLastHandLost, "OnLastHandLost wasn't successfully sent."); | ||
|
|
||
| // Reset our state for the second iteration | ||
| onFirstHandDetected = false; | ||
| onHandActivate = false; | ||
| onHandDeactivate = false; | ||
| onLastHandLost = false; | ||
|
|
||
| yield return rightHand.Show(new Vector3(-0.05f, -0.05f, 1f)); | ||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| // Check if corresponding events were sent | ||
| Assert.IsTrue(onFirstHandDetected, "OnFirstHandDetected wasn't successfully sent."); | ||
| Assert.IsTrue(onHandActivate, "OnHandActivate wasn't successfully sent."); | ||
|
|
||
| yield return rightHand.Hide(); | ||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| // Check if corresponding events were sent | ||
| Assert.IsTrue(onHandDeactivate, "OnHandDeactivate wasn't successfully sent."); | ||
| Assert.IsTrue(onLastHandLost, "OnLastHandLost wasn't successfully sent."); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This checks if the HandConstraint events properly fire when the tracked handedness is set to both hands. | ||
| /// </summary> | ||
| [UnityTest] | ||
| public IEnumerator HandConstraintEventsBothHanded() | ||
| { | ||
| // Disable gaze interactions for this unit test; | ||
| InputTestUtilities.DisableGazeInteractor(); | ||
|
|
||
| // Set up GameObject with a SolverHandler | ||
| GameObject testObject = GameObject.CreatePrimitive(PrimitiveType.Cube); | ||
| SolverHandler solverHandler = testObject.AddComponent<SolverHandler>(); | ||
|
|
||
| // Set it to track interactors | ||
| solverHandler.TrackedHandedness = Handedness.Both; | ||
| solverHandler.TrackedTargetType = TrackedObjectType.HandJoint; | ||
| solverHandler.TrackedHandJoint = TrackedHandJoint.Palm; | ||
|
|
||
| // Set up GameObject with a HandConstraint | ||
| HandConstraint handConstraint = testObject.AddComponent<HandConstraint>(); | ||
|
|
||
| bool onFirstHandDetected = false; | ||
| bool onHandActivate = false; | ||
| bool onHandDeactivate = false; | ||
| bool onLastHandLost = false; | ||
|
|
||
| handConstraint.OnFirstHandDetected.AddListener(() => onFirstHandDetected = true); | ||
| handConstraint.OnHandActivate.AddListener(() => onHandActivate = true); | ||
| handConstraint.OnHandDeactivate.AddListener(() => onHandDeactivate = true); | ||
| handConstraint.OnLastHandLost.AddListener(() => onLastHandLost = true); | ||
|
|
||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| TestHand rightHand = new TestHand(Handedness.Right); | ||
| TestHand leftHand = new TestHand(Handedness.Left); | ||
| Vector3 initialHandPosition = InputTestUtilities.InFrontOfUser(0.5f); | ||
|
|
||
| yield return rightHand.Show(initialHandPosition); | ||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| // Check if corresponding events were sent | ||
| Assert.IsTrue(onFirstHandDetected, "OnFirstHandDetected wasn't successfully sent."); | ||
| Assert.IsTrue(onHandActivate, "OnHandActivate wasn't successfully sent."); | ||
|
|
||
| onFirstHandDetected = false; | ||
| onHandActivate = false; | ||
|
|
||
| yield return leftHand.Show(new Vector3(-0.05f, -0.05f, 1f)); | ||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| // Check if corresponding events were sent (or not) | ||
| Assert.IsFalse(onFirstHandDetected, "OnFirstHandDetected should not have been sent."); | ||
| Assert.IsFalse(onHandActivate, "OnHandActivate should not have been sent."); | ||
|
|
||
| yield return rightHand.Hide(); | ||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| Assert.IsFalse(onFirstHandDetected, "OnFirstHandDetected should not have been sent."); | ||
| Assert.IsTrue(onHandDeactivate, "OnHandDeactivate wasn't successfully sent."); | ||
| Assert.IsTrue(onHandActivate, "OnHandActivate wasn't successfully sent."); | ||
| Assert.IsFalse(onLastHandLost, "OnLastHandLost should not have been sent."); | ||
|
|
||
| onHandDeactivate = false; | ||
| onHandActivate = false; | ||
|
|
||
| yield return leftHand.Hide(); | ||
| yield return RuntimeTestUtilities.WaitForUpdates(); | ||
|
|
||
| // Check if corresponding events were sent | ||
| Assert.IsTrue(onHandDeactivate, "OnHandDeactivate wasn't successfully sent."); | ||
| Assert.IsTrue(onLastHandLost, "OnLastHandLost wasn't successfully sent."); | ||
| } | ||
| } | ||
| } | ||
| #pragma warning restore CS1591 |
11 changes: 11 additions & 0 deletions
11
org.mixedrealitytoolkit.spatialmanipulation/Tests/Runtime/HandConstraintTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.