diff --git a/Runtime/Scripts/WorldAnalysisARFoundationCoroutineHelper.cs b/Runtime/Scripts/WorldAnalysisARFoundationCoroutineHelper.cs index 2aebd0785095b226a7c730b44282c2380cd9a4af..b240bde546727c4f19b6969cf2b3efb8ee7f6d7d 100644 --- a/Runtime/Scripts/WorldAnalysisARFoundationCoroutineHelper.cs +++ b/Runtime/Scripts/WorldAnalysisARFoundationCoroutineHelper.cs @@ -8,11 +8,6 @@ public class WorldAnalysisARFoundationCoroutineHelper : MonoBehaviour private void Awake() { - // If there is an instance, and it's not me, delete myself. - - - Debug.Log("HERE SINGLETON AWAKE"); - if (Instance != null && Instance != this) { Destroy(this); @@ -25,7 +20,6 @@ public class WorldAnalysisARFoundationCoroutineHelper : MonoBehaviour public void StartACoroutine(IEnumerator coroutine) { - Debug.Log("HERE SINGLETON"); StartCoroutine(coroutine); } -} +} \ No newline at end of file diff --git a/Runtime/Scripts/WorldAnalysisARFoundationModuleARKitWorldMap.cs b/Runtime/Scripts/WorldAnalysisARFoundationModuleARKitWorldMap.cs index 5bb1ea438c5ca7c6a42e127f8df837f6f93122c3..5b1ef2042b46b360f4d720e7a9972e07d5ad94c8 100644 --- a/Runtime/Scripts/WorldAnalysisARFoundationModuleARKitWorldMap.cs +++ b/Runtime/Scripts/WorldAnalysisARFoundationModuleARKitWorldMap.cs @@ -119,6 +119,8 @@ public class WorldAnalysisARFoundationModuleARKitWorldMap : WorldAnalysisARFound { foreach (var trackedAnchor in eventArgs.updated) { + Debug.Log("Anchor found " +trackedAnchor.trackableId.ToString()); + if (trackedAnchor.trackableId.ToString() == m_arfoundationAnchorTrackableId) { /// look for an anchor with the trackable Id correspond to the ETSI ARF trackable name @@ -137,12 +139,14 @@ public class WorldAnalysisARFoundationModuleARKitWorldMap : WorldAnalysisARFound { if (url.Length > 0) { + Debug.Log("Load AR Map from URL"); LoadWorldMapFromURL(url); // don't check if url is valid return true ; } else { + Debug.Log("Load AR Map locally"); string localMap = Application.persistentDataPath + "/ARkitWorlMap.map"; if (File.Exists(localMap)) { @@ -191,31 +195,44 @@ public class WorldAnalysisARFoundationModuleARKitWorldMap : WorldAnalysisARFound /// <returns>coroutine</returns> public IEnumerator CoroutineLoadWorldMap(string mapPath) { + while (ARSession.state == ARSessionState.CheckingAvailability || ARSession.state == ARSessionState.None ||ARSession.state == ARSessionState.SessionInitializing) + { + // wait for ar session to be ready + yield return null ; + } + ARSession session = Component.FindAnyObjectByType<ARSession>() ; ARKitSessionSubsystem sessionSubsystem = (ARKitSessionSubsystem)session.subsystem; - FileStream file; - file = File.Open(mapPath, FileMode.Open); - const int bytesPerFrame = 1024 * 10; - var bytesRemaining = file.Length; - var binaryReader = new BinaryReader(file); - var allBytes = new List<byte>(); - while (bytesRemaining > 0) + if (sessionSubsystem == null) { - var bytes = binaryReader.ReadBytes(bytesPerFrame); - allBytes.AddRange(bytes); - bytesRemaining -= bytesPerFrame; - yield return null; + Debug.Log("Cannot load map: no ARKitSessionSubsystem"); } - - var data = new NativeArray<byte>(allBytes.Count, Allocator.Temp); - data.CopyFrom(allBytes.ToArray()); - ARWorldMap worldMap; - if (ARWorldMap.TryDeserialize(data, out worldMap)) + else { - data.Dispose(); + FileStream file; + file = File.Open(mapPath, FileMode.Open); + const int bytesPerFrame = 1024 * 10; + var bytesRemaining = file.Length; + var binaryReader = new BinaryReader(file); + var allBytes = new List<byte>(); + while (bytesRemaining > 0) + { + var bytes = binaryReader.ReadBytes(bytesPerFrame); + allBytes.AddRange(bytes); + bytesRemaining -= bytesPerFrame; + yield return null; + } + + var data = new NativeArray<byte>(allBytes.Count, Allocator.Temp); + data.CopyFrom(allBytes.ToArray()); + ARWorldMap worldMap; + if (ARWorldMap.TryDeserialize(data, out worldMap)) + { + data.Dispose(); + } + sessionSubsystem.ApplyWorldMap(worldMap); + UpdateTrackableInfoWithPose(Vector3.zero, Quaternion.identity); // before trying to find an anchor: default pause is origin of the map } - sessionSubsystem.ApplyWorldMap(worldMap); - UpdateTrackableInfoWithPose(Vector3.zero, Quaternion.identity); // before trying to find an anchor: default pause is origin of the map } } #endif \ No newline at end of file