示例#1
0
        /// <summary>
        /// Extrudes a polygon.
        /// </summary>
        /// <param name="polygon">The polygon to extrude</param>
        /// <param name="distance">Extrusion distance</param>
        /// <param name="normal">Optional normal to extrude along, default is polygon normal</param>
        /// <returns></returns>
        public static List <Polygon> extrudePolygon(Polygon polygon, float distance, Vector3?normal = null)
        {
            normal = normal != null ? normal : polygon.plane.normal;

            Vector3 du = normal.GetValueOrDefault();

            Vertex[]       vertices  = polygon.vertices;
            List <Vertex>  top       = new List <Vertex>();
            List <Vertex>  bot       = new List <Vertex>();
            List <Polygon> polygons  = new List <Polygon>();
            Vector3        invNormal = normal.GetValueOrDefault();

            du        *= distance;
            invNormal *= -1f;

            for (int i = 0; i < vertices.Length; i++)
            {
                int     j     = (i + 1) % vertices.Length;
                Vector3 p1    = vertices[i].position;
                Vector3 p2    = vertices[j].position;
                Vector3 p3    = p2 + du;
                Vector3 p4    = p1 + du;
                Plane   plane = Plane.fromPoints(p1, p2, p3);
                Vertex  v1    = new Vertex(p1, plane.normal);
                Vertex  v2    = new Vertex(p2, plane.normal);
                Vertex  v3    = new Vertex(p3, plane.normal);
                Vertex  v4    = new Vertex(p4, plane.normal);
                Polygon poly  = new Polygon(new List <Vertex>(new Vertex[] { v1, v2, v3, v4 }), polygon.shared);
                polygons.Add(poly);
                top.Add(new Vertex(p4, normal.GetValueOrDefault()));
                bot.Insert(0, new Vertex(p1, invNormal));
            }

            polygons.Add(new Polygon(top, polygon.shared));
            polygons.Add(new Polygon(bot, polygon.shared));

            return(polygons);
        }
示例#2
0
 public Polygon(List <IVertex> vertices, System.Object shared)
 {
     this.vertices = vertices.ToArray();
     this.shared   = shared;
     this.plane    = Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
 }
示例#3
0
 public Polygon(List <IVertex> vertices)
 {
     this.vertices = vertices.ToArray();
     this.plane    = Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
 }
示例#4
0
 public Polygon(IVertex[] vertices, System.Object shared)
 {
     this.vertices = vertices;
     this.shared   = shared;
     this.plane    = Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
 }
示例#5
0
 public Polygon(IVertex[] vertices)
 {
     this.vertices = vertices;
     this.plane    = Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
 }