public static ConwayPoly GyroelongatedBirotunda() { int sides = 10; float bodyHeight = _CalcAntiprismHeight(sides); ConwayPoly poly = Rotunda(); ConwayPoly baseDome = poly.Duplicate(); var boundaryEdges1 = poly.Faces.Remove(poly.Faces.Last()); baseDome.Mirror(Vector3.up, -bodyHeight); baseDome.Halfedges.Flip(); baseDome = baseDome.Rotate(Vector3.up, 36f / 2f); poly.Append(baseDome); var boundaryEdges2 = poly.Faces.Remove(poly.Faces.Last()); boundaryEdges2.Reverse(); for (var i = 0; i < boundaryEdges1.Count; i++) { var edge1 = boundaryEdges1[i]; var edge2 = boundaryEdges2[i]; var side1 = new List <Vertex> { edge1.Vertex, edge1.Prev.Vertex, edge2.Prev.Vertex }; poly.Faces.Add(side1); poly.FaceRoles.Add(ConwayPoly.Roles.New); poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >()); var side2 = new List <Vertex> { edge2.Vertex, edge2.Prev.Vertex, edge1.Prev.Vertex, }; poly.Faces.Add(side2); poly.FaceRoles.Add(ConwayPoly.Roles.NewAlt); poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >()); } poly.Halfedges.MatchPairs(); return(poly); }
public static ConwayPoly MakeUnitileGrid(int pattern, int gridShape, int rows = 5, int cols = 5, bool weld = false) { var ut = new Unitile(pattern, rows, cols, true); switch (gridShape) { case 0: ut.plane(); break; case 1: ut.torus(); break; case 2: ut.conic_frust(1); break; case 3: ut.conic_frust(0.00001f); break; case 4: ut.sphere(); break; case 5: ut.conic_frust(0.00001f, cols, 0); break; // case 5: // ut.mobius(); // break; // case 6: // ut.torus_trefoil(); // break; // case 7: // ut.klein(); // break; // case 8: // ut.klein2(); // break; // case 9: // ut.roman(); // break; // case 10: // ut.roman_boy(); // break; // case 11: // ut.cross_cap(); // break; // case 12: // ut.cross_cap2(); // break; } var vertexRoles = Enumerable.Repeat(ConwayPoly.Roles.New, ut.raw_verts.Count); var faceRoles = new List <ConwayPoly.Roles>(); int foo, isEven, width, height, coloringOffset; for (int i = 0; i < ut.raw_faces.Count; i++) { switch (pattern) { case 1: isEven = cols % 2 == 0 ? (Mathf.FloorToInt(i / (float)cols)) % 2 : 0; foo = ((i + isEven) % 2) + 2; faceRoles.Add((ConwayPoly.Roles)foo); break; case 2: // int width = Mathf.CeilToInt((rows / Mathf.Sqrt(3))) * 2 + 1; // int height = ut.raw_faces.Count / width; // isEven = 0; // foo = ((i/4/width) + isEven) % 2; foo = i < ut.raw_faces.Count / 2 ? 2 : 3; faceRoles.Add((ConwayPoly.Roles)foo); break; case 3: width = Mathf.CeilToInt((rows / Mathf.Sqrt(3))); height = ut.raw_faces.Count / width; coloringOffset = i < ut.raw_faces.Count / 2 ? 0 : 1; foo = i / (height / 2); if (coloringOffset == 1 && width % 3 == 0) { coloringOffset += 1; } if (coloringOffset == 1 && width % 3 == 2) { coloringOffset += 2; } foo += coloringOffset; foo = (foo % 3) + 2; faceRoles.Add((ConwayPoly.Roles)foo); break; case 4: foo = ut.raw_faces[i].Count == 3 ? 2 : 3; faceRoles.Add((ConwayPoly.Roles)foo); break; case 5: // TODO width = rows; height = (Mathf.FloorToInt(cols / 4) + 1) * 4; foo = i < ut.raw_faces.Count / 2 ? 2 : 3; faceRoles.Add((ConwayPoly.Roles)foo); break; case 6: // TODO foo = ut.raw_faces[i].Count == 3 ? 2 : 3; faceRoles.Add((ConwayPoly.Roles)foo); break; // case 7: // foo = i < ut.raw_faces.Count / 2 ? 0 : 1; // faceRoles.Add((Roles)foo); // break; case 8: // TODO foo = ut.raw_faces[i].Count == 3 ? 2 : 3; faceRoles.Add((ConwayPoly.Roles)foo); break; case 9: // TODO foo = ut.raw_faces[i].Count == 8 ? 2 : 3; faceRoles.Add((ConwayPoly.Roles)foo); break; case 10: switch (ut.raw_faces[i].Count) { case 3: foo = 2; break; case 4: foo = 3; break; case 6: foo = 4; break; default: foo = 5; break; } ; faceRoles.Add((ConwayPoly.Roles)foo); break; case 11: switch (ut.raw_faces[i].Count) { case 4: foo = 2; break; case 6: foo = 3; break; case 12: foo = 4; break; default: foo = 5; break; } ; faceRoles.Add((ConwayPoly.Roles)foo); break; default: faceRoles.Add((ConwayPoly.Roles)((i % 2) + 2)); break; } } var poly = new ConwayPoly(ut.raw_verts, ut.raw_faces, faceRoles, vertexRoles); poly.Recenter(); if (gridShape > 0 && weld) { poly = poly.Weld(0.001f); } if (gridShape == 5) { poly = poly.Rotate(Vector3.left, 90); } return(poly); }
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; }