Skip to content

Commit 726fe83

Browse files
author
Michael Hoffman
authored
Merge pull request #10374 from microsoft/OculusVisMerge
Oculus visualization now integrated with MRTK (#10067)
2 parents 75e30f8 + d913b85 commit 726fe83

File tree

5 files changed

+99
-36
lines changed

5 files changed

+99
-36
lines changed

Assets/MRTK/Core/Inspectors/Profiles/MixedRealityControllerVisualizationProfileInspector.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,6 @@ private void RenderControllerList(SerializedProperty controllerList)
230230
{
231231
EditorGUILayout.HelpBox("A controller type must be defined!", MessageType.Error);
232232
}
233-
else
234-
{
235-
// Only check for Oculus if we already know the type is valid (otherwise, null ref)
236-
bool isOculusType = controllerType.Type.FullName.Contains("OculusXRSDKTouchController");
237-
if (isOculusType)
238-
{
239-
EditorGUILayout.HelpBox("Oculus Touch controller model visualization is not managed by MRTK, refer to the Oculus XRSDK Device Manager to configure controller visualization settings", MessageType.Error);
240-
}
241-
}
242233

243234
var handednessValue = mixedRealityControllerHandedness.intValue - 1;
244235

Assets/MRTK/Providers/Oculus/XRSDK/Controllers/OculusXRSDKTouchController.cs

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using UnityEngine;
99
using UnityEngine.XR;
1010
using System;
11+
using System.Threading.Tasks;
12+
using System.Threading;
1113

1214
#if OCULUS_ENABLED
1315
using Unity.XR.Oculus;
@@ -33,6 +35,8 @@ public OculusXRSDKTouchController(
3335
: base(trackingState, controllerHandedness, inputSource, interactions, new OculusTouchControllerDefinition(controllerHandedness))
3436
{ }
3537

38+
internal GameObject OculusControllerVisualization { get; private set; }
39+
3640
private static readonly ProfilerMarker UpdateButtonDataPerfMarker = new ProfilerMarker("[MRTK] OculusXRSDKController.UpdateButtonData");
3741

3842
protected override void UpdateButtonData(MixedRealityInteractionMapping interactionMapping, InputDevice inputDevice)
@@ -91,25 +95,58 @@ protected override void UpdateButtonData(MixedRealityInteractionMapping interact
9195
}
9296
}
9397

94-
/// <summary>
95-
/// Determines whether or not this controller is using MRTK for controller visualization
96-
///
97-
/// When false, the Oculus Touch controller model visualization will not be managed by MRTK
98-
/// Ensure that the Oculus Integration Package is installed and the Ovr Camera Rig is set correctly in the Oculus XRSDK Device Manager to use the
99-
/// Oculus Integration Package's visualization
100-
/// </summary>
101-
internal bool UseMRTKControllerVisualization
98+
/// <inheritdoc />
99+
protected override bool TryRenderControllerModel(System.Type controllerType, InputSourceType inputSourceType)
102100
{
103-
get
101+
if (GetControllerVisualizationProfile() != null &&
102+
GetControllerVisualizationProfile().GetUsePlatformModelsOverride(GetType(), ControllerHandedness))
103+
{
104+
TryRenderControllerModelFromOculus();
105+
return true;
106+
}
107+
else
104108
{
105-
return Visualizer != null && Visualizer.GameObjectProxy != null && Visualizer.GameObjectProxy.activeSelf;
109+
return base.TryRenderControllerModel(controllerType, inputSourceType);
106110
}
107-
set
111+
}
112+
113+
private async void TryRenderControllerModelFromOculus()
114+
{
115+
await WaitForOculusVisuals();
116+
117+
if (this != null)
108118
{
109-
if(Visualizer != null && Visualizer.GameObjectProxy)
119+
if (OculusControllerVisualization != null
120+
&& MixedRealityControllerModelHelpers.TryAddVisualizationScript(OculusControllerVisualization, GetType(), ControllerHandedness)
121+
&& TryAddControllerModelToSceneHierarchy(OculusControllerVisualization))
110122
{
111-
Visualizer.GameObjectProxy.SetActive(value);
123+
OculusControllerVisualization.SetActive(true);
124+
return;
112125
}
126+
127+
Debug.LogWarning("Failed to obtain Oculus controller model; defaulting to BaseController behavior.");
128+
base.TryRenderControllerModel(GetType(), InputSource.SourceType);
129+
}
130+
}
131+
132+
private const int controllerInitializationTimeout = 1000;
133+
private async Task WaitForOculusVisuals()
134+
{
135+
int timeWaited = 0;
136+
while (OculusControllerVisualization == null || timeWaited > controllerInitializationTimeout)
137+
{
138+
await Task.Delay(100);
139+
timeWaited += 100;
140+
}
141+
}
142+
143+
internal void RegisterControllerVisualization(GameObject visualization)
144+
{
145+
OculusControllerVisualization = visualization;
146+
if (GetControllerVisualizationProfile() != null &&
147+
!GetControllerVisualizationProfile().GetUsePlatformModelsOverride(GetType(), ControllerHandedness))
148+
{
149+
OculusControllerVisualization.SetActive(false);
113150
}
114151
}
115152
}

Assets/MRTK/Providers/Oculus/XRSDK/OculusXRSDKDeviceManager.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#if OCULUSINTEGRATION_PRESENT
1616
using System.Collections.Generic;
17-
using UnityEngine;
1817
#endif // OCULUSINTEGRATION_PRESENT
1918

2019
namespace Microsoft.MixedReality.Toolkit.XRSDK.Oculus.Input
@@ -58,6 +57,8 @@ public override void Initialize()
5857
private readonly Dictionary<Handedness, OculusHand> trackedHands = new Dictionary<Handedness, OculusHand>();
5958

6059
private OVRCameraRig cameraRig;
60+
private OVRControllerHelper leftControllerHelper;
61+
private OVRControllerHelper rightControllerHelper;
6162

6263
private OVRHand rightHand;
6364
private OVRSkeleton rightSkeleton;
@@ -95,9 +96,23 @@ public override bool CheckCapability(MixedRealityCapability capability)
9596
protected override GenericXRSDKController GetOrAddController(InputDevice inputDevice)
9697
{
9798
GenericXRSDKController controller = base.GetOrAddController(inputDevice);
98-
if (controller is OculusXRSDKTouchController oculusTouchController)
99+
100+
if (!cameraRig.IsNull() && controller is OculusXRSDKTouchController oculusTouchController && oculusTouchController.OculusControllerVisualization == null)
99101
{
100-
oculusTouchController.UseMRTKControllerVisualization = cameraRig.IsNull();
102+
GameObject platformVisualization = null;
103+
if (oculusTouchController.ControllerHandedness == Handedness.Left)
104+
{
105+
platformVisualization = leftControllerHelper.gameObject;
106+
}
107+
if (oculusTouchController.ControllerHandedness == Handedness.Right)
108+
{
109+
platformVisualization = rightControllerHelper.gameObject;
110+
}
111+
112+
if(platformVisualization != null)
113+
{
114+
oculusTouchController.RegisterControllerVisualization(platformVisualization);
115+
}
101116
}
102117

103118
return controller;
@@ -248,21 +263,31 @@ private void SetupInput()
248263
cameraRig.EnsureGameObjectIntegrity();
249264
}
250265

251-
bool useAvatarHands = SettingsProfile.RenderAvatarHandsInsteadOfController;
252-
// If using Avatar hands, deactivate ovr controller rendering
253-
foreach (var controllerHelper in cameraRig.gameObject.GetComponentsInChildren<OVRControllerHelper>())
266+
bool useAvatarHands = SettingsProfile.RenderAvatarHandsWithControllers;
267+
// If using Avatar hands, initialize the local avatar controller
268+
if (useAvatarHands)
254269
{
255-
controllerHelper.gameObject.SetActive(!useAvatarHands);
270+
GameObject.Instantiate(SettingsProfile.LocalAvatarPrefab, cameraRig.trackingSpace);
256271
}
257272

258-
if (useAvatarHands)
273+
274+
var ovrControllerHelpers = cameraRig.GetComponentsInChildren<OVRControllerHelper>();
275+
foreach (var ovrControllerHelper in ovrControllerHelpers)
259276
{
260-
// Initialize the local avatar controller
261-
GameObject.Instantiate(SettingsProfile.LocalAvatarPrefab, cameraRig.trackingSpace);
277+
switch (ovrControllerHelper.m_controller)
278+
{
279+
case OVRInput.Controller.LTouch:
280+
leftControllerHelper = ovrControllerHelper;
281+
break;
282+
case OVRInput.Controller.RTouch:
283+
rightControllerHelper = ovrControllerHelper;
284+
break;
285+
default:
286+
break;
287+
}
262288
}
263289

264290
var ovrHands = cameraRig.GetComponentsInChildren<OVRHand>();
265-
266291
foreach (var ovrHand in ovrHands)
267292
{
268293
// Manage Hand skeleton data

Assets/MRTK/Providers/Oculus/XRSDK/OculusXRSDKDeviceManagerProfile.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
// Copyright (c) Microsoft Corporation.
3030
// Licensed under the MIT License.
3131

32+
using System;
3233
using UnityEngine;
34+
using UnityEngine.Serialization;
3335

3436
namespace Microsoft.MixedReality.Toolkit.XRSDK.Oculus.Input
3537
{
@@ -60,15 +62,23 @@ public GameObject OVRCameraRigPrefab
6062

6163

6264
[SerializeField]
65+
[FormerlySerializedAs("renderAvatarHandsInsteadOfControllers")]
6366
[Tooltip("Using avatar hands requires a local avatar prefab. Failure to provide one will result in nothing being displayed. \n\n" +
6467
"Note: In order to render avatar hands, you will need to set an app id in Assets/Resources/OvrAvatarSettings. Any number will do, but it needs to be set.")]
65-
private bool renderAvatarHandsInsteadOfControllers = true;
68+
private bool renderAvatarHandsWithControllers = true;
6669

6770
/// <summary>
6871
/// Using avatar hands requires a local avatar prefab. Failure to provide one will result in nothing being displayed.
6972
/// "Note: In order to render avatar hands, you will need to set an app id in Assets/Resources/OvrAvatarSettings. Any number will do, but it needs to be set.")]
7073
/// </summary>
71-
public bool RenderAvatarHandsInsteadOfController => renderAvatarHandsInsteadOfControllers;
74+
[Obsolete("Use RenderAvatarHandsWithControllers instead")]
75+
public bool RenderAvatarHandsInsteadOfController => renderAvatarHandsWithControllers;
76+
77+
/// <summary>
78+
/// Using avatar hands requires a local avatar prefab. Failure to provide one will result in nothing being displayed.
79+
/// "Note: In order to render avatar hands, you will need to set an app id in Assets/Resources/OvrAvatarSettings. Any number will do, but it needs to be set.")]
80+
/// </summary>
81+
public bool RenderAvatarHandsWithControllers => renderAvatarHandsWithControllers;
7282

7383
[SerializeField]
7484
[Tooltip("Prefab reference for LocalAvatar to load, if none are found in scene.")]

Assets/MRTK/Providers/Oculus/XRSDK/Profiles/DefaultOculusXRSDKDeviceManagerProfile.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ MonoBehaviour:
1515
isCustomProfile: 0
1616
ovrCameraRigPrefab: {fileID: 2343937678421323989, guid: 69a746aa83d0d0e45b4e2d33eab0fff4,
1717
type: 3}
18-
renderAvatarHandsInsteadOfControllers: 1
18+
renderAvatarHandsWithControllers: 0
1919
localAvatarPrefab: {fileID: 6297684789857299957, guid: 5357c8e6c4495c04f90e97272375c294,
2020
type: 3}
2121
minimumHandConfidence: 0

0 commit comments

Comments
 (0)