mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
rendering: fix errors following fix for DirectionVectors being swapped
This commit is contained in:
parent
6dd2d3c5d3
commit
eb1eafcab8
@ -14,6 +14,7 @@
|
|||||||
package de.bixilon.minosoft.data.world.light
|
package de.bixilon.minosoft.data.world.light
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.world.BlockPosition
|
import de.bixilon.minosoft.data.world.BlockPosition
|
||||||
|
import glm_.glm
|
||||||
|
|
||||||
interface LightAccessor {
|
interface LightAccessor {
|
||||||
|
|
||||||
@ -24,10 +25,6 @@ interface LightAccessor {
|
|||||||
fun getLightLevel(blockPosition: BlockPosition): Int {
|
fun getLightLevel(blockPosition: BlockPosition): Int {
|
||||||
val blockLight = getBlockLight(blockPosition)
|
val blockLight = getBlockLight(blockPosition)
|
||||||
val skyLight = getSkyLight(blockPosition)
|
val skyLight = getSkyLight(blockPosition)
|
||||||
if (blockLight > skyLight) {
|
return glm.max(blockLight, skyLight)
|
||||||
return blockLight
|
|
||||||
}
|
|
||||||
return skyLight
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,8 @@ open class BlockModelElement(data: JsonObject) {
|
|||||||
val FACE_POSITION_MAP_TEMPLATE = arrayOf(
|
val FACE_POSITION_MAP_TEMPLATE = arrayOf(
|
||||||
intArrayOf(0, 2, 3, 1),
|
intArrayOf(0, 2, 3, 1),
|
||||||
intArrayOf(6, 4, 5, 7),
|
intArrayOf(6, 4, 5, 7),
|
||||||
intArrayOf(2, 6, 7, 3),
|
|
||||||
intArrayOf(1, 5, 4, 0),
|
intArrayOf(1, 5, 4, 0),
|
||||||
|
intArrayOf(2, 6, 7, 3),
|
||||||
intArrayOf(6, 2, 0, 4),
|
intArrayOf(6, 2, 0, 4),
|
||||||
intArrayOf(5, 1, 3, 7)
|
intArrayOf(5, 1, 3, 7)
|
||||||
)
|
)
|
||||||
@ -99,6 +99,9 @@ open class BlockModelElement(data: JsonObject) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun rotateVector(original: Vec3, angle: Double, axis: Axes): Vec3 {
|
fun rotateVector(original: Vec3, angle: Double, axis: Axes): Vec3 {
|
||||||
|
if (angle == 0.0) {
|
||||||
|
return original
|
||||||
|
}
|
||||||
return when (axis) {
|
return when (axis) {
|
||||||
Axes.X -> {
|
Axes.X -> {
|
||||||
val rotatedValues = getRotatedValues(original.y, original.z, glm.sin(angle), glm.cos(angle))
|
val rotatedValues = getRotatedValues(original.y, original.z, glm.sin(angle), glm.cos(angle))
|
||||||
|
@ -92,7 +92,6 @@ class BlockRenderer(data: JsonObject, parent: BlockModel) {
|
|||||||
if (neighbourBlockFullFace && cullFace) {
|
if (neighbourBlockFullFace && cullFace) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
element.render(tintColor, position, lightAccessor, textureMapping, modelMatrix, direction, mesh)
|
element.render(tintColor, position, lightAccessor, textureMapping, modelMatrix, direction, mesh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.chunk.models.renderable
|
package de.bixilon.minosoft.gui.rendering.chunk.models.renderable
|
||||||
|
|
||||||
|
import com.google.common.collect.HashBiMap
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import de.bixilon.minosoft.data.Axes
|
import de.bixilon.minosoft.data.Axes
|
||||||
import de.bixilon.minosoft.data.Directions
|
import de.bixilon.minosoft.data.Directions
|
||||||
@ -31,11 +32,11 @@ import glm_.vec2.Vec2
|
|||||||
import glm_.vec3.Vec3
|
import glm_.vec3.Vec3
|
||||||
import glm_.vec4.Vec4
|
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 fullFaceDirections: MutableSet<Directions> = mutableSetOf()
|
||||||
private val faces: MutableMap<Directions, BlockModelFace> = element.faces.toMutableMap()
|
private val faces: MutableMap<Directions, BlockModelFace> = element.faces.toMutableMap()
|
||||||
private var positions: Array<Vec3> = element.positions.clone()
|
private var positions: Array<Vec3> = element.positions.clone()
|
||||||
private val directionMapping: MutableMap<Directions, Directions> = mutableMapOf()
|
private val directionMapping: HashBiMap<Directions, Directions> = HashBiMap.create()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
rotatePositionsAxes(positions, rotation, rescale)
|
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) {
|
fun render(tintColor: RGBColor?, position: BlockPosition, lightAccessor: LightAccessor, textureMapping: MutableMap<String, Texture>, modelMatrix: Mat4, direction: Directions, mesh: ChunkMesh) {
|
||||||
val realDirection = directionMapping[direction]!!
|
val realDirection = directionMapping.inverse()[direction]!!
|
||||||
val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[realDirection.ordinal]
|
|
||||||
|
|
||||||
val face = faces[realDirection] ?: return // Not our face
|
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
|
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 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]])
|
val drawPositions = arrayOf(positions[positionTemplate[0]], positions[positionTemplate[1]], positions[positionTemplate[2]], positions[positionTemplate[3]])
|
||||||
|
|
||||||
|
|
||||||
fun createQuad(drawPositions: Array<Vec3>, texturePositions: Array<Vec2?>) {
|
fun createQuad(drawPositions: Array<Vec3>, texturePositions: Array<Vec2?>) {
|
||||||
for (vertex in DRAW_ODER) {
|
for (vertex in DRAW_ODER) {
|
||||||
val input = Vec4(drawPositions[vertex.first], 1.0f)
|
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)
|
val texturePositions = face.getTexturePositionArray(realDirection)
|
||||||
createQuad(drawPositions, texturePositions)
|
createQuad(drawPositions, texturePositions)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user