Example #1
0
    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;
    }
Example #2
0
    public void Generate()
    {
        switch (ShapeType)
        {
        case ShapeTypes.Wythoff:
            var wythoff = new WythoffPoly(PolyType, P, Q);
            wythoff.BuildFaces();
            polyBeforeOp = new ConwayPoly(wythoff);
            break;

        case ShapeTypes.Johnson:
            polyBeforeOp = JohnsonPoly.Build(JohnsonPolyType, P);
            break;

        case ShapeTypes.Grid:
            polyBeforeOp = Grids.Grids.MakeGrid(GridType, GridShape, P, Q);
            break;
        }

        var o1 = new OpParams {
            valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
        };

        polyBeforeOp = polyBeforeOp.ApplyOp(op1, o1);

        // Collision Mesh
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(polyBeforeOp, false, null, ColorMethod);

        GetComponent <MeshCollider>().sharedMesh = mesh;
        miscUVs2 = new List <Vector4>();
        mesh.GetUVs(4, miscUVs2);

        if (PolyHydraEnums.OpConfigs[op2].usesFaces)
        {
            var o2 = new OpParams {
                valueA = op2Amount1, valueB = op2Amount2, filterFunc = x => SelectedFaces.Contains(x.index)
            };
            polyAfterOp = polyBeforeOp.ApplyOp(op2, o2);
        }
        else
        {
            var(excluded, included) = polyBeforeOp.Split(new OpParams {
                filterFunc = x => SelectedFaces.Contains(x.index)
            });
            var o2 = new OpParams {
                valueA = op2Amount1, valueB = op2Amount2
            };
            polyAfterOp = included.ApplyOp(op2, o2);
            polyAfterOp.Append(excluded);
            if (AttemptToFillHoles)
            {
                polyAfterOp = polyAfterOp.Weld(0.1f);
                polyAfterOp = polyAfterOp.FillHoles();
            }
        }


        // Final Mesh
        mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(polyAfterOp, false, null, ColorMethod);
        GetComponent <MeshFilter>().mesh = mesh;
    }