Skip to content
Snippets Groups Projects
Commit 608fce80 authored by lacoche's avatar lacoche
Browse files

remove some log, wait for arsession to be ready for loading arkit world map

parent 900e2250
No related branches found
No related tags found
1 merge request!2WA now supports multiple trackable modules, add module mesh for iOS,...
...@@ -8,11 +8,6 @@ public class WorldAnalysisARFoundationCoroutineHelper : MonoBehaviour ...@@ -8,11 +8,6 @@ public class WorldAnalysisARFoundationCoroutineHelper : MonoBehaviour
private void Awake() 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) if (Instance != null && Instance != this)
{ {
Destroy(this); Destroy(this);
...@@ -25,7 +20,6 @@ public class WorldAnalysisARFoundationCoroutineHelper : MonoBehaviour ...@@ -25,7 +20,6 @@ public class WorldAnalysisARFoundationCoroutineHelper : MonoBehaviour
public void StartACoroutine(IEnumerator coroutine) public void StartACoroutine(IEnumerator coroutine)
{ {
Debug.Log("HERE SINGLETON");
StartCoroutine(coroutine); StartCoroutine(coroutine);
} }
} }
\ No newline at end of file
...@@ -119,6 +119,8 @@ public class WorldAnalysisARFoundationModuleARKitWorldMap : WorldAnalysisARFound ...@@ -119,6 +119,8 @@ public class WorldAnalysisARFoundationModuleARKitWorldMap : WorldAnalysisARFound
{ {
foreach (var trackedAnchor in eventArgs.updated) foreach (var trackedAnchor in eventArgs.updated)
{ {
Debug.Log("Anchor found " +trackedAnchor.trackableId.ToString());
if (trackedAnchor.trackableId.ToString() == m_arfoundationAnchorTrackableId) if (trackedAnchor.trackableId.ToString() == m_arfoundationAnchorTrackableId)
{ {
/// look for an anchor with the trackable Id correspond to the ETSI ARF trackable name /// look for an anchor with the trackable Id correspond to the ETSI ARF trackable name
...@@ -137,12 +139,14 @@ public class WorldAnalysisARFoundationModuleARKitWorldMap : WorldAnalysisARFound ...@@ -137,12 +139,14 @@ public class WorldAnalysisARFoundationModuleARKitWorldMap : WorldAnalysisARFound
{ {
if (url.Length > 0) if (url.Length > 0)
{ {
Debug.Log("Load AR Map from URL");
LoadWorldMapFromURL(url); LoadWorldMapFromURL(url);
// don't check if url is valid // don't check if url is valid
return true ; return true ;
} }
else else
{ {
Debug.Log("Load AR Map locally");
string localMap = Application.persistentDataPath + "/ARkitWorlMap.map"; string localMap = Application.persistentDataPath + "/ARkitWorlMap.map";
if (File.Exists(localMap)) if (File.Exists(localMap))
{ {
...@@ -191,31 +195,44 @@ public class WorldAnalysisARFoundationModuleARKitWorldMap : WorldAnalysisARFound ...@@ -191,31 +195,44 @@ public class WorldAnalysisARFoundationModuleARKitWorldMap : WorldAnalysisARFound
/// <returns>coroutine</returns> /// <returns>coroutine</returns>
public IEnumerator CoroutineLoadWorldMap(string mapPath) 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>() ; ARSession session = Component.FindAnyObjectByType<ARSession>() ;
ARKitSessionSubsystem sessionSubsystem = (ARKitSessionSubsystem)session.subsystem; ARKitSessionSubsystem sessionSubsystem = (ARKitSessionSubsystem)session.subsystem;
FileStream file; if (sessionSubsystem == null)
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); Debug.Log("Cannot load map: no ARKitSessionSubsystem");
allBytes.AddRange(bytes);
bytesRemaining -= bytesPerFrame;
yield return null;
} }
else
var data = new NativeArray<byte>(allBytes.Count, Allocator.Temp);
data.CopyFrom(allBytes.ToArray());
ARWorldMap worldMap;
if (ARWorldMap.TryDeserialize(data, out worldMap))
{ {
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 #endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment