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
2 changes: 1 addition & 1 deletion Sample/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ crashlytics-build.properties

# Sample specific

/[Aa]pp/
/[Aa]pp*/
/[Aa]ssets/Packages/
/UWP*/
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ MonoBehaviour:
- _MixedRealityToolkit_Editor_AutoEnableUWPCapabilities
- MixedRealityToolkit_Editor_RunOptimalConfig
- MixedRealityToolkit_Editor_NullDataProviders
values: 0001010100
values: 0101010100
intPreferences:
keys:
- MixedRealityToolkit_Editor_AudioSpatializerCount
values: 01000000
- _MixedRealityToolkit_Editor_ConfiguratorState
values: 0100000000000000
floatPreferences:
keys: []
values: []
Expand Down
4 changes: 2 additions & 2 deletions Sample/Assets/Scripts/QRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine;

namespace QRTracking
namespace SampleQRCodes
Comment thread
yl-msft marked this conversation as resolved.
{
[RequireComponent(typeof(SpatialGraphCoordinateSystem))]
[RequireComponent(typeof(SpatialGraphNodeTracker))]
public class QRCode : MonoBehaviour, IMixedRealityPointerHandler
{
public Microsoft.MixedReality.QR.QRCode qrCode;
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 QRTracking
namespace 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 QRTracking
namespace SampleQRCodes
{
public class QRCodesSetup : MonoBehaviour
{
Expand Down
6 changes: 3 additions & 3 deletions 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 QRTracking
namespace SampleQRCodes
{
public class QRCodesVisualizer : MonoBehaviour
{
Expand Down Expand Up @@ -96,7 +96,7 @@ private void HandleEvents()
if (action.type == ActionData.Type.Added)
{
GameObject qrCodeObject = Instantiate(qrCodePrefab, new Vector3(0, 0, 0), Quaternion.identity);
qrCodeObject.GetComponent<SpatialGraphCoordinateSystem>().Id = action.qrCode.SpatialGraphNodeId;
qrCodeObject.GetComponent<SpatialGraphNodeTracker>().Id = action.qrCode.SpatialGraphNodeId;
qrCodeObject.GetComponent<QRCode>().qrCode = action.qrCode;
qrCodesObjectsList.Add(action.qrCode.Id, qrCodeObject);
}
Expand All @@ -105,7 +105,7 @@ private void HandleEvents()
if (!qrCodesObjectsList.ContainsKey(action.qrCode.Id))
{
GameObject qrCodeObject = Instantiate(qrCodePrefab, new Vector3(0, 0, 0), Quaternion.identity);
qrCodeObject.GetComponent<SpatialGraphCoordinateSystem>().Id = action.qrCode.SpatialGraphNodeId;
qrCodeObject.GetComponent<SpatialGraphNodeTracker>().Id = action.qrCode.SpatialGraphNodeId;
qrCodeObject.GetComponent<QRCode>().qrCode = action.qrCode;
qrCodesObjectsList.Add(action.qrCode.Id, qrCodeObject);
}
Expand Down
23 changes: 23 additions & 0 deletions Sample/Assets/Scripts/SampleQRCodes.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "SampleQRCodes",
"rootNamespace": "",
"references": [
"Microsoft.MixedReality.Toolkit",
"Unity.XR.WindowsMixedReality"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.xr.windowsmr",
"expression": "1.0.0",
"define": "UNITY_XR_WINDOWSMR"
}
],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Sample/Assets/Scripts/SampleQRCodes.asmdef.meta

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

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 QRTracking
namespace SampleQRCodes
{
/// <summary>
/// Inherit from this base class to create a singleton.
Expand Down
130 changes: 0 additions & 130 deletions Sample/Assets/Scripts/SpatialGraphCoordinateSystem.cs

This file was deleted.

79 changes: 79 additions & 0 deletions Sample/Assets/Scripts/SpatialGraphNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using UnityEngine;

namespace SampleQRCodes.WindowsXR
{
internal class SpatialGraphNode
{
public System.Guid Id { get; private set; }
#if WINDOWS_UWP && UNITY_XR_WINDOWSMR
private Windows.Perception.Spatial.SpatialCoordinateSystem CoordinateSystem = null;
#endif

public static SpatialGraphNode FromStaticNodeId(System.Guid id)
{
#if WINDOWS_UWP && UNITY_XR_WINDOWSMR
var coordinateSystem = Windows.Perception.Spatial.Preview.SpatialGraphInteropPreview.CreateCoordinateSystemForNode(id);
return coordinateSystem == null ? null :
new SpatialGraphNode()
{
Id = id,
CoordinateSystem = coordinateSystem
};
#else
return null;
#endif
}


public bool TryLocate(out Pose pose)
{
pose = Pose.identity;

#if WINDOWS_UWP && UNITY_XR_WINDOWSMR
Quaternion rotation = Quaternion.identity;
Vector3 translation = new Vector3(0.0f, 0.0f, 0.0f);

System.IntPtr rootCoordnateSystemPtr = UnityEngine.XR.WindowsMR.WindowsMREnvironment.OriginSpatialCoordinateSystem;
Windows.Perception.Spatial.SpatialCoordinateSystem rootSpatialCoordinateSystem =
(Windows.Perception.Spatial.SpatialCoordinateSystem)System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(rootCoordnateSystemPtr);

// Get the relative transform from the unity origin
System.Numerics.Matrix4x4? relativePose = CoordinateSystem.TryGetTransformTo(rootSpatialCoordinateSystem);

if (relativePose != null)
{
System.Numerics.Vector3 scale;
System.Numerics.Quaternion rotation1;
System.Numerics.Vector3 translation1;

System.Numerics.Matrix4x4 newMatrix = relativePose.Value;

// Platform coordinates are all right handed and unity uses left handed matrices. so we convert the matrix
// from rhs-rhs to lhs-lhs
// Convert from right to left coordinate system
newMatrix.M13 = -newMatrix.M13;
newMatrix.M23 = -newMatrix.M23;
newMatrix.M43 = -newMatrix.M43;

newMatrix.M31 = -newMatrix.M31;
newMatrix.M32 = -newMatrix.M32;
newMatrix.M34 = -newMatrix.M34;

System.Numerics.Matrix4x4.Decompose(newMatrix, out scale, out rotation1, out translation1);
translation = new Vector3(translation1.X, translation1.Y, translation1.Z);
rotation = new Quaternion(rotation1.X, rotation1.Y, rotation1.Z, rotation1.W);
pose = new Pose(translation, rotation);
return true;
}
else
{
// Debug.Log("Id= " + id + " Unable to locate qrcode" );
}
Comment thread
yl-msft marked this conversation as resolved.
#endif // WINDOWS_UWP
Comment thread
yl-msft marked this conversation as resolved.
return false;
}
}
}
11 changes: 11 additions & 0 deletions Sample/Assets/Scripts/SpatialGraphNode.cs.meta

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

45 changes: 45 additions & 0 deletions Sample/Assets/Scripts/SpatialGraphNodeTracker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

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

namespace SampleQRCodes
{
internal class SpatialGraphNodeTracker : MonoBehaviour
{
private SpatialGraphNode node;

public System.Guid Id { get; set; }

void Update()
{
if (node == null || node.Id != Id)
{
node = (Id != System.Guid.Empty) ? SpatialGraphNode.FromStaticNodeId(Id) : null;
Debug.Log("Initialize SpatialGraphNode Id= " + Id);
}

if (node != null)
{
if (node.TryLocate(out Pose pose))
{
// 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
if (CameraCache.Main.transform.parent != null)
{
pose = pose.GetTransformedBy(CameraCache.Main.transform.parent);
}

gameObject.transform.SetPositionAndRotation(pose.position, pose.rotation);
Debug.Log("Id= " + Id + " QRPose = " + pose.position.ToString("F7") + " QRRot = " + pose.rotation.ToString("F7"));
}
else
{
Debug.LogWarning("Cannot locate " + Id);
}
}
}
}
}
Loading