mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
more face culling tests
This commit is contained in:
parent
110bf94706
commit
64bf7fa4d4
@ -28,6 +28,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureTransparenci
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.MemoryTexture
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
||||
import org.testng.Assert.assertFalse
|
||||
import org.testng.Assert.assertTrue
|
||||
import org.testng.annotations.Test
|
||||
|
||||
@Test(groups = ["models", "culling"])
|
||||
@ -49,24 +50,110 @@ class FaceCullingTest {
|
||||
return state
|
||||
}
|
||||
|
||||
private fun createState() = createNeighbour()
|
||||
|
||||
fun noNeighbour() {
|
||||
val face = createFace()
|
||||
assertFalse(FaceCulling.canCull(face, Directions.DOWN, null))
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.DOWN, null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun selfNotTouching() {
|
||||
val face = createFace(null)
|
||||
val neighbour = createNeighbour()
|
||||
assertFalse(FaceCulling.canCull(face, Directions.DOWN, neighbour))
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.DOWN, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun neighbourNotTouching() {
|
||||
val face = createFace()
|
||||
val neighbour = createNeighbour(null)
|
||||
assertFalse(FaceCulling.canCull(face, Directions.DOWN, neighbour))
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.DOWN, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fullNeighbour() {
|
||||
val face = createFace()
|
||||
val neighbour = createNeighbour()
|
||||
assertTrue(FaceCulling.canCull(createState(), face, Directions.DOWN, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sizeMatch() {
|
||||
val face = createFace(SideSize.FaceSize(Vec2(0.0f, 0.5f), Vec2(1.0f, 0.5f)))
|
||||
val neighbour = createNeighbour(side(SideSize.FaceSize(Vec2(0.0f, 0.5f), Vec2(1.0f, 0.5f))))
|
||||
assertTrue(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun greaterNeighbour() {
|
||||
val face = createFace(SideSize.FaceSize(Vec2(0.0f, 0.5f), Vec2(1.0f, 0.5f)))
|
||||
val neighbour = createNeighbour(side(SideSize.FaceSize(Vec2(0.0f, 0.5f), Vec2(1.0f, 0.6f))))
|
||||
assertTrue(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun smallerNeighbour() {
|
||||
val face = createFace(SideSize.FaceSize(Vec2(0.0f, 0.5f), Vec2(1.0f, 0.5f)))
|
||||
val neighbour = createNeighbour(side(SideSize.FaceSize(Vec2(0.0f, 0.5f), Vec2(1.0f, 0.4f))))
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shiftedNeighbour1() {
|
||||
val face = createFace(SideSize.FaceSize(Vec2(0.0f, 0.5f), Vec2(1.0f, 0.5f)))
|
||||
val neighbour = createNeighbour(side(SideSize.FaceSize(Vec2(0.1f, 0.5f), Vec2(1.0f, 0.5f))))
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shiftedNeighbour2() {
|
||||
val face = createFace(SideSize.FaceSize(Vec2(0.0f, 0.5f), Vec2(1.0f, 0.5f)))
|
||||
val neighbour = createNeighbour(side(SideSize.FaceSize(Vec2(0.1f, 0.5f), Vec2(1.0f, 0.6f))))
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shiftedNeighbour3() {
|
||||
val face = createFace(SideSize.FaceSize(Vec2(0.1f, 0.8f), Vec2(0.9f, 0.9f)))
|
||||
val neighbour = createNeighbour(side(SideSize.FaceSize(Vec2(0.1f, 0.5f), Vec2(0.95f, 0.95f))))
|
||||
assertTrue(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun opaqueOnTransparent() {
|
||||
val face = createFace(transparency = TextureTransparencies.OPAQUE)
|
||||
val neighbour = createNeighbour(transparency = TextureTransparencies.TRANSPARENT)
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun transparentOnOpaque() {
|
||||
val face = createFace(transparency = TextureTransparencies.TRANSPARENT)
|
||||
val neighbour = createNeighbour(transparency = TextureTransparencies.OPAQUE)
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun opaqueOnTranslucent() {
|
||||
val face = createFace(transparency = TextureTransparencies.OPAQUE)
|
||||
val neighbour = createNeighbour(transparency = TextureTransparencies.TRANSLUCENT)
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun translucentOnOpaque() {
|
||||
val face = createFace(transparency = TextureTransparencies.TRANSLUCENT)
|
||||
val neighbour = createNeighbour(transparency = TextureTransparencies.OPAQUE)
|
||||
assertFalse(FaceCulling.canCull(createState(), face, Directions.EAST, neighbour))
|
||||
}
|
||||
|
||||
// TODO: force no cull (e.g. leaves), mix of transparency, mix of side sizes
|
||||
|
||||
// TODO: same transparency when same block
|
||||
|
||||
|
||||
private fun side(vararg size: SideSize.FaceSize): SideSize {
|
||||
return SideSize(arrayOf(*size))
|
||||
}
|
||||
}
|
||||
|
@ -75,10 +75,6 @@ abstract class Block(
|
||||
@Deprecated("Interface")
|
||||
open fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) = Unit
|
||||
|
||||
@Deprecated("Interface")
|
||||
open fun canCull(blockState: BlockState, other: BlockState): Boolean = true
|
||||
|
||||
|
||||
fun updateStates(states: Set<BlockState>, default: BlockState, properties: Map<BlockProperties, Array<Any>>) {
|
||||
this::properties.forceSet(properties)
|
||||
this::states.forceSet(states)
|
||||
|
@ -14,20 +14,12 @@
|
||||
package de.bixilon.minosoft.data.registries.blocks.types.pixlyzer.leaves
|
||||
|
||||
import de.bixilon.minosoft.data.registries.blocks.factory.PixLyzerBlockFactory
|
||||
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
|
||||
import de.bixilon.minosoft.data.registries.blocks.types.pixlyzer.PixLyzerBlock
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
|
||||
open class LeavesBlock(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>) : PixLyzerBlock(resourceLocation, registries, data) {
|
||||
|
||||
override fun canCull(blockState: BlockState, other: BlockState): Boolean {
|
||||
if (other.block is LeavesBlock) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
companion object : PixLyzerBlockFactory<LeavesBlock> {
|
||||
|
||||
override fun build(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>): LeavesBlock {
|
||||
|
@ -42,7 +42,7 @@ class BakedModel(
|
||||
val direction = Directions.VALUES[directionIndex].inverted
|
||||
|
||||
for (face in faces) {
|
||||
if (FaceCulling.canCull(face, direction, neighbour)) {
|
||||
if (FaceCulling.canCull(state, face, direction, neighbour)) {
|
||||
continue
|
||||
}
|
||||
face.render(offset, mesh, light, tints)
|
||||
|
@ -19,7 +19,7 @@ import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedFace
|
||||
|
||||
object FaceCulling {
|
||||
|
||||
fun canCull(face: BakedFace, direction: Directions, neighbour: BlockState?): Boolean {
|
||||
fun canCull(block: BlockState, face: BakedFace, direction: Directions, neighbour: BlockState?): Boolean {
|
||||
if (neighbour == null) return false
|
||||
if (!face.touchingSide) return false
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user