Azure / azure-spatial-anchors-samples

Azure Spatial Anchors sample code
Other
293 stars 139 forks source link

NearAnchorCriteria setup #278

Closed konstyanchev closed 3 years ago

konstyanchev commented 3 years ago

Hello,

I'm having trouble locating any anchors when trying to use NearAnchorCriteria.

I'm currently testing on: Unity 2019.4.24f1 ASA: 2.8.1

My steps are as following:

  1. Create first anchor (Anchor A) and upload to ASA.
  2. Create second anchor (Anchor B) and upload to ASA.
  3. Attempt to locate the anchor closest to me (in that case A) and use it as SourceAnchor for NearAnchorCriteria.
  4. Create a new AnchorLocateCriteria and set its Strategy property to Relartionship
  5. Create a watcher that uses the newly created AnchorLocateCriteria.

However, this watcher doesn't locate any anchors. I also tried removing the local anchor for B (B can still be downloaded from the cloud if using a NearDeviceCriteria or Identifiers) but nothing is found. My understanding is that if I already have anchor A, that I found using the 2 other methods, I can use NearAnchorCriteria and A as a starting point to find B or any other anchors that have been created after A. Is there a step that I'm missing? Also, whenever I attempt a NearAnchorCriteria search I'm no longer able to delete any anchors currently visible in the scene. What is the reason for that? Resetting the session and the watcher doesn't seem to help.

pamistel commented 3 years ago

Hi

In order to have the anchors linked with each other they have to be created in the same session. There is also a documentation page explaining how to use different Anchor Locate strategies: https://docs.microsoft.com/en-us/azure/spatial-anchors/concepts/anchor-locate-strategy#nearanchor

Also, in your steps your not mentioning that you're setting the source anchor. Please make sure you set a source anchor when using NearAnchor strategy

konstyanchev commented 3 years ago

Hello,

Thank you for the reply. I am indeed creating my anchors in the same session so I don't think that is the problem.

Also, in your steps your not mentioning that you're setting the source anchor. Please make sure you set a source anchor when using NearAnchor strategy'

Do you mean that an anchor has to be designated as a source anchor during the upload to ASA or as a source for NearAnchorCriteria? If it's the latter I'm doing that in step 3. This is the code I'm using to create the criteria for the watcher. The anchor that gets passed is the first I've created during a session (I've verified the IDs). I've checked the samples app and the NearbyDemo code but apart from changing the strategy and setting a SourceAnchor I don't see anything different.

    private void LocateNearbyAnchors(CloudSpatialAnchor inStartAnchor)
    {
        NearAnchorCriteria naCriteria = new NearAnchorCriteria();
        naCriteria.SourceAnchor = inStartAnchor;
        naCriteria.DistanceInMeters = _sas.NearbyDistance;

        AnchorLocateCriteria locateCriteria = new AnchorLocateCriteria();
        locateCriteria.NearAnchor = naCriteria;
        locateCriteria.Strategy = LocateStrategy.Relationship;

        if (_currentWatcher != null)
        {
            _currentWatcher.Stop();
            _currentWatcher = null;
        }
        _currentWatcher = _cloudSpatialAnchorSession.CreateWatcher(locateCriteria);
        Debug.Log("Anchor Watcher created.");
    } 
pamistel commented 3 years ago

Can i ask you to try the following to make sure it's not the device, network or Azure Service set up:

  1. Clone the ASA sample (clone, don't download as zip)
  2. Download the Mixed Reality Feature Tool.
  3. Run the MR Feature tool and select ...\azure-spatial-anchors-samples\Unity\
  4. Under Azure Mixed reality Services select the following four checkboxes:
    • "Azure Spatial Anchors SDK for Android" 2.10.2
    • "Azure Spatial Anchors SDK Core" 2.10.2
    • "Azure Spatial Anchors SDK for iOS" 2.10.2
    • "Azure Spatial Anchors SDK for Windows" 2.10.2
  5. Finish the MR Feature Tool wizard
  6. Open the project in Unity 2020.3.12
  7. In the Project folders go to Assets>AzureSpatialAnchors.SDK>Resources>SpatialAnchorConfig and type in your ASA credentials
  8. Save
  9. Change the build Platform to "Universal Windows Platform"
  10. Build
  11. Open the .sln in Visual studio and deploy it to your HoloLens 2
  12. Make sure your HoloLens 2 has a working internet connection
  13. Run the NearAnchor example

Does this demo work as expected and you can create 3 anchors, find the first one and then the other 2?

konstyanchev commented 3 years ago

I'll try that and report back. Unfortunately I won't have access to a HL2 device until Thursday so I will update after that. I have tried the NearbyDemo sample on the same device with the same network and credentials and it worked correctly. It finds the first anchor, changes its scale and then finds the 2 other anchors and turns them green. (small note, no anchor is deleted between the placement and location stage as it's the case for the basic demo, but looking at the code that seems to be intentional). This was done with the 2.9.0 SDK and Unity 2020.3.12f1. I was waiting for the Remote Rendering SDK to be compatible with OpenXR before transitioning to Unity 2020. I just saw that it was recently updated so I will update the project to the new Unity version and update the ASA SDK to the latest supported version and try again.

konstyanchev commented 3 years ago

So as mentioned the demo works just fine. Unfortunately it will take me some time to update my project to Unity 2020 and ASA 2.10 as I need to rewrite a significant part of the code. Unrelated to the issue but it looks like now that the world anchor components are replaced by ARAnchors and the NativeToCloud requires that a SpatialAnchorManager.cs is present in the scene. In the demo project an ARFoundation object is added automatically when the scene starts. Could you please tell me how this is happening? I don't think the documentation has been updated yet.