From 0820d076c94d2e35462503c43b760528ca31a544 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Mon, 31 Jul 2023 18:02:29 +0200 Subject: [PATCH] improve texture rotation code --- .../state/apply/SingleBlockStateApply.kt | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/apply/SingleBlockStateApply.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/apply/SingleBlockStateApply.kt index 7a66518d8..11f6d6a6d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/apply/SingleBlockStateApply.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/apply/SingleBlockStateApply.kt @@ -121,6 +121,30 @@ data class SingleBlockStateApply( } } + private fun getTextureRotation(direction: Directions): Int { + if (x == 0 && y == 0) return 0 + + if (x == 0 && direction.axis == Axes.Y) { + return if (direction.negative) -y else y + } + if (y == 0) { + if (direction.axis == Axes.X) { + return if (direction.negative) x else -x + } + } + + // if (direction.axis == Axes.X) uv = uv.pushRight(2, if (rotatedDirection.negative) -x else x) +// + // if ((rotatedDirection == Directions.DOWN && x == 1 || rotatedDirection == Directions.UP && x == 3 || rotatedDirection == Directions.NORTH || rotatedDirection == Directions.SOUTH && x == 2)) { + // uv = uv.pushRight(2, 2) + // } + // if (direction.axis == Axes.Y && y != 0 && !uvLock) { + // uv = uv.pushRight(2, if (rotatedDirection.negative) -y else y) + // } + + return 0 + } + override fun bake(): BakedModel? { if (model.elements == null) return null @@ -143,23 +167,17 @@ data class SingleBlockStateApply( var uv = face.uv.toArray(rotatedDirection, face.rotation) - if (x > 0 && !uvLock) { - if (direction.axis == Axes.X) uv = uv.pushRight(2, if (rotatedDirection.negative) -x else x) - - if ((rotatedDirection == Directions.DOWN && x == 1 || rotatedDirection == Directions.UP && x == 3 || rotatedDirection == Directions.NORTH || rotatedDirection == Directions.SOUTH && x == 2)) { - uv = uv.pushRight(2, 2) - } - } - if (direction.axis == Axes.Y && y != 0 && !uvLock) { - uv = uv.pushRight(2, if (rotatedDirection.negative) -y else y) + if (!uvLock) { + val rotation = getTextureRotation(direction) + uv = uv.pushRight(2, rotation) } val shade = rotatedDirection.shade - val a = positions.properties(rotatedDirection, texture) // TODO: texture might not have been loaded yet - val bakedFace = BakedFace(positions, uv, shade, face.tintIndex, if (a == null) null else rotatedDirection, texture, a) + val faceProperties = positions.properties(rotatedDirection, texture) + val bakedFace = BakedFace(positions, uv, shade, face.tintIndex, if (faceProperties == null) null else rotatedDirection, texture, faceProperties) bakedFaces[rotatedDirection.ordinal] += bakedFace - properties[rotatedDirection.ordinal] += a ?: continue + properties[rotatedDirection.ordinal] += faceProperties ?: continue } }