mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
world-renderer: mesh: calculate max positions (for frustum culling)
This commit is contained in:
parent
8bd1c5ff32
commit
821a849e25
@ -90,7 +90,7 @@ class WorldRenderer(
|
||||
|
||||
mesh = sectionPreparer.prepare(section)
|
||||
|
||||
// for (i in 0 until 1000)
|
||||
for (i in 0 until 1000)
|
||||
mesh = sectionPreparer.prepare(section)
|
||||
|
||||
/*
|
||||
|
@ -13,9 +13,7 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.block.mesh
|
||||
|
||||
import de.bixilon.minosoft.data.registries.AABB
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.EMPTY
|
||||
import glm_.vec3.Vec3i
|
||||
|
||||
class ChunkSectionMeshes(
|
||||
@ -28,11 +26,9 @@ class ChunkSectionMeshes(
|
||||
var transparentMesh: ChunkSectionMesh? = ChunkSectionMesh(renderWindow)
|
||||
private set
|
||||
|
||||
val minPosition = Vec3i.EMPTY
|
||||
val maxPosition = Vec3i.EMPTY
|
||||
|
||||
lateinit var aabb: AABB
|
||||
private set
|
||||
// used for frustum culling
|
||||
val minPosition = Vec3i(16)
|
||||
val maxPosition = Vec3i(0)
|
||||
|
||||
@Synchronized
|
||||
fun load() {
|
||||
@ -58,4 +54,26 @@ class ChunkSectionMeshes(
|
||||
mesh.load()
|
||||
}
|
||||
}
|
||||
|
||||
fun addBlock(x: Int, y: Int, z: Int) {
|
||||
if (x < minPosition.x) {
|
||||
minPosition.x = x
|
||||
}
|
||||
if (y < minPosition.y) {
|
||||
minPosition.y = y
|
||||
}
|
||||
if (z < minPosition.z) {
|
||||
minPosition.z = z
|
||||
}
|
||||
|
||||
if (x > maxPosition.x) {
|
||||
maxPosition.x = x
|
||||
}
|
||||
if (y > maxPosition.y) {
|
||||
maxPosition.y = y
|
||||
}
|
||||
if (z > maxPosition.z) {
|
||||
maxPosition.z = z
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ class CullSectionPreparer(
|
||||
for (y in 0 until ProtocolDefinition.SECTION_HEIGHT_Y) {
|
||||
for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) {
|
||||
block = section.blocks[ChunkSection.getIndex(x, y, z)]
|
||||
val model = block?.model ?: continue
|
||||
|
||||
// ToDo: Chunk borders
|
||||
neighbours[Directions.DOWN.ordinal] = if (y == 0) {
|
||||
@ -59,7 +60,10 @@ class CullSectionPreparer(
|
||||
}
|
||||
|
||||
random.setSeed(VecUtil.generatePositionHash(x, y, z))
|
||||
block?.model?.singleRender(Vec3i(x, y, z), mesh, random, neighbours, 0xFF, floatArrayOf(1.0f, 1.0f, 1.0f, 1.0f))
|
||||
val rendered = model.singleRender(Vec3i(x, y, z), mesh, random, neighbours, 0xFF, floatArrayOf(1.0f, 1.0f, 1.0f, 1.0f))
|
||||
if (rendered) {
|
||||
mesh.addBlock(x, y, z)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +35,13 @@ class MultipartBakedModel(
|
||||
return 0xFF
|
||||
}
|
||||
|
||||
override fun singleRender(position: Vec3i, mesh: ChunkSectionMeshes, random: Random, neighbours: Array<BlockState?>, light: Int, ambientLight: FloatArray) {
|
||||
override fun singleRender(position: Vec3i, mesh: ChunkSectionMeshes, random: Random, neighbours: Array<BlockState?>, light: Int, ambientLight: FloatArray): Boolean {
|
||||
var rendered = false
|
||||
for (model in models) {
|
||||
model.singleRender(position, mesh, random, neighbours, light, ambientLight)
|
||||
if (model.singleRender(position, mesh, random, neighbours, light, ambientLight) && !rendered) {
|
||||
rendered = true
|
||||
}
|
||||
}
|
||||
return rendered
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ class WeightedBakedModel(
|
||||
return getModel(random).getLight(position, random, side, lightAccessor)
|
||||
}
|
||||
|
||||
override fun singleRender(position: Vec3i, mesh: ChunkSectionMeshes, random: Random, neighbours: Array<BlockState?>, light: Int, ambientLight: FloatArray) {
|
||||
getModel(random).singleRender(position, mesh, random, neighbours, light, ambientLight)
|
||||
override fun singleRender(position: Vec3i, mesh: ChunkSectionMeshes, random: Random, neighbours: Array<BlockState?>, light: Int, ambientLight: FloatArray): Boolean {
|
||||
return getModel(random).singleRender(position, mesh, random, neighbours, light, ambientLight)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ interface BakedBlockModel : BakedModel {
|
||||
fun getSize(random: Random, direction: Directions): Array<FaceSize>
|
||||
|
||||
// ToDo: Tint
|
||||
fun singleRender(position: Vec3i, mesh: ChunkSectionMeshes, random: Random, neighbours: Array<BlockState?>, light: Int, ambientLight: FloatArray)
|
||||
fun singleRender(position: Vec3i, mesh: ChunkSectionMeshes, random: Random, neighbours: Array<BlockState?>, light: Int, ambientLight: FloatArray): Boolean
|
||||
|
||||
// ToDo: Get ambient light
|
||||
fun getLight(position: Vec3i, random: Random, side: Directions, lightAccessor: LightAccessor): Int
|
||||
|
@ -35,8 +35,9 @@ class BakedBlockStateModel(
|
||||
return sizes[direction.ordinal]
|
||||
}
|
||||
|
||||
override fun singleRender(position: Vec3i, mesh: ChunkSectionMeshes, random: Random, neighbours: Array<BlockState?>, light: Int, ambientLight: FloatArray) {
|
||||
override fun singleRender(position: Vec3i, mesh: ChunkSectionMeshes, random: Random, neighbours: Array<BlockState?>, light: Int, ambientLight: FloatArray): Boolean {
|
||||
val floatPosition = position.toVec3().array
|
||||
var rendered = false
|
||||
for ((index, faces) in faces.withIndex()) {
|
||||
val direction = Directions.VALUES[index]
|
||||
val neighbour = neighbours[index]?.model
|
||||
@ -50,8 +51,12 @@ class BakedBlockStateModel(
|
||||
continue
|
||||
}
|
||||
face.singleRender(floatPosition, mesh, light, ambientLight)
|
||||
if (!rendered) {
|
||||
rendered = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return rendered
|
||||
}
|
||||
|
||||
override fun greedyRender(start: Vec3i, end: Vec3i, side: Directions, mesh: ChunkSectionMesh, light: Int) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user