Exemplo n.º 1
0
        public static ConwayPoly Rotunda()
        {
            var wythoffPoly = new WythoffPoly(Uniform.Uniforms[29].Wythoff);

            wythoffPoly.BuildFaces();

            var conwayPoly = new ConwayPoly(wythoffPoly);

            conwayPoly = conwayPoly.FaceRemove(new OpParams {
                facesel = FaceSelections.FacingDown
            });
            conwayPoly = conwayPoly.FillHoles();
            return(conwayPoly);
        }
Exemplo n.º 2
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;
    }
Exemplo n.º 3
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;
    }
Exemplo n.º 4
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);
    }
Exemplo n.º 5
0
    public void Generate()
    {
        var        colorMethod = ColorBySides ? PolyHydraEnums.ColorMethods.BySides : PolyHydraEnums.ColorMethods.ByRole;
        ConwayPoly poly        = null;

        // TODO move this into a method on JohnsonPoly
        switch (JohnsonPolyType)
        {
        case PolyHydraEnums.JohnsonPolyTypes.Prism:
            poly = JohnsonPoly.Prism(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.Antiprism:
            poly = JohnsonPoly.Antiprism(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.Pyramid:
            poly = JohnsonPoly.Pyramid(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.ElongatedPyramid:
            poly = JohnsonPoly.ElongatedPyramid(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.GyroelongatedPyramid:
            poly = JohnsonPoly.GyroelongatedPyramid(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.Dipyramid:
            poly = JohnsonPoly.Dipyramid(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.ElongatedDipyramid:
            poly = JohnsonPoly.ElongatedDipyramid(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.GyroelongatedDipyramid:
            poly = JohnsonPoly.GyroelongatedDipyramid(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.Cupola:
            poly = JohnsonPoly.Cupola(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.ElongatedCupola:
            poly = JohnsonPoly.ElongatedCupola(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.GyroelongatedCupola:
            poly = JohnsonPoly.GyroelongatedCupola(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.OrthoBicupola:
            poly = JohnsonPoly.OrthoBicupola(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.GyroBicupola:
            poly = JohnsonPoly.GyroBicupola(sides);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.ElongatedOrthoBicupola:
            poly = JohnsonPoly.ElongatedBicupola(sides, false);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.ElongatedGyroBicupola:
            poly = JohnsonPoly.ElongatedBicupola(sides, true);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.GyroelongatedBicupola:
            poly = JohnsonPoly.GyroelongatedBicupola(sides, false);
            break;

        case PolyHydraEnums.JohnsonPolyTypes.Rotunda:
            poly = JohnsonPoly.Rotunda();
            break;

        case PolyHydraEnums.JohnsonPolyTypes.ElongatedRotunda:
            poly = JohnsonPoly.ElongatedRotunda();
            break;

        case PolyHydraEnums.JohnsonPolyTypes.GyroelongatedRotunda:
            poly = JohnsonPoly.GyroelongatedRotunda();
            break;

        case PolyHydraEnums.JohnsonPolyTypes.GyroelongatedBirotunda:
            poly = JohnsonPoly.GyroelongatedBirotunda();
            break;
        }
        poly = poly.FaceRemove(new OpParams {
            facesel = removeSelection
        });
        poly = poly.ExtendBoundaries(new OpParams {
            valueA = amount1, valueB = angle1
        });
        poly = poly.ExtendBoundaries(new OpParams {
            valueA = amount2, valueB = angle2
        });

        if (ApplyOp)
        {
            var o = new OpParams {
                valueA = opAmount, valueB = op2Amount, facesel = facesel
            };
            poly = poly.ApplyOp(op, o);
        }

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

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