expand aabb to avoid culling.
This commit is contained in:
@@ -14,7 +14,7 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
public GameObject gameObject { get; set; }
|
public GameObject gameObject { get; set; }
|
||||||
public Quaternion originalRotation { get; set; }
|
public Quaternion originalRotation { get; set; }
|
||||||
public uDesktopDuplication.Texture uddTexture { get; set; }
|
public uDesktopDuplication.Texture uddTexture { get; set; }
|
||||||
public Vector3 meshBounds;
|
public Mesh mesh { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MonitorInfo> monitors_ = new List<MonitorInfo>();
|
private List<MonitorInfo> monitors_ = new List<MonitorInfo>();
|
||||||
@@ -78,6 +78,13 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
var go = Instantiate(monitorPrefab);
|
var go = Instantiate(monitorPrefab);
|
||||||
go.name = "Monitor " + i;
|
go.name = "Monitor " + i;
|
||||||
|
|
||||||
|
// Expand AABB
|
||||||
|
var mesh = go.GetComponent<MeshFilter>().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
|
// Assign monitor
|
||||||
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
||||||
texture.monitorId = i;
|
texture.monitorId = i;
|
||||||
@@ -89,15 +96,12 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
// Set parent as this object
|
// Set parent as this object
|
||||||
go.transform.SetParent(transform);
|
go.transform.SetParent(transform);
|
||||||
|
|
||||||
// Calc actual size considering mesh size
|
|
||||||
var bounds = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents * 2f;
|
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
var info = new MonitorInfo();
|
var info = new MonitorInfo();
|
||||||
info.gameObject = go;
|
info.gameObject = go;
|
||||||
info.originalRotation = go.transform.rotation;
|
info.originalRotation = go.transform.rotation;
|
||||||
info.uddTexture = texture;
|
info.uddTexture = texture;
|
||||||
info.meshBounds = bounds;
|
info.mesh = mesh;
|
||||||
monitors_.Add(info);
|
monitors_.Add(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class MultipleMonitorLayouter : MonoBehaviour
|
|||||||
|
|
||||||
var totalWidth = 0f;
|
var totalWidth = 0f;
|
||||||
foreach (var info in monitors) {
|
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 += width;
|
||||||
}
|
}
|
||||||
totalWidth += margin * (n - 1);
|
totalWidth += margin * (n - 1);
|
||||||
@@ -41,10 +41,10 @@ public class MultipleMonitorLayouter : MonoBehaviour
|
|||||||
|
|
||||||
foreach (var info in creator_.monitors) {
|
foreach (var info in creator_.monitors) {
|
||||||
var monitor = info.uddTexture.monitor;
|
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.localPosition = new Vector3(x, 0f, 0f);
|
||||||
info.gameObject.transform.localRotation = info.originalRotation;
|
info.gameObject.transform.localRotation = info.originalRotation;
|
||||||
x += (monitor.widthMeter * info.meshBounds.x) / 2 + margin;
|
x += (monitor.widthMeter * info.mesh.bounds.extents.x) + margin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
|
|||||||
|
|
||||||
var totalWidth = 0f;
|
var totalWidth = 0f;
|
||||||
foreach (var info in monitors) {
|
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 += width;
|
||||||
}
|
}
|
||||||
totalWidth += margin * (n - 1);
|
totalWidth += margin * (n - 1);
|
||||||
@@ -29,7 +29,7 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
|
|||||||
float angle = -totalAngle / 2;
|
float angle = -totalAngle / 2;
|
||||||
foreach (var info in monitors) {
|
foreach (var info in monitors) {
|
||||||
var uddTex = info.uddTexture;
|
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;
|
angle += (width / radius) * 0.5f;
|
||||||
uddTex.transform.localPosition = radius * new Vector3(Mathf.Sin(angle), 0f, Mathf.Cos(angle) - 1f);
|
uddTex.transform.localPosition = radius * new Vector3(Mathf.Sin(angle), 0f, Mathf.Cos(angle) - 1f);
|
||||||
|
|||||||
Reference in New Issue
Block a user