public static ConwayPoly GyroelongatedRotunda() { int sides = 10; float bodyHeight = _CalcAntiprismHeight(sides); ConwayPoly poly = Rotunda(); poly = poly.Lace(new OpParams { facesel = FaceSelections.FacingDown, valueA = 0, valueB = bodyHeight }); return(poly); }
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() { 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; }
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); }