Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,19 @@ You can find the [full article on QR code tracking](https://docs.microsoft.com/w

`QRCodesVisualizer.cs` - Handles all QR code visualizing in the scene and instantiates all QR codes in the local list kept in `QRCodesManager`.

`SpatialGraphCoordinateSystem.cs` - This script is attached to the QR code object and transforms real-world QR code coordinates into the Unity coordinate system. The script also places the virtual QR code in the scene at the same location as the real-world QR code.
`SpatialGraphNodeTracker.cs` - This script is attached to the QR code object and transforms real-world QR code coordinates into the Unity coordinate system. The script also places the virtual QR code in the scene at the same location as the real-world QR code.

`SpatialGraphNode.cs` - This script is abstracting the tracking of a spatial graph static node, which represents the tracking information of QR code in a GUID id.

## OpenXR sample

Note that the ["main" branch](https://github.com/microsoft/MixedReality-QRCode-Sample/tree/main) of this sample is working with Unity's "Windows XR Plugin" which works with the WinRT APIs in in Unity 2019 or 2020 LTS versions.

After upgrading to Unity 2020 or Unity 2021, You can also [use "OpenXR plugin" for HoloLens 2 developement](https://docs.microsoft.com/windows/mixed-reality/develop/unity/mixed-reality-openxr-plugin). With OpenXR plugin, the app can use the built-in support for [SpatialGraphNode](https://docs.microsoft.com/dotnet/api/microsoft.mixedreality.openxr.spatialgraphnode), and the QR code tracking will work mostly the same way as above.

To view the OpenXR version of the QRCode tracking on HoloLens 2, please checkout the "openxr" branch of this sample repro, https://github.com/microsoft/MixedReality-QRCode-Sample/tree/OpenXR.
You can also inspect how to make modifications to existing QRCode Unity project to support OpenXR from this pull request: https://github.com/microsoft/MixedReality-QRCode-Sample/pull/18


## API Reference

Expand Down
2 changes: 1 addition & 1 deletion Sample/Assets/Scripts/QRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine;

namespace SampleQRCodes
namespace Microsoft.MixedReality.SampleQRCodes
{
[RequireComponent(typeof(SpatialGraphNodeTracker))]
public class QRCode : MonoBehaviour, IMixedRealityPointerHandler
Expand Down
2 changes: 1 addition & 1 deletion Sample/Assets/Scripts/QRCodesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Generic;
using UnityEngine;

namespace SampleQRCodes
namespace Microsoft.MixedReality.SampleQRCodes
{
public static class QRCodeEventArgs
{
Expand Down
2 changes: 1 addition & 1 deletion Sample/Assets/Scripts/QRCodesSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using UnityEngine;

namespace SampleQRCodes
namespace Microsoft.MixedReality.SampleQRCodes
{
public class QRCodesSetup : MonoBehaviour
{
Expand Down
2 changes: 1 addition & 1 deletion Sample/Assets/Scripts/QRCodesVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using UnityEngine;

namespace SampleQRCodes
namespace Microsoft.MixedReality.SampleQRCodes
{
public class QRCodesVisualizer : MonoBehaviour
{
Expand Down
10 changes: 8 additions & 2 deletions Sample/Assets/Scripts/SampleQRCodes.asmdef
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "SampleQRCodes",
"name": "Microsoft.MixedReality.SampleQRCodes",
"rootNamespace": "",
"references": [
"Microsoft.MixedReality.Toolkit",
"Unity.XR.WindowsMixedReality"
"Unity.XR.WindowsMixedReality",
"Microsoft.MixedReality.OpenXR"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand All @@ -17,6 +18,11 @@
"name": "com.unity.xr.windowsmr",
"expression": "1.0.0",
"define": "UNITY_XR_WINDOWSMR"
},
{
"name": "com.microsoft.mixedreality.openxr",
"expression": "1.4.0",
"define": "MIXED_REALITY_OPENXR"
}
],
"noEngineReferences": false
Expand Down
2 changes: 1 addition & 1 deletion Sample/Assets/Scripts/Singleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using UnityEngine;

namespace SampleQRCodes
namespace Microsoft.MixedReality.SampleQRCodes
{
/// <summary>
/// Inherit from this base class to create a singleton.
Expand Down
8 changes: 2 additions & 6 deletions Sample/Assets/Scripts/SpatialGraphNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using UnityEngine;

namespace SampleQRCodes.WindowsXR
namespace Microsoft.MixedReality.SampleQRCodes.WindowsXR
{
internal class SpatialGraphNode
{
Expand Down Expand Up @@ -68,11 +68,7 @@ public bool TryLocate(out Pose pose)
pose = new Pose(translation, rotation);
return true;
}
else
{
// Debug.Log("Id= " + id + " Unable to locate qrcode" );
}
#endif // WINDOWS_UWP
#endif
return false;
}
}
Expand Down
13 changes: 11 additions & 2 deletions Sample/Assets/Scripts/SpatialGraphNodeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

using UnityEngine;
using Microsoft.MixedReality.Toolkit.Utilities;
using SpatialGraphNode = SampleQRCodes.WindowsXR.SpatialGraphNode;

namespace SampleQRCodes
#if MIXED_REALITY_OPENXR
using Microsoft.MixedReality.OpenXR;
#else
using SpatialGraphNode = Microsoft.MixedReality.SampleQRCodes.WindowsXR.SpatialGraphNode;
#endif

namespace Microsoft.MixedReality.SampleQRCodes
{
internal class SpatialGraphNodeTracker : MonoBehaviour
{
Expand All @@ -23,7 +28,11 @@ void Update()

if (node != null)
{
#if MIXED_REALITY_OPENXR
if (node.TryLocate(FrameTime.OnUpdate, out Pose pose))
#else
if (node.TryLocate(out Pose pose))
#endif
{
// If there is a parent to the camera that means we are using teleport and we should not apply the teleport
// to these objects so apply the inverse
Expand Down
14 changes: 14 additions & 0 deletions Sample/Assets/XR/Loaders/Open XR Loader.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d3552e428dc7646a88de3ed3650f87da, type: 3}
m_Name: Open XR Loader
m_EditorClassIdentifier:
8 changes: 8 additions & 0 deletions Sample/Assets/XR/Loaders/Open XR Loader.asset.meta

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

Loading