@@ -240,19 +240,11 @@ private Transform FindWaveVRControllerActionsObjInChildren()
240240 private static readonly WVR_DeviceType [ ] s_index2type ;
241241 private static readonly uint [ ] s_type2index ;
242242 private static readonly VRModuleDeviceClass [ ] s_type2class ;
243- private static readonly VRModuleDeviceModel [ ] s_type2model ;
244243
245- //private bool m_hasInputFocus;
246- private readonly bool [ ] m_index2deviceTouched = new bool [ DEVICE_COUNT ] ;
247244 private IVRModuleDeviceStateRW m_headState ;
248245 private IVRModuleDeviceStateRW m_rightState ;
249246 private IVRModuleDeviceStateRW m_leftState ;
250247 private WaveVR_ControllerLoader . ControllerHand [ ] m_deviceHands = new WaveVR_ControllerLoader . ControllerHand [ DEVICE_COUNT ] ;
251- private static Dictionary < string , VRModuleDeviceModel > m_models = new Dictionary < string , VRModuleDeviceModel >
252- {
253- { "WVR_CONTROLLER_FINCH3DOF_2_0" , VRModuleDeviceModel . ViveFocusFinch } ,
254- { "WVR_CONTROLLER_ASPEN_MI6_1" , VRModuleDeviceModel . ViveFocusChirp }
255- } ;
256248
257249 #region 6Dof Controller Simulation
258250
@@ -381,7 +373,6 @@ public override void OnDeactivated()
381373 m_headState = null ;
382374 m_rightState = null ;
383375 m_leftState = null ;
384- ResetTouchState ( ) ;
385376
386377 s_moduleInstance = null ;
387378 }
@@ -542,13 +533,20 @@ private IVRModuleDeviceStateRW UpdateDevicePose(uint deviceIndex, WaveVR.Device
542533 {
543534 if ( ! prevState . isConnected )
544535 {
536+ string renderModelName ;
537+ if ( ! TryGetWVRStringParameter ( s_index2type [ ( int ) deviceIndex ] , "GetRenderModelName" , out renderModelName ) )
538+ {
539+ renderModelName = "wvr_unknown_device" ;
540+ }
541+
545542 currState . isConnected = true ;
546543 currState . deviceClass = s_type2class [ ( int ) content . type ] ;
547- currState . deviceModel = QueryDeviceModel ( s_index2type [ ( int ) deviceIndex ] ) ;
548544 currState . serialNumber = content . type . ToString ( ) ;
549- currState . modelNumber = content . type . ToString ( ) ;
550- currState . renderModelName = content . type . ToString ( ) ;
545+ currState . modelNumber = renderModelName ;
546+ currState . renderModelName = renderModelName ;
551547 currState . input2DType = VRModuleInput2DType . TouchpadOnly ;
548+
549+ SetupKnownDeviceModel ( currState ) ;
552550 }
553551
554552 // update pose
@@ -592,7 +590,6 @@ private void OnNewPoses(params object[] args)
592590 }
593591#endif
594592
595-
596593 if ( m_rightState != null && ! rightDevice . pose . pose . Is6DoFPose )
597594 {
598595 ApplyVirtualArmAndSimulateInput ( m_rightState , m_headState , RIGHT_ARM_MULTIPLIER ) ;
@@ -617,61 +614,6 @@ private void OnNewPoses(params object[] args)
617614
618615 public override uint GetLeftControllerDeviceIndex ( ) { return LEFT_INDEX ; }
619616
620- private bool TryGetAndTouchDeviceIndexByType ( WVR_DeviceType type , out uint deviceIndex )
621- {
622- if ( type < 0 || ( int ) type >= s_type2index . Length )
623- {
624- deviceIndex = INVALID_DEVICE_INDEX ;
625- return false ;
626- }
627-
628- deviceIndex = s_type2index [ ( int ) type ] ;
629- if ( VRModule . IsValidDeviceIndex ( deviceIndex ) )
630- {
631- m_index2deviceTouched [ deviceIndex ] = true ;
632- return true ;
633- }
634- else
635- {
636- return false ;
637- }
638- }
639-
640- private int ResetAndDisconnectUntouchedDevices ( )
641- {
642- var disconnectedCout = 0 ;
643- for ( uint i = 0u , imax = ( uint ) m_index2deviceTouched . Length ; i < imax ; ++ i )
644- {
645- IVRModuleDeviceState prevState ;
646- IVRModuleDeviceStateRW currState ;
647- if ( ! TryGetValidDeviceState ( i , out prevState , out currState ) )
648- {
649- Debug . Assert ( ! m_index2deviceTouched [ i ] ) ;
650- continue ;
651- }
652-
653- if ( ! m_index2deviceTouched [ i ] )
654- {
655- if ( currState . isConnected )
656- {
657- currState . Reset ( ) ;
658- ++ disconnectedCout ;
659- }
660- }
661- else
662- {
663- m_index2deviceTouched [ i ] = false ;
664- }
665- }
666-
667- return disconnectedCout ;
668- }
669-
670- private void ResetTouchState ( )
671- {
672- Array . Clear ( m_index2deviceTouched , 0 , m_index2deviceTouched . Length ) ;
673- }
674-
675617 private void ApplyVirtualArmAndSimulateInput ( IVRModuleDeviceStateRW ctrlState , IVRModuleDeviceStateRW headState , Vector3 handSideMultiplier )
676618 {
677619 if ( ! ctrlState . isConnected ) { return ; }
@@ -799,68 +741,60 @@ public override void TriggerViveControllerHaptic(uint deviceIndex, ushort durati
799741 }
800742 }
801743
802- private VRModuleDeviceModel QueryDeviceModel ( WVR_DeviceType device )
744+ private bool TryGetWVRStringParameter ( WVR_DeviceType device , string paramName , out string result )
803745 {
804- switch ( device )
746+ result = default ( string ) ;
747+ var resultLen = 0u ;
748+ try
805749 {
806- case WVR_DeviceType . WVR_DeviceType_HMD :
807- return VRModuleDeviceModel . ViveFocusHMD ;
808- case WVR_DeviceType . WVR_DeviceType_Controller_Right :
809- case WVR_DeviceType . WVR_DeviceType_Controller_Left :
810- int buffer = 128 ;
811- uint resultLength = 128 ;
812- string parameterName = "GetRenderModelName" ;
813- IntPtr ptrParameterName = Marshal . StringToHGlobalAnsi ( parameterName ) ;
814- IntPtr ptrResult = Marshal . AllocHGlobal ( buffer ) ;
815- uint ret = Interop . WVR_GetParameters ( device , ptrParameterName , ptrResult , resultLength ) ;
816- if ( ret > 0 )
817- {
818- VRModuleDeviceModel model ;
819- if ( m_models . TryGetValue ( Marshal . PtrToStringAnsi ( ptrResult ) , out model ) )
820- {
821- return model ;
822- }
823- else
824- {
825- return VRModuleDeviceModel . Unknown ;
826- }
827- }
828- else
829- {
830- return VRModuleDeviceModel . Unknown ;
831- }
832- default :
833- return VRModuleDeviceModel . Unknown ;
750+ const int resultMaxLen = 128 ;
751+ var resultBuffer = resultMaxLen ;
752+ var resultPtr = Marshal . AllocHGlobal ( resultBuffer ) ;
753+ var paramNamePtr = Marshal . StringToHGlobalAnsi ( paramName ) ;
754+ resultLen = Interop . WVR_GetParameters ( device , paramNamePtr , resultPtr , resultMaxLen ) ;
755+
756+ if ( resultLen > 0u )
757+ {
758+ result = Marshal . PtrToStringAnsi ( resultPtr ) ;
759+ }
834760 }
761+ catch ( Exception e )
762+ {
763+ Debug . LogException ( e ) ;
764+ }
765+
766+ return resultLen > 0u ;
835767 }
836768
837769#if VIU_WAVEVR_3_1_0_OR_NEWER
838770 public override void TriggerHapticVibration ( uint deviceIndex , float durationSeconds = 0.01f , float frequency = 85 , float amplitude = 0.125f , float startSecondsFromNow = 0 )
839771 {
840772 var deviceInput = WaveVR_Controller . Input ( s_index2type [ deviceIndex ] ) ;
773+ var intensity = default ( WVR_Intensity ) ;
841774 if ( deviceInput != null )
842775 {
843776 if ( 0 <= amplitude || amplitude <= 0.2 )
844777 {
845- Interop . WVR_TriggerVibration ( deviceInput . DeviceType , WVR_InputId . WVR_InputId_Alias1_Touchpad , ( uint ) ( durationSeconds * 1000000 ) , ( uint ) frequency , WVR_Intensity . WVR_Intensity_Weak ) ;
778+ intensity = WVR_Intensity . WVR_Intensity_Weak ;
846779 }
847780 else if ( 0.2 < amplitude || amplitude <= 0.4 )
848781 {
849- Interop . WVR_TriggerVibration ( deviceInput . DeviceType , WVR_InputId . WVR_InputId_Alias1_Touchpad , ( uint ) ( durationSeconds * 1000000 ) , ( uint ) frequency , WVR_Intensity . WVR_Intensity_Light ) ;
782+ intensity = WVR_Intensity . WVR_Intensity_Light ;
850783 }
851784 else if ( 0.4 < amplitude || amplitude <= 0.6 )
852785 {
853- Interop . WVR_TriggerVibration ( deviceInput . DeviceType , WVR_InputId . WVR_InputId_Alias1_Touchpad , ( uint ) ( durationSeconds * 1000000 ) , ( uint ) frequency , WVR_Intensity . WVR_Intensity_Normal ) ;
786+ intensity = WVR_Intensity . WVR_Intensity_Normal ;
854787 }
855788 else if ( 0.6 < amplitude || amplitude <= 0.8 )
856789 {
857- Interop . WVR_TriggerVibration ( deviceInput . DeviceType , WVR_InputId . WVR_InputId_Alias1_Touchpad , ( uint ) ( durationSeconds * 1000000 ) , ( uint ) frequency , WVR_Intensity . WVR_Intensity_Strong ) ;
790+ intensity = WVR_Intensity . WVR_Intensity_Strong ;
858791 }
859792 else if ( 0.8 < amplitude || amplitude <= 1 )
860793 {
861- Interop . WVR_TriggerVibration ( deviceInput . DeviceType , WVR_InputId . WVR_InputId_Alias1_Touchpad , ( uint ) ( durationSeconds * 1000000 ) , ( uint ) frequency , WVR_Intensity . WVR_Intensity_Severe ) ;
794+ intensity = WVR_Intensity . WVR_Intensity_Severe ;
862795 }
863796 }
797+ Interop . WVR_TriggerVibration ( deviceInput . DeviceType , WVR_InputId . WVR_InputId_Alias1_Touchpad , ( uint ) ( durationSeconds * 1000000 ) , ( uint ) frequency , intensity ) ;
864798 }
865799#endif
866800#endif
0 commit comments