mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
generic Mesh::drawQuad
This commit is contained in:
parent
74ada0ba02
commit
ab17e2697d
@ -32,6 +32,7 @@ import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.rotate
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3
|
||||
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
class ElementRenderer(
|
||||
@ -107,7 +108,7 @@ class ElementRenderer(
|
||||
val mesh = getMesh(context.meshCollection, texture.transparency)
|
||||
val texturePositions = face.getTexturePositionArray(realDirection)
|
||||
|
||||
for ((drawPositionIndex, texturePositionIndex) in DRAW_ODER) {
|
||||
for ((drawPositionIndex, texturePositionIndex) in Mesh.QUAD_DRAW_ODER) {
|
||||
val input = drawPositions[drawPositionIndex]
|
||||
val output = context.blockPosition.toVec3 + input + DRAW_OFFSET + context.offset
|
||||
|
||||
@ -130,14 +131,6 @@ class ElementRenderer(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val DRAW_ODER = arrayOf(
|
||||
0 to 1,
|
||||
3 to 2,
|
||||
2 to 3,
|
||||
2 to 3,
|
||||
1 to 0,
|
||||
0 to 1,
|
||||
)
|
||||
|
||||
fun createElements(data: JsonObject, model: BlockModel, rotation: Vec3, directionMapping: HashBiMap<Directions, Directions>): List<ElementRenderer> {
|
||||
val result: MutableList<ElementRenderer> = mutableListOf()
|
||||
|
@ -33,6 +33,7 @@ import de.bixilon.minosoft.gui.rendering.block.renderable.WorldEntryRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.block.renderable.block.ElementRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
||||
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||
import glm_.glm
|
||||
import glm_.vec2.Vec2
|
||||
@ -140,7 +141,7 @@ class FluidRenderer(
|
||||
|
||||
private fun createQuad(drawPositions: Array<Vec3>, texturePositions: Array<Vec2?>, texture: Texture, blockPosition: Vec3i, meshCollection: ChunkSectionMeshCollection, tintColor: RGBColor?, light: Int) {
|
||||
val mesh = ElementRenderer.getMesh(meshCollection, texture.transparency)
|
||||
for (vertex in ElementRenderer.DRAW_ODER) {
|
||||
for (vertex in Mesh.QUAD_DRAW_ODER) {
|
||||
mesh.addVertex(
|
||||
position = blockPosition plus drawPositions[vertex.first] plus ElementRenderer.DRAW_OFFSET,
|
||||
textureCoordinates = texturePositions[vertex.second]!!,
|
||||
|
@ -32,7 +32,6 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import glm_.func.rad
|
||||
import glm_.mat4x4.Mat4
|
||||
import glm_.mat4x4.Mat4d
|
||||
import glm_.vec2.Vec2
|
||||
import glm_.vec3.Vec3
|
||||
import glm_.vec3.Vec3d
|
||||
|
||||
@ -93,20 +92,18 @@ class SkyRenderer(
|
||||
|
||||
skySunMesh = SimpleTextureMesh()
|
||||
|
||||
fun addQuad(start: Vec3, end: Vec3, texture: Texture, tintColor: RGBColor) {
|
||||
skySunMesh.addVertex(Vec3(start.x, start.y, start.z), texture, Vec2(0.0, 0.0), tintColor)
|
||||
skySunMesh.addVertex(Vec3(end.x, end.y, start.z), texture, Vec2(0.0f, 1.0), tintColor)
|
||||
skySunMesh.addVertex(Vec3(end.x, end.y, end.z), texture, Vec2(1.0f, 1.0f), tintColor)
|
||||
skySunMesh.addVertex(Vec3(end.x, end.y, end.z), texture, Vec2(1.0f, 1.0f), tintColor)
|
||||
skySunMesh.addVertex(Vec3(start.x, start.y, end.z), texture, Vec2(0.0f, 1.0f), tintColor)
|
||||
skySunMesh.addVertex(Vec3(start.x, start.y, start.z), texture, Vec2(0.0f, 0.0f), tintColor)
|
||||
}
|
||||
|
||||
addQuad(
|
||||
skySunMesh.addQuad(
|
||||
start = Vec3(-0.15f, 1.0f, -0.15f),
|
||||
end = Vec3(+0.15f, 1.0f, +0.15f),
|
||||
texture = sunTexture,
|
||||
tintColor = ChatColors.WHITE.with(alpha = 1.0f - connection.world.rainGradient), // ToDo: Depends on time
|
||||
vertexConsumer = { position, textureCoordinate ->
|
||||
skySunMesh.addVertex(
|
||||
position = position,
|
||||
texture = sunTexture,
|
||||
textureCoordinates = textureCoordinate,
|
||||
tintColor = ChatColors.WHITE.with(alpha = 1.0f - connection.world.rainGradient), // ToDo: Depends on time
|
||||
)
|
||||
}
|
||||
)
|
||||
skySunMesh.load()
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package de.bixilon.minosoft.gui.rendering.util.mesh
|
||||
import de.bixilon.minosoft.data.registries.AABB
|
||||
import de.bixilon.minosoft.data.registries.VoxelShape
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.block.renderable.block.ElementRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||
import de.bixilon.minosoft.util.BitByte.isBit
|
||||
import de.bixilon.minosoft.util.MMath.positiveNegative
|
||||
@ -49,7 +48,7 @@ open class LineMesh : GenericColorMesh() {
|
||||
end + normal1 * normal1Multiplier * halfLineWidth + direction * halfLineWidth,
|
||||
end + normal2 * normal2Multiplier * halfLineWidth + direction * halfLineWidth,
|
||||
)
|
||||
for ((_, positionIndex) in ElementRenderer.DRAW_ODER) {
|
||||
for ((_, positionIndex) in Mesh.QUAD_DRAW_ODER) {
|
||||
addVertex(positions[positionIndex], color)
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct.Companion.BYTES
|
||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||
import de.bixilon.minosoft.util.Util
|
||||
import de.bixilon.minosoft.util.collections.ArrayFloatList
|
||||
import glm_.vec2.Vec2
|
||||
import glm_.vec3.Vec3
|
||||
import org.lwjgl.opengl.GL11.GL_TRIANGLES
|
||||
import org.lwjgl.opengl.GL11.glDrawArrays
|
||||
import org.lwjgl.opengl.GL30.*
|
||||
@ -102,9 +104,38 @@ abstract class Mesh(
|
||||
state = MeshStates.UNLOADED
|
||||
}
|
||||
|
||||
fun addQuad(start: Vec3, end: Vec3, textureStart: Vec2 = Vec2(0.0f, 0.0f), textureEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, textureCoordinate: Vec2) -> Unit) {
|
||||
val positions = arrayOf(
|
||||
start,
|
||||
Vec3(start.x, start.y, end.z),
|
||||
end,
|
||||
Vec3(end.x, end.y, start.z),
|
||||
)
|
||||
val texturePositions = arrayOf(
|
||||
Vec2(textureEnd.x, textureStart.y),
|
||||
textureStart,
|
||||
Vec2(textureStart.x, textureEnd.y),
|
||||
textureEnd,
|
||||
)
|
||||
for ((vertexIndex, textureIndex) in QUAD_DRAW_ODER) {
|
||||
vertexConsumer.invoke(positions[vertexIndex], texturePositions[textureIndex])
|
||||
}
|
||||
}
|
||||
|
||||
enum class MeshStates {
|
||||
PREPARING,
|
||||
LOADED,
|
||||
UNLOADED,
|
||||
}
|
||||
|
||||
companion object {
|
||||
val QUAD_DRAW_ODER = arrayOf(
|
||||
0 to 1,
|
||||
3 to 2,
|
||||
2 to 3,
|
||||
2 to 3,
|
||||
1 to 0,
|
||||
0 to 1,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user