Just a heads up for anyone stumbling across this as of September 2021: UnityEngine.XR.WSA.WorldManager is deprecated so the line to obtain the rootSpatialCoordinateSystem can be replaced with the following:
rootSpatialCoordinateSystem = SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation().CoordinateSystem;
Hi Shaynek, thanks for the article. I was able to run the demo but have one question. there are eventhandlers for add,remove and update qr code. I understand that add event is called when i bring a QR code in front of hololens camera but not able to understand when will the remove and update event be called.
Thanks Shayne, this code saved my project.
The code is outdated though if you are using OpenXR. There's now a better way to compute the QR Code's pose. For QRCodeInformation, I'm adding another field called "SpatialGraphNodeID":
public class QRCodeInformation { public string Data { get; set; } public float Length { get; set; } #if WINDOWS_UWP public SpatialCoordinateSystem QRSpatialCoordinateSystem { get; set; } public Guid SpatialGraphNodeID { get; set; } public QRCodeInformation(string data, SpatialCoordinateSystem qrSpatialCoordinateSystem, float length, Guid spatialGraphNodeID) { Data = data; Length = length; QRSpatialCoordinateSystem = qrSpatialCoordinateSystem; SpatialGraphNodeID = spatialGraphNodeID; } #endif public QRCodeInformation() { } }I had to change some code to match the new constructor's signature.
Then, to find the pose, I use this code instead:
SpatialGraphNode node = SpatialGraphNode.FromStaticNodeId(SpatialGraphNodeID); Pose pose; if (node != null && node.TryLocate(FrameTime.OnUpdate, out pose)) { if (CameraCache.Main.transform.parent != null) { pose = pose.GetTransformedBy(CameraCache.Main.transform.parent); } marker.transform.SetPositionAndRotation(pose.position, pose.rotation); }This snippet is from: Microsoft' QR Source Code
I hate making public posts very much. However, I think this would be a very good PSA for anyone who's about to go Kylo Ren on their equipment.
PS: I could clean up your code to remove any WinRT reference too, but I just have no fight left at the moment.