3d: fix font spacing

This commit is contained in:
Bixilon 2022-04-22 17:46:26 +02:00
parent d276de0bbb
commit 1bbeb91a4e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 11 additions and 9 deletions

View File

@ -130,7 +130,7 @@ class CharData(
fun render3d(transform: Mat4, mesh: SingleWorldMesh, color: RGBColor, shadow: Boolean, italic: Boolean, bold: Boolean, strikethrough: Boolean, underlined: Boolean, scale: Float, light: Int): Float {
val consumer = MeshConsumer(mesh, transform, light)
render(Vec2i(0, 0), color, shadow, italic, bold, strikethrough, underlined, consumer, null, scale)
return width.toFloat()
return scaledWidth.toFloat()
}

View File

@ -39,16 +39,14 @@ object FontLoader : DefaultFactory<FontProviderFactory<*>>(
val providersRaw = fontIndex["providers"].listCast<Map<String, Any>>()!!
val providers: Array<FontProvider?> = arrayOfNulls(providersRaw.size)
val fontLatch = CountUpAndDownLatch(1, latch)
val fontLatch = CountUpAndDownLatch(providersRaw.size, latch)
for ((index, provider) in providersRaw.withIndex()) {
val type = provider["type"].toResourceLocation()
fontLatch.inc()
DefaultThreadPool += {
providers[index] = this[type].check { "Unknown font provider type $type" }.build(renderWindow, provider)
fontLatch.dec()
}
}
fontLatch.dec()
fontLatch.await()
return Font(

View File

@ -191,10 +191,14 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
}
override fun render3dFlat(renderWindow: RenderWindow, matrix: Mat4, scale: Float, mesh: SingleWorldMesh, text: TextComponent, light: Int) {
for ((index, char) in text.message.codePoints().toArray().withIndex()) {
val color = text.color ?: ChatColors.BLACK
val italic = text.formatting.contains(PreChatFormattingCodes.ITALIC)
val bold = text.formatting.contains(PreChatFormattingCodes.BOLD)
val strikethrough = text.formatting.contains(PreChatFormattingCodes.STRIKETHROUGH)
val underlined = text.formatting.contains(PreChatFormattingCodes.UNDERLINED)
for (char in text.message.codePoints()) {
val data = renderWindow.font[char] ?: continue
val color = ChatColors[index % ChatColors.VALUES.size]
val width = data.render3d(matrix, mesh, color, shadow = false, italic = false, bold = false, strikethrough = false, underlined = false, scale = scale, light = light) + Font.HORIZONTAL_SPACING
val width = data.render3d(matrix, mesh, color, shadow = false, italic = italic, bold = bold, strikethrough = strikethrough, underlined = underlined, scale = scale, light = light) + Font.HORIZONTAL_SPACING
matrix.translateAssign(Vec3((width / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION) * scale, 0, 0))
}
}

View File

@ -93,9 +93,9 @@ class SignBlockEntityRenderer(
companion object {
private const val PIXEL_SCALE = 1.0f / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION
private const val TEXT_SCALE = 1.2f
private const val TEXT_SCALE = 1.35f
private const val Z_OFFSET = 0.001f
private const val X_OFFSET = PIXEL_SCALE * 5
private const val X_OFFSET = PIXEL_SCALE * 6
private const val Y_OFFSET = 0.03f
}
}