mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
rendering: add support for uvlock
This commit is contained in:
parent
07654ca1ab
commit
a1cbac33ab
@ -18,6 +18,14 @@ enum class Axes {
|
|||||||
Z;
|
Z;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
fun byDirection(direction: Directions): Axes {
|
||||||
|
return when (direction) {
|
||||||
|
Directions.EAST, Directions.WEST -> X
|
||||||
|
Directions.UP, Directions.DOWN -> Y
|
||||||
|
Directions.NORTH, Directions.SOUTH -> Z
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val AXES = values()
|
val AXES = values()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ open class BlockModelElement(data: JsonObject) {
|
|||||||
|
|
||||||
data["rotation"]?.asJsonObject?.let {
|
data["rotation"]?.asJsonObject?.let {
|
||||||
val axis = Axes.valueOf(it["axis"].asString.toUpperCase())
|
val axis = Axes.valueOf(it["axis"].asString.toUpperCase())
|
||||||
val angle = glm.radians(it["angle"].asDouble)
|
val angle = glm.radians(it["angle"].asFloat)
|
||||||
val rescale = it["rescale"]?.asBoolean ?: false
|
val rescale = it["rescale"]?.asBoolean ?: false
|
||||||
rotatePositions(positions, axis, angle, VecUtil.jsonToVec3(it["origin"].asJsonArray), rescale)
|
rotatePositions(positions, axis, angle, VecUtil.jsonToVec3(it["origin"].asJsonArray), rescale)
|
||||||
}
|
}
|
||||||
@ -64,7 +64,6 @@ open class BlockModelElement(data: JsonObject) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val BLOCK_RESOLUTION = 16f
|
const val BLOCK_RESOLUTION = 16f
|
||||||
|
|
||||||
val FACE_POSITION_MAP_TEMPLATE = arrayOf(
|
val FACE_POSITION_MAP_TEMPLATE = arrayOf(
|
||||||
@ -76,9 +75,9 @@ open class BlockModelElement(data: JsonObject) {
|
|||||||
intArrayOf(5, 1, 3, 7)
|
intArrayOf(5, 1, 3, 7)
|
||||||
)
|
)
|
||||||
|
|
||||||
fun rotatePositions(positions: Array<Vec3>, axis: Axes, angle: Double, origin: Vec3, rescale: Boolean) {
|
fun rotatePositions(positions: Array<Vec3>, axis: Axes, angle: Float, origin: Vec3, rescale: Boolean) {
|
||||||
// TODO: optimize for 90deg, 180deg, 270deg rotations
|
// TODO: optimize for 90deg, 180deg, 270deg rotations
|
||||||
if (angle == 0.0) {
|
if (angle == 0f) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for ((i, position) in positions.withIndex()) {
|
for ((i, position) in positions.withIndex()) {
|
||||||
|
@ -86,8 +86,8 @@ class BlockModelFace {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rotate(angle: Double) {
|
fun rotate(angle: Float) {
|
||||||
if (angle == 0.0) {
|
if (angle == 0f) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val sin = glm.sin(angle)
|
val sin = glm.sin(angle)
|
||||||
|
@ -41,7 +41,6 @@ class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boo
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
rotatePositionsAxes(positions, rotation, rescale)
|
rotatePositionsAxes(positions, rotation, rescale)
|
||||||
// TODO : uvLock
|
|
||||||
for (direction in Directions.DIRECTIONS) {
|
for (direction in Directions.DIRECTIONS) {
|
||||||
if (positions.containsAllVectors(FULL_TEST_POSITIONS[direction.ordinal], 0.0001f)) { // TODO: check if texture is transparent ==> && ! texture.isTransparent
|
if (positions.containsAllVectors(FULL_TEST_POSITIONS[direction.ordinal], 0.0001f)) { // TODO: check if texture is transparent ==> && ! texture.isTransparent
|
||||||
fullFaceDirections.add(direction)
|
fullFaceDirections.add(direction)
|
||||||
@ -51,6 +50,17 @@ class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boo
|
|||||||
faces[direction] = BlockModelFace(it)
|
faces[direction] = BlockModelFace(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (uvLock) {
|
||||||
|
for (direction in Directions.DIRECTIONS) {
|
||||||
|
val axes = Axes.byDirection(direction)
|
||||||
|
val angle = when (axes) {
|
||||||
|
Axes.X -> rotation.x
|
||||||
|
Axes.Y -> rotation.y
|
||||||
|
Axes.Z -> rotation.z
|
||||||
|
}
|
||||||
|
faces[direction]?.rotate(angle)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,18 +155,18 @@ class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boo
|
|||||||
if (rotation == EMPTY_VECTOR) {
|
if (rotation == EMPTY_VECTOR) {
|
||||||
return direction
|
return direction
|
||||||
}
|
}
|
||||||
var rotatedDirectionVector = VecUtil.rotateVector(direction.directionVector, rotation.x.toDouble(), Axes.X)
|
var rotatedDirectionVector = VecUtil.rotateVector(direction.directionVector, rotation.x, Axes.X)
|
||||||
rotatedDirectionVector = VecUtil.rotateVector(rotatedDirectionVector, rotation.y.toDouble(), Axes.Y)
|
rotatedDirectionVector = VecUtil.rotateVector(rotatedDirectionVector, rotation.y, Axes.Y)
|
||||||
return Directions.byDirection(VecUtil.rotateVector(rotatedDirectionVector, rotation.z.toDouble(), Axes.Z))
|
return Directions.byDirection(VecUtil.rotateVector(rotatedDirectionVector, rotation.z, Axes.Z))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rotatePositionsAxes(positions: Array<Vec3>, angles: Vec3, rescale: Boolean) {
|
fun rotatePositionsAxes(positions: Array<Vec3>, angles: Vec3, rescale: Boolean) {
|
||||||
if (angles == EMPTY_VECTOR) {
|
if (angles == EMPTY_VECTOR) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
BlockModelElement.rotatePositions(positions, Axes.X, angles.x.toDouble(), EMPTY_VECTOR, rescale)
|
BlockModelElement.rotatePositions(positions, Axes.X, angles.x, EMPTY_VECTOR, rescale)
|
||||||
BlockModelElement.rotatePositions(positions, Axes.Y, angles.y.toDouble(), EMPTY_VECTOR, rescale)
|
BlockModelElement.rotatePositions(positions, Axes.Y, angles.y, EMPTY_VECTOR, rescale)
|
||||||
BlockModelElement.rotatePositions(positions, Axes.Z, angles.z.toDouble(), EMPTY_VECTOR, rescale)
|
BlockModelElement.rotatePositions(positions, Axes.Z, angles.z, EMPTY_VECTOR, rescale)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val POSITION_1 = Vec3(-0.5f, -0.5f, -0.5f)
|
private val POSITION_1 = Vec3(-0.5f, -0.5f, -0.5f)
|
||||||
|
@ -31,12 +31,12 @@ object VecUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRotatedValues(x: Float, y: Float, sin: Double, cos: Double): Vec2 {
|
fun getRotatedValues(x: Float, y: Float, sin: Float, cos: Float): Vec2 {
|
||||||
return Vec2((x * cos - y * sin).toFloat(), (x * sin + y * cos).toFloat())
|
return Vec2(x * cos - y * sin, x * sin + y * cos)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rotateVector(original: Vec3, angle: Double, axis: Axes): Vec3 {
|
fun rotateVector(original: Vec3, angle: Float, axis: Axes): Vec3 {
|
||||||
if (angle == 0.0) {
|
if (angle == 0f) {
|
||||||
return original
|
return original
|
||||||
}
|
}
|
||||||
return when (axis) {
|
return when (axis) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user