Skip to content

Commit ac96a3e

Browse files
authored
Initial phase of unblocking support for Oculus runtime controller models (#10564)
* Rename model provider class * Rename * Improve glTF loading * Add rotation for Oculus model
1 parent a7ff585 commit ac96a3e

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

Assets/MRTK/Core/Utilities/Gltf/Serialization/GltfUtility.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ namespace Microsoft.MixedReality.Toolkit.Utilities.Gltf.Serialization
2222
public static class GltfUtility
2323
{
2424
private const uint GltfMagicNumber = 0x46546C67;
25+
private const string DefaultObjectName = "GLTF Object";
2526

2627
private static readonly WaitForUpdate Update = new WaitForUpdate();
2728
private static readonly WaitForBackgroundThread BackgroundThread = new WaitForBackgroundThread();
28-
private static readonly string DefaultObjectName = "GLTF Object";
2929

3030
/// <summary>
3131
/// Imports a glTF object from the provided uri.
@@ -63,7 +63,7 @@ public static async Task<GltfObject> ImportGltfObjectFromPathAsync(string uri)
6363

6464
if (gltfObject == null)
6565
{
66-
Debug.LogError("Failed load Gltf Object from json schema.");
66+
Debug.LogError("Failed to load glTF object from JSON schema.");
6767
return null;
6868
}
6969
}
@@ -72,7 +72,6 @@ public static async Task<GltfObject> ImportGltfObjectFromPathAsync(string uri)
7272
byte[] glbData;
7373

7474
#if WINDOWS_UWP
75-
7675
if (useBackgroundThread)
7776
{
7877
try
@@ -123,7 +122,7 @@ public static async Task<GltfObject> ImportGltfObjectFromPathAsync(string uri)
123122

124123
if (gltfObject == null)
125124
{
126-
Debug.LogError("Failed to load GlTF Object from .glb!");
125+
Debug.LogError("Failed to load glTF Object from .glb!");
127126
return null;
128127
}
129128
}
@@ -150,7 +149,7 @@ public static async Task<GltfObject> ImportGltfObjectFromPathAsync(string uri)
150149

151150
if (gltfObject.GameObjectReference == null)
152151
{
153-
Debug.LogError("Failed to construct Gltf Object.");
152+
Debug.LogError("Failed to construct glTF object.");
154153
}
155154

156155
if (useBackgroundThread) { await Update; }
@@ -258,17 +257,23 @@ public static GltfObject GetGltfObjectFromGlb(byte[] glbData)
258257
return null;
259258
}
260259

261-
var jsonChunk = Encoding.ASCII.GetString(glbData, stride * 5, chunk0Length);
262-
var gltfObject = GetGltfObjectFromJson(jsonChunk);
263-
var chunk1Length = (int)BitConverter.ToUInt32(glbData, stride * 5 + chunk0Length);
264-
var chunk1Type = BitConverter.ToUInt32(glbData, stride * 6 + chunk0Length);
260+
string jsonChunk = Encoding.ASCII.GetString(glbData, stride * 5, chunk0Length);
261+
GltfObject gltfObject = GetGltfObjectFromJson(jsonChunk);
262+
int chunk1Length = (int)BitConverter.ToUInt32(glbData, stride * 5 + chunk0Length);
263+
uint chunk1Type = BitConverter.ToUInt32(glbData, stride * 6 + chunk0Length);
265264

266265
if (chunk1Type != (ulong)GltfChunkType.BIN)
267266
{
268267
Debug.LogError("Expected chunk 1 to be BIN data!");
269268
return null;
270269
}
271270

271+
if (gltfObject == null)
272+
{
273+
Debug.LogError("Failed to load glTF object from JSON schema.");
274+
return null;
275+
}
276+
272277
// Per the spec, "byte length of BIN chunk could be up to 3 bytes bigger than JSON-defined buffer.byteLength to satisfy GLB padding requirements"
273278
// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-stored-buffer
274279
Debug.Assert(gltfObject.buffers[0].byteLength <= chunk1Length && gltfObject.buffers[0].byteLength >= chunk1Length - 3, "chunk 1 & buffer 0 length mismatch");

Assets/MRTK/Providers/OpenXR/Scripts/HPReverbG2Controller.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected override void UpdatePoseData(MixedRealityInteractionMapping interactio
6868
}
6969

7070
#if MSFT_OPENXR
71-
private MicrosoftControllerModelProvider controllerModelProvider;
71+
private OpenXRControllerModelProvider controllerModelProvider;
7272

7373
/// <inheritdoc />
7474
protected override bool TryRenderControllerModel(System.Type controllerType, InputSourceType inputSourceType)
@@ -89,7 +89,7 @@ private async void TryRenderControllerModelWithModelProvider()
8989
{
9090
if (controllerModelProvider == null)
9191
{
92-
controllerModelProvider = new MicrosoftControllerModelProvider(ControllerHandedness);
92+
controllerModelProvider = new OpenXRControllerModelProvider(ControllerHandedness);
9393
}
9494

9595
GameObject controllerModel = await controllerModelProvider.TryGenerateControllerModelFromPlatformSDK();

Assets/MRTK/Providers/OpenXR/Scripts/MicrosoftMotionController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected override void UpdatePoseData(MixedRealityInteractionMapping interactio
7272
}
7373

7474
#if MSFT_OPENXR
75-
private MicrosoftControllerModelProvider controllerModelProvider;
75+
private OpenXRControllerModelProvider controllerModelProvider;
7676

7777
/// <inheritdoc />
7878
protected override bool TryRenderControllerModel(System.Type controllerType, InputSourceType inputSourceType)
@@ -93,7 +93,7 @@ private async void TryRenderControllerModelWithModelProvider()
9393
{
9494
if (controllerModelProvider == null)
9595
{
96-
controllerModelProvider = new MicrosoftControllerModelProvider(ControllerHandedness);
96+
controllerModelProvider = new OpenXRControllerModelProvider(ControllerHandedness);
9797
}
9898

9999
GameObject controllerModel = await controllerModelProvider.TryGenerateControllerModelFromPlatformSDK();

Assets/MRTK/Providers/OpenXR/Scripts/OculusController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected override void UpdatePoseData(MixedRealityInteractionMapping interactio
7070
}
7171

7272
#if MSFT_OPENXR
73-
private MicrosoftControllerModelProvider controllerModelProvider;
73+
private OpenXRControllerModelProvider controllerModelProvider;
7474

7575
/// <inheritdoc />
7676
protected override bool TryRenderControllerModel(System.Type controllerType, InputSourceType inputSourceType)
@@ -91,7 +91,7 @@ private async void TryRenderControllerModelWithModelProvider()
9191
{
9292
if (controllerModelProvider == null)
9393
{
94-
controllerModelProvider = new MicrosoftControllerModelProvider(ControllerHandedness);
94+
controllerModelProvider = new OpenXRControllerModelProvider(ControllerHandedness);
9595
}
9696

9797
GameObject controllerModel = await controllerModelProvider.TryGenerateControllerModelFromPlatformSDK();

Assets/MRTK/Providers/OpenXR/Scripts/MicrosoftControllerModelProvider.cs renamed to Assets/MRTK/Providers/OpenXR/Scripts/OpenXRControllerModelProvider.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@
44
using System.Threading.Tasks;
55
using UnityEngine;
66

7-
#if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
7+
#if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
88
using Microsoft.MixedReality.OpenXR;
99
using Microsoft.MixedReality.Toolkit.Utilities.Gltf.Serialization;
1010
using System.Collections.Generic;
11-
#endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
11+
#endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
1212

1313
namespace Microsoft.MixedReality.Toolkit.XRSDK.OpenXR
1414
{
1515
/// <summary>
1616
/// Queries the OpenXR APIs for a renderable controller model.
1717
/// </summary>
18-
internal class MicrosoftControllerModelProvider
18+
internal class OpenXRControllerModelProvider
1919
{
20-
public MicrosoftControllerModelProvider(Utilities.Handedness handedness)
20+
public OpenXRControllerModelProvider(Utilities.Handedness handedness)
2121
{
22-
#if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
22+
#if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
2323
controllerModelProvider = handedness == Utilities.Handedness.Left ? ControllerModel.Left : ControllerModel.Right;
24-
#endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
24+
#endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
2525
}
2626

27-
#if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
27+
#if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
2828
private static readonly Dictionary<ulong, GameObject> ControllerModelDictionary = new Dictionary<ulong, GameObject>(2);
2929
private readonly ControllerModel controllerModelProvider;
30-
#endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
30+
#endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
3131

3232
// Disables "This async method lacks 'await' operators and will run synchronously." when the correct OpenXR package isn't installed
3333
#pragma warning disable CS1998
@@ -39,7 +39,7 @@ public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
3939
{
4040
GameObject gltfGameObject = null;
4141

42-
#if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
42+
#if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
4343
if (!controllerModelProvider.TryGetControllerModelKey(out ulong modelKey))
4444
{
4545
Debug.LogError("Failed to obtain controller model key from platform.");
@@ -76,7 +76,7 @@ public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
7676
ControllerModelDictionary.Add(modelKey, gltfGameObject);
7777
}
7878
}
79-
#endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
79+
#endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
8080

8181
return gltfGameObject;
8282
}

Assets/MRTK/SDK/Profiles/DefaultMixedRealityControllerVisualizationProfile.asset

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,13 @@ MonoBehaviour:
159159
type: 3}
160160
controllerVisualizationType:
161161
reference: Microsoft.MixedReality.Toolkit.Input.RiggedHandVisualizer, Microsoft.MixedReality.Toolkit.SDK
162+
- description: Oculus Controller
163+
controllerType:
164+
reference: Microsoft.MixedReality.Toolkit.XRSDK.OpenXR.OculusController, Microsoft.MixedReality.Toolkit.Providers.OpenXR
165+
handedness: 3
166+
usePlatformModels: 1
167+
platformModelMaterial: {fileID: 0}
168+
overrideModel: {fileID: 0}
169+
controllerVisualizationType:
170+
reference: Microsoft.MixedReality.Toolkit.Input.WindowsMixedRealityControllerVisualizer,
171+
Microsoft.MixedReality.Toolkit.SDK

0 commit comments

Comments
 (0)