From 0000f39be9b9d863d951fa812b46377b17f9b115 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 1 Aug 2023 16:16:44 +0200 Subject: [PATCH] fix pixlyzer model offsetting --- .../models/baked/rotation/ElementRotationTest.kt | 12 ++++++++++++ .../bixilon/minosoft/camera/target/TargetHandler.kt | 2 +- .../blocks/types/pixlyzer/PixLyzerBlock.kt | 9 +++++++-- .../types/properties/offset/RandomOffsetBlock.kt | 4 +++- .../rendering/chunk/outline/BlockOutlineRenderer.kt | 2 +- .../rendering/chunk/preparer/SolidSectionMesher.kt | 3 ++- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/baked/rotation/ElementRotationTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/baked/rotation/ElementRotationTest.kt index 4adafcc82..d1d26ccfb 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/baked/rotation/ElementRotationTest.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/baked/rotation/ElementRotationTest.kt @@ -56,5 +56,17 @@ class ElementRotationTest { baked.assertFace(Directions.UP, floatArrayOf(0.5f, 1.0f, -0.2f, 1.2f, 1.0f, 0.5f, 0.5f, 1.0f, 1.2f, -0.2f, 1.0f, 0.5f), rbgy, 1.0f) } + fun `rotate grass around origin 45 degree on the y axis and rescale`() { + val from = Vec3(0.8, 0, 8) / 16 + val to = Vec3(15.2, 16, 8) / 16 + val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = createFaces(), rotation = ElementRotation(origin = Vec3(0.5f), axis = Axes.Y, angle = 45.0f, rescale = true))), textures = mapOf("test" to minecraft("block/test").texture()))) + + + val baked = model.bake(createTextureManager("block/test"))!! + + + baked.assertFace(Directions.NORTH, floatArrayOf(0.05f, 0.0f, 0.95f, 0.95f, 0.0f, 0.05f, 0.95f, 1.0f, 0.05f, 0.05f, 1.0f, 0.95f)) + } + // TODO: a,z axis } diff --git a/src/main/java/de/bixilon/minosoft/camera/target/TargetHandler.kt b/src/main/java/de/bixilon/minosoft/camera/target/TargetHandler.kt index 87d7d52d7..c1f5c4e07 100644 --- a/src/main/java/de/bixilon/minosoft/camera/target/TargetHandler.kt +++ b/src/main/java/de/bixilon/minosoft/camera/target/TargetHandler.kt @@ -101,7 +101,7 @@ class TargetHandler( return null } var shape = state.block.getOutlineShape(camera.connection, state) ?: return null - state.block.nullCast()?.offsetBlock(blockPosition)?.let { shape += it } + state.block.nullCast()?.offsetShape(blockPosition)?.let { shape += it } shape += blockPosition diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/pixlyzer/PixLyzerBlock.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/pixlyzer/PixLyzerBlock.kt index 7d5326782..6cb5e4b54 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/pixlyzer/PixLyzerBlock.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/pixlyzer/PixLyzerBlock.kt @@ -104,11 +104,16 @@ open class PixLyzerBlock( return identifier.toString() } - override fun offsetBlock(position: Vec3i): Vec3 { + override fun offsetShape(position: Vec3i): Vec3 { val offset = randomOffset ?: return Vec3.EMPTY - return super.offsetBlock(position) + if (offset == RandomOffsetTypes.XZ) NULL_OFFSET_XZ else NULL_OFFSET_XYZ // this corrects wrong pixlyzer data + return super.offsetShape(position) + if (offset == RandomOffsetTypes.XZ) NULL_OFFSET_XZ else NULL_OFFSET_XYZ // this corrects wrong pixlyzer data } + override fun offsetModel(position: Vec3i): Vec3 { + return super.offsetShape(position) + } + + companion object : ResourceLocationCodec, PixLyzerBlockFactory, MultiClassFactory { private val NULL_OFFSET_XYZ = Vec3i(0, 0, 0).getWorldOffset(RandomOffsetTypes.XYZ) private val NULL_OFFSET_XZ = Vec3i(0, 0, 0).getWorldOffset(RandomOffsetTypes.XZ) diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/properties/offset/RandomOffsetBlock.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/properties/offset/RandomOffsetBlock.kt index 6e5380ae2..a645d14f4 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/properties/offset/RandomOffsetBlock.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/properties/offset/RandomOffsetBlock.kt @@ -22,8 +22,10 @@ interface RandomOffsetBlock { val randomOffset: RandomOffsetTypes? // TODO: make non nullable - fun offsetBlock(position: Vec3i): Vec3 { + fun offsetShape(position: Vec3i): Vec3 { val offset = this.randomOffset ?: return Vec3.EMPTY return position.getWorldOffset(offset) } + + fun offsetModel(position: Vec3i): Vec3 = offsetShape(position) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/outline/BlockOutlineRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/outline/BlockOutlineRenderer.kt index 912261218..ad1f0b153 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/outline/BlockOutlineRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/outline/BlockOutlineRenderer.kt @@ -124,7 +124,7 @@ class BlockOutlineRenderer( val blockOffset = target.blockPosition.toVec3d if (target.state.block is RandomOffsetBlock) { - blockOffset += target.state.block.offsetBlock(target.blockPosition) + blockOffset += target.state.block.offsetShape(target.blockPosition) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/preparer/SolidSectionMesher.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/preparer/SolidSectionMesher.kt index b6eb87ed4..77b9090e2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/preparer/SolidSectionMesher.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/preparer/SolidSectionMesher.kt @@ -139,12 +139,13 @@ class SolidSectionMesher( var offset: Vec3? = null if (state.block is RandomOffsetBlock) { - offset = state.block.offsetBlock(position) + offset = state.block.offsetModel(position) floatOffset[0] += offset.x floatOffset[1] += offset.y floatOffset[2] += offset.z } + val tints = tints.getAverageBlockTint(chunk, neighbourChunks, state, x, y, z) var rendered = model.render(position, floatOffset, mesh, random, state, neighbourBlocks, light, tints)