@@ -31,6 +31,7 @@ protected class HandPanData
3131 public Vector2 touchingInitialUV = Vector2 . zero ;
3232 public Vector2 touchingUVOffset = Vector2 . zero ;
3333 public Vector2 touchingUVTotalOffset = Vector2 . zero ;
34+ public Vector3 initialProjectedOffset = Vector3 . zero ;
3435 public IMixedRealityInputSource touchingSource = null ;
3536 public IMixedRealityController currentController = null ;
3637 }
@@ -137,6 +138,21 @@ private bool scaleActive
137138 private List < Vector2 > unTransformedUVs = new List < Vector2 > ( ) ;
138139 private Dictionary < uint , HandPanData > handDataMap = new Dictionary < uint , HandPanData > ( ) ;
139140 private List < IMixedRealityHandPanHandler > handlerInterfaces = new List < IMixedRealityHandPanHandler > ( ) ;
141+ private IMixedRealityInputSystem inputSystem = null ;
142+ private IMixedRealityInputSystem InputSystem
143+ {
144+ get
145+ {
146+ if ( inputSystem == null )
147+ {
148+ MixedRealityServiceRegistry . TryGetService < IMixedRealityInputSystem > ( out inputSystem ) ;
149+ }
150+ return inputSystem ;
151+ }
152+ }
153+
154+ private IMixedRealityEyeGazeProvider EyeTrackingProvider => eyeTrackingProvider ?? ( eyeTrackingProvider = InputSystem ? . EyeGazeProvider ) ;
155+ private IMixedRealityEyeGazeProvider eyeTrackingProvider = null ;
140156 #endregion Private Properties
141157
142158 /// <summary>
@@ -162,11 +178,6 @@ private void Update()
162178 {
163179 if ( touchActive )
164180 {
165- if ( affordancesVisible == false )
166- {
167- SetAffordancesActive ( true ) ;
168- }
169-
170181 foreach ( uint key in handDataMap . Keys )
171182 {
172183 if ( true == UpdateHandTouchingPoint ( key ) )
@@ -200,30 +211,60 @@ private void Update()
200211 {
201212 rightPoint . transform . position = GetContactForHand ( Handedness . Right ) ;
202213 }
214+
215+
203216 }
204217 }
205218 }
206219 #endregion MonoBehaviour Handlers
207220
208221
209222 #region Private Methods
223+ private bool TryGetMRControllerRayPoint ( HandPanData data , out Vector3 rayPoint )
224+ {
225+ if ( data . currentController . InputSource . SourceName . Contains ( "Mixed Reality Controller" ) )
226+ {
227+ if ( ! ( data . currentController . InputSource . Pointers [ 0 ] is GGVPointer ) )
228+ {
229+ Vector3 pos = data . currentController . InputSource . Pointers [ 0 ] . Position ;
230+ Vector3 dir = data . currentController . InputSource . Pointers [ 0 ] . Rays [ 0 ] . Direction * ( data . currentController . InputSource . Pointers [ 0 ] . SphereCastRadius ) ;
231+ rayPoint = data . touchingInitialPt + ( SnapFingerToQuad ( pos + dir ) - data . initialProjectedOffset ) ;
232+ return true ;
233+ }
234+ else //then it IS a GGVPointer
235+ {
236+ rayPoint = data . touchingInitialPt + ( SnapFingerToQuad ( data . currentController . InputSource . Pointers [ 0 ] . Position ) - data . initialProjectedOffset ) ;
237+ return true ;
238+ }
239+ }
240+
241+ rayPoint = Vector3 . zero ;
242+ return false ;
243+ }
244+
210245 private bool UpdateHandTouchingPoint ( uint sourceId )
211246 {
212247 Vector3 tryHandPoint = Vector3 . zero ;
213248 bool tryGetSucceeded = false ;
214249 if ( handDataMap . ContainsKey ( sourceId ) == true )
215250 {
216251 HandPanData data = handDataMap [ sourceId ] ;
252+
217253 if ( data . IsActive == true )
218254 {
219- if ( data . IsSourceNear == true )
255+ if ( TryGetMRControllerRayPoint ( data , out tryHandPoint ) )
256+ {
257+ tryGetSucceeded = true ;
258+ }
259+ else if ( data . IsSourceNear == true )
220260 {
221261 tryGetSucceeded = TryGetHandPositionFromController ( data . currentController , TrackedHandJoint . IndexTip , out tryHandPoint ) ;
222262 }
223263 else
224264 {
225265 tryGetSucceeded = TryGetHandPositionFromController ( data . currentController , TrackedHandJoint . Palm , out tryHandPoint ) ;
226266 }
267+
227268 if ( tryGetSucceeded == true )
228269 {
229270 tryHandPoint = SnapFingerToQuad ( tryHandPoint ) ;
@@ -233,14 +274,16 @@ private bool UpdateHandTouchingPoint(uint sourceId)
233274 data . touchingPointSmoothed = ( data . touchingPointSmoothed * runningAverageSmoothing ) + unfilteredTouchPt ;
234275 data . touchingPoint = data . touchingPointSmoothed ;
235276 }
277+
278+
236279 }
237280 }
238281
239282 return true ;
240283 }
241284 private bool TryGetHandRayPoint ( IMixedRealityController controller , out Vector3 handRayPoint )
242285 {
243- if ( controller != null &&
286+ if ( controller != null &&
244287 controller . InputSource != null &&
245288 controller . InputSource . Pointers != null &&
246289 controller . InputSource . Pointers . Length > 0 &&
@@ -444,7 +487,6 @@ private void SetAffordancesActive(bool active)
444487 {
445488 rightPoint . SetActive ( affordancesVisible ) ;
446489 }
447-
448490 }
449491 private Vector3 GetContactForHand ( Handedness hand )
450492 {
@@ -593,6 +635,8 @@ private Vector3 SnapFingerToQuad(Vector3 pointToSnap)
593635
594636 return Vector3 . ProjectOnPlane ( pointToSnap - planePoint , planeNormal ) + planePoint ;
595637 }
638+
639+
596640 private void SetHandDataFromController ( IMixedRealityController controller , bool isNear )
597641 {
598642 HandPanData data = new HandPanData ( ) ;
@@ -623,6 +667,21 @@ private void SetHandDataFromController(IMixedRealityController controller, bool
623667 }
624668 }
625669
670+ //store value in case of MRController
671+ if ( controller . InputSource . Pointers . Length > 0 )
672+ {
673+ Vector3 pt = controller . InputSource . Pointers [ 0 ] . Position ;
674+ if ( ! ( controller . InputSource . Pointers [ 0 ] is GGVPointer ) )
675+ {
676+ Vector3 dir = controller . InputSource . Pointers [ 0 ] . Rays [ 0 ] . Direction * ( controller . InputSource . Pointers [ 0 ] . SphereCastRadius ) ;
677+ data . initialProjectedOffset = SnapFingerToQuad ( pt + dir ) ;
678+ }
679+ else //pointer is GGVPOinter and has no SphereCastRadius
680+ {
681+ data . initialProjectedOffset = SnapFingerToQuad ( pt ) ;
682+ }
683+ }
684+
626685 data . touchingQuadCoord = GetUVFromPoint ( data . touchingPoint ) ;
627686 data . touchingInitialUV = data . touchingQuadCoord ;
628687 data . touchingUVTotalOffset = totalUVOffset ;
@@ -646,6 +705,8 @@ private void SetHandDataFromController(IMixedRealityController controller, bool
646705 previousContactRatio = 1.0f ;
647706 }
648707
708+ SetAffordancesActive ( isNear ) ;
709+
649710 StartTouch ( data . touchingSource . SourceId ) ;
650711 }
651712 private bool TryGetHandPositionFromController ( IMixedRealityController controller , TrackedHandJoint joint , out Vector3 position )
@@ -660,6 +721,16 @@ private bool TryGetHandPositionFromController(IMixedRealityController controller
660721 position = Vector3 . zero ;
661722 return false ;
662723 }
724+ private void GetControllerPoints ( List < Vector3 > points )
725+ {
726+ foreach ( IMixedRealityInputSource source in inputSystem . DetectedInputSources )
727+ {
728+ if ( source . SourceType == InputSourceType . Controller && source . Pointers [ 0 ] . Result != null )
729+ {
730+ points . Add ( source . Pointers [ 0 ] . Result . Details . Point ) ;
731+ }
732+ }
733+ }
663734 private IMixedRealityHandPanHandler [ ] GetInterfaces ( )
664735 {
665736 List < IMixedRealityHandPanHandler > interfaces = new List < IMixedRealityHandPanHandler > ( ) ;
@@ -790,9 +861,13 @@ public void OnTouchUpdated(HandTrackingInputEventData eventData) { }
790861 /// </summary>
791862 public void OnInputDown ( InputEventData eventData )
792863 {
793- EndTouch ( eventData . SourceId ) ;
794- SetHandDataFromController ( eventData . InputSource . Pointers [ 0 ] . Controller , false ) ;
795- eventData . Use ( ) ;
864+ if ( eventData . MixedRealityInputAction . Description != "None" )
865+ {
866+ SetAffordancesActive ( false ) ;
867+ EndTouch ( eventData . SourceId ) ;
868+ SetHandDataFromController ( eventData . InputSource . Pointers [ 0 ] . Controller , false ) ;
869+ eventData . Use ( ) ;
870+ }
796871 }
797872 public void OnInputUp ( InputEventData eventData )
798873 {
0 commit comments