rendering: fix errors following fix for DirectionVectors being swapped

This commit is contained in:
Lukas 2021-02-28 22:04:43 +01:00
parent 6dd2d3c5d3
commit eb1eafcab8
4 changed files with 13 additions and 16 deletions

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.data.world.light
import de.bixilon.minosoft.data.world.BlockPosition
import glm_.glm
interface LightAccessor {
@ -24,10 +25,6 @@ interface LightAccessor {
fun getLightLevel(blockPosition: BlockPosition): Int {
val blockLight = getBlockLight(blockPosition)
val skyLight = getSkyLight(blockPosition)
if (blockLight > skyLight) {
return blockLight
}
return skyLight
return glm.max(blockLight, skyLight)
}
}

View File

@ -70,8 +70,8 @@ open class BlockModelElement(data: JsonObject) {
val FACE_POSITION_MAP_TEMPLATE = arrayOf(
intArrayOf(0, 2, 3, 1),
intArrayOf(6, 4, 5, 7),
intArrayOf(2, 6, 7, 3),
intArrayOf(1, 5, 4, 0),
intArrayOf(2, 6, 7, 3),
intArrayOf(6, 2, 0, 4),
intArrayOf(5, 1, 3, 7)
)
@ -99,6 +99,9 @@ open class BlockModelElement(data: JsonObject) {
}
fun rotateVector(original: Vec3, angle: Double, axis: Axes): Vec3 {
if (angle == 0.0) {
return original
}
return when (axis) {
Axes.X -> {
val rotatedValues = getRotatedValues(original.y, original.z, glm.sin(angle), glm.cos(angle))

View File

@ -92,7 +92,6 @@ class BlockRenderer(data: JsonObject, parent: BlockModel) {
if (neighbourBlockFullFace && cullFace) {
continue
}
element.render(tintColor, position, lightAccessor, textureMapping, modelMatrix, direction, mesh)
}
}

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.gui.rendering.chunk.models.renderable
import com.google.common.collect.HashBiMap
import com.google.gson.JsonObject
import de.bixilon.minosoft.data.Axes
import de.bixilon.minosoft.data.Directions
@ -31,11 +32,11 @@ import glm_.vec2.Vec2
import glm_.vec3.Vec3
import glm_.vec4.Vec4
class ElementRenderer(element: BlockModelElement, rotation: Vec3, uvLock: Boolean, rescale: Boolean) {
class ElementRenderer(element: BlockModelElement, val rotation: Vec3, uvLock: Boolean, rescale: Boolean) {
private val fullFaceDirections: MutableSet<Directions> = mutableSetOf()
private val faces: MutableMap<Directions, BlockModelFace> = element.faces.toMutableMap()
private var positions: Array<Vec3> = element.positions.clone()
private val directionMapping: MutableMap<Directions, Directions> = mutableMapOf()
private val directionMapping: HashBiMap<Directions, Directions> = HashBiMap.create()
init {
rotatePositionsAxes(positions, rotation, rescale)
@ -53,20 +54,18 @@ class ElementRenderer(element: BlockModelElement, rotation: Vec3, uvLock: Boolea
fun render(tintColor: RGBColor?, position: BlockPosition, lightAccessor: LightAccessor, textureMapping: MutableMap<String, Texture>, modelMatrix: Mat4, direction: Directions, mesh: ChunkMesh) {
val realDirection = directionMapping[direction]!!
val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[realDirection.ordinal]
val realDirection = directionMapping.inverse()[direction]!!
val face = faces[realDirection] ?: return // Not our face
val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[realDirection.ordinal]
val texture = textureMapping[face.textureName] ?: TextureArray.DEBUG_TEXTURE
// if (texture.isTransparent) {
// return // ToDo: force render transparent faces
// }
val lightLevel = lightAccessor.getLightLevel(position + directionMapping[face.cullFace]) // ToDo: rotate cullface
val drawPositions = arrayOf(positions[positionTemplate[0]], positions[positionTemplate[1]], positions[positionTemplate[2]], positions[positionTemplate[3]])
fun createQuad(drawPositions: Array<Vec3>, texturePositions: Array<Vec2?>) {
for (vertex in DRAW_ODER) {
val input = Vec4(drawPositions[vertex.first], 1.0f)
@ -84,7 +83,6 @@ class ElementRenderer(element: BlockModelElement, rotation: Vec3, uvLock: Boolea
)
}
}
val texturePositions = face.getTexturePositionArray(realDirection)
createQuad(drawPositions, texturePositions)
}