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.

ARFoundation 2.1 <-> Azure Cloud Spatial Anchors

Discussion in 'AR' started by shawww, May 16, 2019.

  1. shawww

    shawww

    Joined:
    Sep 30, 2014
    Posts:
    43
    Hello,

    We've been using ARExtensions to grab the native session pointer from the ARFoundation session subsystem and pass it to the Azure Spatial Anchors plugin.

    Everything was working with standard ARKit / Core. When we moved to ARFoundation, Android will receive the session pointer successfully, but crashes when we try to start the cloud anchor session. ARKit crashes when we try to pass in the native pointer.

    I know that once it hits the Microsoft AzureSpatialAnchors.DLL it's out of Unity's hands, and that is where it's crashing. But what I don't understand is why it would treat the native session handler from ARFoundation any different than the one from ARKit or ARCore.

    Help would be much appreciated!
     
    lab3apps likes this.
  2. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    605
    ARFoundation does not support Azure Spatial Anchors directly. If you're trying to pass it an ARAnchor pointer (on ARKit, for instance), you need to first interpret the native pointer provided by ARFoundation -- it is not a raw ARAnchor. See https://forum.unity.com/threads/get...ointer-with-arfoundation.589390/#post-3934855
     
  3. shawww

    shawww

    Joined:
    Sep 30, 2014
    Posts:
    43
    @tdmowrer Super useful information. Explains why it wasn't working on Android, as we were getting stuck on the process frame step.
    In that post it mentions a C header to get the struct -- is there any documentation on this now or since 2.0.2?
    And on ARKit, it fails when we send the session pointer to the Azure plugin. Could it be a similar problem? The pointer to the session that we're getting isn't the actual ARKit session pointer? (we're getting it like var ptr = arSession.subsystem.nativePtr);
     
  4. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    605
    We haven't released the C header yet. However, they all work in a similar way, where the first 4 bytes will be an int representing a version number and the pointer (or other data) will follow that. In the current release, the relevant pointer is always immediately after the version number.
     
    Blarp likes this.
  5. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    605
    Correct; all native pointers work this way.
     
  6. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    267
    Azure Cognitive Services might be a big deal for enterprise AR in the near future.

    I can see microsoft's spatial anchors fitting into this similar to arworldmap for apple, placenote for custom maps

    #randominfo

     
  7. shawww

    shawww

    Joined:
    Sep 30, 2014
    Posts:
    43
    I deleted my last post because I thought it was a stupid question... but I guess I was correct :p seems like we can get a pointer to the native sessions pointer struct, cast it, and get the pointer from there, or do some really dirty C# like this:
    Code (CSharp):
    1. IntPtr pointerToARNativeSession = (IntPtr)(arSession.subsystem.nativePtr.ToInt64() + sizeof(int));
    Have I understood you correctly?
     
    Blarp likes this.
  8. thomas_opuscope

    thomas_opuscope

    Joined:
    Nov 2, 2018
    Posts:
    2
    Hello everyone,

    We've tried to make the Azure Spatial Anchors SDK work with ARFoundation 1.0 and failed, but I'm happy to see others are currently attempting to make it work with ARFoundation v2.1! If needed, I'd gladly help on the initiative and try to help.

    In the meantime, there's this ticket on the Azure Feedback website: https://feedback.azure.com/forums/9...-arfoundation-instead-of-arkit-arcore-plugins
     
    Blarp likes this.
  9. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    605
    Yes, you've understood correctly.
     
    Blarp likes this.
  10. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    267
    if you can barebones the ARF & Azure Spatial proj to Github, that would be awesome @shawww

    If you are able to open src that piece, I'm sure bards will sing of your tales.
     
  11. shawww

    shawww

    Joined:
    Sep 30, 2014
    Posts:
    43
    After bothering quite a few folks on both the Unity and Microsoft side, the conclusion that we arrived at was that the versions of ARKit and ARCore that ARFoundation and Azure Spatial Anchors are relying on are too different. The API calls on Android are similar enough that it doesn't crash immediately when passing the native session handler to ASA, but something breaks later in the flow. Since the session pointers are valid, and they're being sent properly to the native Azure Spatial Anchors plugin, it really seems like it just comes down to that damn version conflict.

    This should be totally doable. It's unfortunate that the UnityARKit and ARCore stuff is locked away in DLLs inside read-only packages now, because it means we can't really hack a fix together without a loooot of guesswork :(

    I'm sure it'll get worked out eventually... but ARFoundation is still just *almost* useful for production AR projects since it doesn't support the cutting edge stuff that is really just beginning to unlock AR's potential.
     
    coder89, haowjern and Blarp like this.
  12. coder89

    coder89

    Joined:
    Oct 26, 2018
    Posts:
    29
    Blarp likes this.