rendering: wip: frustum cull entity hit box

This commit is contained in:
Bixilon 2021-06-09 22:42:53 +02:00 committed by Lukas
parent 4ed60ee19e
commit 3ecf1ef5bf
3 changed files with 18 additions and 4 deletions

View File

@ -21,7 +21,7 @@ data class EntityHitBoxConfig(
@Json(name = "enabled") val enabled: Boolean = true,
@Json(name = "disable_z_buffer") val disableZBuffer: Boolean = false,
@Json(name = "hit_box_color") val hitBoxColor: RGBColor = ChatColors.WHITE,
@Json(name = "eye_height_color") val eyeHeightColor: RGBColor = ChatColors.RED,
@Json(name = "eye_height_color") val eyeHeightColor: RGBColor = ChatColors.DARK_RED,
@Json(name = "render_invisible_entities") val renderInvisibleEntities: Boolean = false,
@Json(name = "invisible_entities_color") val invisibleEntitiesColor: RGBColor = ChatColors.GREEN,
)

View File

@ -74,17 +74,26 @@ class EntityHitBoxRenderer(
}
renderWindow.shaderManager.genericColorShader.use()
fun draw(mesh: EntityHitBoxMesh?) {
mesh ?: return
// ToDo: Improve this
if (!renderWindow.inputHandler.camera.frustum.containsAABB(mesh.aabb)) {
return
}
mesh.draw()
}
for ((entity, mesh) in meshes.toSynchronizedMap()) {
val aabb = entity.aabb
if (aabb != mesh.aabb) {
this.meshes.remove(entity)
mesh.unload()
createMesh(entity)?.draw()
draw(createMesh(entity))
continue
}
mesh.draw()
draw(mesh)
}
@ -96,7 +105,7 @@ class EntityHitBoxRenderer(
companion object : RendererBuilder<EntityHitBoxRenderer> {
override val RESOURCE_LOCATION = ResourceLocation("minosoft:entity_hitbox")
override val RESOURCE_LOCATION = ResourceLocation("minosoft:entity_hit_box")
override fun build(connection: PlayConnection, renderWindow: RenderWindow): EntityHitBoxRenderer {
return EntityHitBoxRenderer(connection, renderWindow)

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.input.camera
import de.bixilon.minosoft.gui.rendering.RenderConstants
import de.bixilon.minosoft.gui.rendering.chunk.models.AABB
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
import de.bixilon.minosoft.gui.rendering.util.VecUtil.of
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
@ -169,6 +170,10 @@ class Frustum(private val camera: Camera) {
return containsRegion(Vec3(from), to)
}
fun containsAABB(aabb: AABB): Boolean {
return containsRegion(Vec3(aabb.min), Vec3(aabb.max))
}
private enum class Planes {
LEFT,
RIGHT,