Skip to content

Commit 38bcc05

Browse files
committed
Update SpatialManipulation dependency on Input
1 parent 5096808 commit 38bcc05

File tree

8 files changed

+68
-91
lines changed

8 files changed

+68
-91
lines changed

UnityProjects/MRTKDevTemplate/Packages/packages-lock.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@
400400
"source": "local",
401401
"dependencies": {
402402
"org.mixedrealitytoolkit.core": "4.0.0",
403+
"org.mixedrealitytoolkit.input": "4.0.0",
403404
"org.mixedrealitytoolkit.uxcore": "4.0.0",
404405
"com.unity.inputsystem": "1.6.1",
405406
"com.unity.xr.interaction.toolkit": "3.0.4"

org.mixedrealitytoolkit.core/Interactables/MRTKBaseInteractable.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
9595
/// <summary>
9696
/// Is this object selected by a gaze-pinch interactor?
9797
/// </summary>
98-
public TimedFlag IsGazePinchSelected { get => isGazePinchSelected; }
98+
public TimedFlag IsGazePinchSelected => isGazePinchSelected;
9999

100100
[SerializeField]
101101
[Tooltip("Is this object selected by a non-gaze ray interactor?")]
@@ -104,7 +104,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
104104
/// <summary>
105105
/// Is this object selected by a non-gaze ray interactor?
106106
/// </summary>
107-
public TimedFlag IsRaySelected { get => isRaySelected; }
107+
public TimedFlag IsRaySelected => isRaySelected;
108108

109109
[SerializeField]
110110
[Tooltip("Is this object selected by a poke interactor?")]
@@ -113,7 +113,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
113113
/// <summary>
114114
/// Is this object selected by a poke interactor?
115115
/// </summary>
116-
public TimedFlag IsPokeSelected { get => isPokeSelected; }
116+
public TimedFlag IsPokeSelected => isPokeSelected;
117117

118118
[SerializeField]
119119
[Tooltip("Is this object selected by a grab interactor?")]
@@ -122,7 +122,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
122122
/// <summary>
123123
/// Is this object selected by a grab interactor?
124124
/// </summary>
125-
public TimedFlag IsGrabSelected { get => isGrabSelected; }
125+
public TimedFlag IsGrabSelected => isGrabSelected;
126126

127127
[SerializeField]
128128
[Tooltip("Is this object hovered by any gaze interactor?")]
@@ -131,7 +131,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
131131
/// <summary>
132132
/// Is this object hovered by any gaze interactor?
133133
/// </summary>
134-
public TimedFlag IsGazeHovered { get => isGazeHovered; }
134+
public TimedFlag IsGazeHovered => isGazeHovered;
135135

136136
[SerializeField]
137137
[Tooltip("Is this object hovered by a gaze-pinch interactor?")]
@@ -140,7 +140,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
140140
/// <summary>
141141
/// Is this object hovered by a gaze-pinch interactor?
142142
/// </summary>
143-
public TimedFlag IsGazePinchHovered { get => isGazePinchHovered; }
143+
public TimedFlag IsGazePinchHovered => isGazePinchHovered;
144144

145145
[SerializeField]
146146
[Tooltip("Is this object hovered by a non-gaze ray interactor?")]
@@ -149,7 +149,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
149149
/// <summary>
150150
/// Is this object hovered by a non-gaze ray interactor?
151151
/// </summary>
152-
public TimedFlag IsRayHovered { get => isRayHovered; }
152+
public TimedFlag IsRayHovered => isRayHovered;
153153

154154
[SerializeField]
155155
[Tooltip("Is this object hovered by a grab interactor?")]
@@ -158,7 +158,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
158158
/// <summary>
159159
/// Is this object hovered by a grab interactor?
160160
/// </summary>
161-
public TimedFlag IsGrabHovered { get => isGrabHovered; }
161+
public TimedFlag IsGrabHovered => isGrabHovered;
162162

163163
[SerializeField]
164164
[Tooltip("Is this object hovered by a near touch/poke interactor?")]
@@ -168,12 +168,12 @@ public class MRTKBaseInteractable : XRBaseInteractable
168168
/// <summary>
169169
/// Is this object hovered by a near touch/poke interactor?
170170
/// </summary>
171-
public TimedFlag IsPokeHovered { get => isPokeHovered; }
171+
public TimedFlag IsPokeHovered => isPokeHovered;
172172

173173
/// <summary>
174174
/// Is this object hovered by any interactor other than passive targeting interactors?
175175
/// </summary>
176-
public TimedFlag IsActiveHovered { get => isActiveHovered; }
176+
public TimedFlag IsActiveHovered => isActiveHovered;
177177

178178
[SerializeField]
179179
[Tooltip("Is this object hovered by any interactor other than only passive targeting interactors?")]

org.mixedrealitytoolkit.core/Subsystems/MRTKLifecycleManager.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using Unity.Profiling;
77
using UnityEngine;
8-
using UnityEngine.InputSystem;
98

109
namespace MixedReality.Toolkit.Subsystems
1110
{
@@ -19,9 +18,6 @@ public class MRTKLifecycleManager :
1918
MonoBehaviour,
2019
IDisposable
2120
{
22-
[SerializeField, Tooltip("A set of input actions to enable/disable according to the app's focus state.")]
23-
private InputActionReference[] inputActionReferences;
24-
2521
private List<IMRTKManagedSubsystem> managedSubsystems = new List<IMRTKManagedSubsystem>();
2622

2723
/// <summary>
@@ -191,17 +187,7 @@ protected void OnApplicationFocus(bool focus)
191187
// and applications should react to an inactive input action by skipping rendering of that action's input avatar
192188
// (depictions of hands or other tracked objects controlled by the user)."
193189

194-
foreach (InputActionReference reference in inputActionReferences)
195-
{
196-
if (focus)
197-
{
198-
reference.action.Enable();
199-
}
200-
else
201-
{
202-
reference.action.Disable();
203-
}
204-
}
190+
205191
}
206192

207193
#endregion MonoBehaviour

org.mixedrealitytoolkit.input/Utilities/TrackedPoseDriverLookup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private void OnValidate()
6262
{
6363
if (FindObjectsByType<TrackedPoseDriverLookup>(FindObjectsSortMode.None).Length > 1)
6464
{
65-
Debug.LogWarning("Found more than one instance of the ControllerLookup class in the hierarchy. There should only be one");
65+
Debug.LogWarning($"Found more than one instance of the {nameof(TrackedPoseDriverLookup)} class in the hierarchy. There should only be one.");
6666
}
6767
}
6868
}
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
2-
"name": "MixedReality.Toolkit.SpatialManipulation",
3-
"rootNamespace": "MixedReality.Toolkit.SpatialManipulation",
4-
"references": [
5-
"MixedReality.Toolkit.Core",
6-
"Unity.InputSystem",
7-
"Unity.XR.CoreUtils",
8-
"Unity.XR.Interaction.Toolkit"
9-
],
10-
"includePlatforms": [],
11-
"excludePlatforms": [],
12-
"allowUnsafeCode": false,
13-
"overrideReferences": false,
14-
"precompiledReferences": [],
15-
"autoReferenced": true,
16-
"defineConstraints": [],
17-
"versionDefines": [],
18-
"noEngineReferences": false
19-
}
2+
"name": "MixedReality.Toolkit.SpatialManipulation",
3+
"rootNamespace": "MixedReality.Toolkit.SpatialManipulation",
4+
"references": [
5+
"MixedReality.Toolkit.Core",
6+
"MixedReality.Toolkit.Input",
7+
"Unity.InputSystem",
8+
"Unity.XR.CoreUtils",
9+
"Unity.XR.Interaction.Toolkit"
10+
],
11+
"includePlatforms": [],
12+
"excludePlatforms": [],
13+
"allowUnsafeCode": false,
14+
"overrideReferences": false,
15+
"precompiledReferences": [],
16+
"autoReferenced": true,
17+
"defineConstraints": [],
18+
"versionDefines": [],
19+
"noEngineReferences": false
20+
}

org.mixedrealitytoolkit.spatialmanipulation/Solvers/HandConstraintPalmUp.cs

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public float HeadGazeProximityThreshold
134134
new ProfilerMarker("[MRTK] HandConstraintPalmUp.IsValidController");
135135

136136
/// <summary>
137-
/// Determines if a hand meets the requirements for use with constraining the
137+
/// Determines if a hand meets the requirements for use with constraining the
138138
/// tracked object and determines if the palm is currently facing the user.
139139
/// </summary>
140140
/// <param name="hand">XRNode representing the hand to validate.</param>
@@ -258,15 +258,15 @@ private bool IsPalmMeetingThresholdRequirements(
258258
new ProfilerMarker("[MRTK] HandConstraintPalmUp.IsUserGazeMeetingThresholdRequirements");
259259

260260
/// <summary>
261-
/// Checks to see if the user is currently gazing at the activation point; it first attempts to do so
261+
/// Checks to see if the user is currently gazing at the activation point; it first attempts to do so
262262
/// using eye gaze, and then falls back to head-based gaze if eye gaze isn't available for use.
263263
/// </summary>
264264
/// <param name="hand">
265265
/// The XRNode representing the user's hand that is used to determine if user gaze meets the gaze threshold.
266266
/// </param>
267267
/// <returns>
268268
/// <see langword="true"/> if the user's gaze is within the proximity threshold of the activation point (both relative to the
269-
/// hand plane), or <see langword="fapse"/>.
269+
/// hand plane), or <see langword="false"/>.
270270
/// </returns>
271271
private bool IsUserGazeMeetingThresholdRequirements(XRNode hand)
272272
{
@@ -275,16 +275,16 @@ private bool IsUserGazeMeetingThresholdRequirements(XRNode hand)
275275
Ray? gazeRay = null;
276276
bool usedEyeGaze = false;
277277

278-
#pragma warning disable CS0618 // Type or member is obsolete
278+
#pragma warning disable CS0618 // Type or member is obsolete
279279
if (ControllerLookup != null)
280280
{
281281
if (ControllerLookup.GazeController != null &&
282282
(ControllerLookup.GazeController.currentControllerState.inputTrackingState &
283283
(InputTrackingState.Position | InputTrackingState.Rotation)) > 0)
284284
{
285285
gazeRay = new Ray(
286-
ControllerLookup.GazeController.transform.position,
287-
ControllerLookup.GazeController.transform.forward);
286+
ControllerLookup.GazeController.transform.position,
287+
ControllerLookup.GazeController.transform.forward);
288288
usedEyeGaze = true;
289289
}
290290
else
@@ -294,7 +294,7 @@ private bool IsUserGazeMeetingThresholdRequirements(XRNode hand)
294294
Camera.main.transform.forward);
295295
}
296296
}
297-
#pragma warning restore CS0618
297+
#pragma warning restore CS0618
298298
else if (TrackedPoseDriverLookup != null)
299299
{
300300
InputTrackingState gazeTrackingStateInput = GetGazeInputTrackingState(TrackedPoseDriverLookup.GazeTrackedPoseDriver);
@@ -315,35 +315,29 @@ private bool IsUserGazeMeetingThresholdRequirements(XRNode hand)
315315
}
316316
else
317317
{
318-
Debug.LogWarning("Neither ControllerLookup nor TrackedPoseDriverLookup are set, unable to determine whether user gaze meets threashold requirements or not.");
318+
Debug.LogWarning("Neither ControllerLookup nor TrackedPoseDriverLookup are set, unable to determine whether user gaze meets threshold requirements or not.");
319319
return false;
320320
}
321321

322-
if (gazeRay.HasValue)
322+
if (gazeRay.HasValue &&
323+
TryGenerateHandPlaneAndActivationPoint(hand, out Plane handPlane, out Vector3 activationPoint) &&
324+
handPlane.Raycast(gazeRay.Value, out float distanceToHandPlane))
323325
{
324-
// Define the activation point as a vector between the wrist and pinky knuckle; then cast it against the plane to get a smooth location
325-
// If we can generate the hand plane or are able to set an activation point on it, and then are able to raycast against it
326-
if (TryGenerateHandPlaneAndActivationPoint(hand, out Plane handPlane, out Vector3 activationPoint) &&
327-
handPlane.Raycast(gazeRay.Value, out float distanceToHandPlane))
328-
{
329-
// Now that we know the dist to the plane, create a vector at that point
330-
Vector3 gazePosOnPlane = gazeRay.Value.origin + gazeRay.Value.direction.normalized * distanceToHandPlane;
331-
Vector3 planePos = handPlane.ClosestPointOnPlane(gazePosOnPlane);
332-
float gazePosDistToActivationPosition = (activationPoint - planePos).sqrMagnitude;
333-
float gazeActivationThreshold = usedEyeGaze ? eyeGazeProximityThreshold : headGazeProximityThreshold;
334-
gazeActivationAlreadyTriggered = (gazePosDistToActivationPosition < gazeActivationThreshold);
335-
336-
return gazeActivationAlreadyTriggered;
337-
}
326+
// Now that we know the distance to the plane, create a vector at that point
327+
Vector3 gazePosOnPlane = gazeRay.Value.origin + gazeRay.Value.direction.normalized * distanceToHandPlane;
328+
Vector3 planePos = handPlane.ClosestPointOnPlane(gazePosOnPlane);
329+
float gazePosDistToActivationPosition = (activationPoint - planePos).sqrMagnitude;
330+
float gazeActivationThreshold = usedEyeGaze ? eyeGazeProximityThreshold : headGazeProximityThreshold;
331+
return gazeActivationAlreadyTriggered = gazePosDistToActivationPosition < gazeActivationThreshold;
338332
}
339333

340334
return false;
341335
}
342336
}
343337

344338
/// <summary>
345-
/// Coroutine function called by the ObjectManipulator of the attached object whenever the object is done
346-
/// being manipulated by the user. This triggers a coroutine that checks to see whether the object should
339+
/// Coroutine function called by the ObjectManipulator of the attached object whenever the object is done
340+
/// being manipulated by the user. This triggers a coroutine that checks to see whether the object should
347341
/// reattach to the hand.
348342
/// </summary>
349343
public void StartWorldLockReattachCheckCoroutine()
@@ -521,7 +515,7 @@ private bool TryGenerateActivationPoint(
521515
}
522516

523517
/// <summary>
524-
/// Coroutine function that's invoked when the attached object becomes world-locked. It uses the
518+
/// Coroutine function that's invoked when the attached object becomes world-locked. It uses the
525519
/// logical checks invoked during IsValidController to determine whether the menu should reattach
526520
/// to the hand or not.
527521
/// </summary>
@@ -531,19 +525,14 @@ private IEnumerator WorldLockedReattachCheck()
531525
{
532526
XRNode? hand = SolverHandler.CurrentTrackedHandedness.ToXRNode();
533527

534-
if (hand.HasValue)
528+
if (hand.HasValue &&
529+
XRSubsystemHelpers.HandsAggregator != null &&
530+
XRSubsystemHelpers.HandsAggregator.TryGetJoint(TrackedHandJoint.Palm, hand.Value, out HandJointPose palmPose) &&
531+
IsPalmMeetingThresholdRequirements(hand.Value, palmPose, Vector3.Angle(palmPose.Up, Camera.main.transform.forward)) &&
532+
IsUserGazeMeetingThresholdRequirements(hand.Value))
535533
{
536-
if (XRSubsystemHelpers.HandsAggregator != null &&
537-
XRSubsystemHelpers.HandsAggregator.TryGetJoint(TrackedHandJoint.Palm, hand.Value, out HandJointPose palmPose))
538-
{
539-
float palmCameraAngle = Vector3.Angle(palmPose.Up, Camera.main.transform.forward);
540-
if (IsPalmMeetingThresholdRequirements(hand.Value, palmPose, palmCameraAngle) &&
541-
IsUserGazeMeetingThresholdRequirements(hand.Value))
542-
{
543-
gazeActivationAlreadyTriggered = false;
544-
SolverHandler.UpdateSolvers = true;
545-
}
546-
}
534+
gazeActivationAlreadyTriggered = false;
535+
SolverHandler.UpdateSolvers = true;
547536
}
548537

549538
yield return null;
@@ -556,8 +545,8 @@ private IEnumerator WorldLockedReattachCheck()
556545
/// A Unity event function that is called when the script component has been enabled.
557546
/// </summary>
558547
/// <remarks>
559-
/// When enabled, ensure that there are no outlying status changes that would prevent HandConstraintPalmUp from
560-
/// properly working (like gazeActivationAlreadyTriggered being set to true previously)
548+
/// When enabled, ensure that there are no outlying status changes that would prevent HandConstraintPalmUp from
549+
/// properly working (like gazeActivationAlreadyTriggered being set to true previously).
561550
/// </remarks>
562551
protected override void OnEnable()
563552
{

org.mixedrealitytoolkit.spatialmanipulation/Solvers/Solver.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public abstract class Solver : MonoBehaviour
2121
private static ControllerLookup controllerLookup;
2222

2323
/// <summary>
24-
/// Get the <see cref="Toolkit.ControllerLookup">ControllerLookup</see> that will be used all application <see cref="Solver"/> objects.
24+
/// Get the <see cref="Toolkit.ControllerLookup"/> that will be used all application <see cref="Solver"/> objects.
2525
/// </summary>
2626
[Obsolete("This property has been deprecated in version 4.0.0. Please use MixedReality.Toolkit.Input.TrackedPoseDriverLookup instead.")]
2727
protected static ControllerLookup ControllerLookup => controllerLookup;
2828

2929
private static TrackedPoseDriverLookup trackedPoseDriverLookup;
3030

3131
/// <summary>
32-
/// Get the <see cref="Toolkit.TrackedPoseDriverLookup">TrackedPoseDriverLookup</see> that will be used by all application <see cref="Solver"/> objects.
32+
/// Get the <see cref="Toolkit.TrackedPoseDriverLookup"/> that will be used by all application <see cref="Solver"/> objects.
3333
/// </summary>
3434
protected static TrackedPoseDriverLookup TrackedPoseDriverLookup => trackedPoseDriverLookup;
3535

@@ -272,7 +272,7 @@ protected virtual void Start()
272272
{
273273
// Find the controller lookup class in the hierarchy. Solvers that require access to the
274274
// left, right or gaze controllers will use the references stored in this class.
275-
#pragma warning disable CS0618 // Type or member is obsolete
275+
#pragma warning disable CS0618 // Type or member is obsolete
276276
if (controllerLookup == null)
277277
{
278278
controllerLookup = ComponentCache<ControllerLookup>.FindFirstActiveInstance();
@@ -284,7 +284,7 @@ protected virtual void Start()
284284
{
285285
trackedPoseDriverLookup = ComponentCache<TrackedPoseDriverLookup>.FindFirstActiveInstance();
286286
}
287-
#pragma warning restore CS0618
287+
#pragma warning restore CS0618
288288
}
289289

290290
#endregion MonoBehaviour Implementation
@@ -370,8 +370,7 @@ protected void UpdateTransformToGoal()
370370
{
371371
if (smoothing)
372372
{
373-
Vector3 pos = transform.position;
374-
Quaternion rot = transform.rotation;
373+
transform.GetPositionAndRotation(out Vector3 pos, out Quaternion rot);
375374
Vector3 scale = transform.localScale;
376375

377376
pos = SmoothTo(pos, GoalPosition, SolverHandler.DeltaTime, moveLerpTime);

org.mixedrealitytoolkit.spatialmanipulation/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"documentationUrl": "https://www.mixedrealitytoolkit.org",
1919
"dependencies": {
2020
"org.mixedrealitytoolkit.core": "4.0.0",
21+
"org.mixedrealitytoolkit.input": "4.0.0",
2122
"org.mixedrealitytoolkit.uxcore": "4.0.0",
2223
"com.unity.inputsystem": "1.6.1",
2324
"com.unity.xr.interaction.toolkit": "3.0.4"
@@ -28,4 +29,4 @@
2829
"msftTestPackages": {
2930
"org.mixedrealitytoolkit.input": "4.0.0"
3031
}
31-
}
32+
}

0 commit comments

Comments
 (0)