Esempio n. 1
0
        public static MeshData BuildChunk(Chunk chunk)
        {
            var meshData = new MeshData(2);

            for (int x = 0; x < Chunk.Size; x++)
            {
                for (int y = 0; y < Chunk.Size; y++)
                {
                    for (int z = 0; z < Chunk.Size; z++)
                    {
                        var offsetPosition = new Vector3Int(x, y, z) + (chunk.Position * Chunk.Size);
                        var block          = chunk[x, y, z];

                        if (block.Definition.Render)
                        {
                            foreach (Direction direction in Enum.GetValues(typeof(Direction)))
                            {
                                var adjacentBlock = chunk.World.GetAdjacentBlock(offsetPosition, direction);
                                var o             = offsetPosition.AdjustByDirection(direction);

                                //if (chunk.Position == Vector3Int.zero && adjacentBlock.Definition.Translucent) Debug.Log($"B: d {block.Definition} o {offsetPosition} p {x} {y} {z} direction {direction} A: d {adjacentBlock.Definition} o {o} {adjacentBlock.Definition.Translucent}");

                                if (!adjacentBlock.Definition.Render || !adjacentBlock.Definition.Translucent &&
                                    adjacentBlock.Definition.Identifier != block.Definition.Identifier)
                                {
                                    int meshLayer = block.Definition.Translucent ? 1 : 0;

                                    meshData.AddQuad(new Vector3(x, y, z), 0, direction,
                                                     block.Definition.GetTexture(direction).Layer);
                                }
                            }
                        }
                    }
                }
            }

            chunk.Dirty    = false;
            chunk.Rendered = true;

            return(meshData);
        }
Esempio n. 2
0
 public Block GetAdjacentBlock(Vector3Int position, Direction direction)
 {
     return(this.GetBlock(position.AdjustByDirection(direction)));
 }
Esempio n. 3
0
 public Chunk GetAdjacentChunk(Vector3Int position, Direction direction)
 {
     return(this.GetChunk(position.AdjustByDirection(direction)));
 }