From 8fd3170f8e83bc6fd52f00f2cfd381a021f70b90 Mon Sep 17 00:00:00 2001 From: jie_zhang Date: Fri, 19 Mar 2021 19:13:48 +0800 Subject: [PATCH] New uvmap for MeshDraft.Prism: Prism should have the same uvmap as Cylinder. --- Runtime/MeshDraft.cs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Runtime/MeshDraft.cs b/Runtime/MeshDraft.cs index c03f0474..8bf7bcd4 100644 --- a/Runtime/MeshDraft.cs +++ b/Runtime/MeshDraft.cs @@ -620,13 +620,10 @@ public MeshDraft AddFlatQuadBand(IReadOnlyList lowerRing, IReadOnlyList throw new ArgumentException("Array sizes must be greater than 2"); } - Vector2 uv00 = new Vector2(0, 0); - Vector2 uv10 = new Vector2(1, 0); - Vector2 uv01 = new Vector2(0, 1); - Vector2 uv11 = new Vector2(1, 1); - Vector3 lower0, upper0, lower1, upper1; - for (int i = 0; i < lowerRing.Count - 1; i++) + int ringCount = lowerRing.Count; + float uvXStep = 1f / ringCount; + for (int i = 0; i < ringCount - 1; i++) { lower0 = lowerRing[i]; lower1 = lowerRing[i + 1]; @@ -634,6 +631,12 @@ public MeshDraft AddFlatQuadBand(IReadOnlyList lowerRing, IReadOnlyList upper1 = upperRing[i + 1]; if (generateUV) { + var uvX0 = i * uvXStep; + var uxX1 = (i + 1) * uvXStep; + Vector2 uv00 = new Vector2(uvX0, 0); + Vector2 uv10 = new Vector2(uxX1, 0); + Vector2 uv01 = new Vector2(uvX0, 1); + Vector2 uv11 = new Vector2(uxX1, 1); AddQuad(lower1, upper1, upper0, lower0, true, uv00, uv01, uv11, uv10); } else @@ -642,12 +645,18 @@ public MeshDraft AddFlatQuadBand(IReadOnlyList lowerRing, IReadOnlyList } } - lower0 = lowerRing[lowerRing.Count - 1]; + lower0 = lowerRing[ringCount - 1]; lower1 = lowerRing[0]; - upper0 = upperRing[upperRing.Count - 1]; + upper0 = upperRing[ringCount - 1]; upper1 = upperRing[0]; if (generateUV) { + var uvX0 = (ringCount - 1) * uvXStep; + var uxX1 = 1; + Vector2 uv00 = new Vector2(uvX0, 0); + Vector2 uv10 = new Vector2(uxX1, 0); + Vector2 uv01 = new Vector2(uvX0, 1); + Vector2 uv11 = new Vector2(uxX1, 1); AddQuad(lower1, upper1, upper0, lower0, true, uv00, uv01, uv11, uv10); } else @@ -914,3 +923,4 @@ public override string ToString() } } } +