public static MeshDraft Band(List <Vector3> lowerRing, List <Vector3> upperRing) { var draft = new MeshDraft { name = "Band" }; if (lowerRing.Count < 3 || upperRing.Count < 3) { Debug.LogError("Array sizes must be greater than 2"); return(draft); } if (lowerRing.Count != upperRing.Count) { Debug.LogError("Array sizes must be equal"); return(draft); } draft.vertices.AddRange(lowerRing); draft.vertices.AddRange(upperRing); var lowerNormals = new List <Vector3>(); var upperNormals = new List <Vector3>(); var lowerUv = new List <Vector2>(); var upperUv = new List <Vector2>(); int i0, i1, i2, i3; Vector3 v0, v1, v2, v3; for (int i = 0; i < lowerRing.Count - 1; i++) { i0 = i; i1 = i + lowerRing.Count; i2 = i + 1; i3 = i + 1 + lowerRing.Count; v0 = draft.vertices[i0]; v1 = draft.vertices[i1]; v2 = draft.vertices[i2]; v3 = draft.vertices[i3]; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); lowerNormals.Add(Vector3.Cross(v1 - v0, v2 - v0).normalized); upperNormals.Add(Vector3.Cross(v3 - v1, v0 - v1).normalized); var u = (float)i / (lowerRing.Count - 1); lowerUv.Add(new Vector2(u, 0)); upperUv.Add(new Vector2(u, 1)); } i0 = lowerRing.Count - 1; i1 = lowerRing.Count * 2 - 1; i2 = 0; i3 = lowerRing.Count; v0 = draft.vertices[i0]; v1 = draft.vertices[i1]; v2 = draft.vertices[i2]; v3 = draft.vertices[i3]; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); lowerNormals.Add(Vector3.Cross(v1 - v0, v2 - v0).normalized); upperNormals.Add(Vector3.Cross(v3 - v1, v0 - v1).normalized); draft.normals.AddRange(lowerNormals); draft.normals.AddRange(upperNormals); lowerUv.Add(new Vector2(1, 0)); upperUv.Add(new Vector2(1, 1)); draft.uv.AddRange(lowerUv); draft.uv.AddRange(upperUv); return(draft); }
public static Mesh Pyramid(float radius, int segments, float height, bool inverted = false) { return(MeshDraft.Pyramid(radius, segments, height, inverted).ToMesh()); }
private static void TriUV(MeshDraft draft, Vector2 first, Vector2 second, Vector2 third) { draft.uv.Add(first); draft.uv.Add(second); draft.uv.Add(third); }