Exemplo n.º 1
0
    public override void Execute(RoadNetworkParameters roadNetworkParameters, ArchitectureStyle[] allArchitectureStyles)
    {
        int worldWidth      = roadNetworkParameters.Width;
        int worldHeight     = roadNetworkParameters.Height;
        int halfWorldWidth  = worldWidth / 2;
        int halfWorldHeight = roadNetworkParameters.Height / 2;

        Vector2 center = new Vector3(halfWorldWidth, halfWorldHeight);

        int mapSize = worldWidth * worldHeight;

        // TODO:
        _elevationMap  = null;
        _populationMap = null;

        _architecturalStyleMap = new int[mapSize];

        for (int y = 0, i = 0; y < worldHeight; y++)
        {
            for (int x = 0; x < worldWidth; x++, i++)
            {
                _architecturalStyleMap[i] = UnityEngine.Random.Range(0, allArchitectureStyles.Length);
            }
        }
    }
    public override void Execute(RoadNetworkParameters roadNetworkParameters, ArchitectureStyle[] architectureStyles)
    {
        int worldWidth      = roadNetworkParameters.Width;
        int worldHeight     = roadNetworkParameters.Height;
        int halfWorldWidth  = worldWidth / 2;
        int halfWorldHeight = roadNetworkParameters.Height / 2;

        Vector2 center = new Vector3(halfWorldWidth, halfWorldHeight);

        Vector2 cityCenter = DivergeFromCenter(_cityCenterDivergence, center);

        int mapSize = worldWidth * worldHeight;

        // TODO:
        _elevationMap  = null;
        _populationMap = null;

        _architecturalStyleMap = new int[mapSize];

        float maxRadius = Mathf.Sqrt(Mathf.Pow(worldWidth, 2.0f) + Mathf.Pow(worldHeight, 2.0f)) / 4.0f;

        for (int y = 0, i = 0; y < worldHeight; y++)
        {
            for (int x = 0; x < worldWidth; x++, i++)
            {
                Vector2 position = new Vector2(x, y);
                _architecturalStyleMap[i] = Mathf.RoundToInt(Mathf.Lerp(0.0f, (float)architectureStyles.Length - 1.0f, Vector2.Distance(position, cityCenter) / maxRadius));
            }
        }
    }
Exemplo n.º 3
0
    public void Run(RoadNetworkParameters roadNetworkParameters, ArchitectureStyle[] allArchitectureStyles)
    {
        if (_cityMapsGenerator == null)
        {
            throw new Exception("_cityMapsGenerator == null");
        }

        if (_terrainMeshGenerator == null)
        {
            throw new Exception("_terrainMeshGenerator == null");
        }

        if (_roadNetworkGenerator == null)
        {
            throw new Exception("_roadNetworkGenerator == null");
        }

        if (_roadNetworkMeshGenerator == null)
        {
            throw new Exception("_roadNetworkMeshGenerator == null");
        }

        if (_blocksExtractor == null)
        {
            throw new Exception("_blocksExtractor == null");
        }

        if (_allotmentsExtractor == null)
        {
            throw new Exception("_allotmentsExtractor == null");
        }

        if (_buildingsGenerator == null)
        {
            throw new Exception("_buildingsGenerator == null");
        }

        if (_buildingsMeshGenerator == null)
        {
            throw new Exception("_buildingsMeshGenerator == null");
        }

        // ---

        // pipeline
        _cityMapsGenerator.Execute(roadNetworkParameters, allArchitectureStyles);
        {
            _terrainMeshGenerator.Execute(roadNetworkParameters, _cityMapsGenerator.elevationMap);
            _roadNetworkGenerator.Execute(roadNetworkParameters, _cityMapsGenerator.elevationMap, _cityMapsGenerator.populationMap, allArchitectureStyles, _cityMapsGenerator.architecturalStylesMap);
        }         // parallel
        {
            _roadNetworkMeshGenerator.Execute(roadNetworkParameters, _roadNetworkGenerator.grid);
            _blocksExtractor.Execute(_roadNetworkGenerator.grid, allArchitectureStyles, _cityMapsGenerator.architecturalStylesMap);
        }         // parallel
        _allotmentsExtractor.Execute(_roadNetworkGenerator.grid, allArchitectureStyles, _cityMapsGenerator.architecturalStylesMap, _blocksExtractor.blocks);
        _buildingsGenerator.Execute(_allotmentsExtractor.allotments);
        _buildingsMeshGenerator.Execute(_buildingsGenerator.buildings);
    }
 public override void Execute(RoadNetworkParameters roadNetworkParameters, float[] elevationMap, float[] populationMap, ArchitectureStyle[] allAchitectureStyles, int[] architecturalStylesMap)
 {
     _grid = IrregularRectangleGrid.Generate(roadNetworkParameters.gridWidth,
                                             roadNetworkParameters.gridHeight,
                                             roadNetworkParameters.minCellWidth,
                                             roadNetworkParameters.maxCellWidth,
                                             roadNetworkParameters.minCellDepth,
                                             roadNetworkParameters.maxCellDepth,
                                             roadNetworkParameters.roadWidth);
 }
Exemplo n.º 5
0
    public override void Execute(RoadNetworkParameters roadNetworkParameters, BaseGrid grid)
    {
        GameObject blockGroundsGameObject = new GameObject("Block Grounds");

        blockGroundsGameObject.transform.localPosition = new Vector3(0, _y, 0);
        blockGroundsGameObject.transform.localRotation = Quaternion.identity;

        float halfRoadWidth = roadNetworkParameters.roadWidth * 0.5f;

        Mesh mesh;

        foreach (Cell[] row in grid)
        {
            foreach (Cell cell in row)
            {
                float halfCellWidth  = cell.width * 0.5f;
                float halfCellHeight = cell.height * 0.5f;

                float x = cell.center.x - halfCellWidth - halfRoadWidth;
                float z = cell.center.y - halfCellHeight - halfRoadWidth;

                GameObject blockGroundGameObject = new GameObject("Block Ground (" + cell.x + ", " + cell.y + ")");

                float blockGroundWidth  = cell.width + roadNetworkParameters.roadWidth;
                float blockGroundHeight = cell.height + roadNetworkParameters.roadWidth;

                mesh = MeshUtils.CreateTopFaceMesh(0, blockGroundWidth, 0, blockGroundHeight, 0, 1, 1, new Rect(0, 0, blockGroundWidth, blockGroundHeight), new Rect(0, 0, 1, 1), Color.white);

                blockGroundGameObject.transform.parent        = blockGroundsGameObject.transform;
                blockGroundGameObject.transform.localPosition = new Vector3(x, 0, z);
                blockGroundGameObject.transform.localRotation = Quaternion.identity;

                blockGroundGameObject.AddComponent <MeshFilter> ().mesh       = mesh;
                blockGroundGameObject.AddComponent <MeshRenderer> ().material = CreateBlockGroundMaterial(halfRoadWidth, (float)roadNetworkParameters.sidewalkWidth, blockGroundWidth, blockGroundHeight);
            }
        }

        BoxCollider boxCollider = blockGroundsGameObject.AddComponent <BoxCollider> ();

        boxCollider.center = new Vector3(grid.bounds.center.x, 0, grid.bounds.center.y);
        boxCollider.size   = new Vector3(grid.bounds.size.x, 0, grid.bounds.size.y);
    }
 public abstract void Execute(RoadNetworkParameters roadNetworkParameters, float[] elevationMap, float[] populationMap, ArchitectureStyle[] allArchitectureStyles, int[] architecturalStyleMap);
 public abstract void Execute(RoadNetworkParameters roadNetworkParameters, BaseGrid grid);
Exemplo n.º 8
0
 public override void Execute(RoadNetworkParameters roadNetworkParameters, BaseGrid grid)
 {
 }
Exemplo n.º 9
0
 public override void Execute(RoadNetworkParameters roadNetworkParameters, float[] elevationMap)
 {
 }
Exemplo n.º 10
0
 public override void Execute(RoadNetworkParameters roadNetworkParameters, ArchitectureStyle[] allArchitectureStyles)
 {
 }
Exemplo n.º 11
0
 public abstract void Execute(RoadNetworkParameters roadNetworkParameters, ArchitectureStyle[] allArchitectureStyles);
Exemplo n.º 12
0
 public abstract void Execute(RoadNetworkParameters roadNetworkParameters, float[] elevationMap);