In my Application I want to scan a QR Code and spawn a Panel on top of it but I have 2 problems with the process…
First of I use Unity 2021 with MRTK3 pre 12 and the QR tracking code is from here:
MixedReality-QRCode-Sample/SpatialGraphNode.cs at main · microsoft/MixedReality-QRCode-Sample · GitHub
Here is how I changed it:
if (node == null)
{
Debug.Log("InitializeSpatialGraphNode");
node = (Id != System.Guid.Empty) ? SpatialGraphNode.FromStaticNodeId(Id) : null;
if (node != null)
{
Debug.Log("Initialize SpatialGraphNode Id= " + Id);
isNew = true;
}
}
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 (Camera.main.transform.parent != null)
{
Debug.Log("Pose before transformedby QRPose = " + pose.position.ToString("F7") + " QRRot = " + pose.rotation.ToString("F7"));
pose = pose.GetTransformedBy(Camera.main.transform.parent);
// Rotate the panel so it faces the user
pose.rotation *= Quaternion.Euler(180, 0, 0);
}
if (isNew)
{
isNew = false;
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);
}
}
When I scan the QR Code my Panel with the SpacialGraphNode Script get spawned in (but always facing away from me? I don’t know why but that’s why the 180° rotation is in there) but it never gets a note so it can’t position my panel. Adding some Debug texts reveals that I always end in the #else path wich just returns null all the time.
If I change the #if WINDOWS_UWP && UNITY_XR_WINDOWSMR to just #if WINDOWS_UWP and switch to player I can see that the code should be reached but then I get an error saying that “WindowsMREnvironment” is not in “UnityEngine.XR.WindowsMR” maybe that is the problem?
I tried running the App through Holographic Remoting and also building it and starting the app on the HoloLens itself. Has anybody an idea what the problem could be?
Best regards