Skip to content

Commit 265a0ea

Browse files
RogPodgekeveleigh
andauthored
Refactored Controller visualization code, Oculus Touch uses their own standalone visualizer (#9589)
* Refactored some of the confusing controller visualization code, Oculus XRSDK Touch controllers no longer rely on MRTK for controller visualization, since they have their own standalone visualization * added failsafe in case Oculus Integration package is not imported * fixed bug where Oculus project config settings would get reset inexplicably * Update Assets/MRTK/Providers/Oculus/XRSDK/Controllers/OculusXRSDKTouchController.cs Co-authored-by: Kurtis <[email protected]> * Update Assets/MRTK/Core/Providers/BaseController.cs Co-authored-by: Kurtis <[email protected]> * Update Assets/MRTK/Providers/Oculus/XRSDK/Controllers/OculusXRSDKTouchController.cs Co-authored-by: Kurtis <[email protected]> * addressing PR comments * fixed obsolete reference * added oculusintegration_present flags * Update Assets/MRTK/Providers/Oculus/XRSDK/OculusXRSDKDeviceManager.cs Co-authored-by: Kurtis <[email protected]> * fixed double negative typo * cached controller settings Co-authored-by: Kurtis <[email protected]>
1 parent 50d3ff1 commit 265a0ea

File tree

7 files changed

+122
-58
lines changed

7 files changed

+122
-58
lines changed

Assets/MRTK/Core/Definitions/Devices/MixedRealityControllerVisualizationProfile.cs

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,29 @@ public GameObject GlobalRightHandVisualizer
154154
/// </summary>
155155
public MixedRealityControllerVisualizationSetting[] ControllerVisualizationSettings => controllerVisualizationSettings;
156156

157-
/// <summary>
158-
/// Gets the override model for a specific controller type and hand
159-
/// </summary>
160-
/// <param name="controllerType">The type of controller to query for</param>
161-
/// <param name="hand">The specific hand assigned to the controller</param>
162-
public GameObject GetControllerModelOverride(Type controllerType, Handedness hand)
157+
private MixedRealityControllerVisualizationSetting? GetControllerVisualizationDefinition(Type controllerType, Handedness hand)
163158
{
164159
for (int i = 0; i < controllerVisualizationSettings.Length; i++)
165160
{
166161
if (SettingContainsParameters(controllerVisualizationSettings[i], controllerType, hand))
167162
{
168-
return controllerVisualizationSettings[i].OverrideControllerModel;
163+
return controllerVisualizationSettings[i];
169164
}
170165
}
171-
172166
return null;
173167
}
174168

169+
/// <summary>
170+
/// Gets the override model for a specific controller type and hand
171+
/// </summary>
172+
/// <param name="controllerType">The type of controller to query for</param>
173+
/// <param name="hand">The specific hand assigned to the controller</param>
174+
public GameObject GetControllerModelOverride(Type controllerType, Handedness hand)
175+
{
176+
MixedRealityControllerVisualizationSetting? setting = GetControllerVisualizationDefinition(controllerType, hand);
177+
return setting.HasValue ? setting.Value.OverrideControllerModel : null;
178+
}
179+
175180
/// <summary>
176181
/// Gets the override <see cref="IMixedRealityControllerVisualizer"/> type for a specific controller type and hand.
177182
/// If the requested controller type is not defined, DefaultControllerVisualizationType is returned.
@@ -180,53 +185,63 @@ public GameObject GetControllerModelOverride(Type controllerType, Handedness han
180185
/// <param name="hand">The specific hand assigned to the controller</param>
181186
public SystemType GetControllerVisualizationTypeOverride(Type controllerType, Handedness hand)
182187
{
183-
for (int i = 0; i < controllerVisualizationSettings.Length; i++)
184-
{
185-
if (SettingContainsParameters(controllerVisualizationSettings[i], controllerType, hand))
186-
{
187-
return controllerVisualizationSettings[i].ControllerVisualizationType;
188-
}
189-
}
190-
191-
return defaultControllerVisualizationType;
188+
MixedRealityControllerVisualizationSetting? setting = GetControllerVisualizationDefinition(controllerType, hand);
189+
return setting.HasValue ? setting.Value.ControllerVisualizationType : null;
192190
}
193191

194192
/// <summary>
195-
/// Gets the UseDefaultModels value defined for the specified controller definition.
196-
/// If the requested controller type is not defined, the default UseDefaultModels is returned.
193+
/// Gets the UsePlatformModels value defined for the specified controller definition.
194+
/// If the requested controller type is not defined, the default UsePlatformModels is returned.
197195
/// </summary>
198196
/// <param name="controllerType">The type of controller to query for</param>
199197
/// <param name="hand">The specific hand assigned to the controller</param>
198+
/// <remarks>
199+
/// GetUseDefaultModelsOverride is obsolete and will be removed in a future Mixed Reality Toolkit release. Please use GetUsePlatformModelsOverride.
200+
/// </remarks>
201+
[Obsolete("GetUseDefaultModelsOverride is obsolete and will be removed in a future Mixed Reality Toolkit release. Please use GetUsePlatformModelsOverride.")]
200202
public bool GetUseDefaultModelsOverride(Type controllerType, Handedness hand)
201203
{
202-
for (int i = 0; i < controllerVisualizationSettings.Length; i++)
203-
{
204-
if (SettingContainsParameters(controllerVisualizationSettings[i], controllerType, hand))
205-
{
206-
return controllerVisualizationSettings[i].UsePlatformModels;
207-
}
208-
}
204+
return GetUsePlatformModelsOverride(controllerType, hand);
205+
}
209206

210-
return usePlatformModels;
207+
/// <summary>
208+
/// Gets the UsePlatformModels value defined for the specified controller definition.
209+
/// If the requested controller type is not defined, the default UsePlatformModels is returned.
210+
/// </summary>
211+
/// <param name="controllerType">The type of controller to query for</param>
212+
/// <param name="hand">The specific hand assigned to the controller</param>
213+
public bool GetUsePlatformModelsOverride(Type controllerType, Handedness hand)
214+
{
215+
MixedRealityControllerVisualizationSetting? setting = GetControllerVisualizationDefinition(controllerType, hand);
216+
return setting.HasValue ? setting.Value.UsePlatformModels : usePlatformModels;
211217
}
212218

213219
/// <summary>
214220
/// Gets the DefaultModelMaterial value defined for the specified controller definition.
215-
/// If the requested controller type is not defined, the global DefaultControllerModelMaterial is returned.
221+
/// If the requested controller type is not defined, the global platformModelMaterial is returned.
216222
/// </summary>
217223
/// <param name="controllerType">The type of controller to query for</param>
218224
/// <param name="hand">The specific hand assigned to the controller</param>
225+
/// <remarks>
226+
/// GetDefaultControllerModelMaterialOverride is obsolete and will be removed in a future Mixed Reality Toolkit release. Please use GetPlatformModelMaterialOverride.
227+
/// </remarks>
228+
[Obsolete("GetDefaultControllerModelMaterialOverride is obsolete and will be removed in a future Mixed Reality Toolkit release. Please use GetPlatformModelMaterial.")]
219229
public Material GetDefaultControllerModelMaterialOverride(Type controllerType, Handedness hand)
220230
{
221-
for (int i = 0; i < controllerVisualizationSettings.Length; i++)
222-
{
223-
if (SettingContainsParameters(controllerVisualizationSettings[i], controllerType, hand))
224-
{
225-
return controllerVisualizationSettings[i].PlatformModelMaterial;
226-
}
227-
}
231+
return GetPlatformModelMaterialOverride(controllerType, hand);
232+
}
233+
234+
/// <summary>
235+
/// Gets the PlatformModelMaterial value defined for the specified controller definition.
236+
/// If the requested controller type is not defined, the global platformModelMaterial is returned.
237+
/// </summary>
238+
/// <param name="controllerType">The type of controller to query for</param>
239+
/// <param name="hand">The specific hand assigned to the controller</param>
240+
public Material GetPlatformModelMaterialOverride(Type controllerType, Handedness hand)
241+
{
228242

229-
return platformModelMaterial;
243+
MixedRealityControllerVisualizationSetting? setting = GetControllerVisualizationDefinition(controllerType, hand);
244+
return setting.HasValue ? setting.Value.PlatformModelMaterial : platformModelMaterial;
230245
}
231246

232247
private bool SettingContainsParameters(MixedRealityControllerVisualizationSetting setting, Type controllerType, Handedness hand)

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public override void OnInspectorGUI()
102102

103103
if (usePlatformControllerModels.boolValue && (leftHandModelPrefab != null || rightHandModelPrefab != null))
104104
{
105-
EditorGUILayout.HelpBox("When default models are used, an attempt is made to obtain controller models from the platform SDK. The global left and right models are only shown if no model can be obtained.", MessageType.Warning);
105+
EditorGUILayout.HelpBox("When platform models are used, an attempt is made to obtain controller models from the platform SDK. The global left and right models are only shown if no model can be obtained.", MessageType.Warning);
106106
}
107107

108108
EditorGUI.BeginChangeCheck();
@@ -208,6 +208,12 @@ private void RenderControllerList(SerializedProperty controllerList)
208208
EditorGUILayout.HelpBox("A controller type must be defined!", MessageType.Error);
209209
}
210210

211+
bool isOculusType = thisProfile.ControllerVisualizationSettings[i].ControllerType.Type.FullName.Contains("OculusXRSDKTouchController");
212+
if (isOculusType)
213+
{
214+
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);
215+
}
216+
211217
var handednessValue = mixedRealityControllerHandedness.intValue - 1;
212218

213219
// Reset in case it was set to something other than left or right.
@@ -233,11 +239,15 @@ private void RenderControllerList(SerializedProperty controllerList)
233239

234240
if (controllerUsePlatformModelOverride.boolValue && overrideModelPrefab != null)
235241
{
236-
EditorGUILayout.HelpBox("When default model is used, the override model will only be used if the default model cannot be loaded from the driver.", MessageType.Warning);
242+
EditorGUILayout.HelpBox("When platform model is used, the override model will only be used if the default model cannot be loaded from the driver.", MessageType.Warning);
237243
}
238244

239245
EditorGUI.BeginChangeCheck();
240246
overrideModelPrefab = EditorGUILayout.ObjectField(new GUIContent(overrideModel.displayName, "If no override model is set, the global model is used."), overrideModelPrefab, typeof(GameObject), false) as GameObject;
247+
if(overrideModelPrefab == null && !controllerUsePlatformModelOverride.boolValue)
248+
{
249+
EditorGUILayout.HelpBox("No override model was assigned and this controller will not attempt to use the platform's model, the global model will be used instead", MessageType.Warning);
250+
}
241251

242252
if (EditorGUI.EndChangeCheck() && CheckVisualizer(overrideModelPrefab))
243253
{

Assets/MRTK/Core/Providers/BaseController.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -234,50 +234,50 @@ public void AssignControllerMappings(MixedRealityInteractionMapping[] mappings)
234234
/// <returns>True if a model was successfully loaded or model rendering is disabled. False if a model tried to load but failed.</returns>
235235
protected virtual bool TryRenderControllerModel(Type controllerType, InputSourceType inputSourceType)
236236
{
237-
if (GetControllerVisualizationProfile() == null ||
238-
!GetControllerVisualizationProfile().RenderMotionControllers)
237+
MixedRealityControllerVisualizationProfile controllerVisualizationProfile = GetControllerVisualizationProfile();
238+
bool controllerVisualizationProfilePresent = controllerVisualizationProfile != null;
239+
240+
if (!controllerVisualizationProfilePresent || !controllerVisualizationProfile.RenderMotionControllers)
239241
{
240242
return true;
241243
}
242244

243245
GameObject controllerModel = null;
246+
bool usePlatformModels = controllerVisualizationProfile.GetUsePlatformModelsOverride(controllerType, ControllerHandedness);
244247

245-
// If a specific controller template wants to override the global model, assign that instead.
246-
if (IsControllerMappingEnabled() &&
247-
GetControllerVisualizationProfile() != null &&
248-
!(GetControllerVisualizationProfile().GetUseDefaultModelsOverride(controllerType, ControllerHandedness)))
248+
// If a specific controller template wants to override the global model, assign it
249+
if (!usePlatformModels)
249250
{
250-
controllerModel = GetControllerVisualizationProfile().GetControllerModelOverride(controllerType, ControllerHandedness);
251+
controllerModel = controllerVisualizationProfile.GetControllerModelOverride(controllerType, ControllerHandedness);
251252
}
252253

253-
// Get the global controller model for each hand.
254-
if (controllerModel == null &&
255-
GetControllerVisualizationProfile() != null)
254+
// If the Controller model is still null in the end, use the global defaults.
255+
if (controllerModel == null)
256256
{
257257
if (inputSourceType == InputSourceType.Controller)
258258
{
259259
if (ControllerHandedness == Handedness.Left &&
260-
GetControllerVisualizationProfile().GlobalLeftHandModel != null)
260+
controllerVisualizationProfile.GlobalLeftHandModel != null)
261261
{
262-
controllerModel = GetControllerVisualizationProfile().GlobalLeftHandModel;
262+
controllerModel = controllerVisualizationProfile.GlobalLeftHandModel;
263263
}
264264
else if (ControllerHandedness == Handedness.Right &&
265-
GetControllerVisualizationProfile().GlobalRightHandModel != null)
265+
controllerVisualizationProfile.GlobalRightHandModel != null)
266266
{
267-
controllerModel = GetControllerVisualizationProfile().GlobalRightHandModel;
267+
controllerModel = controllerVisualizationProfile.GlobalRightHandModel;
268268
}
269269
}
270270
else if (inputSourceType == InputSourceType.Hand)
271271
{
272272
if (ControllerHandedness == Handedness.Left &&
273-
GetControllerVisualizationProfile().GlobalLeftHandVisualizer != null)
273+
controllerVisualizationProfile.GlobalLeftHandVisualizer != null)
274274
{
275-
controllerModel = GetControllerVisualizationProfile().GlobalLeftHandVisualizer;
275+
controllerModel = controllerVisualizationProfile.GlobalLeftHandVisualizer;
276276
}
277277
else if (ControllerHandedness == Handedness.Right &&
278-
GetControllerVisualizationProfile().GlobalRightHandVisualizer != null)
278+
controllerVisualizationProfile.GlobalRightHandVisualizer != null)
279279
{
280-
controllerModel = GetControllerVisualizationProfile().GlobalRightHandVisualizer;
280+
controllerModel = controllerVisualizationProfile.GlobalRightHandVisualizer;
281281
}
282282
}
283283
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Unity.Profiling;
88
using UnityEngine;
99
using UnityEngine.XR;
10+
using System;
1011

1112
#if OCULUS_ENABLED
1213
using Unity.XR.Oculus;
@@ -88,5 +89,27 @@ protected override void UpdateButtonData(MixedRealityInteractionMapping interact
8889
}
8990
}
9091
}
92+
93+
/// <summary>
94+
/// Determines whether or not this controller uses MRTK for controller visualization or not
95+
/// </summary>
96+
internal bool UseMRTKControllerVisualization { get; set; } = false;
97+
98+
/// <inheritdoc/>
99+
/// <remarks>
100+
/// If UseMRTKControllerVisualization is false, Oculus Touch controller model visualization will not be managed by MRTK
101+
/// Ensure that the Oculus Integration Package is installed and the Ovr Camera Rig is set correctly in the Oculus XRSDK Device Manager
102+
/// </remarks>
103+
protected override bool TryRenderControllerModel(Type controllerType, InputSourceType inputSourceType)
104+
{
105+
if (UseMRTKControllerVisualization)
106+
{
107+
return base.TryRenderControllerModel(controllerType, inputSourceType);
108+
}
109+
else
110+
{
111+
return false;
112+
}
113+
}
91114
}
92115
}

Assets/MRTK/Providers/Oculus/XRSDK/MRTK-Quest/Editor/OculusXRSDKHandtrackingConfigurationChecker.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ internal static void InitializeOculusProjectConfig()
125125
defaultOculusProjectConfig.handTrackingSupport = OVRProjectConfig.HandTrackingSupport.ControllersAndHands;
126126
defaultOculusProjectConfig.requiresSystemKeyboard = true;
127127

128+
OVRProjectConfig.CommitProjectConfig(defaultOculusProjectConfig);
129+
128130
Debug.Log("Enabled Oculus Quest Keyboard and Handtracking in the Oculus Project Config");
129131
}
130132
#endif

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ public override bool CheckCapability(MixedRealityCapability capability)
8888

8989
#region Controller Utilities
9090

91+
#if OCULUSINTEGRATION_PRESENT
92+
/// <inheritdoc />
93+
protected override GenericXRSDKController GetOrAddController(InputDevice inputDevice)
94+
{
95+
GenericXRSDKController controller = base.GetOrAddController(inputDevice);
96+
if (controller is OculusXRSDKTouchController oculusTouchController)
97+
{
98+
oculusTouchController.UseMRTKControllerVisualization = cameraRig.IsNull();
99+
}
100+
101+
return controller;
102+
}
103+
#endif
104+
91105
/// <inheritdoc />
92106
protected override Type GetControllerType(SupportedControllerType supportedControllerType)
93107
{

Assets/MRTK/Providers/OpenVR/GenericOpenVRController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ protected override bool TryRenderControllerModel(Type controllerType, InputSourc
254254

255255
// Intercept this call if we are using the default driver provided models.
256256
if (visualizationProfile == null ||
257-
!visualizationProfile.GetUseDefaultModelsOverride(GetType(), ControllerHandedness))
257+
!visualizationProfile.GetUsePlatformModelsOverride(GetType(), ControllerHandedness))
258258
{
259259
return base.TryRenderControllerModel(controllerType, inputSourceType);
260260
}
@@ -282,7 +282,7 @@ protected override bool TryRenderControllerModel(Type controllerType, InputSourc
282282
}
283283

284284
OpenVRRenderModel openVRRenderModel = controllerModelGameObject.AddComponent<OpenVRRenderModel>();
285-
Material overrideMaterial = visualizationProfile.GetDefaultControllerModelMaterialOverride(GetType(), ControllerHandedness);
285+
Material overrideMaterial = visualizationProfile.GetPlatformModelMaterialOverride(GetType(), ControllerHandedness);
286286
if (overrideMaterial != null)
287287
{
288288
openVRRenderModel.shader = overrideMaterial.shader;

0 commit comments

Comments
 (0)