feat: derive atlas tile size from loaded texture dimensions
This commit is contained in:
@@ -16,7 +16,7 @@ public class ChunkMesherTests
|
||||
[Fact]
|
||||
public void EmptyChunk_ProducesNoFaces()
|
||||
{
|
||||
var mesh = new ChunkMesher().Build(new Chunk(), new BlockRegistry());
|
||||
var mesh = new ChunkMesher(128, 128).Build(new Chunk(), new BlockRegistry());
|
||||
Assert.Empty(mesh);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ChunkMesherTests
|
||||
var chunk = new Chunk();
|
||||
chunk[8, 8, 8] = 1; // stone
|
||||
|
||||
var mesh = new ChunkMesher().Build(chunk, new BlockRegistry());
|
||||
var mesh = new ChunkMesher(128, 128).Build(chunk, new BlockRegistry());
|
||||
|
||||
Assert.Equal(6, FaceCount(mesh));
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class ChunkMesherTests
|
||||
for (int z = 0; z < Chunk.Size; z++)
|
||||
chunk[x, y, z] = 1; // stone
|
||||
|
||||
var mesh = new ChunkMesher().Build(chunk, new BlockRegistry());
|
||||
var mesh = new ChunkMesher(128, 128).Build(chunk, new BlockRegistry());
|
||||
|
||||
// 6 sides * 16 * 16 visible faces
|
||||
Assert.Equal(6 * Chunk.Size * Chunk.Size, FaceCount(mesh));
|
||||
@@ -52,10 +52,32 @@ public class ChunkMesherTests
|
||||
var chunk = new Chunk();
|
||||
chunk[0, 0, 0] = 1; // corner block: all 6 neighbors are air/out-of-bounds -> 6 faces
|
||||
|
||||
var mesh = new ChunkMesher().Build(chunk, new BlockRegistry());
|
||||
var mesh = new ChunkMesher(128, 128).Build(chunk, new BlockRegistry());
|
||||
|
||||
// Pins the layout: 6 faces * 6 vertices/face * 6 floats/vertex.
|
||||
Assert.Equal(6 * VerticesPerFace * FloatsPerVertex, mesh.Length);
|
||||
Assert.Equal(0, mesh.Length % FloatsPerVertex);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Mesher_UsesAtlasDimensions_ForTileSize()
|
||||
{
|
||||
var chunk = new Chunk();
|
||||
chunk[0, 0, 0] = 1; // stone, tile (1,0)
|
||||
|
||||
// 128px atlas, 32px tiles => 4x4 grid, normalized tile size 0.25.
|
||||
var mesh = new ChunkMesher(128, 128).Build(chunk, new BlockRegistry());
|
||||
|
||||
// Gather all U coords (offset 3) and V coords (offset 4); each must be a
|
||||
// multiple of 0.25 within [0,1].
|
||||
for (int i = 0; i < mesh.Length; i += 6)
|
||||
{
|
||||
float u = mesh[i + 3];
|
||||
float v = mesh[i + 4];
|
||||
Assert.InRange(u, 0f, 1f);
|
||||
Assert.InRange(v, 0f, 1f);
|
||||
Assert.True(System.Math.Abs(u * 4f - System.MathF.Round(u * 4f)) < 1e-4f, $"u={u} not on 0.25 grid");
|
||||
Assert.True(System.Math.Abs(v * 4f - System.MathF.Round(v * 4f)) < 1e-4f, $"v={v} not on 0.25 grid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user