diff --git a/Assets/RothenburgAR/Scripts/UI/DetailsModelBehaviour.cs b/Assets/RothenburgAR/Scripts/UI/DetailsModelBehaviour.cs index 9a37c11..01b694d 100644 --- a/Assets/RothenburgAR/Scripts/UI/DetailsModelBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/UI/DetailsModelBehaviour.cs @@ -23,7 +23,7 @@ namespace RothenburgAR.UI void FixedUpdate() { - if (_autoRotate == true) + if (_autoRotate == true && CurrentModel != null) { NormalizeRotationSpeed(); CurrentModel.transform.Rotate(Vector3.up, _rotationSpeed); @@ -71,7 +71,7 @@ namespace RothenburgAR.UI { if (CurrentModel == null) return; var previousMousePosition = _previousMousePositions.Dequeue(); - + var endDistance = previousMousePosition.x - data.position.x; _rotationSpeed = endDistance / 15; _autoRotate = true; diff --git a/Assets/RothenburgAR/Scripts/UI/DetailsPanelBehaviour.cs b/Assets/RothenburgAR/Scripts/UI/DetailsPanelBehaviour.cs index d715bad..2ccabed 100644 --- a/Assets/RothenburgAR/Scripts/UI/DetailsPanelBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/UI/DetailsPanelBehaviour.cs @@ -28,7 +28,6 @@ namespace RothenburgAR.UI get { return _currentDisplayedModelGo != null; } } - private string modelToBeDisplayed = null; private GameObject _currentDisplayedModelGo; public void SetText(TextElement el) @@ -53,8 +52,6 @@ namespace RothenburgAR.UI public IEnumerator SetModelCoroutine(PoiData data) { - modelToBeDisplayed = data.ID; - if (!data.IsModelLoaded) { StartCoroutine(data.LoadModel()); @@ -74,21 +71,31 @@ namespace RothenburgAR.UI try { - if (modelToBeDisplayed == data.ID) - SetModel(data.InstantiateModelPrefab()); + SetModel(data.InstantiateModelPrefab()); } catch (Exception) { // ignore, just do not display an object - _currentDisplayedModelGo = null; - modelToBeDisplayed = null; + RemoveModel(); } } public void SetModel(GameObject modelGo) { modelGo.transform.SetParent(UIManager.Instance.UIObjectCamera.transform, false); - modelGo.transform.localPosition += new Vector3(0, 0, 450); + + var meshFilter = modelGo.GetComponentInChildren(); + if (meshFilter == null) throw new Exception("No MeshFilter in Object!"); + + 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 + mesh.RecalculateBounds(); + + var scale = 1f / Mathf.Max(mesh.bounds.size.x, mesh.bounds.size.y, mesh.bounds.size.z); + modelGo.transform.localScale = new Vector3(scale, scale, scale); + modelGo.transform.localPosition = mesh.bounds.center * scale + new Vector3(0, 0, 1.8f); _currentDisplayedModelGo = modelGo; DetailsModel.CurrentModel = _currentDisplayedModelGo; @@ -102,7 +109,7 @@ namespace RothenburgAR.UI { DetailsModel.gameObject.SetActive(false); DetailsModel.CurrentModel = null; - modelToBeDisplayed = null; + if (HasModel) { Destroy(_currentDisplayedModelGo);