chunbk face culling
This commit is contained in:
18
Chunk.cs
18
Chunk.cs
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user