From e68c91f304caf48e3221e71a06fd2fc834e4b19b Mon Sep 17 00:00:00 2001 From: jlacoche <jeremy.lacoche@orange.com> Date: Fri, 5 Jul 2024 09:58:58 +0200 Subject: [PATCH] simplify arcore anchor module and remove arcoreextensions on ios --- Runtime/Scripts/WorldAnalysisARFoundation.cs | 13 ++++- ...dAnalysisARFoundationModuleARCoreAnchor.cs | 58 +++++-------------- 2 files changed, 27 insertions(+), 44 deletions(-) diff --git a/Runtime/Scripts/WorldAnalysisARFoundation.cs b/Runtime/Scripts/WorldAnalysisARFoundation.cs index 671265f..9562f7b 100644 --- a/Runtime/Scripts/WorldAnalysisARFoundation.cs +++ b/Runtime/Scripts/WorldAnalysisARFoundation.cs @@ -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,13 +82,23 @@ 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) + foreach (WorldAnalysisARFoundationModule module in m_trackableModules) { module.Initialize(); } diff --git a/Runtime/Scripts/WorldAnalysisARFoundationModuleARCoreAnchor.cs b/Runtime/Scripts/WorldAnalysisARFoundationModuleARCoreAnchor.cs index 4ef7bc9..9bd2d3e 100644 --- a/Runtime/Scripts/WorldAnalysisARFoundationModuleARCoreAnchor.cs +++ b/Runtime/Scripts/WorldAnalysisARFoundationModuleARCoreAnchor.cs @@ -1,4 +1,4 @@ -#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 { -- GitLab