Skip to content

Commit c378eff

Browse files
author
lawwong
committed
Update to v1.14.0
* Changes - Add ability to identify ViveFlowPhoneController - Add plain fallback model for ViveFocus3Controller & ViveTracker3 - Add Input System support - Required [Input System](https://docs.unity3d.com/Manual/com.unity.inputsystem.html) installed in project - For example, now able to bind v3 position action from HandRole.RightHand device by setting binding path to - <VIUSyntheticDeviceLayoutHandRole>{RightHand}/position - Add new role type "PrimaryHandRole" - PrimaryHand maps first found controller/tracker/trackedhand accrodeing to which dominent hand - API to control PrimaryHandRole dominant hand: - ViveRole.DefaultPrimaryHandRoleHandler.DominantHand - ViveRole.DefaultPrimaryHandRoleHandler.SetRightDominantAndRefresh() - ViveRole.DefaultPrimaryHandRoleHandler.SetLeftDominantAndRefresh() - ViveRole.DefaultPrimaryHandRoleHandler.SwapDominantHandAndRefresh() * Bug Fixes - Fix LiteCoroutine DelayUpdateCall not working in some cases - Fix RenderModelHook shaderOverride not working
2 parents 525544a + bab1135 commit c378eff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+11696
-160
lines changed

Assets/HTC.UnityPlugin/HTC.ViveInputUtility.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"Controller",
1414
"Hand",
1515
"HTC.ViveHandTracking",
16-
"Wave.Essence.Controller.Model"
16+
"Wave.Essence.Controller.Model",
17+
"Unity.InputSystem"
1718
],
1819
"includePlatforms": [],
1920
"excludePlatforms": [],

Assets/HTC.UnityPlugin/LiteCoroutine/LiteCoroutineManager.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ private sealed class Manager : LiteCoroutineManager
5959
{
6060
private readonly YieldStackPool pool = new YieldStackPool();
6161
private readonly List<YieldStack> workingStacks = new List<YieldStack>();
62-
private readonly List<YieldStack> tempStageStackes = new List<YieldStack>();
63-
private readonly List<YieldStack> lateUpdateStageStackes = new List<YieldStack>();
64-
private readonly List<YieldStack> fixedUpdateStageStackes = new List<YieldStack>();
65-
private readonly List<YieldStack> endOfFrameStageStackes = new List<YieldStack>();
62+
private readonly List<YieldStack> tempStageStacks = new List<YieldStack>();
63+
private readonly List<YieldStack> lateUpdateStageStacks = new List<YieldStack>();
64+
private readonly List<YieldStack> fixedUpdateStageStacks = new List<YieldStack>();
65+
private readonly List<YieldStack> endOfFrameStageStacks = new List<YieldStack>();
6666
private Predicate<YieldStack> removeAllInvalidYieldStackPredicate;
6767

6868
private readonly object delayCallLock = new object();
@@ -189,7 +189,7 @@ private bool RemoveAllInvalidYieldStackPredicate(YieldStack stack)
189189
{
190190
if (stack.waitForUpdate)
191191
{
192-
tempStageStackes.Add(stack);
192+
tempStageStacks.Add(stack);
193193
}
194194
}
195195
else
@@ -213,14 +213,15 @@ public override void MainUpdate()
213213
{
214214
lock (workingStacks)
215215
{
216-
if (workingStacks.Count == 0) { return; }
217-
218-
workingStacks.RemoveAll(removeAllInvalidYieldStackPredicate);
216+
if (workingStacks.Count > 0)
217+
{
218+
workingStacks.RemoveAll(removeAllInvalidYieldStackPredicate);
219+
}
219220
}
220221

221-
if (tempStageStackes.Count > 0)
222+
if (tempStageStacks.Count > 0)
222223
{
223-
foreach (var stack in tempStageStackes)
224+
foreach (var stack in tempStageStacks)
224225
{
225226
if (!stack.MoveNext())
226227
{
@@ -248,28 +249,28 @@ public override void MainUpdate()
248249
}
249250
}
250251

251-
tempStageStackes.Clear();
252+
tempStageStacks.Clear();
252253
}
253254

254255
ExecuteDelayAction(ref delayUpdateCall);
255256
}
256257

257-
public override void LateUpdate() { PerformOtherStaget(lateUpdateStageStackes); ExecuteDelayAction(ref delayLateUpdateCall); }
258+
public override void LateUpdate() { PerformOtherStaget(lateUpdateStageStacks); ExecuteDelayAction(ref delayLateUpdateCall); }
258259

259-
public override void FixedeUpdate() { PerformOtherStaget(fixedUpdateStageStackes); ExecuteDelayAction(ref delayFixedUpdateCall); }
260+
public override void FixedeUpdate() { PerformOtherStaget(fixedUpdateStageStacks); ExecuteDelayAction(ref delayFixedUpdateCall); }
260261

261-
public override void EndOfFrameUpdate() { PerformOtherStaget(endOfFrameStageStackes); ExecuteDelayAction(ref delayEndOfFrameCall); }
262+
public override void EndOfFrameUpdate() { PerformOtherStaget(endOfFrameStageStacks); ExecuteDelayAction(ref delayEndOfFrameCall); }
262263

263264
private void PerformOtherStaget(List<YieldStack> stacks)
264265
{
265266
lock (stacks)
266267
{
267268
if (stacks.Count == 0) { return; }
268-
tempStageStackes.AddRange(stacks);
269+
tempStageStacks.AddRange(stacks);
269270
stacks.Clear();
270271
}
271272

272-
foreach (var stack in tempStageStackes)
273+
foreach (var stack in tempStageStacks)
273274
{
274275
var handle = stack.handle;
275276
lock (handle)
@@ -324,7 +325,7 @@ private void PerformOtherStaget(List<YieldStack> stacks)
324325
stack.waitForUpdate = true;
325326
}
326327

327-
tempStageStackes.Clear();
328+
tempStageStacks.Clear();
328329
}
329330

330331
public override void StopAllCoroutine()
@@ -352,17 +353,17 @@ private bool TryGetOtherStageFromYieldInstruction(YieldInstruction yieldInst, ou
352353
{
353354
if (yieldInst is WaitForLateUpdate)
354355
{
355-
stageStacks = lateUpdateStageStackes;
356+
stageStacks = lateUpdateStageStacks;
356357
return true;
357358
}
358359
else if (yieldInst is WaitForEndOfFrame)
359360
{
360-
stageStacks = endOfFrameStageStackes;
361+
stageStacks = endOfFrameStageStacks;
361362
return true;
362363
}
363364
else if (yieldInst is WaitForFixedUpdate)
364365
{
365-
stageStacks = fixedUpdateStageStackes;
366+
stageStacks = fixedUpdateStageStacks;
366367
return true;
367368
}
368369
else if (yieldInst is WaitForSeconds)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public override void CreateCamera(VRCameraHook hook)
163163
#endif
164164

165165
#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
166167
private class RenderModelCreator : RenderModelHook.RenderModelCreator
167168
{
168169
private uint m_index = INVALID_DEVICE_INDEX;
@@ -250,7 +251,7 @@ private bool IsHand()
250251
return m_index == s_leftHandIndex || m_index == s_rightHandIndex;
251252
}
252253
}
253-
254+
#endif
254255
private static OculusVRModule s_moduleInstance;
255256
#endif
256257

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ protected override void UpdateNewConnectedInputDevice(IVRModuleDeviceStateRW sta
8484
updateFunc = UpdateViveCosmosControllerState;
8585
break;
8686
case VRModuleDeviceModel.ViveTracker:
87+
case VRModuleDeviceModel.ViveTracker3:
8788
updateFunc = UpdateViveTrackerState;
8889
break;
8990
case VRModuleDeviceModel.OculusTouchLeft:
@@ -110,13 +111,14 @@ protected override void UpdateNewConnectedInputDevice(IVRModuleDeviceStateRW sta
110111
updateFunc = UpdateViveFocusChirpControllerState;
111112
break;
112113
case VRModuleDeviceModel.ViveFocusFinch:
114+
case VRModuleDeviceModel.ViveFlowPhoneController:
113115
updateFunc = UpdateViveFocusFinchControllerState;
114116
break;
115117
case VRModuleDeviceModel.KhronosSimpleController:
116118
updateFunc = UpdateKhronosSimpleControllerState;
117119
break;
118-
case VRModuleDeviceModel.WaveCRControllerLeft:
119-
case VRModuleDeviceModel.WaveCRControllerRight:
120+
case VRModuleDeviceModel.ViveFocus3ControllerLeft:
121+
case VRModuleDeviceModel.ViveFocus3ControllerRight:
120122
updateFunc = UpdateWaveCRControllerState;
121123
break;
122124
default:
@@ -209,7 +211,7 @@ private void UpdateUnknownControllerState(IVRModuleDeviceStateRW state, InputDev
209211
state.SetButtonTouch(VRModuleRawButton.Grip, gripButton);
210212
state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);
211213
state.SetButtonTouch(VRModuleRawButton.Joystick, secondary2DAxisTouch);
212-
214+
213215
state.SetAxisValue(VRModuleRawAxis.Trigger, triggerValue);
214216
state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, gripValue);
215217
state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxisValue.x);
@@ -245,7 +247,7 @@ private void UpdateViveControllerState(IVRModuleDeviceStateRW state, InputDevice
245247
{
246248
bool systemButton = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage<bool>("SystemButton")); // Always false
247249
float grip = GetDeviceFeatureValueOrDefault(device, CommonUsages.grip); // 0 or 1
248-
250+
249251
state.SetButtonPress(VRModuleRawButton.System, systemButton);
250252
state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
251253
}
@@ -423,9 +425,9 @@ private void UpdateWMRControllerState(IVRModuleDeviceStateRW state, InputDevice
423425
bool menuButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
424426
bool triggerButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);
425427
bool gripButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);
426-
428+
427429
float trigger = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);
428-
430+
429431
state.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuButton);
430432
state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);
431433
state.SetButtonPress(VRModuleRawButton.Grip, gripButton);

Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected enum DefaultModuleOrder
3636

3737
private static readonly Regex s_viveRgx = new Regex("^.*(vive|htc).*$", REGEX_OPTIONS);
3838
private static readonly Regex s_viveCosmosRgx = new Regex("^.*(cosmos).*$", REGEX_OPTIONS);
39+
private static readonly Regex s_ver3Rgx = new Regex("^.*3.0.*$", REGEX_OPTIONS);
3940
private static readonly Regex s_oculusRgx = new Regex("^.*(oculus|quest).*$", REGEX_OPTIONS);
4041
private static readonly Regex s_indexRgx = new Regex("^.*(index|knuckles).*$", REGEX_OPTIONS);
4142
private static readonly Regex s_knucklesRgx = new Regex("^.*(knu_ev1).*$", REGEX_OPTIONS);
@@ -49,16 +50,23 @@ protected enum DefaultModuleOrder
4950

5051
private struct WVRCtrlProfile
5152
{
53+
public Regex reg;
5254
public VRModuleDeviceModel model;
5355
public VRModuleInput2DType input2D;
5456
}
55-
private static Dictionary<string, WVRCtrlProfile> m_wvrModels = new Dictionary<string, WVRCtrlProfile>
57+
58+
private static WVRCtrlProfile[] s_wvrCtrlProfiles = new WVRCtrlProfile[]
5659
{
57-
{ "WVR_CONTROLLER_FINCH3DOF_2_0", new WVRCtrlProfile() { model = VRModuleDeviceModel.ViveFocusFinch, input2D = VRModuleInput2DType.TouchpadOnly } },
58-
{ "WVR_CONTROLLER_ASPEN_MI6_1", new WVRCtrlProfile() { model = VRModuleDeviceModel.ViveFocusChirp, input2D = VRModuleInput2DType.TouchpadOnly } },
59-
{ "WVR_CONTROLLER_ASPEN_XA_XB", new WVRCtrlProfile() { model = VRModuleDeviceModel.ViveFocusChirp, input2D = VRModuleInput2DType.TouchpadOnly } },
60-
{ "WVR_CR_Right_001", new WVRCtrlProfile() { model = VRModuleDeviceModel.WaveCRControllerRight, input2D = VRModuleInput2DType.JoystickOnly } },
61-
{ "WVR_CR_Left_001", new WVRCtrlProfile() { model = VRModuleDeviceModel.WaveCRControllerLeft, input2D = VRModuleInput2DType.JoystickOnly } },
60+
// WVR_CONTROLLER_FINCH3DOF_2_0_PAC_20_9_DARK
61+
new WVRCtrlProfile { reg = new Regex("^.*(pac).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFlowPhoneController, input2D = VRModuleInput2DType.TouchpadOnly },
62+
// WVR_CONTROLLER_FINCH3DOF_2_0
63+
new WVRCtrlProfile { reg = new Regex("^.*(finch).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocusFinch, input2D = VRModuleInput2DType.TouchpadOnly },
64+
// WVR_CONTROLLER_ASPEN_MI6_1, WVR_CONTROLLER_ASPEN_XA_XB
65+
new WVRCtrlProfile { reg = new Regex("^.*(aspen).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocusChirp, input2D = VRModuleInput2DType.TouchpadOnly },
66+
// WVR_CR_Left_001
67+
new WVRCtrlProfile { reg = new Regex("^.*(cr).(left)*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocus3ControllerLeft, input2D = VRModuleInput2DType.TouchpadOnly },
68+
// WVR_CR_Right_001
69+
new WVRCtrlProfile { reg = new Regex("^.*(cr).(right)*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocus3ControllerRight, input2D = VRModuleInput2DType.TouchpadOnly },
6270
};
6371

6472
public bool isActivated { get; private set; }
@@ -186,7 +194,14 @@ protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
186194
}
187195
return;
188196
case VRModuleDeviceClass.GenericTracker:
189-
deviceState.deviceModel = VRModuleDeviceModel.ViveTracker;
197+
if (s_ver3Rgx.IsMatch(deviceState.modelNumber))
198+
{
199+
deviceState.deviceModel = VRModuleDeviceModel.ViveTracker3;
200+
}
201+
else
202+
{
203+
deviceState.deviceModel = VRModuleDeviceModel.ViveTracker;
204+
}
190205
return;
191206
case VRModuleDeviceClass.TrackingReference:
192207
deviceState.deviceModel = VRModuleDeviceModel.ViveBaseStation;
@@ -362,12 +377,12 @@ protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
362377
return;
363378
case VRModuleDeviceClass.Controller:
364379
{
365-
foreach (var p in m_wvrModels)
380+
foreach (var p in s_wvrCtrlProfiles)
366381
{
367-
if (deviceState.modelNumber.Contains(p.Key))
382+
if (p.reg.IsMatch(deviceState.modelNumber))
368383
{
369-
deviceState.deviceModel = p.Value.model;
370-
deviceState.input2DType = p.Value.input2D;
384+
deviceState.deviceModel = p.model;
385+
deviceState.input2DType = p.input2D;
371386
return;
372387
}
373388
}

Assets/HTC.UnityPlugin/VRModule/VRModuleDeviceState.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ public enum VRModuleDeviceModel
6262
OculusTrackedHandLeft,
6363
OculusTrackedHandRight,
6464
KhronosSimpleController,
65-
WaveCRControllerLeft,
66-
WaveCRControllerRight,
65+
ViveFocus3ControllerLeft,
66+
ViveFocus3ControllerRight,
67+
[HideInInspector, Obsolete("Use ViveFocus3ControllerLeft instead.")]
68+
WaveCRControllerLeft = ViveFocus3ControllerLeft,
69+
[HideInInspector, Obsolete("Use ViveFocus3ControllerRight instead.")]
70+
WaveCRControllerRight = ViveFocus3ControllerRight,
6771
ViveTracker3,
72+
ViveFlowPhoneController,
6873
}
6974

7075
public enum VRModuleRawButton
@@ -106,7 +111,9 @@ public enum VRModuleRawButton
106111

107112
public enum VRModuleRawAxis
108113
{
114+
[HideInInspector]
109115
TouchpadX = Axis0X,
116+
[HideInInspector]
110117
TouchpadY = Axis0Y,
111118
Trigger = Axis1X,
112119
CapSenseGrip = Axis2X,
@@ -115,9 +122,16 @@ public enum VRModuleRawAxis
115122
RingCurl = Axis4X,
116123
PinkyCurl = Axis4Y,
117124

125+
[HideInInspector]
118126
JoystickX = Axis2X,
127+
[HideInInspector]
119128
JoystickY = Axis2Y,
120129

130+
Primary2DX = Axis0X,
131+
Primary2DY = Axis0Y,
132+
Secondary2DX = Axis2X,
133+
Secondary2DY = Axis2Y,
134+
121135
// alias
122136
Axis0X = 0,
123137
Axis0Y,
@@ -149,8 +163,8 @@ public enum VRModuleInput2DType
149163
JoystickOnly = ThumbstickOnly,
150164
}
151165

152-
internal class VRModuleDeviceClassReslver : EnumToIntResolver<VRModuleDeviceClass> { public override int Resolve(VRModuleDeviceClass e) { return (int)e; } }
153-
internal class VRModuleDeviceModelReslver : EnumToIntResolver<VRModuleDeviceModel> { public override int Resolve(VRModuleDeviceModel e) { return (int)e; } }
166+
internal class VRModuleDeviceClassResolver : EnumToIntResolver<VRModuleDeviceClass> { public override int Resolve(VRModuleDeviceClass e) { return (int)e; } }
167+
internal class VRModuleDeviceModelResolver : EnumToIntResolver<VRModuleDeviceModel> { public override int Resolve(VRModuleDeviceModel e) { return (int)e; } }
154168
internal class VRModuleRawButtonReslver : EnumToIntResolver<VRModuleRawButton> { public override int Resolve(VRModuleRawButton e) { return (int)e; } }
155169
internal class VRModuleRawAxisReslver : EnumToIntResolver<VRModuleRawAxis> { public override int Resolve(VRModuleRawAxis e) { return (int)e; } }
156170
internal class VRModuleInput2DTypeReslver : EnumToIntResolver<VRModuleInput2DType> { public override int Resolve(VRModuleInput2DType e) { return (int)e; } }

Assets/HTC.UnityPlugin/VRModule/VRModuleDeviceState.cs.meta

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/HTC.UnityPlugin/VRModule/VRModuleManager.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public partial class VRModule : SingletonBehaviour<VRModule>
5151
private DeviceState[] m_prevStates;
5252
private DeviceState[] m_currStates;
5353

54+
[RuntimeInitializeOnLoadMethod]
55+
private static void TryInitializeOnStartup()
56+
{
57+
if (VRModuleSettings.initializeOnStartup)
58+
{
59+
Initialize();
60+
}
61+
}
62+
5463
private static GameObject GetDefaultInitGameObject()
5564
{
5665
return new GameObject("[ViveInputUtility]");

Assets/HTC.UnityPlugin/VRModule/VRModuleSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ namespace HTC.UnityPlugin.VRModuleManagement
1010
public partial class VRModuleSettings : ScriptableObject
1111
{
1212
public const string DEFAULT_RESOURCE_PATH = "VRModuleSettings";
13+
public const string INITIALIZE_ON_STARTUP_TOOLTIP = "Auto initialize VIU core manager at the run time. If disabled and no VIU component used in the scene, manually calling VRModule.Initialize() is required if tempting to use VIUSyntheticDevice as Input System device or binding source.";
14+
public const bool INITIALIZE_ON_STARTUP_DEFAULT_VALUE = false;
15+
16+
[SerializeField, Tooltip(INITIALIZE_ON_STARTUP_TOOLTIP)]
17+
private bool m_initializeOnStartup = INITIALIZE_ON_STARTUP_DEFAULT_VALUE;
18+
public static bool initializeOnStartup { get { return Instance == null ? INITIALIZE_ON_STARTUP_DEFAULT_VALUE : s_instance.m_initializeOnStartup; } set { if (Instance != null) { Instance.m_initializeOnStartup = value; } } }
1319

1420
private static VRModuleSettings s_instance = null;
1521

Binary file not shown.

0 commit comments

Comments
 (0)