mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
fix uvlock rotating
Somehow the tests fail. Interesting.
This commit is contained in:
parent
7a1133200e
commit
3fbc54acc8
@ -116,6 +116,26 @@ class UVLockTest {
|
||||
baked.assertFace(Directions.UP, positions(Directions.UP, from, Vec3(0.5f, 1.0f, 1.0f)), block(0, 0, 8, 0, 8, 16, 0, 16), 1.0f)
|
||||
}
|
||||
|
||||
fun `stairs top y=90`() {
|
||||
val from = Vec3(0.5f, 0.5f, 0.0f)
|
||||
val to = Vec3(1.0f, 1.0f, 1.0f)
|
||||
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = mapOf(Directions.UP to ModelFace("#test", FaceUV(0, 0, 8, 16), 0, -1)))), textures = mapOf("test" to minecraft("block/test").texture())), uvLock = true, y = 1)
|
||||
|
||||
val baked = model.bake(createTextureManager("block/test"))!!
|
||||
|
||||
baked.assertFace(Directions.UP, positions(Directions.UP, Vec3(0, 0.5, 0.5), Vec3(1, 1, 1.0f)), block(0, 0, 16, 0, 16, 8, 0, 8), 1.0f)
|
||||
}
|
||||
|
||||
fun `stairs top y=180`() {
|
||||
val from = Vec3(0.5f, 0.5f, 0.0f)
|
||||
val to = Vec3(1.0f, 1.0f, 1.0f)
|
||||
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = mapOf(Directions.UP to ModelFace("#test", FaceUV(0, 0, 8, 16), 0, -1)))), textures = mapOf("test" to minecraft("block/test").texture())), uvLock = true, y = 2)
|
||||
|
||||
val baked = model.bake(createTextureManager("block/test"))!!
|
||||
|
||||
baked.assertFace(Directions.UP, positions(Directions.UP, Vec3(0, 0.5, 0.0), Vec3(0.5f, 1, 1.0f)), block(8, 0, 16, 0, 16, 16, 9, 16), 1.0f)
|
||||
}
|
||||
|
||||
fun `stairs top y=270`() {
|
||||
val from = Vec3(0.5f, 0.5f, 0.0f)
|
||||
val to = Vec3(1.0f, 1.0f, 1.0f)
|
||||
@ -135,4 +155,6 @@ class UVLockTest {
|
||||
|
||||
baked.assertFace(Directions.UP, positions(Directions.UP, Vec3(0, 0.5, 0), Vec3(1, 1, 0.5f)), block(0, 8, 16, 8, 16, 16, 0, 16), 1.0f)
|
||||
}
|
||||
|
||||
// TODO: test rotation around x axis and combinations
|
||||
}
|
||||
|
@ -148,6 +148,12 @@ data class SingleBlockStateApply(
|
||||
return rotatedX(direction, direction.rotateX(x)) + rotatedY(direction.rotateX(x), rotated)
|
||||
}
|
||||
|
||||
|
||||
private fun FaceUV.rotateLeft(): FaceUV {
|
||||
// return FaceUV(Vec2(start.y, -(start.x - 0.5f) + 0.5f), Vec2(end.y, -(end.x - 0.5f) + 0.5f)) // TODO: tests correct, but result wrong?
|
||||
return FaceUV(Vec2(end.y, -(start.x - 0.5f) + 0.5f), Vec2(start.y, -(end.x - 0.5f) + 0.5f))
|
||||
}
|
||||
|
||||
override fun bake(): BakedModel? {
|
||||
if (model.elements == null) return null
|
||||
|
||||
@ -168,7 +174,24 @@ data class SingleBlockStateApply(
|
||||
.rotateY(direction.rotateX(this.x))
|
||||
|
||||
|
||||
val abc = face.uv ?: if (uvLock) fallbackUV(rotatedDirection, positions.start(), positions.end()) else fallbackUV(direction, element.from, element.to)
|
||||
var abc = face.uv ?: if (uvLock) fallbackUV(rotatedDirection, positions.start(), positions.end()) else fallbackUV(direction, element.from, element.to)
|
||||
|
||||
if (uvLock && face.uv != null) {
|
||||
if (direction.axis == Axes.Y) {
|
||||
if (y == 1) {
|
||||
abc = abc.rotateLeft()
|
||||
abc = abc.rotateLeft()
|
||||
abc = abc.rotateLeft()
|
||||
}
|
||||
if (y == 2) {
|
||||
abc = abc.rotateLeft()
|
||||
abc = abc.rotateLeft()
|
||||
}
|
||||
if (y == 3) {
|
||||
abc = abc.rotateLeft()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var uv = abc.toArray(rotatedDirection, face.rotation)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user