Skip to content

Commit

Permalink
Update to v1.14.0
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lawwong committed Dec 3, 2021
2 parents 525544a + bab1135 commit c378eff
Show file tree
Hide file tree
Showing 41 changed files with 11,696 additions and 160 deletions.
3 changes: 2 additions & 1 deletion Assets/HTC.UnityPlugin/HTC.ViveInputUtility.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"Controller",
"Hand",
"HTC.ViveHandTracking",
"Wave.Essence.Controller.Model"
"Wave.Essence.Controller.Model",
"Unity.InputSystem"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
41 changes: 21 additions & 20 deletions Assets/HTC.UnityPlugin/LiteCoroutine/LiteCoroutineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ private sealed class Manager : LiteCoroutineManager
{
private readonly YieldStackPool pool = new YieldStackPool();
private readonly List<YieldStack> workingStacks = new List<YieldStack>();
private readonly List<YieldStack> tempStageStackes = new List<YieldStack>();
private readonly List<YieldStack> lateUpdateStageStackes = new List<YieldStack>();
private readonly List<YieldStack> fixedUpdateStageStackes = new List<YieldStack>();
private readonly List<YieldStack> endOfFrameStageStackes = new List<YieldStack>();
private readonly List<YieldStack> tempStageStacks = new List<YieldStack>();
private readonly List<YieldStack> lateUpdateStageStacks = new List<YieldStack>();
private readonly List<YieldStack> fixedUpdateStageStacks = new List<YieldStack>();
private readonly List<YieldStack> endOfFrameStageStacks = new List<YieldStack>();
private Predicate<YieldStack> removeAllInvalidYieldStackPredicate;

private readonly object delayCallLock = new object();
Expand Down Expand Up @@ -189,7 +189,7 @@ private bool RemoveAllInvalidYieldStackPredicate(YieldStack stack)
{
if (stack.waitForUpdate)
{
tempStageStackes.Add(stack);
tempStageStacks.Add(stack);
}
}
else
Expand All @@ -213,14 +213,15 @@ public override void MainUpdate()
{
lock (workingStacks)
{
if (workingStacks.Count == 0) { return; }

workingStacks.RemoveAll(removeAllInvalidYieldStackPredicate);
if (workingStacks.Count > 0)
{
workingStacks.RemoveAll(removeAllInvalidYieldStackPredicate);
}
}

if (tempStageStackes.Count > 0)
if (tempStageStacks.Count > 0)
{
foreach (var stack in tempStageStackes)
foreach (var stack in tempStageStacks)
{
if (!stack.MoveNext())
{
Expand Down Expand Up @@ -248,28 +249,28 @@ public override void MainUpdate()
}
}

tempStageStackes.Clear();
tempStageStacks.Clear();
}

ExecuteDelayAction(ref delayUpdateCall);
}

public override void LateUpdate() { PerformOtherStaget(lateUpdateStageStackes); ExecuteDelayAction(ref delayLateUpdateCall); }
public override void LateUpdate() { PerformOtherStaget(lateUpdateStageStacks); ExecuteDelayAction(ref delayLateUpdateCall); }

public override void FixedeUpdate() { PerformOtherStaget(fixedUpdateStageStackes); ExecuteDelayAction(ref delayFixedUpdateCall); }
public override void FixedeUpdate() { PerformOtherStaget(fixedUpdateStageStacks); ExecuteDelayAction(ref delayFixedUpdateCall); }

public override void EndOfFrameUpdate() { PerformOtherStaget(endOfFrameStageStackes); ExecuteDelayAction(ref delayEndOfFrameCall); }
public override void EndOfFrameUpdate() { PerformOtherStaget(endOfFrameStageStacks); ExecuteDelayAction(ref delayEndOfFrameCall); }

private void PerformOtherStaget(List<YieldStack> stacks)
{
lock (stacks)
{
if (stacks.Count == 0) { return; }
tempStageStackes.AddRange(stacks);
tempStageStacks.AddRange(stacks);
stacks.Clear();
}

foreach (var stack in tempStageStackes)
foreach (var stack in tempStageStacks)
{
var handle = stack.handle;
lock (handle)
Expand Down Expand Up @@ -324,7 +325,7 @@ private void PerformOtherStaget(List<YieldStack> stacks)
stack.waitForUpdate = true;
}

tempStageStackes.Clear();
tempStageStacks.Clear();
}

public override void StopAllCoroutine()
Expand Down Expand Up @@ -352,17 +353,17 @@ private bool TryGetOtherStageFromYieldInstruction(YieldInstruction yieldInst, ou
{
if (yieldInst is WaitForLateUpdate)
{
stageStacks = lateUpdateStageStackes;
stageStacks = lateUpdateStageStacks;
return true;
}
else if (yieldInst is WaitForEndOfFrame)
{
stageStacks = endOfFrameStageStackes;
stageStacks = endOfFrameStageStacks;
return true;
}
else if (yieldInst is WaitForFixedUpdate)
{
stageStacks = fixedUpdateStageStackes;
stageStacks = fixedUpdateStageStacks;
return true;
}
else if (yieldInst is WaitForSeconds)
Expand Down
3 changes: 2 additions & 1 deletion Assets/HTC.UnityPlugin/VRModule/Modules/OculusVRModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public override void CreateCamera(VRCameraHook hook)
#endif

#if VIU_OCULUSVR_1_32_0_OR_NEWER || VIU_OCULUSVR_1_36_0_OR_NEWER || VIU_OCULUSVR_1_37_0_OR_NEWER
#if VIU_OCULUSVR_AVATAR
private class RenderModelCreator : RenderModelHook.RenderModelCreator
{
private uint m_index = INVALID_DEVICE_INDEX;
Expand Down Expand Up @@ -250,7 +251,7 @@ private bool IsHand()
return m_index == s_leftHandIndex || m_index == s_rightHandIndex;
}
}

#endif
private static OculusVRModule s_moduleInstance;
#endif

Expand Down
14 changes: 8 additions & 6 deletions Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected override void UpdateNewConnectedInputDevice(IVRModuleDeviceStateRW sta
updateFunc = UpdateViveCosmosControllerState;
break;
case VRModuleDeviceModel.ViveTracker:
case VRModuleDeviceModel.ViveTracker3:
updateFunc = UpdateViveTrackerState;
break;
case VRModuleDeviceModel.OculusTouchLeft:
Expand All @@ -110,13 +111,14 @@ protected override void UpdateNewConnectedInputDevice(IVRModuleDeviceStateRW sta
updateFunc = UpdateViveFocusChirpControllerState;
break;
case VRModuleDeviceModel.ViveFocusFinch:
case VRModuleDeviceModel.ViveFlowPhoneController:
updateFunc = UpdateViveFocusFinchControllerState;
break;
case VRModuleDeviceModel.KhronosSimpleController:
updateFunc = UpdateKhronosSimpleControllerState;
break;
case VRModuleDeviceModel.WaveCRControllerLeft:
case VRModuleDeviceModel.WaveCRControllerRight:
case VRModuleDeviceModel.ViveFocus3ControllerLeft:
case VRModuleDeviceModel.ViveFocus3ControllerRight:
updateFunc = UpdateWaveCRControllerState;
break;
default:
Expand Down Expand Up @@ -209,7 +211,7 @@ private void UpdateUnknownControllerState(IVRModuleDeviceStateRW state, InputDev
state.SetButtonTouch(VRModuleRawButton.Grip, gripButton);
state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);
state.SetButtonTouch(VRModuleRawButton.Joystick, secondary2DAxisTouch);

state.SetAxisValue(VRModuleRawAxis.Trigger, triggerValue);
state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, gripValue);
state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxisValue.x);
Expand Down Expand Up @@ -245,7 +247,7 @@ private void UpdateViveControllerState(IVRModuleDeviceStateRW state, InputDevice
{
bool systemButton = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage<bool>("SystemButton")); // Always false
float grip = GetDeviceFeatureValueOrDefault(device, CommonUsages.grip); // 0 or 1

state.SetButtonPress(VRModuleRawButton.System, systemButton);
state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
}
Expand Down Expand Up @@ -423,9 +425,9 @@ private void UpdateWMRControllerState(IVRModuleDeviceStateRW state, InputDevice
bool menuButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
bool triggerButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);
bool gripButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);

float trigger = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);

state.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuButton);
state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);
state.SetButtonPress(VRModuleRawButton.Grip, gripButton);
Expand Down
37 changes: 26 additions & 11 deletions Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected enum DefaultModuleOrder

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

private struct WVRCtrlProfile
{
public Regex reg;
public VRModuleDeviceModel model;
public VRModuleInput2DType input2D;
}
private static Dictionary<string, WVRCtrlProfile> m_wvrModels = new Dictionary<string, WVRCtrlProfile>

private static WVRCtrlProfile[] s_wvrCtrlProfiles = new WVRCtrlProfile[]
{
{ "WVR_CONTROLLER_FINCH3DOF_2_0", new WVRCtrlProfile() { model = VRModuleDeviceModel.ViveFocusFinch, input2D = VRModuleInput2DType.TouchpadOnly } },
{ "WVR_CONTROLLER_ASPEN_MI6_1", new WVRCtrlProfile() { model = VRModuleDeviceModel.ViveFocusChirp, input2D = VRModuleInput2DType.TouchpadOnly } },
{ "WVR_CONTROLLER_ASPEN_XA_XB", new WVRCtrlProfile() { model = VRModuleDeviceModel.ViveFocusChirp, input2D = VRModuleInput2DType.TouchpadOnly } },
{ "WVR_CR_Right_001", new WVRCtrlProfile() { model = VRModuleDeviceModel.WaveCRControllerRight, input2D = VRModuleInput2DType.JoystickOnly } },
{ "WVR_CR_Left_001", new WVRCtrlProfile() { model = VRModuleDeviceModel.WaveCRControllerLeft, input2D = VRModuleInput2DType.JoystickOnly } },
// WVR_CONTROLLER_FINCH3DOF_2_0_PAC_20_9_DARK
new WVRCtrlProfile { reg = new Regex("^.*(pac).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFlowPhoneController, input2D = VRModuleInput2DType.TouchpadOnly },
// WVR_CONTROLLER_FINCH3DOF_2_0
new WVRCtrlProfile { reg = new Regex("^.*(finch).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocusFinch, input2D = VRModuleInput2DType.TouchpadOnly },
// WVR_CONTROLLER_ASPEN_MI6_1, WVR_CONTROLLER_ASPEN_XA_XB
new WVRCtrlProfile { reg = new Regex("^.*(aspen).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocusChirp, input2D = VRModuleInput2DType.TouchpadOnly },
// WVR_CR_Left_001
new WVRCtrlProfile { reg = new Regex("^.*(cr).(left)*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocus3ControllerLeft, input2D = VRModuleInput2DType.TouchpadOnly },
// WVR_CR_Right_001
new WVRCtrlProfile { reg = new Regex("^.*(cr).(right)*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocus3ControllerRight, input2D = VRModuleInput2DType.TouchpadOnly },
};

public bool isActivated { get; private set; }
Expand Down Expand Up @@ -186,7 +194,14 @@ protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
}
return;
case VRModuleDeviceClass.GenericTracker:
deviceState.deviceModel = VRModuleDeviceModel.ViveTracker;
if (s_ver3Rgx.IsMatch(deviceState.modelNumber))
{
deviceState.deviceModel = VRModuleDeviceModel.ViveTracker3;
}
else
{
deviceState.deviceModel = VRModuleDeviceModel.ViveTracker;
}
return;
case VRModuleDeviceClass.TrackingReference:
deviceState.deviceModel = VRModuleDeviceModel.ViveBaseStation;
Expand Down Expand Up @@ -362,12 +377,12 @@ protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
return;
case VRModuleDeviceClass.Controller:
{
foreach (var p in m_wvrModels)
foreach (var p in s_wvrCtrlProfiles)
{
if (deviceState.modelNumber.Contains(p.Key))
if (p.reg.IsMatch(deviceState.modelNumber))
{
deviceState.deviceModel = p.Value.model;
deviceState.input2DType = p.Value.input2D;
deviceState.deviceModel = p.model;
deviceState.input2DType = p.input2D;
return;
}
}
Expand Down
22 changes: 18 additions & 4 deletions Assets/HTC.UnityPlugin/VRModule/VRModuleDeviceState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ public enum VRModuleDeviceModel
OculusTrackedHandLeft,
OculusTrackedHandRight,
KhronosSimpleController,
WaveCRControllerLeft,
WaveCRControllerRight,
ViveFocus3ControllerLeft,
ViveFocus3ControllerRight,
[HideInInspector, Obsolete("Use ViveFocus3ControllerLeft instead.")]
WaveCRControllerLeft = ViveFocus3ControllerLeft,
[HideInInspector, Obsolete("Use ViveFocus3ControllerRight instead.")]
WaveCRControllerRight = ViveFocus3ControllerRight,
ViveTracker3,
ViveFlowPhoneController,
}

public enum VRModuleRawButton
Expand Down Expand Up @@ -106,7 +111,9 @@ public enum VRModuleRawButton

public enum VRModuleRawAxis
{
[HideInInspector]
TouchpadX = Axis0X,
[HideInInspector]
TouchpadY = Axis0Y,
Trigger = Axis1X,
CapSenseGrip = Axis2X,
Expand All @@ -115,9 +122,16 @@ public enum VRModuleRawAxis
RingCurl = Axis4X,
PinkyCurl = Axis4Y,

[HideInInspector]
JoystickX = Axis2X,
[HideInInspector]
JoystickY = Axis2Y,

Primary2DX = Axis0X,
Primary2DY = Axis0Y,
Secondary2DX = Axis2X,
Secondary2DY = Axis2Y,

// alias
Axis0X = 0,
Axis0Y,
Expand Down Expand Up @@ -149,8 +163,8 @@ public enum VRModuleInput2DType
JoystickOnly = ThumbstickOnly,
}

internal class VRModuleDeviceClassReslver : EnumToIntResolver<VRModuleDeviceClass> { public override int Resolve(VRModuleDeviceClass e) { return (int)e; } }
internal class VRModuleDeviceModelReslver : EnumToIntResolver<VRModuleDeviceModel> { public override int Resolve(VRModuleDeviceModel e) { return (int)e; } }
internal class VRModuleDeviceClassResolver : EnumToIntResolver<VRModuleDeviceClass> { public override int Resolve(VRModuleDeviceClass e) { return (int)e; } }
internal class VRModuleDeviceModelResolver : EnumToIntResolver<VRModuleDeviceModel> { public override int Resolve(VRModuleDeviceModel e) { return (int)e; } }
internal class VRModuleRawButtonReslver : EnumToIntResolver<VRModuleRawButton> { public override int Resolve(VRModuleRawButton e) { return (int)e; } }
internal class VRModuleRawAxisReslver : EnumToIntResolver<VRModuleRawAxis> { public override int Resolve(VRModuleRawAxis e) { return (int)e; } }
internal class VRModuleInput2DTypeReslver : EnumToIntResolver<VRModuleInput2DType> { public override int Resolve(VRModuleInput2DType e) { return (int)e; } }
Expand Down
3 changes: 1 addition & 2 deletions Assets/HTC.UnityPlugin/VRModule/VRModuleDeviceState.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/HTC.UnityPlugin/VRModule/VRModuleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public partial class VRModule : SingletonBehaviour<VRModule>
private DeviceState[] m_prevStates;
private DeviceState[] m_currStates;

[RuntimeInitializeOnLoadMethod]
private static void TryInitializeOnStartup()
{
if (VRModuleSettings.initializeOnStartup)
{
Initialize();
}
}

private static GameObject GetDefaultInitGameObject()
{
return new GameObject("[ViveInputUtility]");
Expand Down
6 changes: 6 additions & 0 deletions Assets/HTC.UnityPlugin/VRModule/VRModuleSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ namespace HTC.UnityPlugin.VRModuleManagement
public partial class VRModuleSettings : ScriptableObject
{
public const string DEFAULT_RESOURCE_PATH = "VRModuleSettings";
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.";
public const bool INITIALIZE_ON_STARTUP_DEFAULT_VALUE = false;

[SerializeField, Tooltip(INITIALIZE_ON_STARTUP_TOOLTIP)]
private bool m_initializeOnStartup = INITIALIZE_ON_STARTUP_DEFAULT_VALUE;
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; } } }

private static VRModuleSettings s_instance = null;

Expand Down
Binary file not shown.
Loading

0 comments on commit c378eff

Please sign in to comment.