mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
3d text: light
This commit is contained in:
parent
d152e8dc91
commit
e2cbcaadb2
@ -128,19 +128,19 @@ class CharData(
|
||||
return (width * scale).ceil
|
||||
}
|
||||
|
||||
fun render3d(transform: Mat4, mesh: WorldMesh, color: RGBColor, shadow: Boolean, italic: Boolean, bold: Boolean, strikethrough: Boolean, underlined: Boolean, scale: Float): Float {
|
||||
val consumer = MeshConsumer(mesh.opaqueMesh!!, transform)
|
||||
fun render3d(transform: Mat4, mesh: WorldMesh, color: RGBColor, shadow: Boolean, italic: Boolean, bold: Boolean, strikethrough: Boolean, underlined: Boolean, scale: Float, light: Int): Float {
|
||||
val consumer = MeshConsumer(mesh.opaqueMesh!!, transform, light)
|
||||
render(Vec2i(0, 0), color, shadow, italic, bold, strikethrough, underlined, consumer, null, scale)
|
||||
return width.toFloat()
|
||||
}
|
||||
|
||||
|
||||
private class MeshConsumer(val mesh: SingleWorldMesh, val transform: Mat4) : GUIVertexConsumer {
|
||||
private class MeshConsumer(val mesh: SingleWorldMesh, val transform: Mat4, val light: Int) : GUIVertexConsumer {
|
||||
override val order: Array<Pair<Int, Int>> get() = mesh.order
|
||||
|
||||
override fun addVertex(position: Vec2t<*>, texture: AbstractTexture, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
val transformed = transform * Vec4(position.x.toFloat() / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION, -position.y.toFloat() / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION, 1.0f, 1.0f)
|
||||
mesh.addVertex(transformed.array, uv, texture, tint.rgb, 0xFF)
|
||||
mesh.addVertex(transformed.array, uv, texture, tint.rgb, light)
|
||||
}
|
||||
|
||||
override fun addCache(cache: GUIMeshCache) {
|
||||
|
@ -56,7 +56,7 @@ interface ChatComponentRenderer<T : ChatComponent> {
|
||||
}
|
||||
}
|
||||
|
||||
fun render3dFlat(renderWindow: RenderWindow, position: Vec3, scale: Float, rotation: Vec3, mesh: WorldMesh, text: ChatComponent) {
|
||||
fun render3dFlat(renderWindow: RenderWindow, position: Vec3, scale: Float, rotation: Vec3, mesh: WorldMesh, text: ChatComponent, light: Int) {
|
||||
val rotationMatrix = Mat4()
|
||||
.rotateDegreesAssign(rotation)
|
||||
.translateAssign(Vec3(0, 0, -1))
|
||||
@ -71,7 +71,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(transformMatrix, mesh, color, false, false, false, false, false, scale) + Font.HORIZONTAL_SPACING
|
||||
val width = data.render3d(transformMatrix, mesh, color, shadow = false, italic = false, bold = false, strikethrough = false, underlined = false, scale = scale, light = light) + Font.HORIZONTAL_SPACING
|
||||
transformMatrix.translateAssign(Vec3((width / TEXT_BLOCK_RESOLUTION) * scale, 0, 0))
|
||||
}
|
||||
}
|
||||
|
@ -44,13 +44,13 @@ class SignBlockEntityRenderer(
|
||||
if (block is StandingSignBlock) {
|
||||
// println("Rendering standing sign at $position (${block.resourceLocation})")
|
||||
} else if (block is WallSignBlock) {
|
||||
renderWallText(position, mesh, blockState)
|
||||
renderWallText(position, mesh, light[6].toInt())
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun renderWallText(position: Vec3i, mesh: WorldMesh, blockState: BlockState) {
|
||||
private fun renderWallText(position: Vec3i, mesh: WorldMesh, light: Int) {
|
||||
val yRotation = when (val rotation = this.blockState.properties[BlockProperties.FACING].nullCast<Directions>() ?: Directions.NORTH) {
|
||||
Directions.SOUTH -> 0.0f
|
||||
Directions.EAST -> 90.0f
|
||||
@ -64,7 +64,7 @@ class SignBlockEntityRenderer(
|
||||
val textPosition = position.toVec3 + rotationVector
|
||||
|
||||
for (line in sign.lines) {
|
||||
ChatComponentRenderer.render3dFlat(renderWindow, textPosition, TEXT_SCALE, Vec3(0.0f, yRotation, 0.0f), mesh, line)
|
||||
ChatComponentRenderer.render3dFlat(renderWindow, textPosition, TEXT_SCALE, Vec3(0.0f, yRotation, 0.0f), mesh, line, light)
|
||||
textPosition.y -= 0.11f
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user