Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Grabbing a world anchor from a session with AR foundation and AR ReferencePoint

Discussion in 'AR' started by mr_kodjo, Mar 5, 2020.

  1. mr_kodjo

    mr_kodjo

    Joined:
    Jan 18, 2020
    Posts:
    4
    I am pretty new to using Azure Spatial Anchors with Unity, but I am following a tutorial on Microsoft's documentation site for using Spatial Anchors. This particular one is directed towards using Hololens, but I am going through and, on my end, trying to configure it towards being used on iOS and Android. But I am getting tripped up at this particular part of the tutorial:

    // Get the WorldAnchor from the CloudSpatialAnchor and use it to position the sphere. sphere.GetComponent<UnityEngine.XR.WSA.WorldAnchor>().SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);

    I am wanting to use an AR ReferencePoint instead of a WorldAnchor but I am having trouble translating the above code to what I need. Particularly the SetNativeSpatialAnchorPtr part. Any help would be great!
     
  2. Magiel_ICT

    Magiel_ICT

    Joined:
    Mar 27, 2021
    Posts:
    2
    To get the position of located Azure Spatial Anchors without UnityEngine.XR.WSA and without WorldAnchors:
    Finally in
    Release v2.9.0 · Azure/azure-spatial-anchors-samples · GitHub
    I found CloudSpatialAnchor.GetPose();

    Code (CSharp):
    1.      
    2.         private void CloudSession_AnchorLocated(object sender, AnchorLocatedEventArgs anchorLocatedEventArgs)
    3.         {
    4.             OnSpatialAnchorFeedback.Invoke($"AnchorLocated Status : '{anchorLocatedEventArgs.Status}' {anchorLocatedEventArgs.Anchor.Identifier} ");
    5.             switch (anchorLocatedEventArgs.Status)
    6.             {
    7.                 case LocateAnchorStatus.Located:
    8.                     Pose anchorPose = Pose.identity;
    9.                     anchorPose = anchorLocatedEventArgs.Anchor.GetPose();
    10.                     SpawnOrMoveCurrentAnchoredObject(anchorPose.position, anchorPose.rotation);
    11.                     break;
    12.                 case LocateAnchorStatus.AlreadyTracked:
    13.                     // This anchor has already been reported and is being tracked
    14.                     break;
    15.                 case LocateAnchorStatus.NotLocatedAnchorDoesNotExist:
    16.                     // The anchor was deleted or never existed in the first place
    17.                     // Drop it, or show UI to ask user to anchor the content anew
    18.                     break;
    19.                 case LocateAnchorStatus.NotLocated:
    20.                     // The anchor hasn't been found given the location data
    21.                     // The user might in the wrong location, or maybe more data will help
    22.                     // Show UI to tell user to keep looking around
    23.                     break;
    24.             }
    25.         }
    26.