private void OnDataReceivedEvent(byte[] obj) { NetworkMessageStruct networkMessage = NetworkMessageStruct.Deserialize(obj); switch (networkMessage.Type) { case MessageType.ColorChange: DeserializeColorAndSendEvent(networkMessage.Message); break; case MessageType.WorldMap: Debug.Log("recieved world map"); ARWorldMap arWorldMap = (ARWorldMap) new PackableARWorldMap(networkMessage.Message); RestartSessionWithWorldMap(arWorldMap); break; case MessageType.Anchor: Debug.Log("recieved anchor"); ulong trackableId1 = BitConverter.ToUInt64(networkMessage.Message, 0); ulong trackableId2 = BitConverter.ToUInt64(networkMessage.Message, sizeof(ulong)); TrackableId trackableId = new TrackableId(trackableId1, trackableId2); AnchorRecieved?.Invoke(trackableId); break; case MessageType.SpawnedObject: DeserializeObjectSpawnAndSendEvent(networkMessage.Message); break; } }
void LoadWorldMap() { Debug.Log("Attempting to load ARWorldMap."); //GlobalMapManager.Instance.DownloadLatestMap(() => //{ // var worldMap = ARWorldMap.Load(GlobalMapManager.Instance.WorldMapPath); // if (worldMap != null) // { // Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); // var config = ARKitManager.Instance.DefaultSessionConfiguration; // config.worldMap = worldMap; // UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; // Debug.Log("Restarting session with worldMap"); // ARKitManager.Instance.Session.RunWithConfigAndOptions(config, runOption); // } //}); var worldMap = ARWorldMap.Load(GlobalMapManager.Instance.WorldMapPath); if (worldMap != null) { Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); var config = ARKitManager.Instance.DefaultSessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; Debug.Log("Restarting session with worldMap"); ARKitManager.Instance.Session.RunWithConfigAndOptions(config, runOption); } }
IEnumerator Load() { var sessionSubsystem = (ARKitSessionSubsystem)m_ARSession.subsystem; if (sessionSubsystem == null) { Log("No session subsystem available. Could not load."); yield break; } var DlUrl = "http://" + IP_InputField.text + ":" + _httpPort.ToString() + "/" + _GetDirectory; UnityWebRequest www = new UnityWebRequest(DlUrl); www.downloadHandler = new DownloadHandlerBuffer(); yield return(www.SendWebRequest()); byte[] worldMap_byte; var allBytes = new List <byte>(); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { // または、バイナリデータで結果を表示 worldMap_byte = www.downloadHandler.data; Debug.Log("hash" + _GetHashedTextString(worldMap_byte)); allBytes.AddRange(worldMap_byte); var worldMap_nativearray = new NativeArray <byte>(allBytes.Count, Allocator.Temp); worldMap_nativearray.CopyFrom(allBytes.ToArray()); ARWorldMap worldMap; if (ARWorldMap.TryDeserialize(worldMap_nativearray, out worldMap)) { worldMap_nativearray.Dispose(); } if (worldMap.valid) { Log("Deserialized successfully."); } else { Log("Data is not a valid ARWorldMap."); yield break; } Log("Apply ARWorldMap to current session."); sessionSubsystem.ApplyWorldMap(worldMap); } }
public IEnumerator Relocate(byte[] receivedBytes) { //start relocation statusGO.SetActive(true); statusText.text = "Start relocalize.."; ARWorldMap arWorldMap = ARWorldMap.SerializeFromByteArray(receivedBytes); //Use the AR Session manager to restart session with received world map to sync up ExampleARSessionManager easm = FindObjectOfType <ExampleARSessionManager>(); easm.StartSession(arWorldMap); //check tracking state and update UI while (_arTrackingState != ARTrackingState.ARTrackingStateLimited || _arTrackingStateReason != ARTrackingStateReason.ARTrackingStateReasonRelocalizing) { yield return(null); //wait until it starts relocalizing } statusText.text = "Relocalizing... look around the area"; while (_arTrackingState != ARTrackingState.ARTrackingStateNormal) { yield return(null); } statusText.text = "Relocalized!"; yield return(null); statusGO.SetActive(false); yield return(null); }
public void StartSession(ARWorldMap arWorldMap = null) { m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface(); Application.targetFrameRate = 60; ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration { planeDetection = planeDetection, alignment = startAlignment, getPointCloudData = getPointCloud, enableLightEstimation = enableLightEstimation, enableAutoFocus = enableAutoFocus, worldMap = arWorldMap }; if (detectionImages != null) { config.referenceImagesGroupName = detectionImages.resourceGroupName; } if (config.IsSupported) { m_session.RunWithConfig(config); UnityARSessionNativeInterface.ARFrameUpdatedEvent += FirstFrameUpdate; } }
public void Load(string name, string filePath) { Debug.LogFormat("Loading ARWorldMap {0}", filePath); var worldMap = ARWorldMap.Load(filePath); if (worldMap != null) { GroundPlaneManager.instance.NewSession(true); m_LoadedMap = worldMap; Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true; var config = m_ARCameraManager.sessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; Debug.Log("Restarting session with worldMap"); session.RunWithConfigAndOptions(config, runOption); loadingname = name; isLoading = true; } }
public void Load(string fileName) { var worldMap = ARWorldMap.Load(Path.Combine(Application.persistentDataPath, string.Concat(fileName, ".worldmap"))); if (worldMap != null) { windowManager.SpawnGuideToLoad(); loadedWorldMapName = fileName; UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true; relocalizing = true; startTime = Time.time; ARKitWorldTrackingSessionConfiguration config = m_ARCameraManager.sessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; foreach (GameObject go in GameObject.FindGameObjectsWithTag("Line")) { Destroy(go); } session.RunWithConfigAndOptions(config, runOption); } }
public void Load() { if (path != null) { Debug.LogFormat("Loading ARWorldMap {0}", path); var worldMap = ARWorldMap.Load(path); if (worldMap != null) { m_LoadedMap = worldMap; Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true; var config = m_ARCameraManager.sessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; //m_TGOPlacement.Reset(); //m_ESAPlacement.Reset(); Debug.Log("Restarting session with worldMap"); session.RunWithConfigAndOptions(config, runOption); } } else { Debug.Log("Please, specify a path"); } }
private void RestartSessionWithWorldMap(ARWorldMap arWorldMap) { if (_arSession.subsystem is ARKitSessionSubsystem arKitSessionSubsystem) { arKitSessionSubsystem.ApplyWorldMap(arWorldMap); } }
public UniTask Load(string dirPath) { string path = GetPath(dirPath); ARWorldMap worldMap = ARWorldMap.Load(path); Debug.Log($"ARWorldMap loaded from {path}"); ARKitWorldTrackingSessionConfiguration config = _camera.sessionConfiguration; config.worldMap = worldMap; const UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; UnityARSessionNativeInterface .ARSessionShouldAttemptRelocalization = true; UnityARSessionNativeInterface .GetARSessionNativeInterface() .RunWithConfigAndOptions(config, runOption); Debug.Log("Restarted session with worldMap"); return(UniTask.CompletedTask); }
public void LoadARWorldMap(ARWorldMap worldMap) { var sessionSubsystem = (ARKitSessionSubsystem)m_ARSession.subsystem; Debug.Log("Applying ARWM"); sessionSubsystem.ApplyWorldMap(worldMap); Debug.Log("ARWM Applied"); }
void OnWorldMap(ARWorldMap worldMap) { if (worldMap != null) { worldMap.Save(path); Debug.LogFormat("ARWorldMap saved to {0}", path); } }
IEnumerator Load() { var sessionSubsystem = (ARKitSessionSubsystem)m_ARSession.subsystem; if (sessionSubsystem == null) { Log("No session subsystem available. Could not load."); yield break; } var file = File.Open(path, FileMode.Open); if (file == null) { Log(string.Format("File {0} does not exist.", path)); yield break; } Log(string.Format("Reading {0}...", path)); 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()); Log(string.Format("Deserializing to ARWorldMap...", path)); ARWorldMap worldMap; if (ARWorldMap.TryDeserialize(data, out worldMap)) { data.Dispose(); } if (worldMap.valid) { Log("Deserialized successfully."); } else { Debug.LogError("Data is not a valid ARWorldMap."); yield break; } Log("Apply ARWorldMap to current session."); sessionSubsystem.ApplyWorldMap(worldMap); }
void OnWorldMapSerialized(ARWorldMap worldMap) { if (worldMap != null) { //we have an operator that converts a ARWorldMap to a serializableARWorldMap serializedWorldMap = worldMap; Debug.Log("ARWorldMap serialized to serializableARWorldMap"); } }
partial void LoadExperience() { if (DataFromFile == null) { Debug.WriteLine("Map data should already be verified to exist before Load button is enabled."); return; } try { var data = DataFromFile; ARWorldMap worldMap = (ARWorldMap)NSKeyedUnarchiver.GetUnarchivedObject(typeof(ARWorldMap), data, out var err); if (err != null) { Debug.WriteLine("No ARWorldMap in archive."); return; } // Display the snapshot image stored in the world map to aid user in relocalizing. var snapshotData = worldMap.GetSnapshotAnchor()?.ImageData; using (var snapshot = UIImage.LoadFromData(snapshotData)) { if (snapshot != null) { _snapShotThumbnail.Image = snapshot; } else { Debug.WriteLine("No snapshot image in world map"); } } // Remove the snapshot anchor from the world map since we do not need it in the scene. worldMap.Anchors = worldMap.Anchors.Where(anchor => anchor.GetType() != typeof(SnapshotAnchor)).ToArray(); var configuration = new ARWorldTrackingConfiguration { PlaneDetection = ARPlaneDetection.Horizontal, EnvironmentTexturing = AREnvironmentTexturing.Automatic, InitialWorldMap = worldMap, }; _sceneView.Session.Run(configuration, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors); // Run the view's session isRelocalizingMap = true; objAnchor = null; } catch (Exception ex) { Debug.WriteLine($"Can't unarchive ARWorldMap from file data: {ex.Message}"); return; } Debug.WriteLine($"Success: Loaded world scene from {MapSaveURL}"); }
static void _world_map_received(IntPtr worldMapPtr) { if (WorldMapReceivedEventInternal == null) { return; } var worldMap = ARWorldMap.FromPtr(worldMapPtr); WorldMapReceivedEventInternal(worldMap); }
private void OnLoadClick() { UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true;//重定位 ARWorldMap newWorldMap = ARWorldMap.Load(Config.path); ARKitWorldTrackingSessionConfiguration configration = m_ARCameraManager.sessionConfiguration; configration.worldMap = newWorldMap; UnityARSessionRunOption option = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; Config.m_Swssion.RunWithConfigAndOptions(configration, option); }
void OnWorldMap(ARWorldMap worldMap) { if (worldMap != null) { if (path != "") { worldMap.Save(path); GroundPlaneManager.instance.Save(nameInput.text); Debug.LogFormat("ARWorldMap saved to {0}", path); nameInput.text = ""; } } }
private async void SendWorldMapAsync() { ARWorldMap worldMap = await GetARWorldMapAsync(); PackableARWorldMap packableARWorldMap = (PackableARWorldMap)worldMap; NetworkMessageStruct networkMessageStruct = new NetworkMessageStruct { Type = MessageType.WorldMap, Message = packableARWorldMap.ARWorldMapData }; SendMessage(networkMessageStruct); }
void OnWorldMap(ARWorldMap worldMap) { if (worldMap != null) { if (path != null) { worldMap.Save(path); Debug.LogFormat("ARWorldMap saved to {0}", path); } else { Debug.Log("Please, specify a path"); } } }
public void OnMessageReceived(byte[] msg) { try { BinaryFormatter bf = new BinaryFormatter(); MemoryStream serializationStream = new MemoryStream(msg, 0, msg.Length, false, false); //serializationStream.Write(msg, 0, msg.Length); object obj = bf.Deserialize(serializationStream); if (obj != null) { if (obj is AppState) { AppState appState = obj as AppState; Debug.Log("AppState received."); } } return; } catch (System.Exception) { } //string s = ""; //foreach (var b in msg) //{ // s = $"{s}, {b}"; //} //Debug.Log(s); SharedARUIManager.sharedARStatusMessage = $"MSG RECEIVED LENGTH: {msg.Length}"; //ARWorldMap if (ARWorldMapController != null) { NativeArray <byte> nativeArray = new NativeArray <byte>(msg, Allocator.Persistent); Debug.Log("Trying to deserialize ARWM"); bool success = ARWorldMap.TryDeserialize(nativeArray, out ARWorldMap worldMap); nativeArray.Dispose(); if (success) { Debug.Log("ARWM Deserialized"); if (worldMap.valid) { Debug.Log("ARWM Valid"); ARWorldMapController.LoadARWorldMap(worldMap); SharedARUIManager.sharedARStatusMessage = "SUCESS"; } } } }
private void CompressMap(ARWorldMap map, Action <NSData, NSError> closure) { DispatchQueue.DefaultGlobalQueue.DispatchAsync(() => { var data = NSKeyedArchiver.ArchivedDataWithRootObject(map, true, out NSError error); if (error == null) { closure(data, null); } else { // archiving failed closure(null, error); } }); }
void LoadSerializedWorldMap(byte[] worldMapInBytes) { ARWorldMap worldMap = ARWorldMap.SerializeFromByteArray(worldMapInBytes); Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true; var config = m_ARCameraManager.sessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; Debug.Log("Restarting session with worldMap"); session.RunWithConfigAndOptions(config, runOption); }
void SaveAndDisposeWorldMap(ARWorldMap worldMap) { Log("Serializing ARWorldMap to byte array..."); var data = worldMap.Serialize(Allocator.Temp); Log(string.Format("ARWorldMap has {0} bytes.", data.Length)); var file = File.Open(path, FileMode.Create); var writer = new BinaryWriter(file); writer.Write(data.ToArray()); writer.Close(); data.Dispose(); worldMap.Dispose(); Log(string.Format("ARWorldMap written to {0}", path)); }
void RestartARSessionWith(ARWorldMap worldMap) { if (worldMap != null) { Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true; var config = arCameraManager.sessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; Debug.Log("Restarting session with worldMap"); UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(config, runOption); } }
void LoadWorldMap() { Debug.LogFormat("Loading ARWorldMap {0}", WorldMapPath); var worldMap = ARWorldMap.Load(WorldMapPath); if (worldMap != null) { Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); var config = ARKitCameraManager.Instance.sessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; Debug.Log("Restarting session with worldMap"); Session.RunWithConfigAndOptions(config, runOption); referenceImage.GetComponent <Image>().sprite = UtilitiesCR.LoadNewSprite(ReferenceImagePath); referenceImage.SetActive(true); } }
public void LoadSerialized() { Debug.Log("Loading ARWorldMap from serialized data"); //we have an operator that converts a serializableARWorldMap to a ARWorldMap ARWorldMap worldMap = serializedWorldMap; if (worldMap != null) { m_LoadedMap = worldMap; Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true; var config = m_ARCameraManager.sessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; Debug.Log("Restarting session with worldMap"); session.RunWithConfigAndOptions(config, runOption); } }
public IEnumerator Relocate(byte[] receivedBytes) { //start relocation ARWorldMap arWorldMap = ARWorldMap.SerializeFromByteArray(receivedBytes); //Use the AR Session manager to restart session with received world map to sync up ExampleARSessionManager easm = FindObjectOfType <ExampleARSessionManager>(); easm.StartSession(arWorldMap); //check tracking state and update UI while (_arTrackingState != ARTrackingState.ARTrackingStateLimited || _arTrackingStateReason != ARTrackingStateReason.ARTrackingStateReasonRelocalizing) { yield return(null); //wait until it starts relocalizing } while (_arTrackingState != ARTrackingState.ARTrackingStateNormal) { yield return(null); } }
public void Load() { Debug.LogFormat("Loading ARWorldMap {0}", path); var worldMap = ARWorldMap.Load(path); if (worldMap != null) { m_LoadedMap = worldMap; Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true; var config = m_ARCameraManager.sessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; Debug.Log("Restarting session with worldMap"); session.RunWithConfigAndOptions(config, runOption); myCube.transform.position = new Vector3(PlayerPrefs.GetFloat("PlayerX"), PlayerPrefs.GetFloat("PlayerY"), PlayerPrefs.GetFloat("PlayerZ")); } }
/// <summary> /// 加载ARWorldMap /// </summary> public void Load() { Debug.LogFormat("Loading ARWorldMap {0}", Path); #if !UNITY_EDITOR var worldMap = ARWorldMap.Load(Path); if (worldMap != null) { m_LoadedMap = worldMap; Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent); UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true; var config = m_ARCameraManager.sessionConfiguration; config.worldMap = worldMap; UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking; Debug.Log("Restarting session with worldMap"); Session.RunWithConfigAndOptions(config, runOption); } #endif StartCoroutine(SceneRecogOver()); }