/// <summary> /// Add a Plane to the Model. /// </summary> /// <param name="width"></param> /// <param name="length"></param> public static Mesh Plane(double width, double length) { var vertices = new[] { -width, -length, 0.0, width, -length, 0.0, width, length, 0.0, -width, length, 0.0 }; var normals = new[] { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; var indices = new ushort[] { 0, 1, 2, 0, 2, 3 }; var mesh = new Hypar.Geometry.Mesh(vertices, normals, indices); return(mesh); }
/// <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); }
/// <summary> /// Create a ruled loft between sections. /// </summary> /// <param name="sections"></param> public static Mesh Loft(IList <Polygon> sections) { var mesh = new Hypar.Geometry.Mesh(); for (var i = 0; i < sections.Count; i++) { var p1 = sections[i]; var p2 = i == sections.Count - 1 ? sections[0] : sections[i + 1]; for (var j = 0; j < p1.Vertices.Count; j++) { var j1 = j == p1.Vertices.Count - 1 ? 0 : j + 1; var v1 = p1.Vertices[j]; var v2 = p1.Vertices[j1]; var v3 = p2.Vertices[j1]; var v4 = p2.Vertices[j]; mesh.AddQuad(new [] { v1, v2, v3, v4 }); } } return(mesh); }