Exemplo n.º 1
0
        /**
         * Get the mesh for a single block and add it to the given mesh data object.
         **/
        public virtual MeshData GetBlockMesh(Chunk chunk, int x, int y, int z, MeshData meshData)
        {
            if(!Register.GetBlockById(chunk.GetBlock(x, y + 1, z)).IsSolid(Direction.UP))
            {
            meshData = MeshData.CreateFaceUp(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x, y - 1, z)).IsSolid(Direction.DOWN))
            {
            meshData = MeshData.CreateFaceDown(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x, y, z + 1)).IsSolid(Direction.NORTH))
            {
            meshData = MeshData.CreateFaceNorth(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x, y, z - 1)).IsSolid(Direction.SOUTH))
            {
            meshData = MeshData.CreateFaceSouth(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x + 1, y, z)).IsSolid(Direction.EAST))
            {
            meshData = MeshData.CreateFaceEast(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x - 1, y, z)).IsSolid(Direction.WEST))
            {
            meshData = MeshData.CreateFaceWest(chunk, x, y, z, this, meshData, 0.5f);
            }

            return meshData;
        }
Exemplo n.º 2
0
        /**
         * Assemble a downwards facing face.
         **/
        public static MeshData CreateFaceDown(Chunk chunk, int x, int y, int z, Block block, MeshData meshData, float size)
        {
            meshData.AddVertex(new Vector3(x - size, y - size, z - size));
            meshData.AddVertex(new Vector3(x + size, y - size, z - size));
            meshData.AddVertex(new Vector3(x + size, y - size, z + size));
            meshData.AddVertex(new Vector3(x - size, y - size, z + size));

            meshData.AddQuadTriangles();

            meshData.uv.AddRange(MeshData.GetFaceUVs(block, Direction.DOWN));

            return meshData;
        }
Exemplo n.º 3
0
 public override MeshData GetBlockMesh(Chunk chunk, int x, int y, int z, MeshData meshData)
 {
     return meshData;
 }
Exemplo n.º 4
0
        /**
         * Update the the linked chunk based on the the data.
         **/
        public void UpdateChunk()
        {
            wasRendered = true;

            MeshData meshData = new MeshData();

            for(int x = 0; x < chunkSize; x++)
            {
            for(int y = 0; y < chunkSize; y++)
            {
                for(int z = 0; z < chunkSize; z++)
                {
                    meshData = Register.GetBlockById(blocks[x, y, z]).GetBlockMesh(this, x, y, z, meshData);
                }
            }
            }

            renderer.RenderMesh(meshData);
        }