/// <summary> /// Constructs a cylinder draft /// </summary> public static MeshDraft Cylinder(float radius, int segments, float height, bool generateUV = true) { float segmentAngle = 360f / segments; float currentAngle = 0; Vector3 halfHeightUp = Vector3.up * height / 2; var draft = new MeshDraft { name = "Cylinder" }; var lowerRing = new List <Vector3>(segments); var lowerDiskUV = new List <Vector2>(); var upperRing = new List <Vector3>(segments); var upperDiskUV = new List <Vector2>(); var strip = new List <Vector3>(); var stripNormals = new List <Vector3>(); var stripUV = new List <Vector2>(); for (var i = 0; i < segments; i++) { Vector3 lowerVertex; Vector3 upperVertex; AddCylinderPoints(radius, currentAngle, halfHeightUp, generateUV, ref strip, ref stripUV, ref stripNormals, out lowerVertex, out upperVertex); lowerRing.Add(lowerVertex); upperRing.Add(upperVertex); if (generateUV) { Vector2 uv = Geometry.PointOnCircle2(0.5f, currentAngle) + new Vector2(0.5f, 0.5f); upperDiskUV.Add(uv); uv.x = 1 - uv.x; lowerDiskUV.Add(uv); } currentAngle += segmentAngle; } Vector3 lowerSeamVertex; Vector3 upperSeamVertex; AddCylinderPoints(radius, currentAngle, halfHeightUp, generateUV, ref strip, ref stripUV, ref stripNormals, out lowerSeamVertex, out upperSeamVertex); if (generateUV) { draft.AddTriangleFan(lowerRing, Vector3.down, lowerDiskUV, true); draft.AddTriangleFan(upperRing, Vector3.up, upperDiskUV); draft.AddTriangleStrip(strip, stripNormals, stripUV); } else { draft.AddTriangleFan(lowerRing, Vector3.down, true); draft.AddTriangleFan(upperRing, Vector3.up); draft.AddTriangleStrip(strip, stripNormals); } return(draft); }
/// <remarks> /// https://en.wikipedia.org/wiki/Triangle_strip /// </remarks> public static MeshDraft TriangleStrip(List <Vector3> strip, Vector3 normal) { var draft = new MeshDraft { name = "TriangleStrip", uv = new List <Vector2>(strip.Count), }; draft.AddTriangleStrip(strip, normal); for (int i = 0; i < strip.Count; i++) { draft.uv.Add(new Vector2((float)i / strip.Count, (float)i / strip.Count)); } return(draft); }