Skip to content

Commit b6da0d3

Browse files
author
lawwong
committed
Add UnityXRHandSubmodule
1 parent 0fa96aa commit b6da0d3

File tree

12 files changed

+2530
-23
lines changed

12 files changed

+2530
-23
lines changed

Assets/HTC.UnityPlugin/HTC.ViveInputUtility.asmdef

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"Wave.Essence.Controller.Model",
1818
"Unity.InputSystem",
1919
"Unity.XR.OpenXR",
20-
"Wave.XRSDK"
20+
"Wave.XRSDK",
21+
"Unity.XR.Hands"
2122
],
2223
"includePlatforms": [],
2324
"excludePlatforms": [],
@@ -36,6 +37,11 @@
3637
"name": "com.htc.upm.wave.essence",
3738
"expression": "5.4.0",
3839
"define": "VIU_WAVE_ESSENCE_5_4_OR_NEWER"
40+
},
41+
{
42+
"name": "com.unity.xr.hands",
43+
"expression": "",
44+
"define": "VIU_UNITY_XR_HAND"
3945
}
4046
],
4147
"noEngineReferences": false

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,19 @@ static OculusVRModule()
474474
#endif
475475
}
476476

477+
private static string s_loaderNameCache;
478+
private static VRModuleKnownXRLoader s_knownLoaderCache;
477479
public override bool ShouldActiveModule()
478480
{
479481
if (!VIUSettings.activateOculusVRModule) { return false; }
480482
#pragma warning disable 0162
481483
#if VIU_XR_GENERAL_SETTINGS
482-
return UnityXRModuleBase.HasActiveLoader(OCULUS_XR_LOADER_NAME);
484+
if (!UnityXRModuleBase.TryGetActiveLoaderName(out var loaderName)) { return false; }
485+
if (s_loaderNameCache != loaderName) {
486+
s_loaderNameCache = loaderName;
487+
s_knownLoaderCache = UnityXRModuleBase.ToKnownXRLoader(loaderName);
488+
}
489+
return s_knownLoaderCache == VRModuleKnownXRLoader.Oculus;
483490
#endif
484491
#if UNITY_2019_3_OR_NEWER
485492
return false;

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ private static int CompareRoleIdx(RoleIdx a, RoleIdx b)
131131
private static string shortIdx(uint i) { return i == INVALID_DEVICE_INDEX ? "X" : i.ToString(); }
132132

133133
private VRModule.SubmoduleBase.Collection submodules = new VRModule.SubmoduleBase.Collection(
134-
new ViveHandTrackingSubmodule(),
135-
new WaveHandTrackingSubmodule(),
136-
new WaveTrackerSubmodule()
134+
new ViveHandTrackingSubmodule()
135+
, new WaveHandTrackingSubmodule()
136+
, new WaveTrackerSubmodule()
137+
, new UnityXRHandSubmodule()
137138
);
138139

139140
private bool[] prevDeviceConnected = new bool[VRModule.MAX_DEVICE_COUNT];
@@ -160,11 +161,12 @@ public override void OnActivated()
160161
EnsureDeviceStateLength(8);
161162
UpdateTrackingSpaceType();
162163
submodules.ActivateAllModules();
163-
Debug.Log("Activated XRLoader Name: " + XRGeneralSettings.Instance.Manager.activeLoader.name);
164+
Debug.Log("[UnityXRModule] OnActivated XRLoader Name: " + XRGeneralSettings.Instance.Manager.activeLoader.name);
164165
}
165166

166167
public override void OnDeactivated()
167168
{
169+
Debug.Log("[UnityXRModule] OnDeactivated");
168170
submodules.DeactivateAllModules();
169171
indexMap.Clear();
170172
}
@@ -208,7 +210,6 @@ public sealed override void BeforeRenderUpdate()
208210
if (!indexMap.TryGetIndex(device, out deviceIndex))
209211
{
210212
string deviceName;
211-
212213
if (indexMap.TryMapAsHMD(device))
213214
{
214215
deviceIndex = VRModule.HMD_DEVICE_INDEX;
@@ -272,27 +273,28 @@ public sealed override void BeforeRenderUpdate()
272273
if ((device.characteristics & InputDeviceCharacteristics.Right) != 0u) { rightIndice.Add(new RoleIdx(currState)); }
273274
else if ((device.characteristics & InputDeviceCharacteristics.Left) != 0u) { leftIndice.Add(new RoleIdx(currState)); }
274275
}
275-
276276
// TODO: update hand skeleton pose
277277
}
278278

279279
// unmap index for disconnected device state
280-
for (uint i = 0u, imax = (uint)prevMaxConnectedIndex; i <= imax; ++i)
280+
for (int i = 0, imax = prevMaxConnectedIndex; i <= imax; ++i)
281281
{
282282
if (prevDeviceConnected[i] && !currDeviceConnected[i])
283283
{
284-
if (indexMap.IsMapped(i))
284+
if (indexMap.IsMapped((uint)i))
285285
{
286-
indexMap.UnmapByIndex(i);
286+
indexMap.UnmapByIndex((uint)i);
287+
//Debug.Log("[UnityXRModule] unmap [" + i + "]");
287288
}
288289
else
289290
{
290291
Debug.LogWarning("[UnityXRModule] unmap failed: [" + i + "] already unmapped");
291292
}
292293

293-
if (TryGetValidDeviceState(i, out prevState, out currState) && currState.isConnected)
294+
if (TryGetValidDeviceState((uint)i, out prevState, out currState) && currState.isConnected)
294295
{
295296
currState.Reset();
297+
//Debug.Log("[UnityXRModule] reset [" + i + "]");
296298
}
297299
else
298300
{
@@ -410,6 +412,11 @@ protected static VRModuleDeviceClass GetDeviceClass(string name, InputDeviceChar
410412
return VRModuleDeviceClass.TrackingReference;
411413
}
412414

415+
if ((characteristics & InputDeviceCharacteristics.HandTracking) != 0)
416+
{
417+
return VRModuleDeviceClass.Invalid;
418+
}
419+
413420
if ((characteristics & InputDeviceCharacteristics.TrackedDevice) != 0)
414421
{
415422
return VRModuleDeviceClass.GenericTracker;

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static bool HasActiveLoader(string loaderName)
161161
public static bool HasActiveLoader(VRModuleKnownXRLoader knownLoader)
162162
{
163163
string activeLoaderName;
164-
return TryGetActiveLoaderName(out activeLoaderName) && knownLoader == ToKnownXRLoader(activeLoaderName);
164+
return TryGetActiveLoaderName(out activeLoaderName) && (knownLoader == ToKnownXRLoader(activeLoaderName));
165165
}
166166

167167
public static VRModuleKnownXRLoader GetKnownActiveLoader()
@@ -178,14 +178,7 @@ public static VRModuleKnownXRLoader GetKnownActiveLoader()
178178
var loaderName = loader.name;
179179
if (string.IsNullOrEmpty(loaderName)) { return VRModuleKnownXRLoader.Unknown; }
180180

181-
foreach (var profile in loaderProfiles)
182-
{
183-
if (string.IsNullOrEmpty(profile.fixedName) || profile.fixedName != loaderName) { continue; }
184-
if (profile.matchNameRgx == null || !profile.matchNameRgx.IsMatch(loaderName)) { continue; }
185-
return profile.loader;
186-
}
187-
188-
return VRModuleKnownXRLoader.Unknown;
181+
return ToKnownXRLoader(loaderName);
189182
}
190183

191184
public static VRModuleKnownXRLoader ToKnownXRLoader(string loaderName)

0 commit comments

Comments
 (0)