@@ -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 {
0 commit comments