world mesh: fix wrong mesh order

This commit is contained in:
Bixilon 2023-05-21 21:51:07 +02:00
parent 0ce0f806c5
commit f3becea60e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 46 additions and 9 deletions

View File

@ -1,4 +0,0 @@
Cube uv:
bottom->top
east->north->west->south

View File

@ -55,7 +55,7 @@ class BakedFaceTest {
}
fun renderFull() {
fun mixed() {
val face = BakedFace(floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f), floatArrayOf(-1f, -2f, -3f, -4f, -5f, -6f, -7f, -8f), 1.0f, -1, null, texture())
val mesh = mesh()
@ -67,13 +67,38 @@ class BakedFaceTest {
val data = mesh.opaqueMesh!!.data.toArray()
val expected = floatArrayOf(
0f, 1f, 2f, -7f, -8f, texture, lightTint,
9f, 10f, 11f, -1f, -2f, texture, lightTint,
6f, 7f, 8f, -3f, -4f, texture, lightTint,
3f, 4f, 5f, -5f, -6f, texture, lightTint,
0f, 1f, 2f, -1f, -2f, texture, lightTint,
9f, 10f, 11f, -7f, -8f, texture, lightTint,
6f, 7f, 8f, -5f, -6f, texture, lightTint,
3f, 4f, 5f, -3f, -4f, texture, lightTint,
)
assertEquals(data, expected)
}
fun blockSouth() {
val face = BakedFace(floatArrayOf(0f, 0f, 0f, 0f, 1f, 0f, 0f, 1f, 1f, 0f, 0f, 1f), floatArrayOf(0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f), 1.0f, -1, null, texture())
val mesh = mesh()
face.render(floatArrayOf(0.0f, 0.0f, 0.0f), mesh, byteArrayOf(0, 0, 0, 0, 0, 0, 0), null)
val texture = 0.buffer()
val lightTint = 0xFFFFFF.buffer()
val data = mesh.opaqueMesh!!.data.toArray()
val expected = floatArrayOf(
0f, 0f, 0f, 0f, 0f, texture, lightTint,
0f, 0f, 1f, 1f, 0f, texture, lightTint,
0f, 1f, 1f, 1f, 1f, texture, lightTint,
0f, 1f, 0f, 0f, 1f, texture, lightTint,
)
assertEquals(data, expected)
}
// TODO: triangle order
}

View File

@ -46,6 +46,22 @@ class FullCubeBakeTest {
baked.assertFace(Directions.EAST, positions(Directions.EAST, from, to), floatArrayOf(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f), 0.6f)
}
fun cube2() {
val from = Vec3(0.0f)
val to = Vec3(1.0f)
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = createFaces())), textures = mapOf("test" to minecraft("block/test").texture())))
val baked = model.bake(createTextureManager("block/test"))!!
baked.assertFace(Directions.DOWN, floatArrayOf(0f, 0f, 0f, 0f, 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f), floatArrayOf(0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f), 0.5f)
baked.assertFace(Directions.UP, floatArrayOf(0f, 1f, 0f, 1f, 1f, 0f, 1f, 1f, 1f, 0f, 1f, 1f), floatArrayOf(0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f), 1.0f)
baked.assertFace(Directions.NORTH, floatArrayOf(0f, 0f, 0f, 1f, 0f, 0f, 1f, 1f, 0f, 0f, 1f, 0f), floatArrayOf(1f, 0f, 0f, 0f, 0f, 1f, 1f, 1f), 0.8f)
baked.assertFace(Directions.SOUTH, floatArrayOf(0f, 0f, 1f, 0f, 1f, 1f, 1f, 1f, 1f, 1f, 0f, 1f), floatArrayOf(0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f), 0.8f)
baked.assertFace(Directions.WEST, floatArrayOf(0f, 0f, 0f, 0f, 1f, 0f, 0f, 1f, 1f, 0f, 0f, 1f), floatArrayOf(0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f), 0.6f)
baked.assertFace(Directions.EAST, floatArrayOf(1f, 0f, 0f, 1f, 0f, 1f, 1f, 1f, 1f, 1f, 1f, 0f), floatArrayOf(1f, 0f, 0f, 0f, 0f, 1f, 1f, 1f), 0.6f)
}
fun y90() {
val from = Vec3(0.0f)
val to = Vec3(1.0f)