浏览代码

Improved handling of screen rotation and texture aspect ratio.

/4.1
Todd Stinson 4 年前
当前提交
48e50dc6
共有 2 个文件被更改,包括 40 次插入17 次删除
  1. 2
      Assets/Scenes/Depth/DepthImages.unity
  2. 55
      Assets/Scripts/TestDepthImage.cs

2
Assets/Scenes/Depth/DepthImages.unity


m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 640, y: 480}
m_SizeDelta: {x: 480, y: 480}
m_Pivot: {x: 0, y: 1}
--- !u!114 &1474869893
MonoBehaviour:

55
Assets/Scripts/TestDepthImage.cs


/// </summary>
static readonly int k_TextureRotationId = Shader.PropertyToID(k_TextureRotationName);
/// <summary>
/// A string builder for construction of strings.
/// </summary>
readonly StringBuilder m_StringBuilder = new StringBuilder();
[SerializeField]
[Tooltip("The AROcclusionManager which will produce frame events.")]
AROcclusionManager m_OcclusionManager;

/// </summary>
ScreenOrientation m_CurrentScreenOrientation;
/// <summary>
/// The current texture aspect ratio remembered so that we can resize the raw image layout when it changes.
float m_TextureAspectRatio = 1.0f;
void OnEnable()
{
m_CurrentScreenOrientation = Screen.orientation;

return;
}
StringBuilder sb = new StringBuilder();
LogTextureInfo(sb, "stencil", humanStencil);
LogTextureInfo(sb, "depth", humanDepth);
LogTextureInfo(sb, "env", envDepth);
Texture2D displayTexture = envDepth;
m_StringBuilder.Clear();
LogTextureInfo(m_StringBuilder, "stencil", humanStencil);
LogTextureInfo(m_StringBuilder, "depth", humanDepth);
LogTextureInfo(m_StringBuilder, "env", envDepth);
m_ImageInfo.text = sb.ToString();
m_ImageInfo.text = m_StringBuilder.ToString();
Debug.Log(sb.ToString());
Debug.Log(m_StringBuilder.ToString());
m_RawImage.texture = envDepth;
m_RawImage.texture = displayTexture;
float textureAspectRatio = (displayTexture == null) ? 1.0f : ((float)displayTexture.width / (float)displayTexture.height);
if (m_CurrentScreenOrientation != Screen.orientation)
if ((m_CurrentScreenOrientation != Screen.orientation)
|| !Mathf.Approximately(m_TextureAspectRatio, textureAspectRatio))
m_TextureAspectRatio = textureAspectRatio;
LayoutRawImage();
}
}

void LayoutRawImage()
{
Debug.Assert(m_RawImage != null, "no raw image");
float minDimension = 480.0f;
float maxDimension = Mathf.Round(minDimension * m_TextureAspectRatio);
Vector2 rectSize;
float rotation;
m_RawImage.rectTransform.sizeDelta = new Vector2(640.0f, 480.0f);
m_RawImage.material.SetFloat(k_TextureRotationId, 0.0f);
rectSize = new Vector2(maxDimension, minDimension);
rotation = 0.0f;
m_RawImage.rectTransform.sizeDelta = new Vector2(640.0f, 480.0f);
m_RawImage.material.SetFloat(k_TextureRotationId, 180.0f);
rectSize = new Vector2(maxDimension, minDimension);
rotation = 180.0f;
m_RawImage.rectTransform.sizeDelta = new Vector2(480.0f, 640.0f);
m_RawImage.material.SetFloat(k_TextureRotationId, 270.0f);
rectSize = new Vector2(minDimension, maxDimension);
rotation = 270.0f;
m_RawImage.rectTransform.sizeDelta = new Vector2(480.0f, 640.0f);
m_RawImage.material.SetFloat(k_TextureRotationId, 90.0f);
rectSize = new Vector2(minDimension, maxDimension);
rotation = 90.0f;
m_RawImage.rectTransform.sizeDelta = rectSize;
m_RawImage.material.SetFloat(k_TextureRotationId, rotation);
}
}
}
正在加载...
取消
保存