wip render text on signs

This commit is contained in:
Bixilon 2022-04-21 02:50:30 +02:00
parent 69255ae57f
commit 6ab96cfcd6
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 21 additions and 14 deletions

View File

@ -21,6 +21,7 @@ import de.bixilon.minosoft.data.text.ChatColors
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.font.Font
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
@ -37,8 +38,7 @@ interface ChatComponentRenderer<T : ChatComponent> {
fun render3DFlat(matrix: Mat4, mesh: WorldMesh, text: T)
companion object : ChatComponentRenderer<ChatComponent> {
const val TEXT_BLOCK_RESOLUTION = 64
var a = 0.0f
const val TEXT_BLOCK_RESOLUTION = 128
override fun render(initialOffset: Vec2i, offset: Vec2i, size: Vec2i, element: Element, renderWindow: RenderWindow, consumer: GUIVertexConsumer?, options: GUIVertexOptions?, renderInfo: TextRenderInfo, text: ChatComponent): Boolean {
return when (text) {
@ -57,15 +57,9 @@ interface ChatComponentRenderer<T : ChatComponent> {
}
fun render3dFlat(renderWindow: RenderWindow, position: Vec3, scale: Float, rotation: Vec3, mesh: WorldMesh, text: ChatComponent) {
position.z = -1.0f
val positionMatrix = Mat4()
.rotateDegreesAssign(rotation)
.translateAssign(position)
a += 3.0f
if (a > 360) {
a = 0.0f
}
.rotateDegreesAssign(rotation)
val text = "abcdefghijkl"
@ -73,7 +67,7 @@ interface ChatComponentRenderer<T : ChatComponent> {
for ((index, char) in text.codePoints().toArray().withIndex()) {
val data = renderWindow.font[char] ?: continue
val color = ChatColors[index % ChatColors.VALUES.size]
val width = data.render3d(positionMatrix, mesh, color, false, false, false, false, false, scale) + 1.0f
val width = data.render3d(positionMatrix, mesh, color, false, false, false, false, false, scale) + Font.HORIZONTAL_SPACING
positionMatrix.translateAssign(Vec3((width / TEXT_BLOCK_RESOLUTION) * scale, 0, 0))
}
}

View File

@ -15,8 +15,11 @@ package de.bixilon.minosoft.gui.rendering.world.entities.renderer.sign
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.cast.CastUtil.nullCast
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.entities.block.SignBlockEntity
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.types.entity.sign.StandingSignBlock
import de.bixilon.minosoft.data.registries.blocks.types.entity.sign.WallSignBlock
import de.bixilon.minosoft.gui.rendering.RenderWindow
@ -34,16 +37,26 @@ class SignBlockEntityRenderer(
override fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array<BlockState?>, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean {
val block = this.blockState.block
if (position.x != 0 || position.y != 1 || position.z != 0) {
return false
}
if (block is StandingSignBlock) {
// println("Rendering standing sign at $position (${block.resourceLocation})")
} else if (block is WallSignBlock) {
println("Rendering wall sign at $position (${block.resourceLocation})")
val rotation = this.blockState.properties[BlockProperties.FACING].nullCast<Directions>() ?: Directions.NORTH
val yRotation = when (rotation) {
Directions.NORTH -> 0.0f
Directions.EAST -> 90.0f
Directions.SOUTH -> 180.0f
Directions.WEST -> 270.0f
else -> TODO()
}
val rotationVector = Vec3(180.0f, yRotation, 180.0f)
for ((index, line) in sign.lines.withIndex()) {
ChatComponentRenderer.render3dFlat(renderWindow, position.toVec3 + Vec3(0.95f, 0.75f - (index * 0.1f), 1.86f), 1.0f, rotationVector, mesh, line)
}
}
ChatComponentRenderer.render3dFlat(renderWindow, position.toVec3 + Vec3(0, 1.0f, 0.0f), 1.0f, Vec3(), mesh, sign.lines[0])
// ToDo
return true