refactored async 3d model loading error handling

removed done //TODO comments
This commit is contained in:
2018-10-12 16:05:14 +02:00
parent d51cdf5a97
commit 6a1775efe2
6 changed files with 26 additions and 13 deletions

View File

@@ -48,7 +48,6 @@ namespace RothenburgAR.Exhibition
if (newTitle.Position.HasValue) if (newTitle.Position.HasValue)
TitleBehaviour.transform.localPosition = newTitle.Position.Value; TitleBehaviour.transform.localPosition = newTitle.Position.Value;
//TODO set scale to resize the title relative to tracker size
TitleBehaviour.DataText = newTitle.Text; TitleBehaviour.DataText = newTitle.Text;
} }

View File

@@ -77,7 +77,6 @@ namespace RothenburgAR.PointOfInterest
var modelDescription = new PoiModelDescription(); var modelDescription = new PoiModelDescription();
modelDescription.ModelPath = PathHelper.CombinePaths(PathHelper.MediaPath, mediaID, mediaID + ".obj"); 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.ModelPrefabName = string.Empty;
modelDescription.Scale = Vector3.one; modelDescription.Scale = Vector3.one;
modelDescription.Position = Vector3.zero; modelDescription.Position = Vector3.zero;

View File

@@ -32,11 +32,16 @@ namespace RothenburgAR.PointOfInterest
} }
} }
public bool ModelLoadFailed { get; private set; }
public IEnumerator LoadModel() public IEnumerator LoadModel()
{ {
ModelLoadFailed = false;
if (!File.Exists(ModelDescription.ModelPath)) 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); var loader = new OBJLoader(ModelDescription.ModelPath);
@@ -49,10 +54,18 @@ namespace RothenburgAR.PointOfInterest
yield return new WaitForSecondsRealtime(.1f); yield return new WaitForSecondsRealtime(.1f);
} }
var model = loader.BuildUnityObjects(); try
{
var model = loader.BuildUnityObjects();
model.SetActive(false); model.SetActive(false);
_modelPrefab = model; _modelPrefab = model;
}
catch (System.Exception)
{
ModelLoadFailed = true;
yield break;
}
} }
public GameObject GetModelPrefab() public GameObject GetModelPrefab()

View File

@@ -60,12 +60,19 @@ namespace RothenburgAR.UI
Icon3D.SetActive(true); Icon3D.SetActive(true);
IconLoading.SetActive(true); IconLoading.SetActive(true);
while (!data.IsModelLoaded) while (!data.IsModelLoaded && !data.ModelLoadFailed)
{ {
yield return new WaitForSecondsRealtime(.1f); yield return new WaitForSecondsRealtime(.1f);
} }
} }
if (data.ModelLoadFailed)
{
//TODO maybe display error message to user
RemoveModel();
yield break;
}
try try
{ {
SetModel(data.InstantiateModelPrefab()); SetModel(data.InstantiateModelPrefab());
@@ -87,7 +94,7 @@ namespace RothenburgAR.UI
var mesh = meshFilter.mesh; var mesh = meshFilter.mesh;
if (mesh == null) throw new Exception("No Mesh in Model!"); 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(); mesh.RecalculateBounds();
var scale = 1f / Mathf.Max(mesh.bounds.size.x, mesh.bounds.size.y, mesh.bounds.size.z); var scale = 1f / Mathf.Max(mesh.bounds.size.x, mesh.bounds.size.y, mesh.bounds.size.z);

View File

@@ -57,7 +57,6 @@ namespace RothenburgAR.Updater
{ {
get get
{ {
//TODO read documentation
return Operation.isDone && Request.isDone; return Operation.isDone && Request.isDone;
} }
} }

View File

@@ -26,10 +26,6 @@ namespace RothenburgAR.Updater
void Start() void Start()
{ {
/* TODO: allg. fragen
punkt zum eintragen der credentials?
*/
#if !UNITY_EDITOR #if !UNITY_EDITOR
logFileHandler = new LogFileHandler(); logFileHandler = new LogFileHandler();
#else #else