Skip to content

Commit

Permalink
New uvmap for MeshDraft.Prism: Prism should have the same uvmap as Cy…
Browse files Browse the repository at this point in the history
…linder.
  • Loading branch information
jie_zhang authored and BasmanovDaniil committed Mar 21, 2021
1 parent 372c9b9 commit 8fd3170
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Runtime/MeshDraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,20 +620,23 @@ public MeshDraft AddFlatQuadBand(IReadOnlyList<Vector3> 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];
upper0 = upperRing[i];
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
Expand All @@ -642,12 +645,18 @@ public MeshDraft AddFlatQuadBand(IReadOnlyList<Vector3> 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
Expand Down Expand Up @@ -914,3 +923,4 @@ public override string ToString()
}
}
}

0 comments on commit 8fd3170

Please sign in to comment.