예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }