public static IBlock Extrude(IPoly polygon, Vector3 direction, float floorDistance, float ceilingDistance, Func <IEnumerable <Vector3>, IPoly> polyConstructor = null, Func <IEnumerable <IPoly>, IBlock> blockConstructor = null) { if (polyConstructor == null) { polyConstructor = polygon.Clone; } IPoly floor = polygon.Clone(polygon.GetPoints().Select(x => x + direction * floorDistance)); IPoly ceiling = polygon.Clone(polygon.GetPoints().Select(x => x + direction * ceilingDistance)); List <IPoly> faces = new List <IPoly>(); for (int i = 0; i < polygon.Resolution; i++) { Vector3 lr = floor.GetPoint(i); Vector3 ll = floor.GetPoint((i + 1) % polygon.Resolution); Vector3 ul = ceiling.GetPoint((i + 1) % polygon.Resolution); Vector3 ur = ceiling.GetPoint(i); faces.Add(polyConstructor(new Vector3[] { lr, ll, ul, ur })); } faces.Add(polyConstructor(ceiling.GetPoints())); faces.Add(polyConstructor(floor.GetPoints().Reverse())); if (blockConstructor == null) { blockConstructor = (x) => new Block(x); } return(blockConstructor(faces)); }
/// <summary> /// Make a concave polygon into a convex one /// </summary> /// <param name="poly"></param> /// <returns></returns> public static IEnumerable <IPoly> MakeConvex(IPoly poly) { List <Vector3> input = poly.GetPoints().ToList(); List <List <Vector3> > output = BayazitDecomposer.ConvexPartition(input); return(output.Select(x => poly.Clone(x.ToArray()))); }
public Vector3[] GetPoints() { return(poly.GetPoints()); }