@@ -52,6 +52,39 @@ public partial class VRModule : SingletonBehaviour<VRModule>
5252
5353 public sealed class OculusVRModule : VRModule . ModuleBase
5454 {
55+ public enum OVRSystemHeadset
56+ {
57+ None = 0 ,
58+
59+ GearVR_R320 , // Note4 Innovator
60+ GearVR_R321 , // S6 Innovator
61+ GearVR_R322 , // Commercial 1
62+ GearVR_R323 , // Commercial 2 (USB Type C)
63+ GearVR_R324 , // Commercial 3 (USB Type C)
64+ GearVR_R325 , // Commercial 4 (USB Type C)
65+
66+ // Standalone headsets
67+ Oculus_Go = 7 ,
68+ Oculus_Quest ,
69+ Oculus_Quest_2 ,
70+
71+ // PC headsets
72+ Rift_DK1 = 0x1000 ,
73+ Rift_DK2 ,
74+ Rift_CV1 ,
75+ Rift_CB ,
76+ Rift_S ,
77+ Oculus_Link_Quest ,
78+ Oculus_Link_Quest_2 ,
79+ }
80+
81+ public override int moduleOrder { get { return ( int ) DefaultModuleOrder . OculusVR ; } }
82+
83+ public override int moduleIndex { get { return ( int ) VRModuleSelectEnum . OculusVR ; } }
84+
85+ public const string OCULUS_XR_LOADER_NAME = "Oculus Loader" ;
86+ public const string OCULUS_XR_LOADER_CLASS_NAME = "OculusLoader" ;
87+
5588#if VIU_OCULUSVR
5689 private class Skeleton
5790 {
@@ -136,16 +169,7 @@ public Quaternion GetOpenXRRotation(OVRPlugin.BoneId boneId)
136169 return Bones [ ( int ) boneId ] . rotation * fixQuat ;
137170 }
138171 }
139- #endif
140-
141- public override int moduleOrder { get { return ( int ) DefaultModuleOrder . OculusVR ; } }
142-
143- public override int moduleIndex { get { return ( int ) VRModuleSelectEnum . OculusVR ; } }
144-
145- public const string OCULUS_XR_LOADER_NAME = "Oculus Loader" ;
146- public const string OCULUS_XR_LOADER_CLASS_NAME = "OculusLoader" ;
147172
148- #if VIU_OCULUSVR
149173 private class CameraCreator : VRCameraHook . CameraCreator
150174 {
151175 public override bool shouldActive { get { return s_moduleInstance == null ? false : s_moduleInstance . isActivated ; } }
@@ -160,10 +184,8 @@ public override void CreateCamera(VRCameraHook hook)
160184#endif
161185 }
162186 }
163- #endif
164187
165- #if VIU_OCULUSVR_1_32_0_OR_NEWER || VIU_OCULUSVR_1_36_0_OR_NEWER || VIU_OCULUSVR_1_37_0_OR_NEWER
166- #if VIU_OCULUSVR_AVATAR
188+ #if VIU_OCULUSVR_AVATAR && VIU_OCULUSVR_1_32_0_OR_NEWER
167189 private class RenderModelCreator : RenderModelHook . RenderModelCreator
168190 {
169191 private uint m_index = INVALID_DEVICE_INDEX ;
@@ -209,8 +231,8 @@ public override void UpdateRenderModel()
209231 // set render model index
210232 m_controllerModel . gameObject . SetActive ( true ) ;
211233 m_controllerModel . shaderOverride = hook . overrideShader ;
212- #if VIU_OCULUSVR_1_32_0_OR_NEWER || VIU_OCULUSVR_1_36_0_OR_NEWER
213- m_controllerModel . gameObject . AddComponent ( System . Type . GetType ( " OvrAvatarTouchController" ) ) ;
234+ #if VIU_OCULUSVR_1_32_0_OR_NEWER && ! VIU_OCULUSVR_1_37_0_OR_NEWER
235+ m_controllerModel . gameObject . AddComponent < OvrAvatarTouchController > ( ) ;
214236#endif
215237 m_controllerModel . SetDeviceIndex ( m_index ) ;
216238 }
@@ -252,19 +274,19 @@ private bool IsHand()
252274 }
253275 }
254276#endif
255- private static OculusVRModule s_moduleInstance ;
256- #endif
257277
258- #if VIU_OCULUSVR
259278 private const uint s_leftControllerIndex = 1 ;
260279 private const uint s_rightControllerIndex = 2 ;
261280 private const uint s_leftHandIndex = 7 ;
262281 private const uint s_rightHandIndex = 8 ;
263282
283+ private static OculusVRModule s_moduleInstance ;
264284 private static readonly OVRPlugin . Node [ ] s_index2node ;
265285 private static readonly VRModuleDeviceClass [ ] s_index2class ;
266286 private static readonly HandJointName [ ] s_ovrBoneIdToHandJointName ;
267287
288+ private OVRPlugin . SystemHeadset m_systemHeadsetType ;
289+ private string m_systemHeadsetName ;
268290 private OVRPlugin . TrackingOrigin m_prevTrackingSpace ;
269291
270292 private bool m_isLeftHandTracked ;
@@ -310,8 +332,10 @@ static OculusVRModule()
310332 OVRPlugin . Node . TrackerOne ,
311333 OVRPlugin . Node . TrackerTwo ,
312334 OVRPlugin . Node . TrackerThree ,
335+ #if VIU_OCULUSVR_20_0_OR_NEWER
313336 OVRPlugin . Node . HandLeft ,
314337 OVRPlugin . Node . HandRight ,
338+ #endif
315339 } ;
316340
317341 s_index2class = new [ ]
@@ -323,10 +347,13 @@ static OculusVRModule()
323347 VRModuleDeviceClass . TrackingReference ,
324348 VRModuleDeviceClass . TrackingReference ,
325349 VRModuleDeviceClass . TrackingReference ,
350+ #if VIU_OCULUSVR_20_0_OR_NEWER
326351 VRModuleDeviceClass . TrackedHand ,
327352 VRModuleDeviceClass . TrackedHand ,
353+ #endif
328354 } ;
329355
356+ #if VIU_OCULUSVR_20_0_OR_NEWER
330357 s_ovrBoneIdToHandJointName = new HandJointName [ ( int ) OVRPlugin . BoneId . Max ] ;
331358
332359 s_ovrBoneIdToHandJointName [ ( int ) OVRPlugin . BoneId . Hand_WristRoot ] = HandJointName . Wrist ;
@@ -357,30 +384,36 @@ static OculusVRModule()
357384 s_ovrBoneIdToHandJointName [ ( int ) OVRPlugin . BoneId . Hand_Pinky2 ] = HandJointName . PinkyIntermediate ;
358385 s_ovrBoneIdToHandJointName [ ( int ) OVRPlugin . BoneId . Hand_Pinky3 ] = HandJointName . PinkyDistal ;
359386 s_ovrBoneIdToHandJointName [ ( int ) OVRPlugin . BoneId . Hand_PinkyTip ] = HandJointName . PinkyTip ;
387+ #endif
360388 }
361389
362390 public override bool ShouldActiveModule ( )
363391 {
364- #if UNITY_2019_3_OR_NEWER && VIU_XR_GENERAL_SETTINGS
365- return VIUSettings . activateOculusVRModule && ( UnityXRModule . HasActiveLoader ( OCULUS_XR_LOADER_NAME ) ||
366- XRSettings . enabled && XRSettings . loadedDeviceName == "Oculus" ) ;
392+ if ( ! VIUSettings . activateOculusVRModule ) { return false ; }
393+ #pragma warning disable 0162
394+ #if VIU_XR_GENERAL_SETTINGS
395+ return UnityXRModuleBase . HasActiveLoader ( OCULUS_XR_LOADER_NAME ) ;
396+ #endif
397+ #if UNITY_2019_3_OR_NEWER
398+ return false ;
367399#else
368- return VIUSettings . activateOculusVRModule && XRSettings . enabled && XRSettings . loadedDeviceName == "Oculus" ;
400+ return XRSettings . enabled && XRSettings . loadedDeviceName == "Oculus" ;
369401#endif
402+ #pragma warning restore 0162
370403 }
371404
372405 public override void OnActivated ( )
373406 {
374- Debug . Log ( "OculusVRModule activated. " ) ;
407+ Debug . Log ( "[VIU][ OculusVRModule] OnActivated " ) ;
375408
409+ m_systemHeadsetType = OVRPlugin . GetSystemHeadsetType ( ) ;
410+ m_systemHeadsetName = m_systemHeadsetType . ToString ( ) ;
376411 m_prevTrackingSpace = OVRPlugin . GetTrackingOriginType ( ) ;
377412 UpdateTrackingSpaceType ( ) ;
378413
379414 EnsureDeviceStateLength ( ( uint ) s_index2node . Length ) ;
380415
381- #if VIU_OCULUSVR_1_32_0_OR_NEWER || VIU_OCULUSVR_1_36_0_OR_NEWER || VIU_OCULUSVR_1_37_0_OR_NEWER
382416 s_moduleInstance = this ;
383- #endif
384417 }
385418
386419 public override void OnDeactivated ( )
@@ -426,22 +459,20 @@ public override void Update()
426459
427460 public override uint GetLeftControllerDeviceIndex ( )
428461 {
429- if ( ! OVRPlugin . GetNodePositionValid ( OVRPlugin . Node . HandLeft ) || ! OVRPlugin . GetNodeOrientationValid ( OVRPlugin . Node . HandLeft ) )
430- {
431- return INVALID_DEVICE_INDEX ;
432- }
433-
434- return m_isLeftHandTracked ? s_leftHandIndex : s_leftControllerIndex ;
462+ IVRModuleDeviceState prevState ;
463+ IVRModuleDeviceStateRW currState ;
464+ if ( TryGetValidDeviceState ( s_leftHandIndex , out prevState , out currState ) ) { return s_leftHandIndex ; }
465+ if ( TryGetValidDeviceState ( s_leftControllerIndex , out prevState , out currState ) && currState . isConnected ) { return s_leftControllerIndex ; }
466+ return INVALID_DEVICE_INDEX ;
435467 }
436468
437469 public override uint GetRightControllerDeviceIndex ( )
438470 {
439- if ( ! OVRPlugin . GetNodePositionValid ( OVRPlugin . Node . HandRight ) || ! OVRPlugin . GetNodeOrientationValid ( OVRPlugin . Node . HandRight ) )
440- {
441- return INVALID_DEVICE_INDEX ;
442- }
443-
444- return m_isRightHandTracked ? s_rightHandIndex : s_rightControllerIndex ;
471+ IVRModuleDeviceState prevState ;
472+ IVRModuleDeviceStateRW currState ;
473+ if ( TryGetValidDeviceState ( s_rightHandIndex , out prevState , out currState ) ) { return s_rightHandIndex ; }
474+ if ( TryGetValidDeviceState ( s_rightControllerIndex , out prevState , out currState ) && currState . isConnected ) { return s_rightControllerIndex ; }
475+ return INVALID_DEVICE_INDEX ;
445476 }
446477
447478 private static RigidPose ToPose ( OVRPlugin . Posef value )
@@ -467,6 +498,11 @@ public override void BeforeRenderUpdate()
467498
468499 if ( ! OVRPlugin . GetNodePresent ( node ) )
469500 {
501+ if ( prevState . isConnected )
502+ {
503+ Debug . Log ( "[VIU][OculusVRModule] device disconnected. name:" + prevState . modelNumber + " model:" + prevState . deviceModel ) ;
504+ }
505+
470506 currState . Reset ( ) ;
471507 continue ;
472508 }
@@ -502,15 +538,14 @@ public override void BeforeRenderUpdate()
502538 // update device connected state
503539 if ( ! prevState . isConnected )
504540 {
505- var platform = OVRPlugin . GetSystemHeadsetType ( ) ;
506- var ovrProductName = platform . ToString ( ) ;
541+ var deviceName = m_systemHeadsetName + " " + node + " " + deviceClass ;
507542
508543 currState . isConnected = true ;
509544 currState . deviceClass = deviceClass ;
510545 // FIXME: how to get device id from OVRPlugin?
511- currState . modelNumber = ovrProductName + " " + deviceClass ;
512- currState . renderModelName = ovrProductName + " " + deviceClass ;
513- currState . serialNumber = ovrProductName + " " + node + ( deviceClass == VRModuleDeviceClass . TrackedHand ? "TrackedHand" : "" ) ;
546+ currState . modelNumber = deviceName ;
547+ currState . renderModelName = deviceName ;
548+ currState . serialNumber = deviceName ;
514549
515550 switch ( deviceClass )
516551 {
@@ -521,64 +556,64 @@ public override void BeforeRenderUpdate()
521556 currState . deviceModel = VRModuleDeviceModel . OculusSensor ;
522557 break ;
523558 case VRModuleDeviceClass . Controller :
524- switch ( platform )
559+ switch ( ( OVRSystemHeadset ) m_systemHeadsetType )
525560 {
526- #if ! VIU_OCULUSVR_19_0_OR_NEWER
527- case OVRPlugin . SystemHeadset. Oculus_Go:
561+ case OVRSystemHeadset . Oculus_Go :
528562 currState . deviceModel = VRModuleDeviceModel . OculusGoController ;
529563 currState . input2DType = VRModuleInput2DType . TouchpadOnly ;
530564 break ;
531-
532- case OVRPlugin . SystemHeadset. GearVR_R320:
533- case OVRPlugin. SystemHeadset. GearVR_R321:
534- case OVRPlugin. SystemHeadset. GearVR_R322:
535- case OVRPlugin. SystemHeadset. GearVR_R323:
536- case OVRPlugin. SystemHeadset. GearVR_R324:
537- case OVRPlugin. SystemHeadset. GearVR_R325:
565+ case OVRSystemHeadset . GearVR_R320 :
566+ case OVRSystemHeadset . GearVR_R321 :
567+ case OVRSystemHeadset . GearVR_R322 :
568+ case OVRSystemHeadset . GearVR_R323 :
569+ case OVRSystemHeadset . GearVR_R324 :
570+ case OVRSystemHeadset . GearVR_R325 :
538571 currState . deviceModel = VRModuleDeviceModel . OculusGearVrController ;
539572 currState . input2DType = VRModuleInput2DType . TouchpadOnly ;
540573 break ;
541- #endif
542- case OVRPlugin . SystemHeadset . Rift_DK1 :
543- case OVRPlugin . SystemHeadset . Rift_DK2 :
544- case OVRPlugin . SystemHeadset . Rift_CV1 :
545- switch ( node )
574+ case OVRSystemHeadset . Rift_DK1 :
575+ case OVRSystemHeadset . Rift_DK2 :
576+ case OVRSystemHeadset . Rift_CV1 :
577+ if ( node == OVRPlugin . Node . HandLeft )
578+ {
579+ currState . deviceModel = VRModuleDeviceModel . OculusTouchLeft ;
580+ }
581+ else
546582 {
547- case OVRPlugin . Node . HandLeft :
548- currState . deviceModel = VRModuleDeviceModel . OculusTouchLeft ;
549- break ;
550- case OVRPlugin . Node . HandRight :
551- default :
552- currState . deviceModel = VRModuleDeviceModel . OculusTouchRight ;
553- break ;
583+ currState . deviceModel = VRModuleDeviceModel . OculusTouchRight ;
554584 }
555585 currState . input2DType = VRModuleInput2DType . JoystickOnly ;
556586 break ;
557- #if VIU_OCULUSVR_16_0_OR_NEWER
558- case OVRPlugin . SystemHeadset. Oculus_Link_Quest:
559- #endif
560- #if VIU_OCULUSVR_1_37_0_OR_NEWER
561- case OVRPlugin . SystemHeadset. Oculus_Quest:
562- case OVRPlugin . SystemHeadset . Rift_S :
563- switch ( node )
587+ case OVRSystemHeadset . Oculus_Link_Quest :
588+ case OVRSystemHeadset . Oculus_Link_Quest_2 :
589+ case OVRSystemHeadset . Oculus_Quest :
590+ case OVRSystemHeadset . Oculus_Quest_2 :
591+ case OVRSystemHeadset . Rift_S :
592+ if ( node == OVRPlugin . Node . HandLeft )
593+ {
594+ currState . deviceModel = VRModuleDeviceModel . OculusQuestControllerLeft ;
595+ }
596+ else
564597 {
565- case OVRPlugin . Node . HandLeft :
566- currState . deviceModel = VRModuleDeviceModel . OculusQuestControllerLeft ;
567- break ;
568- case OVRPlugin . Node . HandRight :
569- default :
570- currState . deviceModel = VRModuleDeviceModel . OculusQuestControllerRight ;
571- break ;
598+ currState . deviceModel = VRModuleDeviceModel . OculusQuestControllerRight ;
572599 }
573600 currState . input2DType = VRModuleInput2DType . JoystickOnly ;
574601 break ;
575- #endif
576602 }
577603 break ;
578604 case VRModuleDeviceClass . TrackedHand :
579- currState. deviceModel = node == OVRPlugin . Node . HandLeft ? VRModuleDeviceModel . OculusTrackedHandLeft : VRModuleDeviceModel . OculusTrackedHandRight ;
605+ if ( node == OVRPlugin . Node . HandLeft )
606+ {
607+ currState . deviceModel = VRModuleDeviceModel . OculusTrackedHandLeft ;
608+ }
609+ else
610+ {
611+ currState . deviceModel = VRModuleDeviceModel . OculusTrackedHandRight ;
612+ }
580613 break ;
581614 }
615+
616+ Debug . Log ( "[VIU][OculusVRModule] device connected. name:" + deviceName + " model:" + currState . deviceModel ) ;
582617 }
583618
584619 // update device pose
0 commit comments