protected override SpongyAnchor CreateAnchor(AnchorId id, Transform parent, Pose initialPose) { SpongyAnchorXR spongyAnchorXR = null; if (IsTracking()) { DebugLogExtra($"Creating refPt at initial ({initialPose.position.x:0.000}, {initialPose.position.y:0.000}, {initialPose.position.z:0.000})"); XRReferencePoint xrReferencePoint; bool created = xrReferencePointManager.TryAddReferencePoint(initialPose, out xrReferencePoint); if (created) { Pose xrPose = xrReferencePoint.pose; DebugLogExtra($"Created refPt {id} at ({xrPose.position.x:0.000}, {xrPose.position.y:0.000}, {xrPose.position.z:0.000}) is {xrReferencePoint.trackingState}"); var newAnchorObject = new GameObject(id.FormatStr()); newAnchorObject.transform.parent = parent; newAnchorObject.transform.SetGlobalPose(initialPose); spongyAnchorXR = newAnchorObject.AddComponent <SpongyAnchorXR>(); anchorsByTrackableId[xrReferencePoint.trackableId] = spongyAnchorXR; spongyAnchorXR.TrackableId = xrReferencePoint.trackableId; DebugLogExtra($"{id} {DebugVector3("P=", initialPose.position)}, {DebugQuaternion("Q=", initialPose.rotation)}"); } } return(spongyAnchorXR); }
private static void DebugOutExtra(string label, XRAnchor xrAnchor, SpongyAnchorXR tracker) { Debug.Assert(xrAnchor.trackableId == tracker.TrackableId); Vector3 tP = tracker.transform.position; Vector3 tR = tracker.transform.rotation.eulerAngles; Vector3 rP = xrAnchor.pose.position; Vector3 rR = xrAnchor.pose.rotation.eulerAngles; rR = new Vector3(1.0f, 2.0f, 3.0f); Debug.Log($"{label}{tracker.name}-{tracker.TrackableId}/{xrAnchor.trackingState}: {DebugVector3("tP=", tP)}|{DebugEuler("tR=", tR)} <=> {DebugVector3("rP=", rP)}|{DebugEuler("rR=", rR)}"); }
protected override SpongyAnchor DestroyAnchor(AnchorId id, SpongyAnchor spongyAnchor) { SpongyAnchorXR spongyAnchorXR = spongyAnchor as SpongyAnchorXR; if (spongyAnchorXR != null) { Debug.Assert(anchorsByTrackableId[spongyAnchorXR.TrackableId] == spongyAnchorXR); anchorsByTrackableId.Remove(spongyAnchorXR.TrackableId); xrReferencePointManager.TryRemoveReferencePoint(spongyAnchorXR.TrackableId); GameObject.Destroy(spongyAnchorXR.gameObject); } RemoveSpongyAnchorById(id); return(null); }
private SpongyAnchorXR PrepAnchor(AnchorId anchorId, Transform parent, TrackableId trackableId, Pose xrPose) { var newAnchorObject = new GameObject(anchorId.FormatStr()); newAnchorObject.transform.parent = parent; newAnchorObject.transform.SetGlobalPose(xrPose); SpongyAnchorXR spongyAnchorXR = newAnchorObject.AddComponent <SpongyAnchorXR>(); anchorsByTrackableId[trackableId] = spongyAnchorXR; spongyAnchorXR.TrackableId = trackableId; spongyAnchorXR.IsReliablyLocated = false; DebugLogExtra($"{anchorId} {DebugVector3("P=", xrPose.position)}, {DebugQuaternion("Q=", xrPose.rotation)}"); return(spongyAnchorXR); }
protected override SpongyAnchor CreateAnchor(AnchorId id, Transform parent, Pose initialPose) { SpongyAnchorXR spongyAnchorXR = null; if (IsTracking()) { DebugLogExtra($"Creating anchor at initial ({initialPose.position.x:0.000}, {initialPose.position.y:0.000}, {initialPose.position.z:0.000})"); XRAnchor xrAnchor; bool created = xrAnchorManager.TryAddAnchor(initialPose, out xrAnchor); if (created) { spongyAnchorXR = PrepAnchor(id, parent, xrAnchor.trackableId, xrAnchor.pose); } } return(spongyAnchorXR); }
private static void DebugOutExtra(string label, XRReferencePoint referencePoint, SpongyAnchorXR tracker) { #if WLT_EXTRA_LOGGING Debug.Assert(referencePoint.trackableId == tracker.TrackableId); Vector3 tP = tracker.transform.position; Vector3 tR = tracker.transform.rotation.eulerAngles; Vector3 rP = referencePoint.pose.position; Vector3 rR = referencePoint.pose.rotation.eulerAngles; rR = new Vector3(1.0f, 2.0f, 3.0f); Debug.Log($"{label}{tracker.name}-{tracker.TrackableId}/{referencePoint.trackingState}: {DebugVector3("tP=", tP)}|{DebugEuler("tR=", tR)} <=> {DebugVector3("rP=", rP)}|{DebugEuler("rR=", rR)}"); #endif // WLT_EXTRA_LOGGING }