private IEnumerator SaveReconstructionCoroutine(string environmentProfileName, bool saveChangesInProfile) { Validate(); if (_currentState == ReconstructionState.Scanning && _pause) { IEnvironmentProfile environmentProfile = GetEnvironmentByName(environmentProfileName); int index = 0; string path = _environmentProfileRepository.GetPath(environmentProfile.Id); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } List <string> meshesName = new List <string>(); List <Thread> threads = new List <Thread>(); _saveFinished = false; // Delete old reconstruction meshes DeleteReconstructionMeshFiles(environmentProfileName, false); foreach (MeshFilter meshFilter in _reconstruction.GetComponentsInChildren <MeshFilter>()) { Mesh mesh = meshFilter.mesh; Vector3[] vertices = mesh.vertices; int[] triangles = mesh.triangles; string meshName = Path.Combine(path, (++index).ToString()); meshesName.Add(meshName + ".obj"); Thread thread = new Thread(() => _modelFileManipulator.SaveMeshToFile(meshName, vertices, triangles)); thread.Start(); threads.Add(thread); yield return(null); } Thread invokeOnFinished = new Thread(() => ScanThreads(threads, out _saveFinished)); invokeOnFinished.Start(); yield return(new WaitWhile(() => !_saveFinished)); _environmentProfileRepository.SetMeshes(environmentProfile.Id, meshesName); if (saveChangesInProfile) { yield return(StartCoroutine(SaveReconstructionChangesInProfile())); _reconstructionSaved.Invoke(); } else { // Invoked only after the meshes are completly saved on disk _reconstructionSaved.Invoke(); } } else { Debug.LogWarning("Trying to save a mesh of a non initialized or ongoing reconstruction."); } }
protected override void Initialize() { IEnvironmentProfile environmentProfile = _environmentProfileRepository.SelectedEnvironment; if (_slamLocalizer.IsFinished && environmentProfile != null) { string mapName = environmentProfile.MapName; if (string.IsNullOrEmpty(mapName)) { mapName = string.Format("{0}\\{1}", _environmentProfileRepository.GetPath(environmentProfile.Id), environmentProfile.Id); _environmentProfileRepository.SetMapName(environmentProfile.Id, mapName); } _slamLocalizer.SaveSlamMap(mapName); } Finish(); }
private void DeleteDefaultEnvironments() { IEnvironmentProfile defaultEnvironment = _environmentProfileRepository.FindByName(EnvironmentConstants.DefaultEnvironmentName); if (defaultEnvironment == null) { return; } string environmentPath = _environmentProfileRepository.GetPath(defaultEnvironment.Id); _environmentProfileRepository.Delete(defaultEnvironment.Id); if (Directory.Exists(environmentPath)) { Directory.Delete(environmentPath, true); } _environmentProfileRepository.Save(); }
protected override void Initialize() { IEnvironmentProfile defaultEnvironment = _environmentProfileRepository.GetDefault(); if (defaultEnvironment == null) { Finish(); return; } string environmentPath = _environmentProfileRepository.GetPath(defaultEnvironment.Id); _environmentProfileRepository.Delete(defaultEnvironment.Id); if (Directory.Exists(environmentPath)) { Directory.Delete(environmentPath, true); } Finish(); }