mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
rendering: fix advanced optimizer in combination with rotated blocks
This commit is contained in:
parent
026a2d2751
commit
18b42ff019
@ -207,7 +207,7 @@ abstract class Entity(
|
||||
delta.y = collisionsToCheck.computeOffset(aabb, deltaPosition.y, Axes.Y)
|
||||
aabb.offsetAssign(0f, delta.y, 0f)
|
||||
}
|
||||
val xPriority = delta.x <= delta.z
|
||||
val xPriority = delta.x > delta.z
|
||||
if (delta.x != 0.0f && xPriority) {
|
||||
delta.x = collisionsToCheck.computeOffset(aabb, deltaPosition.x, Axes.X)
|
||||
aabb.offsetAssign(delta.x, 0f, 0f)
|
||||
|
@ -297,6 +297,6 @@ class Camera(
|
||||
companion object {
|
||||
private val CAMERA_UP_VEC3 = Vec3(0.0f, 1.0f, 0.0f)
|
||||
private const val PLAYER_HEIGHT = 1.3 // player is 1.8 blocks high, the camera is normally at 0.5. 1.8 - 0.5 = 1.13
|
||||
const val PLAYER_WIDTH = 0.6
|
||||
const val PLAYER_WIDTH = 0.60001
|
||||
}
|
||||
}
|
||||
|
@ -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.Directions
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
@ -27,6 +28,9 @@ import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
|
||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||
import de.bixilon.minosoft.gui.rendering.textures.TextureTransparencies
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3
|
||||
import glm_.Java
|
||||
import glm_.vec3.Vec3
|
||||
import glm_.vec3.Vec3i
|
||||
|
||||
class BlockRenderer : BlockRenderInterface {
|
||||
@ -36,18 +40,32 @@ class BlockRenderer : BlockRenderInterface {
|
||||
private val textureMapping: MutableMap<String, Texture> = mutableMapOf()
|
||||
override val faceBorderSizes: Array<Array<FaceSize>?> = arrayOfNulls(Directions.DIRECTIONS.size)
|
||||
override val transparentFaces: BooleanArray = BooleanArray(Directions.DIRECTIONS.size)
|
||||
private val directionMapping: HashBiMap<Directions, Directions> = HashBiMap.create()
|
||||
|
||||
constructor(data: JsonObject, parent: BlockModel) {
|
||||
val newElements = ElementRenderer.createElements(data, parent)
|
||||
val rotation = Java.glm.radians(data.toVec3())
|
||||
createDirectionMapping(rotation)
|
||||
val newElements = ElementRenderer.createElements(data, parent, rotation, directionMapping)
|
||||
// reverse drawing order (for e.g. grass block side overlays
|
||||
this.elements.addAll(newElements.reversed())
|
||||
textures.putAll(parent.textures)
|
||||
}
|
||||
|
||||
private fun createDirectionMapping(rotation: Vec3) {
|
||||
for (direction in Directions.DIRECTIONS) {
|
||||
try {
|
||||
directionMapping[direction] = ElementRenderer.getRotatedDirection(rotation, direction)
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constructor(data: List<JsonObject>, models: Map<ResourceLocation, BlockModel>) {
|
||||
for (state in data) {
|
||||
val rotation = Java.glm.radians(state.toVec3())
|
||||
createDirectionMapping(rotation)
|
||||
val parent = models[ResourceLocation(state["model"].asString)]!!
|
||||
val newElements = ElementRenderer.createElements(state, parent)
|
||||
val newElements = ElementRenderer.createElements(state, parent, rotation, directionMapping)
|
||||
this.elements.addAll(newElements)
|
||||
textures.putAll(parent.textures)
|
||||
}
|
||||
@ -104,7 +122,7 @@ class BlockRenderer : BlockRenderInterface {
|
||||
var neighbourFaceSize: Array<FaceSize>? = null
|
||||
val neighbourBlock = neighbourBlocks[direction.ordinal]
|
||||
// ToDo: We need to rotate the direction first and then rotate it
|
||||
neighbourBlock?.getBlockRenderer(blockPosition + direction)?.let {
|
||||
neighbourBlock?.getBlockRenderer(blockPosition + directionMapping[direction])?.let {
|
||||
if (it.transparentFaces[invertedDirection.ordinal]) {
|
||||
isNeighbourTransparent = true
|
||||
}
|
||||
|
@ -30,15 +30,13 @@ import de.bixilon.minosoft.gui.rendering.textures.TextureTransparencies
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.rotate
|
||||
import glm_.Java.Companion.glm
|
||||
import glm_.vec3.Vec3
|
||||
import glm_.vec3.Vec3i
|
||||
|
||||
class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boolean, rescale: Boolean) {
|
||||
class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boolean, rescale: Boolean, private val directionMapping: HashBiMap<Directions, Directions>) {
|
||||
val faceBorderSize: Array<FaceSize?> = arrayOfNulls(Directions.DIRECTIONS.size)
|
||||
private val faces: MutableMap<Directions, BlockModelFace> = mutableMapOf()
|
||||
private var transformedPositions: Array<Vec3> = parent.transformedPositions.clone()
|
||||
private val directionMapping: HashBiMap<Directions, Directions> = HashBiMap.create()
|
||||
private val from = parent.from
|
||||
private val to = parent.to
|
||||
|
||||
@ -48,8 +46,6 @@ class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boo
|
||||
direction.getFaceBorderSizes(from, to)?.let {
|
||||
faceBorderSize[direction.ordinal] = it
|
||||
}
|
||||
|
||||
directionMapping[direction] = getRotatedDirection(rotation, direction)
|
||||
parent.faces[direction]?.let {
|
||||
faces[direction] = BlockModelFace(it)
|
||||
}
|
||||
@ -116,14 +112,13 @@ class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boo
|
||||
0 to 1,
|
||||
)
|
||||
|
||||
fun createElements(state: JsonObject, parent: BlockModel): MutableList<ElementRenderer> {
|
||||
val rotation = glm.radians(state.asVec3())
|
||||
fun createElements(state: JsonObject, parent: BlockModel, rotation: Vec3, directionMapping: HashBiMap<Directions, Directions>): MutableList<ElementRenderer> {
|
||||
val uvLock = state["uvlock"]?.asBoolean ?: false
|
||||
val rescale = state["rescale"]?.asBoolean ?: false
|
||||
val parentElements = parent.elements
|
||||
val result: MutableList<ElementRenderer> = mutableListOf()
|
||||
for (parentElement in parentElements) {
|
||||
result.add(ElementRenderer(parentElement, rotation, uvLock, rescale))
|
||||
result.add(ElementRenderer(parentElement, rotation, uvLock, rescale, directionMapping))
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -162,7 +157,3 @@ class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun JsonObject.asVec3(): Vec3 {
|
||||
return Vec3(this["x"]?.asFloat ?: 0, this["y"]?.asFloat ?: 0, this["z"]?.asFloat ?: 0)
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ object VecUtil {
|
||||
val ONES_VEC3 = Vec3(1)
|
||||
|
||||
fun JsonElement.toVec3(): Vec3 {
|
||||
when (this) {
|
||||
is JsonArray -> return Vec3(this[0].asFloat, this[1].asFloat, this[2].asFloat)
|
||||
is JsonObject -> TODO()
|
||||
return when (this) {
|
||||
is JsonArray -> Vec3(this[0].asFloat, this[1].asFloat, this[2].asFloat)
|
||||
is JsonObject -> Vec3(this["x"]?.asFloat ?: 0, this["y"]?.asFloat ?: 0, this["z"]?.asFloat ?: 0)
|
||||
else -> throw IllegalArgumentException("Not a Vec3!")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user