Exemple #1
0
    public void GenerateTerrain(int x, int y, int z, int value, BlockTerrain.Chunk chunk, MeshGenerator g)
    {
        Vector3 v000 = new Vector3(x, y, z);
        Vector3 v001 = new Vector3(x, y, z + 1.0f);
        Vector3 v010 = new Vector3(x, y + 0.125f, z);
        Vector3 v011 = new Vector3(x, y + 0.125f, z + 1.0f);
        Vector3 v100 = new Vector3(x + 1.0f, y, z);
        Vector3 v101 = new Vector3(x + 1.0f, y, z + 1.0f);
        Vector3 v110 = new Vector3(x + 1.0f, y + 0.125f, z);
        Vector3 v111 = new Vector3(x + 1.0f, y + 0.125f, z + 1.0f);

        GreedyTerrainMesh terrainMesh = g.AlphaTest;

        int content = chunk.GetCellContent(x - 1, y, z);

        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v001, v011, v010, v000, TextureSlot, Color.white);
        }

        content = chunk.GetCellContent(x, y, z - 1);
        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v000, v010, v110, v100, TextureSlot, Color.white);
        }

        content = chunk.GetCellContent(x + 1, y, z);
        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v100, v110, v111, v101, TextureSlot, Color.white);
        }

        content = chunk.GetCellContent(x, y + 1, z);
        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v111, v110, v010, v011, TextureSlot, Color.white);
        }

        content = chunk.GetCellContent(x, y, z + 1);
        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v101, v111, v011, v001, TextureSlot, Color.white);
        }
    }
Exemple #2
0
    public void GenerateCubeBlocks(BlockTerrain.Chunk chunk)
    {
        bool[] isTransparent              = BlocksData.IsTransparent;
        IStandardCubeBlock[] cubeBlocks   = BlocksData.StandardCubeBlocks;
        INormalBlock[]       normalBlocks = BlocksData.NormalBlocks;

        for (int x = 0; x < 16; x++)
        {
            for (int z = 0; z < 16; z++)
            {
                for (int y = 0; y < 128; y++)
                {
                    int value   = chunk.GetCellValue(x, y, z);
                    int content = BlockTerrain.GetContent(value);
                    if (isTransparent[content])
                    {
                        normalBlocks[content].GenerateTerrain(x, y, z, value, chunk, this);
                    }
                    else
                    {
                        Vector3 v000 = new Vector3(x, y, z);
                        Vector3 v001 = new Vector3(x, y, z + 1.0f);
                        Vector3 v010 = new Vector3(x, y + 1.0f, z);
                        Vector3 v011 = new Vector3(x, y + 1.0f, z + 1.0f);
                        Vector3 v100 = new Vector3(x + 1.0f, y, z);
                        Vector3 v101 = new Vector3(x + 1.0f, y, z + 1.0f);
                        Vector3 v110 = new Vector3(x + 1.0f, y + 1.0f, z);
                        Vector3 v111 = new Vector3(x + 1.0f, y + 1.0f, z + 1.0f);

                        var cellFace = new CellFace();
                        var block    = cubeBlocks[content];
                        int neighbor = chunk.GetCellContent(x - 1, y, z);
                        if (neighbor != BlockTerrain.NULL_BLOCK_CONTENT && BlocksData.IsTransparent[neighbor])
                        {
                            block.GenerateTerrain(x, y, z, value, CellFace.BACK, chunk, ref cellFace);
                            Terrain.NormalQuad(v000, v001, v011, v010, cellFace.TextureSlot, cellFace.Color);
                        }

                        neighbor = chunk.GetCellContent(x, y - 1, z);
                        if (neighbor != BlockTerrain.NULL_BLOCK_CONTENT && BlocksData.IsTransparent[neighbor])
                        {
                            block.GenerateTerrain(x, y, z, value, CellFace.BOTTOM, chunk, ref cellFace);
                            Terrain.NormalQuad(v001, v000, v100, v101, cellFace.TextureSlot, cellFace.Color);
                        }

                        neighbor = chunk.GetCellContent(x, y, z - 1);
                        if (neighbor != BlockTerrain.NULL_BLOCK_CONTENT && BlocksData.IsTransparent[neighbor])
                        {
                            block.GenerateTerrain(x, y, z, value, CellFace.LEFT, chunk, ref cellFace);
                            Terrain.NormalQuad(v100, v000, v010, v110, cellFace.TextureSlot, cellFace.Color);
                        }

                        neighbor = chunk.GetCellContent(x + 1, y, z);
                        if (neighbor != BlockTerrain.NULL_BLOCK_CONTENT && BlocksData.IsTransparent[neighbor])
                        {
                            block.GenerateTerrain(x, y, z, value, CellFace.FRONT, chunk, ref cellFace);
                            Terrain.NormalQuad(v101, v100, v110, v111, cellFace.TextureSlot, cellFace.Color);
                        }

                        neighbor = chunk.GetCellContent(x, y + 1, z);
                        if (neighbor != BlockTerrain.NULL_BLOCK_CONTENT && BlocksData.IsTransparent[neighbor])
                        {
                            block.GenerateTerrain(x, y, z, value, CellFace.TOP, chunk, ref cellFace);
                            Terrain.NormalQuad(v011, v111, v110, v010, cellFace.TextureSlot, cellFace.Color);
                        }

                        neighbor = chunk.GetCellContent(x, y, z + 1);
                        if (neighbor != BlockTerrain.NULL_BLOCK_CONTENT && BlocksData.IsTransparent[neighbor])
                        {
                            block.GenerateTerrain(x, y, z, value, CellFace.RIGHT, chunk, ref cellFace);
                            Terrain.NormalQuad(v001, v101, v111, v011, cellFace.TextureSlot, cellFace.Color);
                        }
                    }
                }
            }
        }
    }
Exemple #3
0
    public void GenerateFluidTerrain(int x, int y, int z, int value, BlockTerrain.Chunk chunk, GreedyTerrainMesh terrainMesh, Color topColor, Color sideColor)
    {
        float height1, height2, height3, height4;

        int data = BlockTerrain.GetData(value);

        if (GetIsTop(data))
        {
            int   cellValueFast  = chunk.GetCellValue(x - 1, y, z - 1);
            int   cellValueFast2 = chunk.GetCellValue(x, y, z - 1);
            int   cellValueFast3 = chunk.GetCellValue(x + 1, y, z - 1);
            int   cellValueFast4 = chunk.GetCellValue(x - 1, y, z);
            int   cellValueFast5 = chunk.GetCellValue(x + 1, y, z);
            int   cellValueFast6 = chunk.GetCellValue(x - 1, y, z + 1);
            int   cellValueFast7 = chunk.GetCellValue(x, y, z + 1);
            int   cellValueFast8 = chunk.GetCellValue(x + 1, y, z + 1);
            float h           = CalculateNeighborHeight(cellValueFast);
            float num         = CalculateNeighborHeight(cellValueFast2);
            float h2          = CalculateNeighborHeight(cellValueFast3);
            float num2        = CalculateNeighborHeight(cellValueFast4);
            float num3        = CalculateNeighborHeight(cellValueFast5);
            float h3          = CalculateNeighborHeight(cellValueFast6);
            float num4        = CalculateNeighborHeight(cellValueFast7);
            float h4          = CalculateNeighborHeight(cellValueFast8);
            float levelHeight = GetLevelHeight(GetLevel(data));
            height1 = CalculateFluidVertexHeight(h, num, num2, levelHeight);
            height2 = CalculateFluidVertexHeight(num, h2, levelHeight, num3);
            height3 = CalculateFluidVertexHeight(levelHeight, num3, num4, h4);
            height4 = CalculateFluidVertexHeight(num2, levelHeight, h3, num4);
        }
        else
        {
            height1 = 1f;
            height2 = 1f;
            height3 = 1f;
            height4 = 1f;
        }

        Vector3 v000 = new Vector3(x, y, z);
        Vector3 v001 = new Vector3(x, y, z + 1f);
        Vector3 v010 = new Vector3(x, y + height1, z);
        Vector3 v011 = new Vector3(x, y + height4, z + 1f);
        Vector3 v100 = new Vector3(x + 1.0f, y, z);
        Vector3 v101 = new Vector3(x + 1.0f, y, z + 1f);
        Vector3 v110 = new Vector3(x + 1.0f, y + height2, z);
        Vector3 v111 = new Vector3(x + 1.0f, y + height3, z + 1f);

        int v = chunk.GetCellValue(x - 1, y, z);

        if (v != BlockTerrain.NULL_BLOCK_VALUE && BlockTerrain.GetContent(v) != Index)
        {
            terrainMesh.NormalQuad(v001, v011, v010, v000, TextureSlot, sideColor);
        }

        v = chunk.GetCellValue(x, y - 1, z);
        if (v != BlockTerrain.NULL_BLOCK_VALUE && BlockTerrain.GetContent(v) != Index)
        {
            terrainMesh.NormalQuad(v000, v100, v101, v001, TextureSlot, sideColor);
        }

        v = chunk.GetCellValue(x, y, z - 1);
        if (v != BlockTerrain.NULL_BLOCK_VALUE && BlockTerrain.GetContent(v) != Index)
        {
            terrainMesh.NormalQuad(v000, v010, v110, v100, TextureSlot, sideColor);
        }

        v = chunk.GetCellValue(x + 1, y, z);
        if (v != BlockTerrain.NULL_BLOCK_VALUE && BlockTerrain.GetContent(v) != Index)
        {
            terrainMesh.NormalQuad(v100, v110, v111, v101, TextureSlot, sideColor);
        }

        v = chunk.GetCellValue(x, y + 1, z);
        if (v != BlockTerrain.NULL_BLOCK_VALUE && BlockTerrain.GetContent(v) != Index)
        {
            terrainMesh.NormalQuad(v111, v110, v010, v011, TextureSlot, topColor);
        }

        v = chunk.GetCellValue(x, y, z + 1);
        if (v != BlockTerrain.NULL_BLOCK_VALUE && BlockTerrain.GetContent(v) != Index)
        {
            terrainMesh.NormalQuad(v101, v111, v011, v001, TextureSlot, sideColor);
        }
    }