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