Exemple #1
0
    public void UpdateMeshFrom3dBoundedByHeightMap(
        float[,] heightMap, Defines.MapParams mapSize,
        Vector3 samplingRate, float spaceCreationThreshold)
    {
        var spaceMap = HeightMapAssembler.AssembleSpaceMap(mapSize);
        var vertices = new List <Vector3>();
        var colors   = new List <Color>();

        for (int x = 0; x < mapSize.width; x += (int)samplingRate.x)
        {
            for (int y = 0; y < mapSize.height; y += (int)samplingRate.y)
            {
                for (int z = 0; z < mapSize.depth; z += (int)samplingRate.z)
                {
                    //Debug.Log("Vertex " + x + ", " + y + ", " + z + " = " + spaceMap[x, y, z]);
                    if (heightMap[x, y] * mapSize.depth > z && spaceMap[x, y, z] > spaceCreationThreshold)
                    {
                        vertices.Add(new Vector3(x / (int)samplingRate.x, y / (int)samplingRate.y, z));
                        colors.Add(ColorPicker.GetColor(colorParams, heightMap[x, y]));
                    }
                }
            }
        }
        var mesh = VoxelHandler.CreateMulticubeMesh(vertices, colors);

        filter.mesh = mesh;
    }
Exemple #2
0
    public static float[,] Generate(IEnumerable <Defines.GeneratorLayer> layerParams, Defines.MapParams mapSize, Vector3 globalScale)
    {
        float[,] result = new float[mapSize.width, mapSize.height];
        foreach (Defines.GeneratorLayer layer in layerParams)
        {
            System.Func <float, float, float> generatorMethod = GeneratorMethods2d.ChooseFunc(layer);
            float[,] map = HeightMapAssembler.AssembleHeightMap(mapSize, generatorMethod, globalScale);

            // prone to change when I find an elegant way of doing this (Zip?)
            for (int i = 0; i < mapSize.width; i++)
            {
                for (int j = 0; j < mapSize.height; j++)
                {
                    result[i, j] += map[i, j] * layer.significance;
                }
            }
        }

        Normalize(result);
        return(result);
    }