improve sign rendering

This commit is contained in:
Bixilon 2022-04-22 01:19:20 +02:00
parent 2ae7c2575c
commit 4f8d10db4c
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 15 additions and 16 deletions

View File

@ -144,7 +144,7 @@ class CharData(
}
override fun addCache(cache: GUIMeshCache) {
throw IllegalStateException()
throw IllegalStateException("This is not hud!")
}
}

View File

@ -57,18 +57,22 @@ interface ChatComponentRenderer<T : ChatComponent> {
}
fun render3dFlat(renderWindow: RenderWindow, position: Vec3, scale: Float, rotation: Vec3, mesh: WorldMesh, text: ChatComponent) {
val rotationMatrix = Mat4()
.rotateDegreesAssign(rotation)
.translateAssign(Vec3(0, 0, -1))
val positionMatrix = Mat4()
.translateAssign(position)
.rotateDegreesAssign(rotation)
val text = "abcdefghijkl"
val transformMatrix = positionMatrix * rotationMatrix
val text = "abcdefghijklmnop"
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) + Font.HORIZONTAL_SPACING
positionMatrix.translateAssign(Vec3((width / TEXT_BLOCK_RESOLUTION) * scale, 0, 0))
val width = data.render3d(transformMatrix, mesh, color, false, false, false, false, false, scale) + Font.HORIZONTAL_SPACING
transformMatrix.translateAssign(Vec3((width / TEXT_BLOCK_RESOLUTION) * scale, 0, 0))
}
}
}

View File

@ -43,17 +43,8 @@ class SignBlockEntityRenderer(
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(PIXEL_SCALE * 5, 0.75f - (index * 0.11f), 0.126f), 1.2f, Vec3(0.0f, 0.0f, 0.0f), mesh, line)
}
}
@ -61,4 +52,8 @@ class SignBlockEntityRenderer(
return true
}
companion object {
private const val PIXEL_SCALE = 1.0f / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION
}
}

View File

@ -166,7 +166,7 @@ class SolidCullSectionPreparer(
random.setSeed(0L)
}
tints = tintColorCalculator.getAverageTint(chunk, neighbourChunks, blockState, x, y, z)
rendered = false // rendered = model.singleRender(position, mesh, random, blockState, neighbourBlocks, light, ambientLight, tints)
rendered = model.singleRender(position, mesh, random, blockState, neighbourBlocks, light, ambientLight, tints)
if (blockEntityModel is MeshedBlockEntityRenderer<*>) {
rendered = blockEntityModel.singleRender(position, mesh, random, blockState, neighbourBlocks, light, ambientLight, tints) || rendered