Skip to content

Commit 72f3611

Browse files
ChengNan Yanglawwong
authored andcommitted
Add Vive wrist tracker support
1 parent 32c8499 commit 72f3611

11 files changed

Lines changed: 208 additions & 34 deletions

File tree

Assets/HTC.UnityPlugin/VRModule/Modules/Editor/WaveVRModuleEditor.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,37 @@ public WaveVRSymbolRequirementCollection()
261261
},
262262
reqFileNames = new string[] { "WaveXRBuildCheck.cs" },
263263
});
264+
265+
Add(new SymbolRequirement()
266+
{
267+
symbol = "VIU_WAVEVR_TRACKER",
268+
reqMethods = new SymbolRequirement.ReqMethodInfo[]
269+
{
270+
new SymbolRequirement.ReqMethodInfo()
271+
{
272+
typeName = "Wave.Native.Interop",
273+
name = "WVR_StartTracker",
274+
bindingAttr = BindingFlags.Public | BindingFlags.Static,
275+
}
276+
},
277+
reqFileNames = new string[] { "wvr.cs" },
278+
});
279+
280+
Add(new SymbolRequirement()
281+
{
282+
symbol = "VIU_WAVEVR_TRACKER_CHECK",
283+
reqMethods = new SymbolRequirement.ReqMethodInfo[]
284+
{
285+
new SymbolRequirement.ReqMethodInfo()
286+
{
287+
typeName = "Wave.XR.BuildCheck.CheckIfTrackerEnabled",
288+
name = "ValidateEnabled",
289+
argTypeNames = new string[0],
290+
bindingAttr = BindingFlags.Public | BindingFlags.Static,
291+
}
292+
},
293+
reqFileNames = new string[] { "WaveXRBuildCheck.cs" },
294+
});
264295
}
265296
}
266297
}

Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModule.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ protected override void UpdateNewConnectedInputDevice(IVRModuleDeviceStateRW sta
123123
case VRModuleDeviceModel.ViveFocus3ControllerRight:
124124
updateFunc = UpdateWaveCRControllerState;
125125
break;
126+
case VRModuleDeviceModel.ViveWristTracker:
127+
updateFunc = UpdateViveWristTrackerState;
128+
break;
126129
default:
127130
updateFunc = UpdateUnknownControllerState;
128131
break;
@@ -595,6 +598,15 @@ private void UpdateKhronosSimpleControllerState(IVRModuleDeviceStateRW state, In
595598
// [Vector3] PointerAngularVelocity
596599
}
597600

601+
private void UpdateViveWristTrackerState(IVRModuleDeviceStateRW state, InputDevice device)
602+
{
603+
bool primaryButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryButton);
604+
bool menuButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
605+
606+
state.SetButtonPress(VRModuleRawButton.A, primaryButton);
607+
state.SetButtonPress(VRModuleRawButton.System, menuButton);
608+
}
609+
598610
private void UpdateWaveCRControllerState(IVRModuleDeviceStateRW state, InputDevice device)
599611
{
600612
bool primary2DAxisClick = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisClick);

Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModuleBase.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ private struct XRInputSubsystemProfile
8484
private uint moduleLeftIndex = INVALID_DEVICE_INDEX;
8585
private VRModule.SubmoduleBase.Collection submodules = new VRModule.SubmoduleBase.Collection(
8686
new ViveHandTrackingSubmodule(),
87-
new WaveHandTrackingSubmodule()
87+
new WaveHandTrackingSubmodule(),
88+
new WaveTrackerSubmodule()
8889
);
8990

9091
protected VRModuleKnownXRLoader KnownActiveLoader { get { return knownActiveLoader; } }
@@ -238,9 +239,9 @@ public sealed override void BeforeRenderUpdate()
238239

239240
// process hand role
240241
var subRightIndex = submodules.GetFirstRightHandedIndex();
241-
var currentRight = (subRightIndex == INVALID_DEVICE_INDEX || (TryGetValidDeviceState(uxrRightIndex, out prevState, out currState) && currState.isPoseValid)) ? uxrRightIndex : subRightIndex;
242+
var currentRight = (subRightIndex == INVALID_DEVICE_INDEX || (TryGetValidDeviceState(uxrRightIndex, out prevState, out currState) && currState.isPoseValid && currState.deviceClass == VRModuleDeviceClass.Controller)) ? uxrRightIndex : subRightIndex;
242243
var subLeftIndex = submodules.GetFirstLeftHandedIndex();
243-
var currentLeft = (subLeftIndex == INVALID_DEVICE_INDEX || (TryGetValidDeviceState(uxrLeftIndex, out prevState, out currState) && currState.isPoseValid)) ? uxrLeftIndex : subLeftIndex;
244+
var currentLeft = (subLeftIndex == INVALID_DEVICE_INDEX || (TryGetValidDeviceState(uxrLeftIndex, out prevState, out currState) && currState.isPoseValid && currState.deviceClass == VRModuleDeviceClass.Controller)) ? uxrLeftIndex : subLeftIndex;
244245
var roleChanged = ChangeProp.Set(ref moduleRightIndex, currentRight);
245246
roleChanged |= ChangeProp.Set(ref moduleLeftIndex, currentLeft);
246247

@@ -262,7 +263,8 @@ public override void Update()
262263
InputDevice device;
263264
if (indexMap.TryGetDevice(deviceIndex, out device))
264265
{
265-
if ((device.characteristics & InputDeviceCharacteristics.Controller) > 0)
266+
if ((device.characteristics & InputDeviceCharacteristics.Controller) > 0
267+
|| (device.characteristics & InputDeviceCharacteristics.TrackedDevice) > 0)
266268
{
267269
IVRModuleDeviceState prevState;
268270
IVRModuleDeviceStateRW currState;

Assets/HTC.UnityPlugin/VRModule/Modules/WaveVRModule.cs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,9 @@ public override void UpdateRenderModel()
6262
{
6363
if (!ChangeProp.Set(ref m_index, hook.GetModelDeviceIndex())) { return; }
6464

65-
if (VRModule.IsValidDeviceIndex(m_index) && m_index == VRModule.GetRightControllerDeviceIndex())
65+
if (VRModule.GetDeviceState(m_index).deviceClass == VRModuleDeviceClass.Controller)
6666
{
67-
if (VRModule.GetDeviceState(m_index).deviceClass == VRModuleDeviceClass.TrackedHand)
68-
{
69-
// VIUWaveVRRenderModel currently doesn't support tracked hand
70-
// Fallback to default model instead
71-
UpdateDefaultRenderModel(true);
72-
73-
if (m_modelObj != null)
74-
{
75-
m_modelObj.SetActive(false);
76-
}
77-
}
78-
else
67+
if (m_index == VRModule.GetRightControllerDeviceIndex())
7968
{
8069
UpdateDefaultRenderModel(false);
8170

@@ -100,20 +89,6 @@ public override void UpdateRenderModel()
10089

10190
m_modelObj.SetActive(true);
10291
}
103-
}
104-
else if (VRModule.IsValidDeviceIndex(m_index) && m_index == VRModule.GetLeftControllerDeviceIndex())
105-
{
106-
if (VRModule.GetDeviceState(m_index).deviceClass == VRModuleDeviceClass.TrackedHand)
107-
{
108-
// VIUSteamVRRenderModel currently doesn't support tracked hand
109-
// Fallback to default model instead
110-
UpdateDefaultRenderModel(true);
111-
112-
if (m_modelObj != null)
113-
{
114-
m_modelObj.SetActive(false);
115-
}
116-
}
11792
else
11893
{
11994
UpdateDefaultRenderModel(false);
@@ -145,6 +120,18 @@ public override void UpdateRenderModel()
145120
m_modelObj.SetActive(true);
146121
}
147122
}
123+
else if (VRModule.GetDeviceState(m_index).deviceClass == VRModuleDeviceClass.TrackedHand
124+
|| VRModule.GetDeviceState(m_index).deviceClass == VRModuleDeviceClass.GenericTracker)
125+
{
126+
//VIUWaveVRRenderModel currently doesn't support tracked hand
127+
// Fallback to default model instead
128+
UpdateDefaultRenderModel(true);
129+
130+
if (m_modelObj != null)
131+
{
132+
m_modelObj.SetActive(false);
133+
}
134+
}
148135
else
149136
{
150137
UpdateDefaultRenderModel(false);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//========= Copyright 2016-2022, HTC Corporation. All rights reserved. ===========
2+
3+
using UnityEngine;
4+
5+
namespace HTC.UnityPlugin.VRModuleManagement
6+
{
7+
public partial class VRModuleSettings : ScriptableObject
8+
{
9+
public const bool ACTIVATE_WAVE_TRACKER_SUBMODULE_DEFAULT_VALUE = true;
10+
11+
[SerializeField]
12+
private bool m_activateWaveTrackerSubmodule = ACTIVATE_WAVE_TRACKER_SUBMODULE_DEFAULT_VALUE;
13+
14+
public static bool activateWaveTrackerSubmodule { get { return Instance == null ? ACTIVATE_WAVE_TRACKER_SUBMODULE_DEFAULT_VALUE : s_instance.m_activateWaveTrackerSubmodule; } set { if (Instance != null) { Instance.m_activateWaveTrackerSubmodule = value; } } }
15+
}
16+
}

Assets/HTC.UnityPlugin/VRModule/Submodules/PartialSettings/WaveTrackerSubmoduleSettings.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//========= Copyright 2016-2022, HTC Corporation. All rights reserved. ===========
2+
3+
using UnityEngine;
4+
5+
#if VIU_WAVEVR_TRACKER
6+
using Wave.XR.Settings;
7+
#endif
8+
9+
namespace HTC.UnityPlugin.VRModuleManagement
10+
{
11+
public class WaveTrackerSubmodule : VRModule.SubmoduleBase
12+
{
13+
#if VIU_WAVEVR_TRACKER
14+
private static readonly string log_prefix = "[" + typeof(WaveTrackerSubmodule).Name + "] ";
15+
16+
public override bool ShouldActiveModule() { return VRModuleSettings.activateWaveTrackerSubmodule; }
17+
18+
protected override void OnActivated()
19+
{
20+
ActivateTracker(true);
21+
}
22+
23+
protected override void OnDeactivated()
24+
{
25+
ActivateTracker(false);
26+
}
27+
28+
private void ActivateTracker(bool enable)
29+
{
30+
WaveXRSettings settings = WaveXRSettings.GetInstance();
31+
if (settings != null && settings.EnableTracker != enable)
32+
{
33+
settings.EnableTracker = enable;
34+
Debug.Log(log_prefix + " ActivateTracker " + (settings.EnableTracker ? "Activate." : "Deactivate."));
35+
SettingsHelper.SetBool(WaveXRSettings.EnableTrackerText, settings.EnableTracker);
36+
}
37+
}
38+
#endif
39+
}
40+
}

Assets/HTC.UnityPlugin/VRModule/Submodules/WaveTrackerSubmodule.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected enum DefaultModuleOrder
4444
private static readonly Regex s_daydreamRgx = new Regex("^.*(daydream).*$", REGEX_OPTIONS);
4545
private static readonly Regex s_wmrRgx = new Regex("(^.*(asus|acer|dell|lenovo|hp|samsung|windowsmr|windows).*(mr|$))|spatial", REGEX_OPTIONS);
4646
private static readonly Regex s_magicLeapRgx = new Regex("^.*(magicleap).*$", REGEX_OPTIONS);
47-
private static readonly Regex s_waveVrRgx = new Regex("^.*(wvr).*$", REGEX_OPTIONS);
47+
private static readonly Regex s_waveVrRgx = new Regex("^.*(wvr|wave).*$", REGEX_OPTIONS);
4848
private static readonly Regex s_khrRgx = new Regex("^.*(khr).*$", REGEX_OPTIONS);
4949
private static readonly Regex s_leftRgx = new Regex("^.*(left|_l).*$", REGEX_OPTIONS);
5050
private static readonly Regex s_rightRgx = new Regex("^.*(right|_r).*$", REGEX_OPTIONS);
@@ -68,6 +68,8 @@ private struct WVRCtrlProfile
6868
new WVRCtrlProfile { reg = new Regex("cr.+left", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocus3ControllerLeft, input2D = VRModuleInput2DType.JoystickOnly },
6969
// WVR_CR_Right_001
7070
new WVRCtrlProfile { reg = new Regex("cr.+right", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocus3ControllerRight, input2D = VRModuleInput2DType.JoystickOnly },
71+
// Wave Tracker0 HTC-211012-Tracker0, Wave Tracker1 HTC-211012-Tracker1
72+
new WVRCtrlProfile { reg = new Regex("^.*(tracker).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveWristTracker, input2D = VRModuleInput2DType.None },
7173
};
7274

7375
public bool isActivated { get; private set; }
@@ -401,6 +403,19 @@ protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
401403
}
402404
}
403405
break;
406+
case VRModuleDeviceClass.GenericTracker:
407+
{
408+
foreach (var p in s_wvrCtrlProfiles)
409+
{
410+
if (p.reg.IsMatch(deviceState.modelNumber))
411+
{
412+
deviceState.deviceModel = p.model;
413+
deviceState.input2DType = p.input2D;
414+
return;
415+
}
416+
}
417+
}
418+
break;
404419
}
405420
}
406421
else if (s_khrRgx.IsMatch(deviceState.modelNumber))

Assets/HTC.UnityPlugin/VRModule/VRModuleDeviceState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public enum VRModuleDeviceModel
7272
ViveFlowPhoneController,
7373
OculusQuest2ControllerLeft,
7474
OculusQuest2ControllerRight,
75+
ViveWristTracker,
7576
}
7677

7778
public enum VRModuleRawButton

0 commit comments

Comments
 (0)