chunbk face culling

This commit is contained in:
maxwes08
2025-09-22 10:56:55 +02:00
parent 81ef6d8a29
commit 9a61dfd74c
5 changed files with 118 additions and 4 deletions

View File

@@ -10,6 +10,7 @@
private Dictionary<ushort, BlockData> _blockData;
private Blocks[] _blocks;
public Dictionary<Orientation, Chunk> Neighbors = new();
public Chunk(int x, int y)
{
@@ -89,7 +90,7 @@
( 0, 0, -1) // -Z
};
private void UpdateChunkMesh()
public void UpdateChunkMesh()
{
List<FaceData> faces = new List<FaceData>(Size * Size * Height / 2);
@@ -129,6 +130,21 @@
int ni = GetBlockIndex(nx, ny, nz);
if (GetBlockIndex(nx, ny, nz) == -1)
{
if (Neighbors.TryGetValue((Orientation)face, out Chunk neighbor) && neighbor != null)
{
int localX = nx;
int localZ = nz;
if (nx < 0) localX = nx + Size;
if (nx >= Size) localX = nx - Size;
if (nz < 0) localZ = nz + Size;
if (nz >= Size) localZ = nz - Size;
Blocks neighborBlock = neighbor.GetBlock(localX, y, localZ);
if (neighborBlock != Blocks.Air)
continue;
}
AddFace();
continue;
}