From 6a1775efe2ad61031030a3a659c9a946800e8627 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 12 Oct 2018 16:05:14 +0200 Subject: [PATCH] refactored async 3d model loading error handling removed done //TODO comments --- .../Scripts/Exhibition/ExhibitBehaviour.cs | 1 - .../PointOfInterest/PoiApiDataPreloader.cs | 1 - .../Scripts/PointOfInterest/PoiData.cs | 21 +++++++++++++++---- .../Scripts/UI/DetailsPanelBehaviour.cs | 11 ++++++++-- .../Scripts/Updater/HttpHandler.cs | 1 - .../Scripts/Updater/UpdaterBehaviour.cs | 4 ---- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Assets/RothenburgAR/Scripts/Exhibition/ExhibitBehaviour.cs b/Assets/RothenburgAR/Scripts/Exhibition/ExhibitBehaviour.cs index 79dd500..2e1f059 100644 --- a/Assets/RothenburgAR/Scripts/Exhibition/ExhibitBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/Exhibition/ExhibitBehaviour.cs @@ -48,7 +48,6 @@ namespace RothenburgAR.Exhibition if (newTitle.Position.HasValue) TitleBehaviour.transform.localPosition = newTitle.Position.Value; - //TODO set scale to resize the title relative to tracker size TitleBehaviour.DataText = newTitle.Text; } diff --git a/Assets/RothenburgAR/Scripts/PointOfInterest/PoiApiDataPreloader.cs b/Assets/RothenburgAR/Scripts/PointOfInterest/PoiApiDataPreloader.cs index 92aa099..644a93c 100644 --- a/Assets/RothenburgAR/Scripts/PointOfInterest/PoiApiDataPreloader.cs +++ b/Assets/RothenburgAR/Scripts/PointOfInterest/PoiApiDataPreloader.cs @@ -77,7 +77,6 @@ namespace RothenburgAR.PointOfInterest var modelDescription = new PoiModelDescription(); modelDescription.ModelPath = PathHelper.CombinePaths(PathHelper.MediaPath, mediaID, mediaID + ".obj"); - //TODO dont have model size information, find a way to scale model to fit into view? modelDescription.ModelPrefabName = string.Empty; modelDescription.Scale = Vector3.one; modelDescription.Position = Vector3.zero; diff --git a/Assets/RothenburgAR/Scripts/PointOfInterest/PoiData.cs b/Assets/RothenburgAR/Scripts/PointOfInterest/PoiData.cs index eb1a3ab..146b465 100644 --- a/Assets/RothenburgAR/Scripts/PointOfInterest/PoiData.cs +++ b/Assets/RothenburgAR/Scripts/PointOfInterest/PoiData.cs @@ -32,11 +32,16 @@ namespace RothenburgAR.PointOfInterest } } + public bool ModelLoadFailed { get; private set; } + public IEnumerator LoadModel() { + ModelLoadFailed = false; if (!File.Exists(ModelDescription.ModelPath)) { - throw new FileNotFoundException(ModelDescription.ModelPath + " does not exist;"); + Debug.LogError(ModelDescription.ModelPath + " does not exist;"); + ModelLoadFailed = true; + yield break; } var loader = new OBJLoader(ModelDescription.ModelPath); @@ -49,10 +54,18 @@ namespace RothenburgAR.PointOfInterest yield return new WaitForSecondsRealtime(.1f); } - var model = loader.BuildUnityObjects(); + try + { + var model = loader.BuildUnityObjects(); - model.SetActive(false); - _modelPrefab = model; + model.SetActive(false); + _modelPrefab = model; + } + catch (System.Exception) + { + ModelLoadFailed = true; + yield break; + } } public GameObject GetModelPrefab() diff --git a/Assets/RothenburgAR/Scripts/UI/DetailsPanelBehaviour.cs b/Assets/RothenburgAR/Scripts/UI/DetailsPanelBehaviour.cs index 7de1d3f..3dcaf60 100644 --- a/Assets/RothenburgAR/Scripts/UI/DetailsPanelBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/UI/DetailsPanelBehaviour.cs @@ -60,12 +60,19 @@ namespace RothenburgAR.UI Icon3D.SetActive(true); IconLoading.SetActive(true); - while (!data.IsModelLoaded) + while (!data.IsModelLoaded && !data.ModelLoadFailed) { yield return new WaitForSecondsRealtime(.1f); } } + if (data.ModelLoadFailed) + { + //TODO maybe display error message to user + RemoveModel(); + yield break; + } + try { SetModel(data.InstantiateModelPrefab()); @@ -87,7 +94,7 @@ namespace RothenburgAR.UI var mesh = meshFilter.mesh; if (mesh == null) throw new Exception("No Mesh in Model!"); - //TODO remove when model metadata rotation is no longer a thing + //TODO remove when metadata model rotation is no longer a thing mesh.RecalculateBounds(); var scale = 1f / Mathf.Max(mesh.bounds.size.x, mesh.bounds.size.y, mesh.bounds.size.z); diff --git a/Assets/RothenburgAR/Scripts/Updater/HttpHandler.cs b/Assets/RothenburgAR/Scripts/Updater/HttpHandler.cs index b3c6f79..eea8faf 100644 --- a/Assets/RothenburgAR/Scripts/Updater/HttpHandler.cs +++ b/Assets/RothenburgAR/Scripts/Updater/HttpHandler.cs @@ -57,7 +57,6 @@ namespace RothenburgAR.Updater { get { - //TODO read documentation return Operation.isDone && Request.isDone; } } diff --git a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs index 0f8548b..459b874 100644 --- a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs @@ -26,10 +26,6 @@ namespace RothenburgAR.Updater void Start() { - /* TODO: allg. fragen - punkt zum eintragen der credentials? - */ - #if !UNITY_EDITOR logFileHandler = new LogFileHandler(); #else