Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • arf/world-analysis-api-helpers/unity-world-analysis-arfoundation-wrapper-package
1 result
Show changes
Commits on Source (1)
...@@ -8,6 +8,7 @@ using System.Collections; ...@@ -8,6 +8,7 @@ using System.Collections;
using System.Linq; using System.Linq;
using ETSI.ARF.OpenAPI.WorldStorage; using ETSI.ARF.OpenAPI.WorldStorage;
using ETSI.ARF.WorldStorage.REST; using ETSI.ARF.WorldStorage.REST;
using ;
//Implementation of the WorldAnalysis interface //Implementation of the WorldAnalysis interface
public class WorldAnalysisARFoundation : MonoBehaviour, WorldAnalysisInterface public class WorldAnalysisARFoundation : MonoBehaviour, WorldAnalysisInterface
...@@ -81,13 +82,23 @@ public class WorldAnalysisARFoundation : MonoBehaviour, WorldAnalysisInterface ...@@ -81,13 +82,23 @@ public class WorldAnalysisARFoundation : MonoBehaviour, WorldAnalysisInterface
WorldAnalysisARFoundationModuleMesh meshModule = new WorldAnalysisARFoundationModuleMesh(); WorldAnalysisARFoundationModuleMesh meshModule = new WorldAnalysisARFoundationModuleMesh();
m_trackableModules.Add(meshModule); m_trackableModules.Add(meshModule);
#endif #endif
#if ETSIARF_ARCORE_EXTENSIONS
#if UNITY_ANDROID #if UNITY_ANDROID
// todo add script define symbol for using arcore extensions // todo add script define symbol for using arcore extensions
WorldAnalysisARFoundationModuleARCoreAnchor arCoreAnchorModule = new WorldAnalysisARFoundationModuleARCoreAnchor(); WorldAnalysisARFoundationModuleARCoreAnchor arCoreAnchorModule = new WorldAnalysisARFoundationModuleARCoreAnchor();
m_trackableModules.Add(arCoreAnchorModule); 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 #endif
foreach(WorldAnalysisARFoundationModule module in m_trackableModules) foreach (WorldAnalysisARFoundationModule module in m_trackableModules)
{ {
module.Initialize(); module.Initialize();
} }
......
#if UNITY_ANDROID #if UNITY_ANDROID && ETSIARF_ARCORE_EXTENSIONS
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -12,39 +12,17 @@ using static WorldAnalysisARFoundationModule; ...@@ -12,39 +12,17 @@ using static WorldAnalysisARFoundationModule;
public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFoundationModule public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFoundationModule
{ {
/// <summary> /// <summary>
/// /// Anchor manager
/// </summary> /// </summary>
private ARAnchorManager m_anchorManager; private ARAnchorManager m_anchorManager;
/// <summary> /// <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 /// List of cloud anchors with tracking infos
/// </summary> /// </summary>
private Dictionary<string, TrackableInfo> m_trackedCloudAnchors = new Dictionary<string, TrackableInfo>(); private Dictionary<string, TrackableInfo> m_trackedCloudAnchors = new Dictionary<string, TrackableInfo>();
/// <summary> /// <summary>
/// /// Correspondance between local trackable and etsi uuid
/// </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
/// </summary> /// </summary>
private Dictionary<string, string> m_localIdToCloudId = new Dictionary<string, string>(); private Dictionary<string, string> m_localIdToEtsiId = new Dictionary<string, string>();
/// <summary>
/// ETSI ID
/// </summary>
private Dictionary<string, string> m_CloudIdToETSIId = new Dictionary<string, string>();
/// <summary>
///
/// </summary>
private GameObject m_anchorPrefab;
/// <summary> /// <summary>
/// Initialize ARCore cloud anchors tracking module /// Initialize ARCore cloud anchors tracking module
...@@ -53,9 +31,8 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda ...@@ -53,9 +31,8 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
{ {
XROrigin origin = UnityEngine.Object.FindAnyObjectByType<XROrigin>(); XROrigin origin = UnityEngine.Object.FindAnyObjectByType<XROrigin>();
m_anchorManager = origin.gameObject.AddComponent<ARAnchorManager>(); m_anchorManager = origin.gameObject.AddComponent<ARAnchorManager>();
m_cloudAnchorAdded = new List<string>(); GameObject anchorPrefab = (GameObject)Resources.Load("ARFAnchorTrackingPrefab");
m_anchorPrefab = (GameObject)Resources.Load("ARFAnchorTrackingPrefab"); m_anchorManager.anchorPrefab = anchorPrefab;
m_anchorManager.anchorPrefab = m_anchorPrefab;
m_anchorManager.anchorsChanged += OnTrackedCloudAnchorChanged; m_anchorManager.anchorsChanged += OnTrackedCloudAnchorChanged;
} }
...@@ -88,7 +65,7 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda ...@@ -88,7 +65,7 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
{ {
return false; 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; return true;
} }
...@@ -125,9 +102,9 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda ...@@ -125,9 +102,9 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
TrackableInfo info = new TrackableInfo(); TrackableInfo info = new TrackableInfo();
info.name = trackedCloudAnchor.name; info.name = trackedCloudAnchor.name;
string localId = trackedCloudAnchor.trackableId.subId1.ToString("X16");// there must be a better way : does it work every time? 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 else
{ {
...@@ -169,25 +146,23 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda ...@@ -169,25 +146,23 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
await System.Threading.Tasks.Task.Delay(100); await System.Threading.Tasks.Task.Delay(100);
} }
string googleCloudID = trackable.Name; string googleCloudID = trackable.Name;
m_CloudIdToETSIId.Add(googleCloudID, trackable.UUID.ToString()); ResolveCloudAnchor(googleCloudID, trackable.UUID.ToString());
ResolveCloudAnchor(googleCloudID);
} }
/// <summary> /// <summary>
/// Resolves Cloud Anchors using a given id /// Resolves Cloud Anchors using a given id
/// </summary> /// </summary>
/// <param name="cloudId"></param> /// <param name="cloudId"></param>
public void ResolveCloudAnchor(string cloudId) public void ResolveCloudAnchor(string cloudId, string etsiId)
{ {
var promise = m_anchorManager.ResolveCloudAnchorAsync(cloudId); var promise = m_anchorManager.ResolveCloudAnchorAsync(cloudId);
if (promise.State == PromiseState.Done) if (promise.State == PromiseState.Done)
{ {
Debug.LogFormat("Failed to resolve Cloud Anchor " + cloudId); Debug.Log("Failed to resolve Cloud Anchor " + cloudId);
} }
else else
{ {
_resolvePromises.Add(promise); var coroutine = ResolveAnchor(promise, cloudId, etsiId);
var coroutine = ResolveAnchor(promise, cloudId);
WorldAnalysisARFoundationCoroutineHelper.Instance.StartACoroutine(coroutine); WorldAnalysisARFoundationCoroutineHelper.Instance.StartACoroutine(coroutine);
} }
} }
...@@ -197,17 +172,14 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda ...@@ -197,17 +172,14 @@ public class WorldAnalysisARFoundationModuleARCoreAnchor : WorldAnalysisARFounda
/// </summary> /// </summary>
/// <param name="promise"></param> /// <param name="promise"></param>
/// <returns></returns> /// <returns></returns>
private IEnumerator ResolveAnchor(ResolveCloudAnchorPromise promise, string cloudId) private IEnumerator ResolveAnchor(ResolveCloudAnchorPromise promise, string cloudId, string etsiId)
{ {
yield return promise; yield return promise;
var result = promise.Result; var result = promise.Result;
_resolvePromises.Remove(promise);
_resolveResults.Add(result);
if (result.CloudAnchorState == CloudAnchorState.Success) if (result.CloudAnchorState == CloudAnchorState.Success)
{ {
Debug.Log("ARCloud Anchor Resolve Sucess" +cloudId); 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 else
{ {
......