mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 18:34:56 -04:00
outsource y rotation tests
This commit is contained in:
parent
b95129b7af
commit
c7bb465681
@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.models
|
|||||||
|
|
||||||
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
||||||
import de.bixilon.minosoft.assets.MemoryAssetsManager
|
import de.bixilon.minosoft.assets.MemoryAssetsManager
|
||||||
|
import de.bixilon.minosoft.gui.rendering.models.block.element.ModelElement
|
||||||
import de.bixilon.minosoft.gui.rendering.models.loader.BlockLoader
|
import de.bixilon.minosoft.gui.rendering.models.loader.BlockLoader
|
||||||
import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader
|
import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader
|
||||||
import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader.Companion.model
|
import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader.Companion.model
|
||||||
@ -41,4 +42,14 @@ object ModelTestUtil {
|
|||||||
|
|
||||||
return assets
|
return assets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun block(vararg elements: Int): FloatArray {
|
||||||
|
val result = FloatArray(elements.size)
|
||||||
|
|
||||||
|
for ((index, value) in elements.withIndex()) {
|
||||||
|
result[index] = value / ModelElement.BLOCK_SIZE
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ object BakedModelTestUtil {
|
|||||||
|
|
||||||
fun BakedModel.assertFace(direction: Directions, positions: FloatArray, uv: FloatArray? = null, shade: Float? = null, texture: String? = null) {
|
fun BakedModel.assertFace(direction: Directions, positions: FloatArray, uv: FloatArray? = null, shade: Float? = null, texture: String? = null) {
|
||||||
val faces = this.faces[direction.ordinal]
|
val faces = this.faces[direction.ordinal]
|
||||||
if (faces.size != 1) throw IllegalArgumentException("Model has more/less than once face!")
|
if (faces.size != 1) throw IllegalArgumentException("Model has more/less than once fac: ${faces.size}!")
|
||||||
val face = faces.first()
|
val face = faces.first()
|
||||||
|
|
||||||
Assert.assertEquals(face.positions, positions, "Vertices mismatch")
|
Assert.assertEquals(face.positions, positions, "Vertices mismatch")
|
||||||
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.models.baked
|
|||||||
import de.bixilon.kotlinglm.vec3.Vec3
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
import de.bixilon.minosoft.data.direction.Directions
|
import de.bixilon.minosoft.data.direction.Directions
|
||||||
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
||||||
|
import de.bixilon.minosoft.gui.rendering.models.ModelTestUtil.block
|
||||||
import de.bixilon.minosoft.gui.rendering.models.baked.BakedModelTestUtil.assertFace
|
import de.bixilon.minosoft.gui.rendering.models.baked.BakedModelTestUtil.assertFace
|
||||||
import de.bixilon.minosoft.gui.rendering.models.baked.BakedModelTestUtil.createFaces
|
import de.bixilon.minosoft.gui.rendering.models.baked.BakedModelTestUtil.createFaces
|
||||||
import de.bixilon.minosoft.gui.rendering.models.baked.BakedModelTestUtil.createTextureManager
|
import de.bixilon.minosoft.gui.rendering.models.baked.BakedModelTestUtil.createTextureManager
|
||||||
@ -23,23 +24,12 @@ 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.element.ModelElement
|
||||||
import de.bixilon.minosoft.gui.rendering.models.block.element.ModelElement.Companion.BLOCK_SIZE
|
import de.bixilon.minosoft.gui.rendering.models.block.element.ModelElement.Companion.BLOCK_SIZE
|
||||||
import de.bixilon.minosoft.gui.rendering.models.block.state.apply.SingleBlockStateApply
|
import de.bixilon.minosoft.gui.rendering.models.block.state.apply.SingleBlockStateApply
|
||||||
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedModel
|
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
@Test(groups = ["models"])
|
@Test(groups = ["models"])
|
||||||
class CuboidBakeTest {
|
class CuboidBakeTest {
|
||||||
|
|
||||||
private fun block(vararg elements: Int): FloatArray {
|
|
||||||
val result = FloatArray(elements.size)
|
|
||||||
|
|
||||||
for ((index, value) in elements.withIndex()) {
|
|
||||||
result[index] = value / BLOCK_SIZE
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
fun cuboidY90_1() {
|
fun cuboidY90_1() {
|
||||||
val from = Vec3(1, 0, 0) / BLOCK_SIZE
|
val from = Vec3(1, 0, 0) / BLOCK_SIZE
|
||||||
val to = Vec3(16, 16, 16) / BLOCK_SIZE
|
val to = Vec3(16, 16, 16) / BLOCK_SIZE
|
||||||
@ -71,38 +61,4 @@ class CuboidBakeTest {
|
|||||||
baked.assertFace(Directions.WEST, block(2, 2, 1, 2, 15, 1, 2, 15, 16, 2, 2, 16), block(1, 2, 1, 15, 16, 15, 16, 2), 0.6f)
|
baked.assertFace(Directions.WEST, block(2, 2, 1, 2, 15, 1, 2, 15, 16, 2, 2, 16), block(1, 2, 1, 15, 16, 15, 16, 2), 0.6f)
|
||||||
baked.assertFace(Directions.EAST, block(13, 2, 1, 13, 2, 16, 13, 15, 16, 13, 15, 1), block(15, 2, 0, 2, 0, 15, 15, 15), 0.6f)
|
baked.assertFace(Directions.EAST, block(13, 2, 1, 13, 2, 16, 13, 15, 16, 13, 15, 1), block(15, 2, 0, 2, 0, 15, 15, 15), 0.6f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rotatedUp() {
|
|
||||||
val from = Vec3(6, 0, 6) / BLOCK_SIZE
|
|
||||||
val to = Vec3(10, 16, 16) / BLOCK_SIZE
|
|
||||||
|
|
||||||
fun bake(rotation: Int): BakedModel {
|
|
||||||
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = mapOf(Directions.UP to createFaces(from, to)[Directions.UP]!!))), textures = mapOf("test" to minecraft("block/test").texture())), y = rotation)
|
|
||||||
|
|
||||||
return model.bake(createTextureManager("block/test"))!!
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bake(0).assertFace(Directions.UP, block(6, 16, 6, 10, 16, 6, 10, 16, 16, 6, 16, 16))
|
|
||||||
bake(1).assertFace(Directions.UP, block(0, 16, 6, 10, 16, 6, 10, 16, 10, 0, 16, 10))
|
|
||||||
bake(2).assertFace(Directions.UP, block(6, 16, 0, 10, 16, 0, 10, 16, 10, 6, 16, 10))
|
|
||||||
bake(3).assertFace(Directions.UP, block(6, 16, 6, 16, 16, 6, 16, 16, 10, 6, 16, 10))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun rotatedDown() {
|
|
||||||
val from = Vec3(6, 0, 6) / BLOCK_SIZE
|
|
||||||
val to = Vec3(10, 16, 16) / BLOCK_SIZE
|
|
||||||
|
|
||||||
fun bake(rotation: Int): BakedModel {
|
|
||||||
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = mapOf(Directions.DOWN to createFaces(from, to)[Directions.DOWN]!!))), textures = mapOf("test" to minecraft("block/test").texture())), y = rotation)
|
|
||||||
|
|
||||||
return model.bake(createTextureManager("block/test"))!!
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bake(0).assertFace(Directions.DOWN, block(6, 0, 6, 6, 0, 16, 10, 0, 16, 10, 0, 6))
|
|
||||||
bake(1).assertFace(Directions.DOWN, block(0, 0, 6, 0, 0, 10, 10, 0, 10, 10, 0, 6))
|
|
||||||
bake(2).assertFace(Directions.DOWN, block(6, 0, 0, 6, 0, 10, 10, 0, 10, 10, 0, 0))
|
|
||||||
bake(3).assertFace(Directions.DOWN, block(6, 0, 6, 6, 0, 10, 16, 0, 10, 16, 0, 6))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.gui.rendering.models.baked
|
||||||
|
|
||||||
|
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.ModelTestUtil.block
|
||||||
|
import de.bixilon.minosoft.gui.rendering.models.baked.BakedModelTestUtil.assertFace
|
||||||
|
import de.bixilon.minosoft.gui.rendering.models.baked.BakedModelTestUtil.createFaces
|
||||||
|
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.BakedModel
|
||||||
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
||||||
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
|
@Test(groups = ["models"])
|
||||||
|
class YRotationTest {
|
||||||
|
|
||||||
|
|
||||||
|
fun rotatedDown() {
|
||||||
|
val from = Vec3(6, 0, 6) / ModelElement.BLOCK_SIZE
|
||||||
|
val to = Vec3(10, 16, 16) / ModelElement.BLOCK_SIZE
|
||||||
|
|
||||||
|
fun bake(rotation: Int): BakedModel {
|
||||||
|
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = mapOf(Directions.DOWN to createFaces(from, to)[Directions.DOWN]!!))), textures = mapOf("test" to Namespaces.minecraft("block/test").texture())), y = rotation)
|
||||||
|
|
||||||
|
return model.bake(BakedModelTestUtil.createTextureManager("block/test"))!!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bake(0).assertFace(Directions.DOWN, block(6, 0, 6, 6, 0, 16, 10, 0, 16, 10, 0, 6))
|
||||||
|
bake(1).assertFace(Directions.DOWN, block(0, 0, 6, 0, 0, 10, 10, 0, 10, 10, 0, 6))
|
||||||
|
bake(2).assertFace(Directions.DOWN, block(6, 0, 0, 6, 0, 10, 10, 0, 10, 10, 0, 0))
|
||||||
|
bake(3).assertFace(Directions.DOWN, block(6, 0, 6, 6, 0, 10, 16, 0, 10, 16, 0, 6))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rotatedUp() {
|
||||||
|
val from = Vec3(6, 0, 6) / ModelElement.BLOCK_SIZE
|
||||||
|
val to = Vec3(10, 16, 16) / ModelElement.BLOCK_SIZE
|
||||||
|
|
||||||
|
fun bake(rotation: Int): BakedModel {
|
||||||
|
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = mapOf(Directions.UP to createFaces(from, to)[Directions.UP]!!))), textures = mapOf("test" to Namespaces.minecraft("block/test").texture())), y = rotation)
|
||||||
|
|
||||||
|
return model.bake(BakedModelTestUtil.createTextureManager("block/test"))!!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bake(0).assertFace(Directions.UP, block(6, 16, 6, 10, 16, 6, 10, 16, 16, 6, 16, 16))
|
||||||
|
bake(1).assertFace(Directions.UP, block(0, 16, 6, 10, 16, 6, 10, 16, 10, 0, 16, 10))
|
||||||
|
bake(2).assertFace(Directions.UP, block(6, 16, 0, 10, 16, 0, 10, 16, 10, 6, 16, 10))
|
||||||
|
bake(3).assertFace(Directions.UP, block(6, 16, 6, 16, 16, 6, 16, 16, 10, 6, 16, 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rotatedNorth() {
|
||||||
|
val from = Vec3(6, 0, 6) / ModelElement.BLOCK_SIZE
|
||||||
|
val to = Vec3(10, 16, 16) / ModelElement.BLOCK_SIZE
|
||||||
|
|
||||||
|
fun bake(rotation: Int): BakedModel {
|
||||||
|
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = mapOf(Directions.NORTH to createFaces(from, to)[Directions.NORTH]!!))), textures = mapOf("test" to Namespaces.minecraft("block/test").texture())), y = rotation)
|
||||||
|
|
||||||
|
return model.bake(BakedModelTestUtil.createTextureManager("block/test"))!!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bake(0).assertFace(Directions.NORTH, block(6, 0, 6, 10, 0, 6, 10, 16, 6, 6, 16, 6))
|
||||||
|
bake(1).assertFace(Directions.NORTH, block(0, 0, 6, 10, 0, 6, 10, 16, 6, 0, 16, 6))
|
||||||
|
bake(2).assertFace(Directions.NORTH, block(6, 0, 0, 10, 0, 0, 10, 16, 0, 6, 16, 0))
|
||||||
|
bake(3).assertFace(Directions.NORTH, block(6, 0, 6, 16, 0, 6, 16, 16, 6, 6, 16, 6))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rotatedSouth() {
|
||||||
|
val from = Vec3(6, 0, 6) / ModelElement.BLOCK_SIZE
|
||||||
|
val to = Vec3(10, 16, 16) / ModelElement.BLOCK_SIZE
|
||||||
|
|
||||||
|
fun bake(rotation: Int): BakedModel {
|
||||||
|
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = mapOf(Directions.SOUTH to createFaces(from, to)[Directions.SOUTH]!!))), textures = mapOf("test" to Namespaces.minecraft("block/test").texture())), y = rotation)
|
||||||
|
|
||||||
|
return model.bake(BakedModelTestUtil.createTextureManager("block/test"))!!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bake(0).assertFace(Directions.SOUTH, block(6, 0, 16, 6, 16, 16, 10, 16, 16, 10, 0, 16))
|
||||||
|
bake(1).assertFace(Directions.SOUTH, block(0, 0, 10, 0, 16, 10, 10, 16, 10, 10, 0, 10))
|
||||||
|
bake(2).assertFace(Directions.SOUTH, block(6, 0, 10, 6, 16, 10, 10, 16, 10, 10, 0, 10))
|
||||||
|
bake(3).assertFace(Directions.SOUTH, block(6, 0, 10, 6, 16, 10, 16, 16, 10, 16, 0, 10))
|
||||||
|
}
|
||||||
|
}
|
@ -57,7 +57,7 @@ data class SingleBlockStateApply(
|
|||||||
val x = this[offset + 0]
|
val x = this[offset + 0]
|
||||||
val y = this[offset + 2]
|
val y = this[offset + 2]
|
||||||
|
|
||||||
this[offset + 0] = -y + 1.0f
|
this[offset + 0] = -y + 1.0f // translates to origin and back; same as (y-0.5f) + 0.5f
|
||||||
this[offset + 2] = x
|
this[offset + 2] = x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user