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> /// Contract the polygon toward a specified point. /// locks controlls which edges are not able to move to complete the operation /// </summary> /// <param name="poly"></param> /// <param name="center"></param> /// <param name="tValue"></param> /// <param name="lockList"></param> /// <returns></returns> public static IPoly Contract(this IPoly poly, Vector3 center, float tValue, bool[] locks) { if (locks == null) { return(Contract(poly, center, tValue)); } else { Vector3[] output = new Vector3[poly.Resolution]; for (int i = 0; i < poly.Resolution; i++) { Vector3 point = poly.GetPoint(i); bool rightLock = locks[i]; int minusIndex = (i + poly.Resolution - 1) % poly.Resolution; bool leftLock = locks[minusIndex]; if (!rightLock && !leftLock) { output[i] = Vector3.Lerp(point, center, tValue); } else if (leftLock && rightLock) { output[i] = point; } else if (leftLock && !rightLock) { output[i] = Vector3.Lerp(point, poly.GetEdge(minusIndex).Center(), tValue); } else if (!leftLock && rightLock) { output[i] = Vector3.Lerp(point, poly.GetEdge(i).Center(), tValue); } } return(poly.Clone(output)); } }
public static IPoly RemoveDuplicateVerticies(IPoly poly) { List <Vector3> output = new List <Vector3>(); for (int i = 0; i < poly.Resolution; i++) { if (output.Count == 0) { output.Add(poly.GetPoint(i)); } else { Vector3 point = poly.GetPoint(i); Vector3 last = output[output.Count - 1]; if (!Math3d.Compare(point, last)) { output.Add(point); } } } if (Math3d.Compare(output[0], output[output.Count - 1])) { output.RemoveAt(0); } return(poly.Clone(output.ToArray())); }
/// <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()))); }
/// <summary> /// Contract the polygon toward a specified point. /// </summary> /// <param name="distance"></param> /// <param name="center"></param> /// <param name="lockList"></param> /// <returns></returns> public static IPoly Contract(this IPoly poly, Vector3 center, float tValue) { Vector3[] output = new Vector3[poly.Resolution]; for (int i = 0; i < poly.Resolution; i++) { output[i] = Vector3.Lerp(poly.GetPoint(i), center, tValue); } return(poly.Clone(output)); }
public IPoly Clone() { return(new TexturedPoly(poly.Clone(), material, matrix)); }
public IPoly Clone() { return(new CSGShape(poly.Clone(), rValue)); }