From be1e0c25bb633294622545dde8a81c97fd402bab Mon Sep 17 00:00:00 2001 From: hecomi Date: Thu, 10 Nov 2016 23:06:24 +0900 Subject: [PATCH] expand aabb to avoid culling. --- .../Examples/Scripts/MultipleMonitorCreator.cs | 14 +++++++++----- .../Examples/Scripts/MultipleMonitorLayouter.cs | 12 ++++++------ .../Scripts/MultipleMonitorRoundLayouter.cs | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs index 10844a6..a747aa2 100644 --- a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs +++ b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs @@ -14,7 +14,7 @@ public class MultipleMonitorCreator : MonoBehaviour public GameObject gameObject { get; set; } public Quaternion originalRotation { get; set; } public uDesktopDuplication.Texture uddTexture { get; set; } - public Vector3 meshBounds; + public Mesh mesh { get; set; } } private List monitors_ = new List(); @@ -78,6 +78,13 @@ public class MultipleMonitorCreator : MonoBehaviour var go = Instantiate(monitorPrefab); go.name = "Monitor " + i; + // Expand AABB + var mesh = go.GetComponent().mesh; // clone + var aabbScale = mesh.bounds.size; + aabbScale.y = Mathf.Max(aabbScale.y, aabbScale.x); + aabbScale.z = Mathf.Max(aabbScale.z, aabbScale.x); + mesh.bounds = new Bounds(mesh.bounds.center, aabbScale); + // Assign monitor var texture = go.GetComponent(); texture.monitorId = i; @@ -89,15 +96,12 @@ public class MultipleMonitorCreator : MonoBehaviour // Set parent as this object go.transform.SetParent(transform); - // Calc actual size considering mesh size - var bounds = go.GetComponent().sharedMesh.bounds.extents * 2f; - // Save var info = new MonitorInfo(); info.gameObject = go; info.originalRotation = go.transform.rotation; info.uddTexture = texture; - info.meshBounds = bounds; + info.mesh = mesh; monitors_.Add(info); } } diff --git a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorLayouter.cs b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorLayouter.cs index 065a65c..98f80bd 100644 --- a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorLayouter.cs +++ b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorLayouter.cs @@ -15,13 +15,13 @@ public class MultipleMonitorLayouter : MonoBehaviour protected virtual void Update() { - if (updateEveryFrame) { - Layout(); + if (updateEveryFrame) { + Layout(); } } void LateUpdate() - { + { margin = Mathf.Max(margin, 0f); } @@ -32,7 +32,7 @@ public class MultipleMonitorLayouter : MonoBehaviour var totalWidth = 0f; foreach (var info in monitors) { - var width = info.uddTexture.monitor.widthMeter * info.meshBounds.x; + var width = info.uddTexture.monitor.widthMeter * (info.mesh.bounds.extents.x * 2f); totalWidth += width; } totalWidth += margin * (n - 1); @@ -41,10 +41,10 @@ public class MultipleMonitorLayouter : MonoBehaviour foreach (var info in creator_.monitors) { var monitor = info.uddTexture.monitor; - x += (monitor.widthMeter * info.meshBounds.x) / 2; + x += (monitor.widthMeter * info.mesh.bounds.extents.x); info.gameObject.transform.localPosition = new Vector3(x, 0f, 0f); info.gameObject.transform.localRotation = info.originalRotation; - x += (monitor.widthMeter * info.meshBounds.x) / 2 + margin; + x += (monitor.widthMeter * info.mesh.bounds.extents.x) + margin; } } diff --git a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorRoundLayouter.cs b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorRoundLayouter.cs index 784ee1f..a45abf8 100644 --- a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorRoundLayouter.cs +++ b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorRoundLayouter.cs @@ -18,7 +18,7 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter var totalWidth = 0f; foreach (var info in monitors) { - var width = info.uddTexture.monitor.widthMeter * info.meshBounds.x; + var width = info.uddTexture.monitor.widthMeter * (info.mesh.bounds.extents.x * 2f); totalWidth += width; } totalWidth += margin * (n - 1); @@ -29,7 +29,7 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter float angle = -totalAngle / 2; foreach (var info in monitors) { var uddTex = info.uddTexture; - var width = uddTex.monitor.widthMeter * info.meshBounds.x; + var width = uddTex.monitor.widthMeter * (info.mesh.bounds.extents.x * 2f); angle += (width / radius) * 0.5f; uddTex.transform.localPosition = radius * new Vector3(Mathf.Sin(angle), 0f, Mathf.Cos(angle) - 1f);