Пример #1
0
    public void resizeHexagonCube(GameObject hexCube, Rule.Axis axis, float newLength)
    {
        switch (axis)
        {
        case Rule.Axis.X:
            break;

        case Rule.Axis.Y:
            break;

        case Rule.Axis.Z:
            hexCube.transform.localScale = new Vector3(newLength / Mathf.Sqrt(3), hexCube.transform.localScale.y, newLength);
            break;
        }
    }
Пример #2
0
    private Rule.Axis chooseAxis(Rule rule, Transform curTrans)
    {
        switch (rule.axis)
        {
        case Rule.Axis.X:
            return(rule.axis);

        case Rule.Axis.Y:
            return(rule.axis);

        case Rule.Axis.Z:
            return(rule.axis);

        case Rule.Axis.XZ:
            return((curTrans.lossyScale.x >= curTrans.lossyScale.z) ? Rule.Axis.X : Rule.Axis.Z);

        case Rule.Axis.XY:
            return((curTrans.lossyScale.x >= curTrans.lossyScale.y) ? Rule.Axis.X : Rule.Axis.Y);

        case Rule.Axis.YZ:
            return((curTrans.lossyScale.y >= curTrans.lossyScale.z) ? Rule.Axis.Y : Rule.Axis.Z);

        case Rule.Axis.XYZ:
            Rule.Axis ax = (curTrans.lossyScale.x >= curTrans.lossyScale.y) ? Rule.Axis.X : Rule.Axis.Y;
            if (ax == Rule.Axis.X)
            {
                return((curTrans.lossyScale.x >= curTrans.lossyScale.z) ? Rule.Axis.X : Rule.Axis.Z);
            }
            else
            {
                return((curTrans.lossyScale.y >= curTrans.lossyScale.z) ? Rule.Axis.Y : Rule.Axis.Z);
            }

        default:
            break;
        }
        Debug.LogWarning("Did not find suitable axis for rule for shape " + curTrans.name + ".");
        return(Rule.Axis.X);
    }
Пример #3
0
    IEnumerator generate()
    {
        yield return(new WaitUntil(() => grammar.finishedRuleReading));

        List <GameObject> processedShapes = new List <GameObject>();
        List <GameObject> buildings       = new List <GameObject>();

        while (shapes.Count > 0)
        {
            GameObject currentShape = shapes[0];
            // Should make into queue
            shapes.RemoveAt(0);

            Rule chosenRule = ruleSelector.selectRule(currentShape);

            // Check if we are trying to protrude a protruded shape to wrap up our terminal shape
            if (chosenRule is ProtrudeRule && currentShape.GetComponent <Shape>().hasProtruded)
            {
                chosenRule = null;
            }

            if (currentShape.tag == "StartShape")
            {
                buildings.Add(currentShape);
                currentShape.tag = "Building";
            }

            if (chosenRule != null)
            {
                Rule.Axis ruleAxis = chosenRule.axis;
                // Choose the axis for the rule to be performed on if multiple axes are available.
                if (!chosenRule.multiDimensional)
                {
                    chosenRule.axis = chooseAxis(chosenRule, currentShape.transform);
                }

                GameObject[] newShapes = chosenRule.ruleAction(currentShape.transform);

                // If the rule split the previous shape into new components
                if (newShapes != null)
                {
                    // If we return with the current shape continue with it
                    if (newShapes[0] != currentShape)
                    {
                        MeshRenderer rend = currentShape.GetComponent <MeshRenderer>();
                        if (rend != null)
                        {
                            rend.enabled = false;
                        }
                        Collider col = currentShape.GetComponent <Collider>();
                        if (col != null)
                        {
                            col.enabled = false;
                        }
                    }
                    foreach (GameObject shape in newShapes)
                    {
                        if (!shapes.Contains(shape))
                        {
                            shapes.Insert(0, shape);
                            Shape shapeS = shape.GetComponent <Shape>();
                            if (shapeS.parent == null && shape.tag != "StartShape")
                            {
                                shapeS.setParent(currentShape);
                            }
                        }
                    }
                }
                // Revert to allow for multiple axes again
                chosenRule.axis = ruleAxis;
            }
            else
            {
                // We are at a terminal shape
                currentShape.GetComponent <Shape>().assignMaterial();
                currentShape.tag = "TerminalShape";
            }
            // Add the handled shape to our list of processed shapes for later use
            processedShapes.Add(currentShape);
        }

        // Fix potential occlusions of shapes
        grammarObject.GetComponent <OcclusionHandler>().handleOcclusion();
        assignParents(processedShapes);
        cleanParentlessShapes();
        grammarObject.GetComponent <RoofCreator>().createRoofs(buildings.ToArray());
        if (Finished != null)
        {
            Finished();
        }
    }