mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
model bakery: flip uv y coordinate
minosoft uv starts from top left, minecraft/opengl from bottom left. LOTS of tests need to be fixed.
This commit is contained in:
parent
f3becea60e
commit
0a2f2cef08
@ -57,12 +57,12 @@ data class ModelFace(
|
|||||||
fun fallbackUV(direction: Directions, from: Vec3, to: Vec3): FaceUV {
|
fun fallbackUV(direction: Directions, from: Vec3, to: Vec3): FaceUV {
|
||||||
return when (direction) {
|
return when (direction) {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
Directions.DOWN -> FaceUV(from.x, 1.0f - to.z, to.x, 1.0f - from.z )
|
Directions.DOWN -> FaceUV(from.x, 1.0f - from.z, to.x, 1.0f - to.z)
|
||||||
Directions.UP -> FaceUV(from.x, from.z, to.x, to.z )
|
Directions.UP -> FaceUV(from.x, to.z, to.x, from.z )
|
||||||
Directions.NORTH -> FaceUV(1.0f - to.x, 1.0f - to.y, 1.0f - from.x, 1.0f - from.y )
|
Directions.NORTH -> FaceUV(1.0f - to.x, 1.0f - from.y, 1.0f - from.x, 1.0f - to.y)
|
||||||
Directions.SOUTH -> FaceUV(from.x, 1.0f - to.y, to.x, 1.0f - from.y )
|
Directions.SOUTH -> FaceUV(from.x, 1.0f - from.y, to.x, 1.0f - to.y)
|
||||||
Directions.WEST -> FaceUV(from.z, 1.0f - to.y, to.z, 1.0f - from.y )
|
Directions.WEST -> FaceUV(from.z, 1.0f - from.y, to.z, 1.0f - to.y)
|
||||||
Directions.EAST -> FaceUV(1.0f - to.z, 1.0f - to.y, 1.0f - from.z, 1.0f - from.y )
|
Directions.EAST -> FaceUV(1.0f - to.z, 1.0f - from.y, 1.0f - from.z, 1.0f - to.y)
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,7 +70,13 @@ data class ModelFace(
|
|||||||
fun deserialize(direction: Directions, from: Vec3, to: Vec3, data: JsonObject): ModelFace {
|
fun deserialize(direction: Directions, from: Vec3, to: Vec3, data: JsonObject): ModelFace {
|
||||||
val texture = data["texture"].toString()
|
val texture = data["texture"].toString()
|
||||||
|
|
||||||
val uv = data["uv"]?.listCast<Number>()?.let { FaceUV(start = Vec2(it[0], it[1]) / BLOCK_SIZE, end = Vec2(it[2], it[3]) / BLOCK_SIZE) } ?: fallbackUV(direction, from, to)
|
val uv = data["uv"]?.listCast<Number>()?.let {
|
||||||
|
// auto transform (flip) y coordinate (in minosoft 0|0 is left up, not like in minecraft/opengl where it is left down)
|
||||||
|
FaceUV(
|
||||||
|
start = Vec2(it[0], it[3].toFloat()) / BLOCK_SIZE,
|
||||||
|
end = Vec2(it[2], it[1].toFloat()) / BLOCK_SIZE,
|
||||||
|
)
|
||||||
|
} ?: fallbackUV(direction, from, to)
|
||||||
|
|
||||||
val rotation = data["rotation"]?.toInt()?.rotation() ?: 0
|
val rotation = data["rotation"]?.toInt()?.rotation() ?: 0
|
||||||
val cull = data["cullface"]?.toString()?.let { if (it == "none") null else Directions[it] }
|
val cull = data["cullface"]?.toString()?.let { if (it == "none") null else Directions[it] }
|
||||||
|
@ -62,18 +62,18 @@ class SingleWorldMesh(context: RenderContext, initialCacheSize: Int, onDemand: B
|
|||||||
companion object {
|
companion object {
|
||||||
// TODO: uv coordinates should start in the upper left corner, then a 0=>0 mapping is possible
|
// TODO: uv coordinates should start in the upper left corner, then a 0=>0 mapping is possible
|
||||||
val TRIANGLE_ORDER = intArrayOf(
|
val TRIANGLE_ORDER = intArrayOf(
|
||||||
0, 3,
|
0, 0,
|
||||||
3, 0,
|
3, 3,
|
||||||
2, 1,
|
2, 2,
|
||||||
2, 1,
|
2, 2,
|
||||||
1, 2,
|
1, 1,
|
||||||
0, 3,
|
0, 0,
|
||||||
)
|
)
|
||||||
val QUAD_ORDER = intArrayOf(
|
val QUAD_ORDER = intArrayOf(
|
||||||
0, 3,
|
0, 0,
|
||||||
3, 0,
|
3, 3,
|
||||||
2, 1,
|
2, 2,
|
||||||
1, 2,
|
1, 1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user