public void Generate() { poly = JohnsonPoly.Build(JohnsonPolyType, sides); Face face; var sidesFilter = poly.FaceselToFaceFilterFunc(FaceSelections.FourSided); var roleFilter = poly.FaceselToFaceFilterFunc(FaceSelections.New); Func <FilterParams, bool> filterFunc = x => sidesFilter(x); for (int i = 0; i < splits; i++) { face = poly.GetFace(new OpParams(filterFunc), 0); if (face != null) { var edges = face.GetHalfedges(); poly = poly.SplitLoop(poly.GetFaceLoop(edges[edgeIndex % edges.Count]), splitRatio); } // Change the filter after the first loop iteration as we can // ensure we get the right face based on it's role filterFunc = x => sidesFilter(x) && roleFilter(x); } if (ApplyOp) { var o1 = new OpParams(op1Amount1, op1Amount2, op1Facesel); poly = poly.ApplyOp(op1, o1); var o2 = new OpParams(op2Amount1, op2Amount2, op2Facesel); poly = poly.ApplyOp(op2, o2); } if (Canonicalize) { poly = poly.Canonicalize(0.1, 0.1); } poly = poly.Transform(Position, Rotation, Scale); var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod); GetComponent <MeshFilter>().mesh = mesh; }
public void Generate() { poly = JohnsonPoly.Build(JohnsonPolyType, sides); if (ApplyOp) { var o1 = new OpParams { valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel }; poly = poly.ApplyOp(op1, o1); } // Find and remove the edge loop var face = poly.Faces[ConwayPoly.ActualMod(StartingFace, poly.Faces.Count)]; var edges = face.GetHalfedges(); var startingEdge = edges[ConwayPoly.ActualMod(StartingEdge, edges.Count)]; loop = poly.GetFaceLoop(startingEdge); var faceIndices = loop.Select(x => x.Item1).ToList(); if (LoopAction == LoopActions.Remove) { poly = poly.FaceRemove(false, faceIndices); } else if (LoopAction == LoopActions.Keep) { poly = poly.FaceRemove(true, faceIndices); } else if (LoopAction == LoopActions.SplitFaces) { poly = poly.SplitLoop(loop); } else if (LoopAction == LoopActions.Split) { ConwayPoly otherPoly; (otherPoly, poly) = poly.Split(new OpParams(x => faceIndices.Contains(x.index))); poly.FaceRoles = Enumerable.Repeat(ConwayPoly.Roles.Existing, poly.Faces.Count).ToList(); poly.VertexRoles = Enumerable.Repeat(ConwayPoly.Roles.Existing, poly.Vertices.Count).ToList(); otherPoly.FaceRoles = Enumerable.Repeat(ConwayPoly.Roles.New, otherPoly.Faces.Count).ToList(); otherPoly.VertexRoles = Enumerable.Repeat(ConwayPoly.Roles.New, otherPoly.Vertices.Count).ToList(); poly.Append(otherPoly); } else if (LoopAction == LoopActions.SetRole) { var faceRoles = new List <ConwayPoly.Roles>(); for (var faceIndex = 0; faceIndex < poly.Faces.Count; faceIndex++) { faceRoles.Add(faceIndices.Contains(faceIndex) ? ConwayPoly.Roles.Existing : ConwayPoly.Roles.New); } poly.FaceRoles = faceRoles; } if (ApplyOp) { var o2 = new OpParams { valueA = op2Amount1, valueB = op2Amount2, facesel = op2Facesel }; poly = poly.ApplyOp(op2, o2); } if (Canonicalize) { poly = poly.Canonicalize(0.1, 0.1); } poly = poly.Transform(Position, Rotation, Scale); var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod); GetComponent <MeshFilter>().mesh = mesh; }