protected override SpongyAnchor CreateAnchor(AnchorId id, Transform parent, Pose initialPose)
        {
            DebugLogExtra($"Creating anchor {id.FormatStr()}");
            initialPose = AnchorFromSpongy.Multiply(initialPose);
            SpongyAnchorARF newAnchor = null;

#if WLT_ADD_ANCHOR_COMPONENT
            GameObject go = new GameObject(id.FormatStr());
            go.transform.SetParent(parent);
            go.transform.SetGlobalPose(initialPose);
            ARAnchor arAnchor = go.AddComponent <ARAnchor>();
            newAnchor = WrapARAnchor(id, arAnchor.trackableId, go);
#else // WLT_ADD_ANCHOR_COMPONENT
            var arAnchor = arAnchorManager.AddAnchor(initialPose);
            if (arAnchor == null)
            {
                Debug.LogError($"ARAnchorManager failed to create ARAnchor {id}");
                return(null);
            }
            arAnchor.gameObject.name = id.FormatStr();
            newAnchor = WrapARAnchor(id, arAnchor.trackableId, arAnchor.gameObject);
#endif // WLT_ADD_ANCHOR_COMPONENT
            Debug.Assert(newAnchor != null);
            return(newAnchor);
        }
 /// <summary>
 /// Callback when the set of active spatial anchors changes.
 /// </summary>
 /// <param name="obj">Callback arguments</param>
 /// <remarks>
 /// The only anchor change event we care about is when anchors, which are in the "waitOnLoading" dictionary,
 /// are added. Those are anchors which have been loaded but now need to be finalized.
 /// We ignore other anchor added/changed/removed events.
 /// And in fact, when anchor persistence isn't supported, we don't even bother registering for this event.
 /// </remarks>
 private void OnAnchorsChanged(ARAnchorsChangedEventArgs obj)
 {
     foreach (var added in obj.added)
     {
         DebugLogExtra($"Process Added={added.trackableId}");
         TrackableId trackableId = added.trackableId;
         AnchorId    anchorId;
         if (waitOnLoading.TryGetValue(trackableId, out anchorId))
         {
             Debug.Assert(SpongyAnchors.FindIndex(x => x.anchorId == anchorId) < 0, $"OnAnchorsChanged: {anchorId.FormatStr()} in waiting list, but already in SpongyAnchors");
             added.gameObject.name = anchorId.FormatStr();
             SpongyAnchorARF spongyARF = WrapARAnchor(anchorId, trackableId, added.gameObject);
             // Adding through this path means it was just loaded from anchorStore, which means it's already saved.
             spongyARF.IsSaved = true;
             SpongyAnchors.Add(new SpongyAnchorWithId()
             {
                 anchorId     = anchorId,
                 spongyAnchor = spongyARF
             }
                               );
             waitOnLoading.Remove(trackableId);
         }
         else
         {
             DebugLogExtra($"Incoming trackableId={trackableId} but not in waiting list of {waitOnLoading.Count} pending anchors");
         }
     }
 }
        private SpongyAnchorARF WrapARAnchor(AnchorId anchorId, TrackableId trackableId, GameObject newAnchorObject)
        {
            SpongyAnchorARF spongyAnchorARF = newAnchorObject.AddComponent <SpongyAnchorARF>();

            anchorsByTrackableId[trackableId] = spongyAnchorARF;
            spongyAnchorARF.TrackableId       = trackableId;

            return(spongyAnchorARF);
        }
Esempio n. 4
0
        protected override SpongyAnchor CreateAnchor(AnchorId id, Transform parent, Pose initialPose)
        {
            Debug.Log($"Creating anchor {id.FormatStr()}");
            var referencePoint = arReferencePointManager.AddReferencePoint(initialPose);

            referencePoint.gameObject.name = id.FormatStr();
            SpongyAnchorARF newAnchor = referencePoint.gameObject.AddComponent <SpongyAnchorARF>();

            return(newAnchor);
        }
        protected override SpongyAnchor CreateAnchor(AnchorId id, Transform parent, Pose initialPose)
        {
#if WLT_EXTRA_LOGGING
            Debug.Log($"Creating anchor {id.FormatStr()}");
#endif // WLT_EXTRA_LOGGING
            initialPose = AnchorFromSpongy.Multiply(initialPose);
            var arAnchor = arReferencePointManager.AddReferencePoint(initialPose);
            if (arAnchor == null)
            {
                Debug.LogError($"ARReferencePoinManager failed to create ARAnchor {id}");
                return(null);
            }
            arAnchor.gameObject.name = id.FormatStr();
            SpongyAnchorARF newAnchor = arAnchor.gameObject.AddComponent <SpongyAnchorARF>();
            return(newAnchor);
        }
 private static void DebugOutExtra(string label, ARAnchor arAnchor, SpongyAnchorARF tracker)
 {
     Debug.Assert(arAnchor.trackableId == tracker.TrackableId);
     Debug.Log($"{label}{tracker.name}-{tracker.TrackableId}/{arAnchor.trackingState}: T={tracker.transform.GetGlobalPose().ToString("F3")} AR={arAnchor.transform.GetGlobalPose().ToString("F3")}");
 }