Commit e68c91f3 authored by Jérémy Lacoche's avatar Jérémy Lacoche
Browse files

simplify arcore anchor module and remove arcoreextensions on ios

parent 172068e0
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ using System.Collections;
using System.Linq;
using ETSI.ARF.OpenAPI.WorldStorage;
using ETSI.ARF.WorldStorage.REST;
using ;

//Implementation of the WorldAnalysis interface
public class WorldAnalysisARFoundation : MonoBehaviour, WorldAnalysisInterface
@@ -81,10 +82,20 @@ public class WorldAnalysisARFoundation : MonoBehaviour, WorldAnalysisInterface
        WorldAnalysisARFoundationModuleMesh meshModule = new WorldAnalysisARFoundationModuleMesh();
        m_trackableModules.Add(meshModule);
#endif
#if ETSIARF_ARCORE_EXTENSIONS
    
#if UNITY_ANDROID
        // todo add script define symbol for using arcore extensions
        WorldAnalysisARFoundationModuleARCoreAnchor arCoreAnchorModule = new WorldAnalysisARFoundationModuleARCoreAnchor();
        m_trackableModules.Add(arCoreAnchorModule);
#else
        /// on other os : if arcore extensions is in the scene we disable it
        Google.XR.ARCoreExtensions.ARCoreExtensions arCoreExtensions = Component.FindObjectOfType<Google.XR.ARCoreExtensions.ARCoreExtensions>();
        if (arCoreExtensions != null)
        {
            arCoreExtensions.enabled = false; 
        }
#endif
#endif

        foreach (WorldAnalysisARFoundationModule module in m_trackableModules)
+15 −43
Original line number Diff line number Diff line
#if UNITY_ANDROID
#if UNITY_ANDROID && ETSIARF_ARCORE_EXTENSIONS
using System;
using System.Collections;
using System.Collections.Generic;
@@ -12,39 +12,17 @@ using static WorldAnalysisARFoundationModule;
public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFoundationModule 
{
    /// <summary>
    /// 
    ///  Anchor manager
    /// </summary>
    private ARAnchorManager m_anchorManager;
    /// <summary>
    /// IDs of all the cloud anchors that have been resolved 
    /// </summary>
    private List<string> m_cloudAnchorAdded;//useful ?
    /// <summary>
    /// List of cloud anchors with tracking infos
    /// </summary>
    private Dictionary<string, TrackableInfo> m_trackedCloudAnchors = new Dictionary<string, TrackableInfo>();
    /// <summary>
    /// 
    /// </summary>
    private List<ResolveCloudAnchorPromise> _resolvePromises = new List<ResolveCloudAnchorPromise>();
    /// <summary>
    /// 
    /// </summary>
    private List<ResolveCloudAnchorResult> _resolveResults = new List<ResolveCloudAnchorResult>();
    /// <summary>
    /// Correspondance between google cloud id and local trackable id
    /// Correspondance between local trackable and etsi uuid
    /// </summary>
    private Dictionary<string, string> m_localIdToCloudId = new Dictionary<string, string>();

    /// <summary>
    /// ETSI ID
    /// </summary>
    private Dictionary<string, string> m_CloudIdToETSIId = new Dictionary<string, string>();

    /// <summary>
    /// 
    /// </summary>
    private GameObject m_anchorPrefab;
    private Dictionary<string, string> m_localIdToEtsiId = new Dictionary<string, string>();

    /// <summary>
    /// Initialize ARCore cloud anchors tracking module
@@ -53,9 +31,8 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
    {
        XROrigin origin = UnityEngine.Object.FindAnyObjectByType<XROrigin>();
        m_anchorManager = origin.gameObject.AddComponent<ARAnchorManager>();
        m_cloudAnchorAdded = new List<string>();
        m_anchorPrefab = (GameObject)Resources.Load("ARFAnchorTrackingPrefab");
        m_anchorManager.anchorPrefab = m_anchorPrefab;
        GameObject anchorPrefab = (GameObject)Resources.Load("ARFAnchorTrackingPrefab");
        m_anchorManager.anchorPrefab = anchorPrefab;
        m_anchorManager.anchorsChanged += OnTrackedCloudAnchorChanged;
    }

@@ -88,7 +65,7 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
        {
            return false;
        }
        AddNewARCoreCloudAnchor(trackable);
        AddNewARCoreCloudAnchor(trackable); // here we don't check if the cloud anchor is correctly resolved, this could be imrpoved but would require this method to be async (change of api)
        return true;
    }

@@ -125,9 +102,9 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
            TrackableInfo info = new TrackableInfo();
            info.name = trackedCloudAnchor.name;
            string localId = trackedCloudAnchor.trackableId.subId1.ToString("X16");// there must be a better way : does it work every time?
            if (m_localIdToCloudId.ContainsKey(localId))
            if (m_localIdToEtsiId.ContainsKey(localId))
            {
                info.name =  m_CloudIdToETSIId[m_localIdToCloudId[localId]];
                info.name = m_localIdToEtsiId[localId];
            }
            else
            {
@@ -169,25 +146,23 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
            await System.Threading.Tasks.Task.Delay(100);
        }
        string googleCloudID = trackable.Name;
        m_CloudIdToETSIId.Add(googleCloudID, trackable.UUID.ToString());
        ResolveCloudAnchor(googleCloudID);
        ResolveCloudAnchor(googleCloudID, trackable.UUID.ToString());
    }

    /// <summary>
    /// Resolves Cloud Anchors using a given id
    /// </summary>
    /// <param name="cloudId"></param>
    public void ResolveCloudAnchor(string cloudId)
    public void ResolveCloudAnchor(string cloudId, string etsiId)
    {
        var promise = m_anchorManager.ResolveCloudAnchorAsync(cloudId);
        if (promise.State == PromiseState.Done)
        {
            Debug.LogFormat("Failed to resolve Cloud Anchor " + cloudId);
            Debug.Log("Failed to resolve Cloud Anchor " + cloudId);
        }
        else
        {
            _resolvePromises.Add(promise);
            var coroutine = ResolveAnchor(promise, cloudId);
            var coroutine = ResolveAnchor(promise, cloudId, etsiId);
            WorldAnalysisARFoundationCoroutineHelper.Instance.StartACoroutine(coroutine);
        }
    }
@@ -197,17 +172,14 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
    /// </summary>
    /// <param name="promise"></param>
    /// <returns></returns>
    private IEnumerator ResolveAnchor(ResolveCloudAnchorPromise promise, string cloudId)
    private IEnumerator ResolveAnchor(ResolveCloudAnchorPromise promise, string cloudId, string etsiId)
    {
        yield return promise;
        var result = promise.Result;
        _resolvePromises.Remove(promise);
        _resolveResults.Add(result);

        if (result.CloudAnchorState == CloudAnchorState.Success)
        {
            Debug.Log("ARCloud Anchor Resolve Sucess" +cloudId);
            m_localIdToCloudId.Add(result.Anchor.trackableId.subId2.ToString("X16"), cloudId); // should be a better way: not sure about that but subId2 of the ARCloudAnchor seems to correspond to subId1 of local anchor that is updated by Anchor Manager
            m_localIdToEtsiId.Add(result.Anchor.trackableId.subId2.ToString("X16"), etsiId); // should be a better way: not sure about that but subId2 of the ARCloudAnchor seems to correspond to subId1 of local anchor that is updated by Anchor Manager
        }
        else
        {