made 3d models position themselves in center of UIObjectCamera's view so it does not go outside its field of view
This commit is contained in:
@@ -23,7 +23,7 @@ namespace RothenburgAR.UI
|
|||||||
|
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
{
|
{
|
||||||
if (_autoRotate == true)
|
if (_autoRotate == true && CurrentModel != null)
|
||||||
{
|
{
|
||||||
NormalizeRotationSpeed();
|
NormalizeRotationSpeed();
|
||||||
CurrentModel.transform.Rotate(Vector3.up, _rotationSpeed);
|
CurrentModel.transform.Rotate(Vector3.up, _rotationSpeed);
|
||||||
@@ -71,7 +71,7 @@ namespace RothenburgAR.UI
|
|||||||
{
|
{
|
||||||
if (CurrentModel == null) return;
|
if (CurrentModel == null) return;
|
||||||
var previousMousePosition = _previousMousePositions.Dequeue();
|
var previousMousePosition = _previousMousePositions.Dequeue();
|
||||||
|
|
||||||
var endDistance = previousMousePosition.x - data.position.x;
|
var endDistance = previousMousePosition.x - data.position.x;
|
||||||
_rotationSpeed = endDistance / 15;
|
_rotationSpeed = endDistance / 15;
|
||||||
_autoRotate = true;
|
_autoRotate = true;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ namespace RothenburgAR.UI
|
|||||||
get { return _currentDisplayedModelGo != null; }
|
get { return _currentDisplayedModelGo != null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private string modelToBeDisplayed = null;
|
|
||||||
private GameObject _currentDisplayedModelGo;
|
private GameObject _currentDisplayedModelGo;
|
||||||
|
|
||||||
public void SetText(TextElement el)
|
public void SetText(TextElement el)
|
||||||
@@ -53,8 +52,6 @@ namespace RothenburgAR.UI
|
|||||||
|
|
||||||
public IEnumerator SetModelCoroutine(PoiData data)
|
public IEnumerator SetModelCoroutine(PoiData data)
|
||||||
{
|
{
|
||||||
modelToBeDisplayed = data.ID;
|
|
||||||
|
|
||||||
if (!data.IsModelLoaded)
|
if (!data.IsModelLoaded)
|
||||||
{
|
{
|
||||||
StartCoroutine(data.LoadModel());
|
StartCoroutine(data.LoadModel());
|
||||||
@@ -74,21 +71,31 @@ namespace RothenburgAR.UI
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (modelToBeDisplayed == data.ID)
|
SetModel(data.InstantiateModelPrefab());
|
||||||
SetModel(data.InstantiateModelPrefab());
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
// ignore, just do not display an object
|
// ignore, just do not display an object
|
||||||
_currentDisplayedModelGo = null;
|
RemoveModel();
|
||||||
modelToBeDisplayed = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetModel(GameObject modelGo)
|
public void SetModel(GameObject modelGo)
|
||||||
{
|
{
|
||||||
modelGo.transform.SetParent(UIManager.Instance.UIObjectCamera.transform, false);
|
modelGo.transform.SetParent(UIManager.Instance.UIObjectCamera.transform, false);
|
||||||
modelGo.transform.localPosition += new Vector3(0, 0, 450);
|
|
||||||
|
var meshFilter = modelGo.GetComponentInChildren<MeshFilter>();
|
||||||
|
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;
|
_currentDisplayedModelGo = modelGo;
|
||||||
DetailsModel.CurrentModel = _currentDisplayedModelGo;
|
DetailsModel.CurrentModel = _currentDisplayedModelGo;
|
||||||
@@ -102,7 +109,7 @@ namespace RothenburgAR.UI
|
|||||||
{
|
{
|
||||||
DetailsModel.gameObject.SetActive(false);
|
DetailsModel.gameObject.SetActive(false);
|
||||||
DetailsModel.CurrentModel = null;
|
DetailsModel.CurrentModel = null;
|
||||||
modelToBeDisplayed = null;
|
|
||||||
if (HasModel)
|
if (HasModel)
|
||||||
{
|
{
|
||||||
Destroy(_currentDisplayedModelGo);
|
Destroy(_currentDisplayedModelGo);
|
||||||
|
|||||||
Reference in New Issue
Block a user