void Rebuild()
    {
        // Build the initial poly
        polymorphSkinnedMeshRenderer = gameObject.GetComponent <SkinnedMeshRenderer>();
        poly = JohnsonPoly.Build(JohnsonPolyType, sides);
        poly.Recenter();
        poly = poly.ApplyOp(PreMorph.op, new OpParams(PreMorph.opAmount1, PreMorph.opAmount2, PreMorph.opFacesel));

        // Build the mesh without any morph ops
        var baseMesh = MakeMorphTarget(0, 0);

        baseMesh.ClearBlendShapes();
        baseMesh = AddBlendShapeFrameFromMesh("Base", baseMesh, baseMesh);
        baseMesh.RecalculateNormals();
        baseMesh.RecalculateTangents();

        // Build the morphed meshes
        for (var i = 0; i < Morphs.Count; i++)
        {
            var morphedMesh = MakeMorphTarget(i, 1);
            baseMesh = AddBlendShapeFrameFromMesh(i.ToString(), baseMesh, morphedMesh);
            // baseMesh.RecalculateNormals();
            // baseMesh.RecalculateTangents();
        }
        polymorphSkinnedMeshRenderer.sharedMesh = baseMesh;
        initialized = true;
    }
Beispiel #2
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;
        }
    }
Beispiel #3
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);
    }
Beispiel #4
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;
    }
Beispiel #5
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;
    }
Beispiel #6
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;
    }
Beispiel #7
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;
    }
Beispiel #8
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;
    }
Beispiel #9
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;
    }
Beispiel #10
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;
    }
Beispiel #11
0
    public void Generate()
    {
        if (Random.seed != 0)
        {
            Random.seed = RandomSeed;
        }

        poly = JohnsonPoly.Build(JohnsonPolyType, Sides);
        poly = poly.Transform(PositionBefore, RotationBefore, ScaleBefore);

        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.Recenter();

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

            do
            {
                offset += Random.Range(SliceMin, SliceMax);
                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(-Gap * axis.x, -Gap * axis.y, -Gap * axis.z);
                result = result.Transform(gapVector);
                float randomShift       = Random.Range(ShiftMin, ShiftMax);
                var   randomShiftVector = new Vector3(randomShift * axis.y, randomShift * axis.z, randomShift * axis.x);
                result.Append(sliced.bottom.Transform(randomShiftVector));
                input = sliced.top;
            } while (offset < SliceEnd);

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

        if (SliceX)
        {
            poly = DoSlices(poly, Vector3.right);
        }
        if (SliceY)
        {
            poly = DoSlices(poly, Vector3.up);
        }
        if (SliceZ)
        {
            poly = DoSlices(poly, Vector3.forward);
        }

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

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

        // poly.Recenter();

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

        GetComponent <MeshFilter>().mesh = mesh;
    }
Beispiel #12
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;
    }
Beispiel #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();
    }
Beispiel #14
0
 public override void Generate()
 {
     poly = JohnsonPoly.Build(JohnsonPolyType, sides);
     base.Generate();
 }
Beispiel #15
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();

            if (SliceDistance < 0.01f)
            {
                return(result);
            }
            float offset = SliceStart;

            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), true, false, false, true);
                result.Append(sliced.cap);
            } while (offset < SliceEnd);

            return(result);
        }

        var output = new ConwayPoly();

        if (SliceX)
        {
            output.Append(DoSlices(poly, Vector3.right));
        }
        if (SliceY)
        {
            output.Append(DoSlices(poly, Vector3.up));
        }
        if (SliceZ)
        {
            output.Append(DoSlices(poly, Vector3.forward));
        }

        if (Shell)
        {
            var shellParams = new OpParams {
                valueA = SliceDistance - ShellSpacing
            };
            output = output.ApplyOp(Ops.Shell, shellParams);
        }

        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);
        }

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

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