Exemplo n.º 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);
        }

        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;
    }
Exemplo n.º 2
0
    public void MakeWythoff(string symbol)
    {
        symbol = symbol.Replace("p", PrismP.ToString());
        symbol = symbol.Replace("q", PrismQ.ToString());

        if (WythoffPoly == null || WythoffPoly.WythoffSymbol != symbol)
        {
            if (_wythoffCache == null)
            {
                _wythoffCache = new Dictionary <string, WythoffPoly>();
            }
            if (_wythoffCache.ContainsKey(symbol))
            {
                WythoffPoly = _wythoffCache[symbol];
            }
            else
            {
                WythoffPoly           = new WythoffPoly(symbol);
                _wythoffCache[symbol] = WythoffPoly;
            }
        }
        WythoffPoly.BuildFaces(BuildAux: BypassOps);

        //_faceCount = WythoffPoly.FaceCount;
        //_vertexCount = WythoffPoly.VertexCount;
    }
Exemplo n.º 3
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;
    }
Exemplo n.º 4
0
    public void Build(int p, int q)
    {
        P = p;
        Q = q;

        switch (ShapeType)
        {
        case PolyHydraEnums.ShapeTypes.Uniform:
            var wythoff = new WythoffPoly(PolyType, P, Q);
            wythoff.BuildFaces();
            poly = new ConwayPoly(wythoff);
            break;

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

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

        case PolyHydraEnums.ShapeTypes.Other:
            poly = JohnsonPoly.BuildOther(OtherPolyType, P, Q);
            break;

        case PolyHydraEnums.ShapeTypes.Waterman:
            poly = WatermanPoly.Build(1f, P, Q, true);
            break;
        }
    }
Exemplo n.º 5
0
    public override void Generate()
    {
        var wythoff = new WythoffPoly(PolyType, PrismP, PrismQ);

        wythoff.BuildFaces();
        poly = new ConwayPoly(wythoff);
        base.Generate();
    }
Exemplo n.º 6
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;
    }
Exemplo n.º 7
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;
    }
Exemplo n.º 8
0
    public ConwayPoly GenerateWythoff(Uniform polyType)
    {
        var wythoff = new WythoffPoly(polyType.Wythoff);

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

        // var o = new OpParams {valueA = .2f, valueB = .2f, facesel = FaceSelections.All};
        // poly = poly.ApplyOp(op, o);
        // var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(poly, false, null, ColorMethod);
        // GetComponent<MeshFilter>().mesh = mesh;
        return(poly);
    }
Exemplo n.º 9
0
        public static ConwayPoly Rotunda()
        {
            var wythoffPoly = new WythoffPoly(Uniform.Uniforms[29].Wythoff);

            wythoffPoly.BuildFaces();

            var conwayPoly = new ConwayPoly(wythoffPoly);

            conwayPoly = conwayPoly.FaceRemove(new OpParams {
                facesel = FaceSelections.FacingDown
            });
            conwayPoly = conwayPoly.FillHoles();
            return(conwayPoly);
        }
Exemplo n.º 10
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);
    }
Exemplo n.º 11
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;
    }
Exemplo n.º 12
0
    public Mesh BuildMeshFromWythoffPoly(WythoffPoly source)
    {
        var meshVertices       = new List <Vector3>();
        var meshTriangles      = new List <int>();
        var MeshVertexToVertex = new List <int>();        // Mapping of mesh vertices to poly vertices (one to many as we duplicate verts)
        var meshColors         = new List <Color>();

        var mesh            = new Mesh();
        int meshVertexIndex = 0;

        foreach (Wythoff.Face face in source.faces)
        {
            face.CalcTriangles();
        }

        for (int faceType = 0; faceType < source.FaceTypeCount; faceType++)
        {
            foreach (Wythoff.Face face in source.faces)
            {
                if (face.configuration == source.FaceSidesByType[faceType])
                {
                    var faceColor = faceColors[(int)((face.configuration + 2) % faceColors.Length)];
                    // Vertices
                    for (int i = 0; i < face.triangles.Length; i++)
                    {
                        Vector v = source.Vertices[face.triangles[i]];
                        meshVertices.Add(v.getVector3());
                        meshColors.Add(faceColor);
                        meshTriangles.Add(meshVertexIndex);
                        MeshVertexToVertex.Add(face.triangles[i]);
                        meshVertexIndex++;
                    }
                }
            }
        }

        mesh.vertices  = meshVertices.ToArray();
        mesh.triangles = meshTriangles.ToArray();
        mesh.colors    = meshColors.ToArray();
        mesh.RecalculateNormals();
        return(mesh);
    }
Exemplo n.º 13
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;
        }

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

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

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

        if (ApplyOp)
        {
            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 points = poly.ListVerticesByPoints().ToList();

        if (JitterAmount > 0)
        {
            for (int i = 0; i < points.Count(); i++)
            {
                var point = points[i];
                points[i] = new Vector3(
                    point.x + Random.value * JitterAmount,
                    point.y + Random.value * JitterAmount,
                    point.z + Random.value * JitterAmount
                    );
            }
        }
        var faceIndices = poly.ListFacesByVertexIndices();

        // This whole mess is because I can't find a way to regenerate
        // a probuilder mesh and therefore have to continually create/destroy gameobjects
        // (which is a mess in edit mode)
        // If anyone can explain how to simply take an existing probuilder object clear it
        // and pass in a list of Vector3's and lists of ordered indexes for faces
        // then please do.

        if (pbmesh != null && pbmesh.gameObject != null)
        {
            if (Application.isPlaying)
            {
                Destroy(pbmesh.gameObject);
            }
            else
            {
                var go = pbmesh.gameObject;
                UnityEditor.EditorApplication.delayCall += () =>
                {
                    DestroyImmediate(go);
                };
            }
        }
        var colors = Enumerable.Range(0, 8).Select(x => Colors.Evaluate(((x / 8f) * ColorRange + ColorOffset) % 1)).ToArray();

        pbmesh = ProBuilderMesh.Create(points, new List <Face>());
        var faces = new List <PBFace>();

        for (var i = 0; i < faceIndices.Length; i++)
        {
            var face   = faceIndices[i];
            var result = AppendElements.CreatePolygon(pbmesh, face, false);
            if (result != null)
            {
                pbmesh.SetFaceColor(result, colors[(int)poly.FaceRoles[i]]);
                faces.Add(result);
            }
        }

        if (faces.Count < 1 || pbmesh == null)
        {
            return;
        }

        pbmesh.SetMaterial(faces, material);
        pbmesh.ToMesh();
        pbmesh.Refresh();
    }
Exemplo n.º 14
0
    public static Mesh BuildMeshFromWythoffPoly(WythoffPoly source, Color[] colors)
    {
        if (colors == null)
        {
            colors = DefaultFaceColors;
        }
        var meshVertices       = new List <Vector3>();
        var meshTriangles      = new List <int>();
        var MeshVertexToVertex = new List <int>();    // Mapping of mesh vertices to poly vertices (one to many as we duplicate verts)
        var meshColors         = new List <Color>();
        var meshUVs            = new List <Vector2>();

        var mesh            = new Mesh();
        int meshVertexIndex = 0;

        foreach (Wythoff.Face face in source.faces)
        {
            face.CalcTriangles();
        }

        for (int faceType = 0; faceType < source.FaceTypeCount; faceType++)
        {
            foreach (Wythoff.Face face in source.faces)
            {
                if (face.configuration == source.FaceSidesByType[faceType])
                {
                    var v0     = source.Vertices[face.points[0]].getVector3();
                    var v1     = source.Vertices[face.points[1]].getVector3();
                    var v2     = source.Vertices[face.points[2]].getVector3();
                    var normal = Vector3.Cross(v1 - v0, v2 - v0);
                    var c      = face.center.getVector3();
                    var yAxis  = c - v0;
                    var xAxis  = Vector3.Cross(yAxis, normal);

                    var faceColor = colors[(int)((face.configuration + 2) % colors.Length)];
                    // Vertices
                    for (int i = 0; i < face.triangles.Length; i++)
                    {
                        Vector3 vcoords = source.Vertices[face.triangles[i]].getVector3();
                        meshVertices.Add(vcoords);
                        meshColors.Add(faceColor);

                        var u = Vector3.Project(vcoords, xAxis).magnitude;
                        var v = Vector3.Project(vcoords, yAxis).magnitude;
                        meshUVs.Add(new Vector2(u, v));

                        meshTriangles.Add(meshVertexIndex);
                        MeshVertexToVertex.Add(face.triangles[i]);
                        meshVertexIndex++;
                    }
                }
            }
        }

        mesh.vertices  = meshVertices.ToArray();
        mesh.triangles = meshTriangles.ToArray();
        mesh.colors    = meshColors.ToArray();
        mesh.uv        = meshUVs.ToArray();
        mesh.RecalculateNormals();
        mesh.RecalculateTangents();
        mesh.RecalculateBounds();
        return(mesh);
    }
Exemplo n.º 15
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;
    }
Exemplo n.º 16
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;
    }
Exemplo n.º 17
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;
    }
Exemplo n.º 18
0
    public void Generate()
    {
        switch (ShapeType)
        {
        case ShapeTypes.Wythoff:
            var wythoff = new WythoffPoly(PolyType, PrismP, PrismQ);
            wythoff.BuildFaces();
            preOpPoly = new ConwayPoly(wythoff);
            break;

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

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

        // var animValue1 = Mathf.PerlinNoise(Time.time / AnimateAmountRate, 0) * Mathf.PerlinNoise(Time.time / AnimateAmountRate * 3.1f, Time.time);
        var animValue1 = 1;

        if (ApplyOp)
        {
            var o1 = new OpParams {
                valueA = op1Amount1 * animValue1, valueB = op1Amount2, facesel = op1Facesel
            };
            preOpPoly = preOpPoly.ApplyOp(op1, o1);
        }

        if (PreCanonicalize)
        {
            preOpPoly = preOpPoly.Canonicalize(0.01, 0.01);
        }

        var postOpPoly = preOpPoly.Transform(Position, Rotation, Scale);

        var animValue2 = Mathf.Sin(Time.time / AnimateAmountRate);
        // var animValue2 = Mathf.PerlinNoise(Time.time / AnimateAmountRate, 0) * Mathf.PerlinNoise(Time.time / AnimateAmountRate * .3f, 10) -.5f;
        var _amount = AnimateAmount > 0 ? animValue2 * AnimateAmount : Amount;
        var o       = new OpParams(_amount, NormalBlend, Facesel);

        postOpPoly = postOpPoly.Segment(o);

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

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

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

        GetComponent <MeshFilter>().mesh = mesh;
    }