Exemple #1
0
    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;
    }
Exemple #2
0
        public static ConwayPoly ElongatedCupola(int sides)
        {
            ConwayPoly poly       = Cupola(sides);
            float      bodyHeight = _CalcSideLength(sides * 2);

            poly = poly.Loft(new OpParams {
                facesel = FaceSelections.OnlyFirst, valueB = bodyHeight
            });
            return(poly);
        }
Exemple #3
0
        public static ConwayPoly ElongatedRotunda()
        {
            int        sides      = 10;
            float      bodyHeight = _CalcSideLength(sides);
            ConwayPoly poly       = Rotunda();

            poly = poly.Loft(new OpParams {
                valueB = bodyHeight, facesel = FaceSelections.FacingDown
            });
            return(poly);
        }
Exemple #4
0
    private ConwayPoly RibbedExtrude(ConwayPoly poly, int numRibs)
    {
        float translateForwardsPerRib = Random.Range(0.02f, 0.2f);
        float ribDepth = Random.Range(0.02f, 0.2f);

        for (int i = 0; i < numRibs; i++)
        {
            poly = poly.Loft(new OpParams {
                valueA = ribDepth, valueB = translateForwardsPerRib * 0.25f, facesel = FaceSelections.FacingStraightForward
            });
            poly = poly.Loft(new OpParams {
                valueA = 0, valueB = translateForwardsPerRib * 0.5f, facesel = FaceSelections.FacingStraightForward
            });
            poly = poly.Loft(new OpParams {
                valueA = -ribDepth, valueB = translateForwardsPerRib * 0.25f, facesel = FaceSelections.FacingStraightForward
            });
            poly = poly.Loft(new OpParams {
                valueA = 0, valueB = translateForwardsPerRib * 0.25f, facesel = FaceSelections.FacingStraightForward
            });
        }

        return(poly);
    }
Exemple #5
0
    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;
    }
Exemple #6
0
    private ConwayPoly MakeSection(ConwayPoly spaceship)
    {
        if (Random.value < ChanceOfLaceSegment)
        {
            spaceship = spaceship.Lace(new OpParams {
                valueA = Random.Range(loftLow, loftHigh), facesel = FaceSelections.FacingStraightForward, valueB = Random.Range(.2f, .5f)
            });
        }
        else if (Random.value < ChanceOfStakeSegment && !alreadyStake)  // Only do this once
        {
            spaceship = spaceship.Stake(new OpParams {
                valueA = Random.Range(loftLow, loftHigh), facesel = FaceSelections.FacingForward
            });
            alreadyStake = true;
        }
        else if (Random.value < ChanceOfRibbedSegment)
        {
            spaceship = RibbedExtrude(spaceship, Random.Range(2, 7));
        }
        else  // Just a normal section
        {
            spaceship = spaceship.Loft(new OpParams {
                valueA = Random.Range(loftLow, loftHigh), valueB = Random.Range(.2f, .5f), facesel = FaceSelections.FacingStraightForward
            });

            // Each simple section can have wings or fins
            if (Random.value < ChanceOfWings)
            {
                var newWings = MakeWings(spaceship, MakeSideFaceFilter(numSides));
                wings.Append(newWings);
            }
            else if (Random.value < ChanceOfFins)
            {
                spaceship = spaceship.Loft(new OpParams {
                    valueA = Random.Range(.5f, 0), valueB = Random.Range(0.05f, 1.0f), facesel = FaceSelections.AllNew
                });
            }
            else if (Random.value < ChanceOfAntenna)
            {
                antennae.Append(MakeAntenna(spaceship));
            }
        }

        spaceship = spaceship.FaceSlide(new OpParams {
            valueA = Random.Range(-.3f, .3f), valueB = 0, facesel = FaceSelections.FacingStraightForward
        });
        return(spaceship);
    }
Exemple #7
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;
    }
Exemple #8
0
    public void Generate()
    {
        Random.seed = seed;

        spaceship = JohnsonPoly.Prism(numSides);
        wings     = new ConwayPoly();
        antennae  = new ConwayPoly();

        float angleCorrection = 180f / numSides;

        if (numSides % 2 != 0)
        {
            angleCorrection /= 2f;
        }
        spaceship = spaceship.Rotate(Vector3.up, angleCorrection);
        spaceship = spaceship.Rotate(Vector3.left, -90);

        alreadyStake = false;

        for (int i = 0; i < 2; i++)  // Loop twice - once for the back and once for the front.
        {
            for (int j = 0; j <= numSections; j++)
            {
                spaceship = MakeSection(spaceship);
            }

            // Second time through loop:
            // Flip everything around ready to generate the back sections

            spaceship = spaceship.Rotate(Vector3.up, 180);
            wings     = wings.Rotate(Vector3.up, 180);
            antennae  = antennae.Rotate(Vector3.up, 180);

            // Change random range for front sections
            loftLow  = -0.35f;
            loftHigh = 0.15f;
        }



        // Make the engines
        var engines = spaceship.FaceKeep(new OpParams {
            facesel = FaceSelections.FacingStraightBackward
        });

        spaceship = spaceship.FaceRemove(new OpParams {
            facesel = FaceSelections.FacingStraightBackward
        });
        engines = engines.Loft(new OpParams {
            valueA = Random.Range(.3f, .4f), valueB = Random.Range(-.2f, .2f)
        });
        // spaceship = engines;
        if (EngineVariant)
        {
            var engineRim = engines.FaceRemove(new OpParams {
                facesel = FaceSelections.Existing
            });
            engines = engines.FaceKeep(new OpParams {
                facesel = FaceSelections.Existing
            });
            engines = engines.Ortho(new OpParams {
                valueA = 0
            });
            engines = engines.Loft(new OpParams {
                valueA = Random.Range(0, .25f), valueB = -.5f
            });
            engines.Append(engineRim);
        }
        else
        {
            engines = engines.Loft(new OpParams {
                valueA = Random.Range(.25f, .75f), valueB = Random.Range(0, .2f), facesel = FaceSelections.Existing
            });
            engines = engines.Loft(new OpParams {
                valueA = Random.Range(.1f, .3f), valueB = Random.Range(-.3f, -.7f), facesel = FaceSelections.AllNew
            });
        }

        // Make the nose section
        if (NoseLength > 0)
        {
            spaceship = spaceship.Loft(new OpParams {
                valueA = .2f, valueB = 0, facesel = FaceSelections.FacingStraightForward
            });
            spaceship = spaceship.FaceSlide(new OpParams {
                valueA = .12f, facesel = FaceSelections.Existing
            });
            if (NoseVariant)
            {
                spaceship = spaceship.Lace(new OpParams {
                    valueA = NoseSharpness, valueB = NoseLength, facesel = FaceSelections.Existing
                });
            }
            else
            {
                spaceship = spaceship.Loft(new OpParams {
                    valueA = NoseSharpness, valueB = NoseLength, facesel = FaceSelections.Existing
                });
            }
        }


        // Add panel insets to the hull
        spaceship = spaceship.Loft(new OpParams {
            valueA = 0.1f, valueB = 0.025f
        });

        // Add panel insets to the wings
        wings = wings.Loft(new OpParams {
            valueA = 0.1f, valueB = 0.025f
        });

        spaceship.Append(engines);
        spaceship.Append(wings);
        spaceship.Append(antennae);

        // Build the final mesh
        var mesh = PolyMeshBuilder.BuildMeshFromConwayPoly(spaceship, false);

        GetComponent <MeshFilter>().mesh       = mesh;
        GetComponent <MeshRenderer>().material = material;
    }
Exemple #9
0
    public static ConwayPoly ApplyOp(ConwayPoly conway, ConwayOperator op)
    {
        switch (op.opType)
        {
        case Ops.Identity:
            break;

        case Ops.Kis:
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            break;

        case Ops.Dual:
            conway = conway.Dual();
            break;

        case Ops.Ambo:
            conway = conway.Ambo();
            break;

        case Ops.Zip:
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            conway = conway.Dual();
            break;

        case Ops.Expand:
            conway = conway.Ambo();
            conway = conway.Ambo();
            break;

        case Ops.Bevel:
            conway = conway.Ambo();
            conway = conway.Dual();
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            conway = conway.Dual();
            break;

        case Ops.Join:
            // conway = conway.Join(op.amount);  // Not currently used as it results in non-coplanar faces
            conway = conway.Ambo();
            conway = conway.Dual();
            break;

        case Ops.Needle:
            conway = conway.Dual();
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            break;

        case Ops.Ortho:
            conway = conway.Ambo();
            conway = conway.Ambo();
            conway = conway.Dual();
            break;

        case Ops.Meta:
            conway = conway.Ambo();
            conway = conway.Dual();
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            break;

        case Ops.Truncate:
            conway = conway.Dual();
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            conway = conway.Dual();
            break;

        case Ops.Gyro:
            conway = conway.Gyro(op.amount);
            break;

        case Ops.Snub:
            conway = conway.Gyro(op.amount);
            conway = conway.Dual();
            break;

        case Ops.Exalt:
            conway = conway.Dual();
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            conway = conway.Dual();
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            break;

        case Ops.Yank:
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            conway = conway.Dual();
            conway = conway.Kis(op.amount, op.faceSelections, op.randomize);
            conway = conway.Dual();
            break;

        case Ops.Subdivide:
            conway = conway.Subdivide();
            break;

        case Ops.Loft:
            conway = conway.Loft(op.amount, op.faceSelections);
            break;

        case Ops.Quinto:
            conway = conway.Quinto(op.amount);
            break;

        case Ops.JoinedLace:
            conway = conway.JoinedLace(op.amount);
            break;

        case Ops.Lace:
            conway = conway.Lace(op.amount, op.faceSelections);
            break;

        case Ops.Stake:
            conway = conway.Stake(op.amount, op.faceSelections);
            break;

//					case Ops.Medial:
//						conway = conway.Medial((int)op.amount);
//						break;
//					case Ops.EdgeMedial:
//						conway = conway.EdgeMedial((int)op.amount);
//						break;
//					case Ops.JoinedMedial:
//						conway = conway.JoinedMedial();
//						break;
        case Ops.Propeller:
            conway = conway.Propeller(op.amount);
            break;

        case Ops.Whirl:
            conway = conway.Whirl(op.amount);
            break;

        case Ops.Volute:
            conway = conway.Volute(op.amount);
            break;

        case Ops.Extrude:
            // Split faces
            conway = conway.FaceScale(0, ConwayPoly.FaceSelections.All, false);
            conway = conway.Extrude(op.amount, false, op.randomize);
            break;

        case Ops.VertexScale:
            conway = conway.VertexScale(op.amount, op.faceSelections, op.randomize);
            break;

        case Ops.FaceOffset:
            // Split faces
            var origRoles = conway.FaceRoles;
            conway           = conway.FaceScale(0, ConwayPoly.FaceSelections.All, false);
            conway.FaceRoles = origRoles;
            conway           = conway.Offset(op.amount, op.faceSelections, op.randomize);
            break;

        case Ops.FaceScale:
            conway = conway.FaceScale(op.amount, op.faceSelections, op.randomize);
            break;

        case Ops.FaceRotate:
            conway = conway.FaceRotate(op.amount, op.faceSelections, 0, op.randomize);
            break;

//					case Ops.Chamfer:
//						conway = conway.Chamfer();
//						break;
//					case Ops.Ribbon:
//						conway = conway.Ribbon(op.amount, false, 0.1f);
//						break;
//					case Ops.FaceTranslate:
//						conway = conway.FaceTranslate(op.amount, op.faceSelections);
//						break;
//					case Ops.FaceRotateX:
//						conway = conway.FaceRotate(op.amount, op.faceSelections, 1);
//						break;
//					case Ops.FaceRotateY:
//						conway = conway.FaceRotate(op.amount, op.faceSelections, 2);
//						break;
        case Ops.FaceRemove:
            conway = conway.FaceRemove(op.faceSelections, false);
            break;

        case Ops.FaceKeep:
            conway = conway.FaceRemove(op.faceSelections, true);
            break;

        case Ops.AddDual:
            conway = conway.AddDual(op.amount);
            break;

        case Ops.Canonicalize:
            conway = conway.Canonicalize(op.amount, op.amount);
            break;

        case Ops.CanonicalizeI:
            conway = conway.Canonicalize((int)op.amount, (int)op.amount);
            break;
        }

        return(conway);
    }