Exemple #1
0
        public Mesh BuildMesh(TerrainChunk chunk)
        {
            chunk.ForEachNonEmptyVisibleBlock(block =>
            {
                var blockLocalIndex = block.LocalIndex;

                var blockMinVertex = new Vector3(
                    blockLocalIndex.X * config.BlockSize - config.HalfBlockSize,
                    blockLocalIndex.Y * config.BlockSize - config.HalfBlockSize,
                    blockLocalIndex.Z * config.BlockSize - config.HalfBlockSize
                    );

                var blockUVs = TerrainBlockUVs.Create(block.BlockType);

                if (chunk.IsBlockEmpty(blockLocalIndex.StepUp()))
                {
                    AddBlockFace_up(blockMinVertex, blockUVs);
                }

                if (chunk.IsBlockEmpty(blockLocalIndex.StepDown()))
                {
                    AddBlockFace_down(blockMinVertex, blockUVs);
                }

                if (chunk.IsBlockEmpty(blockLocalIndex.StepForward()))
                {
                    AddBlockFace_forward(blockMinVertex, blockUVs);
                }

                if (chunk.IsBlockEmpty(blockLocalIndex.StepRight()))
                {
                    AddBlockFace_right(blockMinVertex, blockUVs);
                }

                if (chunk.IsBlockEmpty(blockLocalIndex.StepBack()))
                {
                    AddBlockFace_back(blockMinVertex, blockUVs);
                }

                if (chunk.IsBlockEmpty(blockLocalIndex.StepLeft()))
                {
                    AddBlockFace_left(blockMinVertex, blockUVs);
                }
            });

            return(BuildMesh());
        }
Exemple #2
0
        public Mesh BuildBlockMesh(TerrainBlock.Type blockType)
        {
            var blockMinVertex = new Vector3(
                -config.HalfBlockSize,
                -config.HalfBlockSize,
                -config.HalfBlockSize
                );

            var blockUVs = TerrainBlockUVs.Create(blockType);

            AddBlockFace_up(blockMinVertex, blockUVs);
            AddBlockFace_down(blockMinVertex, blockUVs);
            AddBlockFace_forward(blockMinVertex, blockUVs);
            AddBlockFace_right(blockMinVertex, blockUVs);
            AddBlockFace_back(blockMinVertex, blockUVs);
            AddBlockFace_left(blockMinVertex, blockUVs);

            return(BuildMesh());
        }