mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
fix sign text flipping
This commit is contained in:
parent
0f3e15cd82
commit
c78ace5f4c
@ -65,15 +65,14 @@ class SignBlockEntityRenderer(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderText(offset: FloatArray, rotationVector: Vec3, yRotation: Float, mesh: ChunkMesh, light: Int) {
|
private fun renderText(offset: FloatArray, rotationVector: Vec3, yRotation: Float, mesh: SingleChunkMesh, light: Int) {
|
||||||
val textPosition = offset.toVec3() + rotationVector
|
val textPosition = offset.toVec3() + rotationVector
|
||||||
|
|
||||||
val textMesh = mesh.textMesh!!
|
|
||||||
var primitives = 0
|
var primitives = 0
|
||||||
for (line in sign.lines) {
|
for (line in sign.lines) {
|
||||||
primitives += ChatComponentRenderer.calculatePrimitiveCount(line)
|
primitives += ChatComponentRenderer.calculatePrimitiveCount(line)
|
||||||
}
|
}
|
||||||
textMesh.data.ensureSize(primitives * textMesh.order.size * SingleChunkMesh.WorldMeshStruct.FLOATS_PER_VERTEX)
|
mesh.data.ensureSize(primitives * mesh.order.size * SingleChunkMesh.WorldMeshStruct.FLOATS_PER_VERTEX)
|
||||||
|
|
||||||
val alignment = context.connection.profiles.block.rendering.entities.sign.fontAlignment
|
val alignment = context.connection.profiles.block.rendering.entities.sign.fontAlignment
|
||||||
|
|
||||||
@ -90,7 +89,7 @@ class SignBlockEntityRenderer(
|
|||||||
|
|
||||||
val rotationVector = Vec3(X_OFFSET, 17.5f / BLOCK_SIZE - Y_OFFSET, 9.0f / BLOCK_SIZE + Z_OFFSET)
|
val rotationVector = Vec3(X_OFFSET, 17.5f / BLOCK_SIZE - Y_OFFSET, 9.0f / BLOCK_SIZE + Z_OFFSET)
|
||||||
rotationVector.signRotate(yRotation.rad)
|
rotationVector.signRotate(yRotation.rad)
|
||||||
renderText(offset, rotationVector, yRotation, mesh, light)
|
renderText(offset, rotationVector, yRotation, mesh.textMesh!!, light)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderWallText(position: FloatArray, mesh: ChunkMesh, light: Int) {
|
private fun renderWallText(position: FloatArray, mesh: ChunkMesh, light: Int) {
|
||||||
@ -104,7 +103,7 @@ class SignBlockEntityRenderer(
|
|||||||
|
|
||||||
val rotationVector = Vec3(X_OFFSET, 12.5f / BLOCK_SIZE - Y_OFFSET, 2.0f / BLOCK_SIZE + Z_OFFSET)
|
val rotationVector = Vec3(X_OFFSET, 12.5f / BLOCK_SIZE - Y_OFFSET, 2.0f / BLOCK_SIZE + Z_OFFSET)
|
||||||
rotationVector.signRotate(yRotation.rad)
|
rotationVector.signRotate(yRotation.rad)
|
||||||
renderText(position, rotationVector, yRotation, mesh, light)
|
renderText(position, rotationVector, yRotation, mesh.textMesh!!, light)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Vec3.signRotate(yRotation: Float) {
|
private fun Vec3.signRotate(yRotation: Float) {
|
||||||
|
@ -63,7 +63,6 @@ class SingleChunkMesh(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
|
|
||||||
val TRIANGLE_ORDER = intArrayOf(
|
val TRIANGLE_ORDER = intArrayOf(
|
||||||
0, 0,
|
0, 0,
|
||||||
3, 3,
|
3, 3,
|
||||||
|
@ -18,6 +18,8 @@ import de.bixilon.kotlinglm.vec2.Vec2
|
|||||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||||
import de.bixilon.minosoft.gui.rendering.chunk.mesh.SingleChunkMesh
|
import de.bixilon.minosoft.gui.rendering.chunk.mesh.SingleChunkMesh
|
||||||
import de.bixilon.minosoft.gui.rendering.font.renderer.component.ChatComponentRenderer
|
import de.bixilon.minosoft.gui.rendering.font.renderer.component.ChatComponentRenderer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.renderer.properties.FontProperties
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.renderer.properties.FormattingProperties
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMeshCache
|
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMeshCache
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
|
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
|
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
|
||||||
@ -34,6 +36,28 @@ class WorldGUIConsumer(val mesh: SingleChunkMesh, val transform: Mat4, val light
|
|||||||
mesh.addVertex(transformed, uv, (texture as Texture?) ?: whiteTexture.texture, tint.rgb, light)
|
mesh.addVertex(transformed, uv, (texture as Texture?) ?: whiteTexture.texture, tint.rgb, light)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun addChar(start: Vec2, end: Vec2, texture: Texture?, uvStart: Vec2, uvEnd: Vec2, italic: Boolean, tint: RGBColor, options: GUIVertexOptions?) {
|
||||||
|
// TODO: remove that override and change vertex order globally
|
||||||
|
val topOffset = if (italic) (end.y - start.y) / FontProperties.CHAR_BASE_HEIGHT * FormattingProperties.ITALIC_OFFSET else 0.0f
|
||||||
|
|
||||||
|
val positions = arrayOf(
|
||||||
|
Vec2(start.x + topOffset, start.y),
|
||||||
|
Vec2(end.x + topOffset, start.y),
|
||||||
|
end,
|
||||||
|
Vec2(start.x, end.y),
|
||||||
|
)
|
||||||
|
val texturePositions = arrayOf(
|
||||||
|
uvStart,
|
||||||
|
Vec2(uvEnd.x, uvStart.y),
|
||||||
|
uvEnd,
|
||||||
|
Vec2(uvStart.x, uvEnd.y),
|
||||||
|
)
|
||||||
|
|
||||||
|
for (index in 0 until order.size step 2) {
|
||||||
|
addVertex(positions[order[index]], texture, texturePositions[order[index + 1]], tint, options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun addCache(cache: GUIMeshCache) {
|
override fun addCache(cache: GUIMeshCache) {
|
||||||
throw IllegalStateException("This is not hud!")
|
throw IllegalStateException("This is not hud!")
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import de.bixilon.minosoft.data.text.ChatComponent
|
|||||||
import de.bixilon.minosoft.data.text.EmptyComponent
|
import de.bixilon.minosoft.data.text.EmptyComponent
|
||||||
import de.bixilon.minosoft.data.text.TextComponent
|
import de.bixilon.minosoft.data.text.TextComponent
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderContext
|
import de.bixilon.minosoft.gui.rendering.RenderContext
|
||||||
import de.bixilon.minosoft.gui.rendering.chunk.mesh.ChunkMesh
|
|
||||||
import de.bixilon.minosoft.gui.rendering.chunk.mesh.SingleChunkMesh
|
import de.bixilon.minosoft.gui.rendering.chunk.mesh.SingleChunkMesh
|
||||||
import de.bixilon.minosoft.gui.rendering.font.WorldGUIConsumer
|
import de.bixilon.minosoft.gui.rendering.font.WorldGUIConsumer
|
||||||
import de.bixilon.minosoft.gui.rendering.font.manager.FontManager
|
import de.bixilon.minosoft.gui.rendering.font.manager.FontManager
|
||||||
@ -53,17 +52,16 @@ interface ChatComponentRenderer<T : ChatComponent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun render3dFlat(context: RenderContext, position: Vec3, properties: TextRenderProperties, rotation: Vec3, maxSize: Vec2, mesh: ChunkMesh, text: ChatComponent, light: Int): TextRenderInfo {
|
fun render3dFlat(context: RenderContext, position: Vec3, properties: TextRenderProperties, rotation: Vec3, maxSize: Vec2, mesh: SingleChunkMesh, text: ChatComponent, light: Int): TextRenderInfo {
|
||||||
val matrix = Mat4()
|
val matrix = Mat4()
|
||||||
.translateAssign(position)
|
.translateAssign(position)
|
||||||
.rotateDegreesAssign(rotation)
|
.rotateDegreesAssign(rotation)
|
||||||
.translateAssign(Vec3(0, 0, -1))
|
.translateAssign(Vec3(0, 0, -1))
|
||||||
|
|
||||||
val textMesh = mesh.textMesh!!
|
|
||||||
val primitives = calculatePrimitiveCount(text)
|
val primitives = calculatePrimitiveCount(text)
|
||||||
textMesh.data.ensureSize(primitives * textMesh.order.size * SingleChunkMesh.WorldMeshStruct.FLOATS_PER_VERTEX)
|
mesh.data.ensureSize(primitives * mesh.order.size * SingleChunkMesh.WorldMeshStruct.FLOATS_PER_VERTEX)
|
||||||
|
|
||||||
val consumer = WorldGUIConsumer(textMesh, matrix, light)
|
val consumer = WorldGUIConsumer(mesh, matrix, light)
|
||||||
|
|
||||||
val info = TextRenderInfo(maxSize)
|
val info = TextRenderInfo(maxSize)
|
||||||
render(TextOffset(), context.font, properties, info, null, null, text)
|
render(TextOffset(), context.font, properties, info, null, null, text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user