/// <summary> /// Extrude a Polyon. /// </summary> /// <param name="perimeter">The Polygon to extrude.</param> /// <param name="voids">A collection of Polygons representing voids in the extrusion.</param> /// <param name="height">The height of the extrusion.</param> /// <param name="capped">A flag indicating whether the extrusion should be capped.</param> /// <returns></returns> public static Mesh Extrude(Polygon perimeter, double height, IList <Polygon> voids = null, bool capped = true) { var mesh = new Hypar.Geometry.Mesh(); var perimeters = new List <Polygon>(); perimeters.Add(perimeter); if (voids != null) { perimeters.AddRange(voids); } foreach (var boundary in perimeters) { var verts = boundary.Vertices; for (var i = 0; i < verts.Count; i++) { Vector3 a; Vector3 b; if (i == verts.Count - 1) { a = verts[i]; b = verts[0]; } else { a = verts[i]; b = verts[i + 1]; } var v1 = new Vector3(a.X, a.Y, 0.0); var v2 = new Vector3(b.X, b.Y, 0.0); var v3 = new Vector3(b.X, b.Y, height); var v4 = new Vector3(a.X, a.Y, height); mesh.AddQuad(new [] { v1, v2, v3, v4 }); } } if (capped) { mesh.AddTesselatedFace(perimeter, voids, new Transform()); mesh.AddTesselatedFace(perimeter, voids, new Transform(new Vector3(0, 0, height)), true); } return(mesh); }
/// <summary> /// Extrude an Polygon along an ICurve. /// </summary> /// <param name="curve">The ICurve along which to extrude.</param> /// <param name="perimeter">A Polygon to extrude.</param> /// <param name="voids">A collection of Polygons representing voids in the extrusion.</param> /// <param name="capped">A flag indicating whether the extrusion should be capped.</param> /// <param name="startSetback">The setback trom the start of the line of the extrusion.</param> /// <param name="endSetback">The setback from the end of the line of the end of the extrusion.</param> /// <returns></returns> public static Mesh ExtrudeAlongCurve(ICurve curve, Polygon perimeter, IList <Polygon> voids = null, bool capped = true, double startSetback = 0.0, double endSetback = 0.0) { var mesh = new Hypar.Geometry.Mesh(); var l = curve.Length; var ssb = startSetback / l; var esb = endSetback / l; var transforms = new List <Transform>(); var polys = new List <Polygon>(); transforms.AddRange(curve.Frames(ssb, esb)); for (var i = 0; i < transforms.Count - 1; i++) { ExtrudePolygon(ref mesh, perimeter, transforms[i], transforms[i + 1]); if (voids != null) { foreach (var p in voids) { ExtrudePolygon(ref mesh, p, transforms[i], transforms[i + 1], true); } } } if (curve is Polygon) { ExtrudePolygon(ref mesh, perimeter, transforms[transforms.Count - 1], transforms[0]); if (voids != null) { foreach (var p in voids) { ExtrudePolygon(ref mesh, p, transforms[transforms.Count - 1], transforms[0], true); } } } if (capped) { mesh.AddTesselatedFace(perimeter, voids, transforms[0]); mesh.AddTesselatedFace(perimeter, voids, transforms[transforms.Count - 1], true); } return(mesh); }