예제 #1
0
파일: PolyUI.cs 프로젝트: livazz/Polyhydra
    void AddRandomOpButtonClicked()
    {
        int maxOpIndex  = Enum.GetValues(typeof(PolyHydra.Ops)).Length;
        int opTypeIndex = Random.Range(1, maxOpIndex - 2); // No canonicalize as it's pretty rough at the moment
        var opType      = (PolyHydra.Ops)opTypeIndex;
        var opConfig    = poly.opconfigs[opType];

        ConwayPoly.FaceSelections faceSelection = ConwayPoly.FaceSelections.None;
        var maxFaceSel = Enum.GetValues(typeof(ConwayPoly.FaceSelections)).Length - 1; // Exclude "None"

        // Keep picking a random facesel until we get one that will have an effect
        while (!poly.FaceSelectionIsValid(faceSelection))
        {
            faceSelection = (ConwayPoly.FaceSelections)Random.Range(1, maxFaceSel);
        }
        // TODO pick another facesel if all faces are chosen
        var newOp = new PolyHydra.ConwayOperator
        {
            opType         = opType,
            faceSelections = Random.value > 0.25f ? 0: faceSelection,
            randomize      = Random.value > 0.8f,
            amount         = Random.value > 0.25f ? opConfig.amountDefault : Random.Range(opConfig.amountMin, opConfig.amountMax),
            disabled       = false
        };

        poly.ConwayOperators.Add(newOp);
        AddOpItemToUI(newOp);
        Rebuild();
    }
예제 #2
0
    // Returns true if at least one face matches the facesel rule but all of them
    public bool FaceSelectionIsValid(ConwayPoly.FaceSelections facesel)
    {
        if (ConwayOperators.Count == 0 && PolyType > 0)
        {
            _conwayPoly = new ConwayPoly(WythoffPoly);                                                      // We need a conway poly
        }
        int includedFaceCount = Enumerable.Range(0, _conwayPoly.Faces.Count).Count(x => _conwayPoly.IncludeFace(x, facesel));

        return(includedFaceCount > 0 && includedFaceCount < _conwayPoly.Faces.Count);
    }