Exemple #1
0
        private void AddBlockFace_left(Vector3 blockMinVertex, TerrainBlockUVs blockUVs)
        {
            AddFacesForNextFourVertices();

            vertices.Add(blockMinVertex + new Vector3(0, 0, 1) * config.BlockSize);
            vertices.Add(blockMinVertex + new Vector3(0, 1, 1) * config.BlockSize);
            vertices.Add(blockMinVertex + new Vector3(0, 1, 0) * config.BlockSize);
            vertices.Add(blockMinVertex + new Vector3(0, 0, 0) * config.BlockSize);

            uvs.AddRange(blockUVs.SideUVs);
        }
Exemple #2
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 #3
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());
        }