From 818f046b50023606c9fb8ca98ec99ea78ec081e0 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Mon, 26 Jun 2023 21:20:30 +0200 Subject: [PATCH] face properties test --- .../state/baked/cull/FacePropertiesTest.kt | 95 +++++++++++++++++++ .../block/state/baked/cull/FaceCulling.kt | 2 +- .../state/baked/cull/side/SideProperties.kt | 4 +- 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/FacePropertiesTest.kt diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/FacePropertiesTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/FacePropertiesTest.kt new file mode 100644 index 000000000..0913a8e40 --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/FacePropertiesTest.kt @@ -0,0 +1,95 @@ +/* + * Minosoft + * Copyright (C) 2020-2023 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.models.block.state.baked.cull + +import de.bixilon.kotlinglm.vec2.Vec2 +import de.bixilon.kotlinglm.vec3.Vec3 +import de.bixilon.minosoft.data.direction.Directions +import de.bixilon.minosoft.data.registries.identified.Namespaces +import de.bixilon.minosoft.gui.rendering.models.baked.BakedModelTestUtil +import de.bixilon.minosoft.gui.rendering.models.block.BlockModel +import de.bixilon.minosoft.gui.rendering.models.block.element.ModelElement +import de.bixilon.minosoft.gui.rendering.models.block.state.apply.SingleBlockStateApply +import de.bixilon.minosoft.gui.rendering.models.block.state.baked.cull.side.FaceProperties +import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureTransparencies +import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture +import org.testng.Assert.assertEquals +import org.testng.Assert.assertNull +import org.testng.annotations.Test + +@Test(groups = ["models", "culling"]) +class FacePropertiesTest { + + fun fullBlock() { + val from = Vec3(0.0f) + val to = Vec3(1.0f) + val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = BakedModelTestUtil.createFaces())), textures = mapOf("test" to Namespaces.minecraft("block/test").texture()))) + + val baked = model.bake(BakedModelTestUtil.createTextureManager("block/test"))!! + + assertEquals(baked.getProperties(Directions.DOWN)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.UP)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.NORTH)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.SOUTH)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.WEST)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.EAST)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + } + + fun lowerSlab() { + val from = Vec3(0.0f, 0.0f, 0.0f) + val to = Vec3(1.0f, 0.5f, 1.0f) + val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = BakedModelTestUtil.createFaces())), textures = mapOf("test" to Namespaces.minecraft("block/test").texture()))) + + val baked = model.bake(BakedModelTestUtil.createTextureManager("block/test"))!! + + assertEquals(baked.getProperties(Directions.DOWN)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertNull(baked.getProperties(Directions.UP)?.faces) + assertEquals(baked.getProperties(Directions.NORTH)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 0.5f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.SOUTH)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 0.5f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.WEST)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 0.5f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.EAST)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 0.5f), TextureTransparencies.OPAQUE))) + } + + fun upperSlab() { + val from = Vec3(0.0f, 0.5f, 0.0f) + val to = Vec3(1.0f, 1.0f, 1.0f) + val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = BakedModelTestUtil.createFaces())), textures = mapOf("test" to Namespaces.minecraft("block/test").texture()))) + + val baked = model.bake(BakedModelTestUtil.createTextureManager("block/test"))!! + + assertNull(baked.getProperties(Directions.DOWN)?.faces) + assertEquals(baked.getProperties(Directions.UP)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.NORTH)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.5f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.SOUTH)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.5f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.WEST)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.5f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + assertEquals(baked.getProperties(Directions.EAST)?.faces, arrayOf(FaceProperties(Vec2(0.0f, 0.5f), Vec2(1.0f, 1.0f), TextureTransparencies.OPAQUE))) + } + + fun `mini cube`() { + val from = Vec3(0.1f, 0.2f, 0.3f) + val to = Vec3(0.7f, 0.8f, 0.9f) + val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = BakedModelTestUtil.createFaces())), textures = mapOf("test" to Namespaces.minecraft("block/test").texture()))) + + val baked = model.bake(BakedModelTestUtil.createTextureManager("block/test"))!! + + assertNull(baked.getProperties(Directions.DOWN)?.faces) + assertNull(baked.getProperties(Directions.UP)?.faces) + assertNull(baked.getProperties(Directions.NORTH)?.faces) + assertNull(baked.getProperties(Directions.SOUTH)?.faces) + assertNull(baked.getProperties(Directions.WEST)?.faces) + assertNull(baked.getProperties(Directions.EAST)?.faces) + } + + // TODO: north/south and west/east slabs +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/FaceCulling.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/FaceCulling.kt index a7c020fc8..4ec49000f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/FaceCulling.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/FaceCulling.kt @@ -59,7 +59,7 @@ object FaceCulling { // overlapping is broken, see https://stackoverflow.com/questions/7342935/algorithm-to-compute-total-area-covered-by-a-set-of-overlapping-segments var area = 0.0f - for (quad in this.sizes) { + for (quad in this.faces) { val width = minOf(target.end.x, quad.end.x) - maxOf(quad.start.x, target.start.x) val height = minOf(target.end.y, quad.end.y) - maxOf(quad.start.y, target.start.y) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/side/SideProperties.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/side/SideProperties.kt index 4c8f1687f..c699414be 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/side/SideProperties.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/cull/side/SideProperties.kt @@ -16,10 +16,10 @@ package de.bixilon.minosoft.gui.rendering.models.block.state.baked.cull.side import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureTransparencies class SideProperties( - val sizes: Array, + val faces: Array, val transparency: TextureTransparencies?, ) { init { - if (sizes.isEmpty()) throw IllegalCallerException("sizes is empty!") + if (faces.isEmpty()) throw IllegalCallerException("properties is empty!") } }