コード例 #1
0
    public void Generate()
    {
        var wythoff = new WythoffPoly(PolyType, PrismP, PrismQ);

        wythoff.BuildFaces();
        poly = new ConwayPoly(wythoff);

        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
            };
            poly = poly.ApplyOp(op1, o1);
            var o2 = new OpParams {
                valueA = op2Amount1, valueB = op2Amount2, facesel = op2Facesel
            };
            poly = poly.ApplyOp(op2, o2);
        }

        if (Canonicalize)
        {
            poly = poly.Canonicalize(0.01, 0.01);
        }


        poly = poly.LoftAlongProfile(new OpParams(DomeDepth, DomeHeight, domeFaceSel), Profile, Shear, shearDirection, flipProfile: FlipProfile);

        // poly = poly.Transform(Position, Rotation, Scale);

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, Colors, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #2
0
    public void Generate()
    {
        poly = WatermanPoly.Build(1f, root, c, MergeFaces);

        if (ApplyOps)
        {
            var o1 = new OpParams {
                valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
            };
            poly = poly.ApplyOp(op1, o1);
            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, Colors, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #3
0
ファイル: GableTest.cs プロジェクト: IxxyXR/polyhydra-upm
    public void Generate()
    {
        poly = JohnsonPoly.Polygon(sides);
        poly = poly.Loft(new OpParams(0.5f));
        var gableSel = FaceSelections.Existing;

        for (int i = 0; i < Iterations; i++)
        {
            poly = poly.Gable(new OpParams(Bud1, Bud2, FaceSelections.Existing));

            poly.ClearTags();
            var newFaces = poly.GetFaceSelection(FaceSelections.New);
            poly.TagFaces("fork1", filter: x => x.index == newFaces.FirstOrDefault(), introvert: true);
            poly.TagFaces("fork2", filter: x => x.index == newFaces.LastOrDefault(), introvert: true);

            poly = poly.Loft(new OpParams(BranchLengthScale, BranchLength, FaceSelections.New));
            // poly = poly.Loft(new OpParams((5f-i)/10f, (BranchLength-i)/BranchLengthScale, FaceSelections.New));
            poly = poly.FaceSlide(new OpParams(amount1, direction1 * i, selectByTags: "fork1"));
            poly = poly.FaceSlide(new OpParams(amount2, direction2 * i, selectByTags: "fork2"));
        }

        // poly = poly.Transform(Position, Rotation, Scale);
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #4
0
    public void Generate()
    {
        var poly = Grids.Grids.MakeGrid(GridType, GridShape, width, depth);

        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1 * Mathf.Abs(op1Animate ? Mathf.Sin(Time.time) : 1), valueB = op1Amount2, facesel = op1Facesel
            };
            poly = poly.ApplyOp(op1, o1);
        }
        poly = poly.LoftAlongProfile(domeFaceSel, DomeHeight, DomeSegments, easingType);
        if (ApplyOp)
        {
            var o2 = new OpParams {
                valueA = op2Amount1 * Mathf.Abs(op2Animate ? Mathf.Cos(Time.time * .6f) : 1), valueB = op2Amount2, facesel = op2Facesel
            };
            poly = poly.ApplyOp(op2, o2);
        }
        poly = poly.Transform(Position, Rotation, Scale);

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #5
0
ファイル: SwirlySquares.cs プロジェクト: IxxyXR/polyhydra-upm
    public void Generate()
    {
        poly = Grids.Grids.MakeGrid(GridType, GridShape, width, depth);
        poly.ClearTags();
        poly.TagFaces("#FFFFFF", filter: whiteFilter);
        poly.TagFaces("#000000", filter: blackFilter);

        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
            };
            poly = poly.ApplyOp(op1, o1);
            var o2 = new OpParams {
                valueA = op2Amount1, valueB = op2Amount2, facesel = op2Facesel
            };
            poly = poly.ApplyOp(op2, o2);
            var o3 = new OpParams {
                valueA = op3Amount1, valueB = op3Amount2, facesel = op3Facesel
            };
            poly = poly.ApplyOp(op3, o3);
        }
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, meshColors, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #6
0
    public void Generate()
    {
        poly = poly.Transform(Position, Rotation, Scale);
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #7
0
ファイル: SliceTest.cs プロジェクト: IxxyXR/polyhydra-upm
    public void Generate()
    {
        var wythoff = new WythoffPoly(PolyType, PrismP, PrismQ);

        wythoff.BuildFaces();
        poly = new ConwayPoly(wythoff);
        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
            };
            poly = poly.ApplyOp(op1, o1);
        }

        if (Canonicalize)
        {
            poly = poly.Canonicalize(0.01, 0.01);
        }

        poly = poly.Transform(Position, Rotation, Scale);

        var pos = SlicePosition;

        if (animateSlice > 0)
        {
            pos.y = .1f + transform.position.y + ((Time.time % 2f) * animateSlice);
        }

        var result = poly.SliceByPlane(new Plane(Quaternion.Euler(SliceRotation) * Vector3.up, pos), Cap, includeTop, includeBottom);

        poly = result.bottom;
        var top = result.top.Transform(topTransform);

        poly.Append(top);

        // var sliceWythoff = new WythoffPoly(PolyTypes.Cube, 3, 3);
        // sliceWythoff.BuildFaces();
        // var slicePoly = new ConwayPoly(wythoff);
        // slicePoly = slicePoly.Transform(SlicePosition, SliceRotation, Vector3.one * SliceScale);
        // var result = poly.SliceByPoly(slicePoly, Cap);
        // poly = result.outside;
        // var top = result.outside.Transform(topTransform);

        if (Weld)
        {
            poly = poly.Weld(0.0001f);
        }

        if (ApplyOp)
        {
            var o2 = new OpParams {
                valueA = op2Amount1, valueB = op2Amount2, facesel = op2Facesel
            };
            poly = poly.ApplyOp(op2, o2);
        }

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #8
0
    public void Generate()
    {
        var poly = JohnsonPoly.BuildOther(otherPolyType, sides, segments);

        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
            };
            poly = poly.ApplyOp(op1, o1);
            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;
    }
コード例 #9
0
    public void Generate()
    {
        var colorMethod = ColorBySides ? PolyHydraEnums.ColorMethods.BySides : PolyHydraEnums.ColorMethods.ByRole;
        var poly        = Grids.Grids.MakeGrid(GridType, GridShape, width, depth);

        poly = poly.FaceRemove(new OpParams {
            facesel = removeSelection
        });
        for (int i = 0; i < repeats; i++)
        {
            float angle = Mathf.Sin(((float)i / repeats) * frequency * Mathf.PI) * amplitude;
            poly = poly.ExtendBoundaries(new OpParams {
                valueA = amount, valueB = angle
            });
        }

        if (ApplyOp)
        {
            var o = new OpParams {
                valueA = opAmount, valueB = op2Amount, facesel = facesel
            };
            poly = poly.ApplyOp(op, o);
        }

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, colorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #10
0
ファイル: ExampleBase.cs プロジェクト: IxxyXR/polyhydra-upm
    public virtual void Generate()
    {
        float animMultiplier = Mathf.Abs(Mathf.Sin(Time.time * AnimationSpeed) * AnimationAmount);

        if (ApplyOp)
        {
            for (var i = 0; i < op1iterations; i++)
            {
                poly = poly.ApplyOp(op1, new OpParams {
                    valueA  = op1Amount1 * (op1Animate ? animMultiplier : 1),
                    valueB  = op1Amount2,
                    facesel = op1Facesel
                });
            }
            for (var i = 0; i < op2iterations; i++)
            {
                poly = poly.ApplyOp(op2, new OpParams {
                    valueA  = op2Amount1 * (op2Animate ? animMultiplier : 1),
                    valueB  = op2Amount2,
                    facesel = op2Facesel
                });
            }
            for (var i = 0; i < op3iterations; i++)
            {
                poly = poly.ApplyOp(op3, new OpParams {
                    valueA  = op3Amount1 * (op3Animate ? animMultiplier : 1),
                    valueB  = op3Amount2,
                    facesel = op3Facesel
                });
            }
        }

        AfterAllOps();

        Color[] colors = null;
        if (UseCustomColors)
        {
            colors = Enumerable.Range(0, 8).Select(x => Colors.Evaluate(((x / 8f) * ColorRange + ColorOffset) % 1)).ToArray();
        }

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, colors, ColorMethod, UVMethod);

        if (Rescale)
        {
            var size         = mesh.bounds.size;
            var maxDimension = Mathf.Max(size.x, size.y, size.z);
            var scale        = (1f / maxDimension) * 2f;
            if (scale > 0 && scale != Mathf.Infinity)
            {
                transform.localScale = new Vector3(scale, scale, scale);
            }
            else
            {
                Debug.LogError("Failed to rescale");
            }
        }

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #11
0
    public void Generate()
    {
        var wythoff = new WythoffPoly(PolyType, PrismP, PrismQ);

        wythoff.BuildFaces();
        poly = new ConwayPoly(wythoff);
        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
            };
            poly = poly.ApplyOp(op1, o1);
        }

        if (Canonicalize)
        {
            poly = poly.Canonicalize(0.01, 0.01);
        }

        poly = poly.Transform(Position, Rotation, Scale);

        var pos = SlicePosition;

        if (animateSlice > 0)
        {
            pos.y = .1f + transform.position.y + ((Time.time % 2f) * animateSlice);
        }

        var rot        = Quaternion.Euler(SliceRotation) * Vector3.up;
        var slicePlane = new Plane(rot, pos);
        var result     = poly.SliceByPlane(slicePlane, Cap, includeTop, includeBottom);

        poly = result.bottom;
        var slicePoint = slicePlane.normal * (-slicePlane.distance + SegmentHeight);

        slicePlane.SetNormalAndPosition(slicePlane.normal, slicePoint);
        var(top, segment, _) = result.top.SliceByPlane(slicePlane, Cap, includeTop, includeBottom);
        segment = segment.Transform(SegmentTransform);
        poly.Append(top);
        poly.Append(segment);

        if (Weld)
        {
            poly = poly.Weld(0.0001f);
        }

        if (ApplyOp)
        {
            var o2 = new OpParams {
                valueA = op2Amount1, valueB = op2Amount2, facesel = op2Facesel
            };
            poly = poly.ApplyOp(op2, o2);
        }

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #12
0
    public void Generate()
    {
        var wythoff = new WythoffPoly(PolyType, PrismP, PrismQ);

        wythoff.BuildFaces();
        var        poly = new ConwayPoly(wythoff);
        ConwayPoly d, x, xd, dx, dxd;
        var        o = new OpParams {
            valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
        };

        d = poly.Dual();

        x = poly.ApplyOp(op, o);

        xd = d.ApplyOp(op, o);

        dx = poly.ApplyOp(op, o);
        dx = dx.Dual();

        dxd = d.ApplyOp(op, o);
        dxd = dxd.Dual();

        if (Canonicalize)
        {
            x   = x.Canonicalize(0.01, 0.01);
            dx  = dx.Canonicalize(0.01, 0.01);
            dxd = dxd.Canonicalize(0.01, 0.01);
            xd  = xd.Canonicalize(0.01, 0.01);
        }

        Debug.Log($"x: {x.vef.v},{x.vef.e},{x.vef.f}");
        Debug.Log($"xd: {xd.vef.v},{xd.vef.e},{xd.vef.f}");
        Debug.Log($"dx: {dx.vef.v},{dx.vef.e},{dx.vef.f}");
        Debug.Log($"dxd: {dxd.vef.v},{dxd.vef.e},{dxd.vef.f}");

        var allPoly = new ConwayPoly();

        x   = x.Transform(-Vector3.left);
        xd  = xd.Transform(Vector3.left * 2);
        dx  = dx.Transform(Vector3.left * 4);
        dxd = dxd.Transform(Vector3.left * 6);

        allPoly.Append(x);
        allPoly.Append(xd);
        allPoly.Append(dx);
        allPoly.Append(dxd);
        allPoly.Recenter();

        allPoly = allPoly.Transform(Position, Rotation, Scale);

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(allPoly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #13
0
    public void Generate()
    {
        Func <FilterParams, bool> pickRandomly = x =>
        {
            // Sets random seed based on face index
            // So that the results are the same if we call more than once
            Random.InitState(x.index);
            return(Random.value < Density);
        };

        // Generate the ground grid and extrude random buildings
        var grid = Grids.Grids.MakeGrid(GridType, GridShape, width, depth);

        grid = grid.VertexRotate(new OpParams(Jitter, randomValues: true));
        var floors = grid.FaceKeep(new OpParams(.1f, pickRandomly));
        var houses = floors.Loft(new OpParams(0, x => Random.Range(.5f, 1.5f)));

        var(walls, roofs) = houses.Split(new OpParams(FaceSelections.Existing));

        // Make window holes
        walls = walls.Loft(new OpParams(0.75f, FaceSelections.AllNew));
        walls = walls.FaceSlide(new OpParams(0.15f, FaceSelections.Existing));
        walls = walls.FaceRemove(new OpParams(FaceSelections.Existing));

        // Thicken the walls
        walls = walls.Shell(0.025f);

        // Add domes to the roofs
        var domes = roofs.LoftAlongProfile(FaceSelections.All, DomeHeight, DomeSegments, easingType);

        // Make nice patterns on the ground
        var ground = grid.Dual();

        ground = ground.Bevel(new OpParams(0.25f));
        ground = ground.Medial(new OpParams(3f));

        // Add some edging around buildings
        var edging = floors.Transform(new Vector3(0, .03f, 0));

        edging = edging.FaceScale(new OpParams(0.25f));
        edging.SetFaceRoles(ConwayPoly.Roles.Existing);

        // Assemble everything
        var town = new ConwayPoly();

        town.Append(edging);
        town.Append(ground);
        town.Append(walls);
        town.Append(domes);

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(town, false, Colors, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #14
0
ファイル: TowersTest.cs プロジェクト: IxxyXR/polyhydra-upm
    public void Generate()
    {
        poly = JohnsonPoly.Polygon(4);
        poly = poly.Loft(new OpParams(0, height));
        var loop = poly.GetFaceLoop(poly.Halfedges.First());

        poly = poly.MultiSplitLoop(loop, divisions);



        // poly = poly.Transform(Position, Rotation, Scale);
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #15
0
    public void MakePolyhedron()
    {
        switch (ShapeType)
        {
        case PolyHydraEnums.ShapeTypes.Uniform:
            var wythoff = new WythoffPoly(UniformPolyType, PrismP, PrismQ);
            wythoff.BuildFaces();
            _conwayPoly = new ConwayPoly(wythoff);
            break;

        case PolyHydraEnums.ShapeTypes.Johnson:
            _conwayPoly = JohnsonPoly.Build(JohnsonPolyType, PrismP);
            break;

        case PolyHydraEnums.ShapeTypes.Grid:
            _conwayPoly = Grids.Grids.MakeGrid(GridType, GridShape, PrismP, PrismQ);
            break;

        case PolyHydraEnums.ShapeTypes.Waterman:
            _conwayPoly = WatermanPoly.Build(PrismP, PrismQ);
            break;

        case PolyHydraEnums.ShapeTypes.Other:
            _conwayPoly = JohnsonPoly.BuildOther(OtherPolyType, PrismP, PrismQ);
            break;
        }
        _conwayPoly.basePolyhedraInfo = new ConwayPoly.BasePolyhedraInfo {
            P = PrismP, Q = PrismQ
        };

        foreach (var op in ConwayOperators.ToList())
        {
            if (op.disabled || op.opType == Ops.Identity)
            {
                continue;
            }
            _conwayPoly = ApplyOp(_conwayPoly, ref stashed, op);
            _conwayPoly.basePolyhedraInfo = new ConwayPoly.BasePolyhedraInfo {
                P = PrismP, Q = PrismQ
            };
        }
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(_conwayPoly, GenerateSubmeshes, null, ColorMethod);

        AssignFinishedMesh(mesh);
    }
コード例 #16
0
    public void Generate()
    {
        switch (ShapeType)
        {
        case ShapeTypes.Wythoff:
            var wythoff1 = new WythoffPoly(PolyType1, P1, Q1);
            wythoff1.BuildFaces();
            poly1 = new ConwayPoly(wythoff1);
            var wythoff2 = new WythoffPoly(PolyType2, P2, Q2);
            wythoff2.BuildFaces();
            poly2 = new ConwayPoly(wythoff2);
            break;

        case ShapeTypes.Johnson:
            poly1 = JohnsonPoly.Build(JohnsonPolyType1, P1);
            poly2 = JohnsonPoly.Build(JohnsonPolyType2, P2);
            break;

        case ShapeTypes.Grid:
            poly1 = Grids.Grids.MakeGrid(GridType, GridShape1, P1, Q1, false);
            poly2 = Grids.Grids.MakeGrid(GridType, GridShape2, P2, Q2, false);
            break;
        }

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

        poly1 = poly1.ApplyOp(op1, o1);

        var o2 = new OpParams {
            valueA = op2Amount1, valueB = op2Amount2, facesel = op2Facesel
        };

        poly2 = poly2.ApplyOp(op2, o2);

        poly1.Morph(poly2, morphAmount, reverseVertexOrder);

        // Final Mesh
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly1, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #17
0
    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;
    }
コード例 #18
0
    public void Generate()
    {
        Func <FilterParams, bool> pickRandomly = x =>
        {
            // Sets random seed based on face index
            // So that the results are the same if we call more than once
            Random.InitState(x.index);
            return(Random.value < Density);
        };

        // Generate the ground grid and extrude random buildings
        var grid = Grids.Grids.MakeGrid(GridType, GridShape, width, depth);

        grid = grid.VertexRotate(new OpParams(Jitter, randomValues: true));
        var faceSelectionFunc = grid.FaceselToFaceFilterFunc(faceSelection);
        Func <FilterParams, bool> filterFunc = x => pickRandomly(x) && faceSelectionFunc(x);
        var floors = grid.FaceKeep(new OpParams(.1f, filterFunc));
        var houses = floors.Loft(new OpParams(0, x => Random.Range(.5f, 1.5f)));

        var(walls, roofs) = houses.Split(new OpParams(FaceSelections.Existing));

        // Make window holes
        walls = walls.Loft(new OpParams(0.75f, FaceSelections.AllNew));
        walls = walls.FaceSlide(new OpParams(0.15f, FaceSelections.Existing));
        walls = walls.FaceRemove(new OpParams(FaceSelections.Existing));

        // Thicken the walls
        walls = walls.Shell(0.025f);

        // Add domes to the roofs
        var domes = roofs.LoftAlongProfile(new OpParams(DomeDepth, DomeHeight, FaceSelections.All), Profile, flipProfile: FlipProfile);

        // Assemble everything
        var town = new ConwayPoly();

        town.Append(grid);
        town.Append(walls);
        town.Append(domes);

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(town, false, Colors, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #19
0
    public void Generate()
    {
        var poly        = JohnsonPoly.Antiprism(4);
        var cube        = JohnsonPoly.Prism(4);
        var decorations = new ConwayPoly();

        cube = cube.Transform(Vector3.zero, Vector3.zero, Vector3.one * cubeScale);
        foreach (var face in poly.Faces)
        {
            for (float angle = 0; angle < 360; angle += theta)
            {
                var pos  = face.GetPolarPoint(angle, distance);
                var look = Quaternion.LookRotation(face.Normal, Vector3.up).eulerAngles + new Vector3(90, 0, 0);
                decorations.Append(cube.Transform(pos, look, Vector3.one));
            }
        }
        //poly.Append(decorations);
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(decorations, false);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #20
0
    public void Generate()
    {
        var poly        = Grids.Grids.MakeGrid(GridType, GridShape, width, depth);
        var colorMethod = ColorBySides ? PolyHydraEnums.ColorMethods.BySides : PolyHydraEnums.ColorMethods.ByRole;

        if (ApplyOp)
        {
            var o = new OpParams {
                valueA = opAmount, valueB = op2Amount, facesel = facesel
            };
            poly = poly.ApplyOp(op, o);
        }

        var bitsJoined = Enumerable.Repeat("".PadRight(width, '1'), depth).ToArray();

        for (var i = 0; i < bits.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length; i++)
        {
            var line = bits.Split(new[] { Environment.NewLine }, StringSplitOptions.None)[i];
            bitsJoined[i] = line.PadRight(width, '0').Substring(0, width);
        }
        Func <FilterParams, bool> filterFunc = f =>
        {
            int x = Mathf.FloorToInt(f.index / width);
            int y = f.index % width;
            Debug.Log($"{f.index} {x}x{y}");
            return(!(x < bitsJoined[y].Length && bitsJoined[y].Substring(x, 1) == "1"));
        };

        poly = poly.FaceRemove(new OpParams {
            filterFunc = filterFunc
        });
        poly = poly.Shell(new OpParams {
            valueA = extrusionAmount
        });

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, colorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #21
0
    public Mesh MakeMorphTarget(int morphIndex, float amount)
    {
        var morphedPoly = poly.Duplicate();

        for (var i = 0; i < Morphs.Count; i++)
        {
            float a           = i == morphIndex ? amount : 0; // Zero amount for ops other than the requested one
            var   morphOp     = Morphs[i];
            var   morphParams = new OpParams(
                Mathf.Lerp(morphOp.opAmount1Start, morphOp.opAmount1End, a),
                Mathf.Lerp(morphOp.opAmount2Start, morphOp.opAmount2End, a),
                morphOp.opFacesel
                );
            morphedPoly = morphedPoly.ApplyOp(morphOp.op, morphParams);
            morphedPoly = morphedPoly.ApplyOp(PostMorph.op, new OpParams(PostMorph.opAmount1, PostMorph.opAmount2, PostMorph.opFacesel));
        }
        var result = PolyMeshBuilder.BuildMeshFromConwayPoly(morphedPoly, false, null, ColorMethod);

        // result.RecalculateNormals();
        // result.RecalculateTangents();
        return(result);
    }
コード例 #22
0
    void Start()
    {
        // 1. Create a starting shape
        ConwayPoly poly1 = JohnsonPoly.Build(PolyHydraEnums.JohnsonPolyTypes.Prism, 4);

        // 2. Apply an operator to the starting shape
        poly1 = poly1.ApplyOp(Ops.Chamfer, new OpParams(.3f));

        // 3. Create a second shape
        ConwayPoly poly2 = JohnsonPoly.Build(PolyHydraEnums.JohnsonPolyTypes.Pyramid, 4);

        // 4. Move our second shape down by 0.5
        poly2 = poly1.Transform(new Vector3(0, .5f, 0));

        // 5. Join the two shapes
        poly1.Append(poly2);

        // 6. Build and apply the mesh
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly1);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #23
0
    public void Generate()
    {
        poly = JohnsonPoly.Polygon(sides);
        poly = poly.Loft(new OpParams(0.5f));

        for (int i = 0; i < 3; i++)
        {
            poly = poly.SplitFaces(new OpParams(FaceSelections.Existing));

            poly.ClearTags();
            poly.TagFaces("split1", FaceSelections.New, introvert: true);
            poly.TagFaces("split2", FaceSelections.New, introvert: true);

            poly = poly.Loft(new OpParams(0.01f, 1f, FaceSelections.AllNew));
            poly = poly.FaceSlide(new OpParams(amount1, direction1 * i, selectByTags: "split1"));
            poly = poly.FaceSlide(new OpParams(amount2, direction2 * i, selectByTags: "split2"));
        }

        poly = poly.Transform(Position, Rotation, Scale);
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #24
0
ファイル: ExtendTest.cs プロジェクト: IxxyXR/polyhydra-upm
    public void Generate()
    {
        var colorMethod = ColorBySides ? PolyHydraEnums.ColorMethods.BySides : PolyHydraEnums.ColorMethods.ByRole;
        var poly        = Grids.Grids.MakeGrid(GridType, GridShape, width, depth);

        poly = poly.FaceRemove(new OpParams {
            facesel = removeSelection
        });
        poly = poly.ExtendBoundaries(new OpParams {
            valueA = amount, valueB = angle
        });

        if (ApplyOp)
        {
            var o = new OpParams {
                valueA = opAmount, valueB = op2Amount, facesel = facesel
            };
            poly = poly.ApplyOp(op, o);
        }

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, colorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #25
0
    public void Generate()
    {
        switch (ShapeType)
        {
        case ShapeTypes.Wythoff:
            var wythoff = new WythoffPoly(PolyType, PrismP, PrismQ);
            wythoff.BuildFaces();
            poly = new ConwayPoly(wythoff);
            break;

        case ShapeTypes.Johnson:
            poly = JohnsonPoly.Build(JohnsonPolyType, PrismP);
            break;

        case ShapeTypes.Grid:
            poly = Grids.Grids.MakeGrid(GridType, GridShape, PrismP, PrismQ);
            break;

        case ShapeTypes.Other:
            poly = JohnsonPoly.BuildOther(OtherPolyType, PrismP, PrismQ);
            break;
        }

        if (applyPreOp)
        {
            var preOpParams = new OpParams {
                valueA = preOpAmount1, valueB = preOpAmount2, facesel = preOpFacesel
            };
            for (int i = 0; i < preOpIterations; i++)
            {
                poly = poly.ApplyOp(preOp, preOpParams);
            }
        }

        OpParams amount1Func = null;

        switch (Equation)
        {
        case Equations.LinearX:
            amount1Func = new OpParams
            {
                funcA = x => offset1 + Mathf.Sin((x.poly.Faces[x.index].Centroid.x * frequency1 + phase1 - (Time.time * animationSpeed1))) * amplitude1,
                funcB = x => offset2 + Mathf.Sin((x.poly.Faces[x.index].Centroid.x * frequency2 + phase2 - (Time.time * animationSpeed2))) * amplitude2
            };
            break;

        case Equations.LinearY:
            amount1Func = new OpParams
            {
                funcA = x => offset1 + Mathf.Sin((x.poly.Faces[x.index].Centroid.y * frequency1 + phase1 - (Time.time * animationSpeed1))) * amplitude1,
                funcB = x => offset2 + Mathf.Sin((x.poly.Faces[x.index].Centroid.y * frequency2 + phase2 - (Time.time * animationSpeed2))) * amplitude2
            };
            break;

        case Equations.LinearZ:
            amount1Func = new OpParams
            {
                funcA = x => offset1 + Mathf.Sin((x.poly.Faces[x.index].Centroid.z * frequency1 + phase1 - (Time.time * animationSpeed1))) * amplitude1,
                funcB = x => offset2 + Mathf.Sin((x.poly.Faces[x.index].Centroid.z * frequency2 + phase2 - (Time.time * animationSpeed2))) * amplitude2
            };
            break;

        case Equations.Radial:
            amount1Func = new OpParams
            {
                funcA = x => offset1 + Mathf.Sin((x.poly.Faces[x.index].Centroid.magnitude * frequency1 + phase1 - (Time.time * animationSpeed1))) * amplitude1,
                funcB = x => offset2 + Mathf.Sin((x.poly.Faces[x.index].Centroid.magnitude * frequency2 + phase2 - (Time.time * animationSpeed2))) * amplitude2
            };
            break;

        case Equations.Perlin:
            amount1Func = new OpParams
            {
                funcA = x => offset1 + Mathf.PerlinNoise(x.poly.Faces[x.index].Centroid.x * frequency1 + phase1 - (Time.time * animationSpeed1), x.poly.Faces[x.index].Centroid.z * frequency1 + phase1 - (Time.time * animationSpeed1)) * amplitude1,
                funcB = x => offset2 + Mathf.PerlinNoise(x.poly.Faces[x.index].Centroid.x * frequency2 + phase2 - (Time.time * animationSpeed2), x.poly.Faces[x.index].Centroid.z * frequency2 + phase2 - Time.time) * amplitude2,
            };
            break;
        }

        poly = poly.ApplyOp(op, amount1Func);
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #26
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;
    }
コード例 #27
0
    public void Generate()
    {
        var wythoff = new WythoffPoly(PolyType, PrismP, PrismQ);

        wythoff.BuildFaces();
        poly = new ConwayPoly(wythoff);
        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
            };
            poly = poly.ApplyOp(op1, o1);
        }

        if (Canonicalize)
        {
            poly = poly.Canonicalize(0.01, 0.01);
        }

        poly = poly.Transform(Position, Rotation, Scale);

        var rot = SliceRotation;

        if (animateSlice > 0)
        {
            rot.y = Time.time * animateSlice;
        }
        SliceRotation = rot;

        var sliceWythoff = new WythoffPoly(SlicePolyType, 3, 3);

        sliceWythoff.BuildFaces();
        var slicePoly = new ConwayPoly(sliceWythoff);

        slicePoly = slicePoly.Transform(SlicePosition, SliceRotation, Vector3.one * SliceScale);
        var result = poly.SliceByPoly(slicePoly, Cap, FaceCount);

        poly = result.outside;
        var inside = result.inside.Transform(insideTransform);

        poly.Append(inside);

        if (ShowSlicePoly)
        {
            poly.Append(slicePoly);
        }

        if (Weld)
        {
            poly = poly.Weld(0.0001f);
        }

        if (ApplyOp)
        {
            var o2 = new OpParams {
                valueA = op2Amount1, valueB = op2Amount2, facesel = op2Facesel
            };
            poly = poly.ApplyOp(op2, o2);
        }

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #28
0
    public void Generate()
    {
        var multigrid = new MultiGrid(Divisions, Dimensions, Offset, MinDistance, MaxDistance, colorRatio, colorIndex, colorIntersect);

        (poly, shapes, colors) = multigrid.Build(SharedVertices, randomize);
        if (shapes.Count == 0)
        {
            return;
        }
        if (ColorMethod == PolyHydraEnums.ColorMethods.ByTags)
        {
            float colorMin = colors.Min();
            float colorMax = colors.Max();

            for (var faceIndex = 0; faceIndex < poly.Faces.Count; faceIndex++)
            {
                var   face       = poly.Faces[faceIndex];
                var   colorIndex = colors[faceIndex];
                float colorValue;
                switch (ColorFunction)
                {
                case ColorFunctions.Mod:
                    colorValue = colorIndex % 1;
                    break;

                case ColorFunctions.ActualMod:
                    colorValue = PolyUtils.ActualMod(colorIndex, 1);
                    break;

                case ColorFunctions.Normalized:
                    colorValue = Mathf.InverseLerp(colorMin, colorMax, colorIndex);
                    break;

                case ColorFunctions.Abs:
                    colorValue = Mathf.Abs(colorIndex);
                    break;

                default:
                    colorValue = colorIndex;
                    break;
                }
                string colorString = ColorUtility.ToHtmlStringRGB(ColorGradient.Evaluate(colorValue));
                var    tag         = new Tuple <string, ConwayPoly.TagType>(
                    $"#{colorString}",
                    TagType);
                poly.FaceTags[faceIndex].Add(tag);
            }
        }

        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
            };
            poly = poly.ApplyOp(op1, o1);
            var o2 = new OpParams {
                valueA = op2Amount1, valueB = op2Amount2, facesel = op2Facesel
            };
            poly = poly.ApplyOp(op2, o2);
            var o3 = new OpParams {
                valueA = op3Amount1, valueB = op3Amount2, facesel = op3Facesel
            };
            poly = poly.ApplyOp(op3, o3);
        }

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #29
0
    public void Generate()
    {
        poly = JohnsonPoly.Build(JohnsonPolyType, Sides);
        poly = poly.Transform(PositionBefore, RotationBefore, ScaleBefore);

        if (ApplyOp)
        {
            var o0 = new OpParams {
                valueA = op0Amount1, valueB = op0Amount2, facesel = op0Facesel
            };
            poly = poly.ApplyOp(op0, o0);
        }

        if (Canonicalize)
        {
            poly = poly.Canonicalize(0.01, 0.01);
        }

        poly.Recenter();

        ConwayPoly DoSlices(ConwayPoly input, Vector3 axis)
        {
            var   result = new ConwayPoly();
            float offset = SliceStart;

            int failsafe = 100;

            do
            {
                offset += SliceDistance;
                var planePos  = new Vector3(offset * axis.x, offset * axis.y, offset * axis.z);
                var sliced    = input.SliceByPlane(new Plane(Quaternion.Euler(SliceAngle) * axis, planePos), Cap);
                var gapVector = new Vector3(-SliceGap * axis.x, -SliceGap * axis.y, -SliceGap * axis.z);
                result = result.Transform(gapVector);
                var lerp  = Mathf.InverseLerp(SliceStart, SliceEnd, offset);
                var shift = new Vector3(Mathf.Sin(lerp * frequency) * amplitude, 0, 0);
                result.Append(sliced.bottom.Transform(shift));
                input = sliced.top;
                failsafe--;
            } while (offset < SliceEnd && failsafe > 0);

            result.Append(input);
            if (Weld)
            {
                result = result.Weld(0.0001f);
            }
            return(result);
        }

        var output = new ConwayPoly();

        output.Append(DoSlices(poly, Vector3.up));

        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1, valueB = op1Amount2, facesel = op1Facesel
            };
            output = output.ApplyOp(op1, o1);
            if (Weld)
            {
                poly = poly.Weld(0.0001f);
            }
            var o2 = new OpParams {
                valueA = op2Amount1, valueB = op2Amount2, facesel = op2Facesel
            };
            output = output.ApplyOp(op2, o2);
        }

        output.Recenter();

        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(output, false, null, ColorMethod);

        GetComponent <MeshFilter>().mesh = mesh;
    }
コード例 #30
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;
    }