builder apply (multipart): combine model to built one

This commit is contained in:
Bixilon 2023-04-28 15:22:42 +02:00
parent 6cd22eed73
commit 6bf89cf3f5
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 72 additions and 1 deletions

View File

@ -13,10 +13,15 @@
package de.bixilon.minosoft.gui.rendering.models.block.state.builder
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.gui.rendering.models.block.state.apply.BlockStateApply
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedFace
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedModel
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakingUtil.compact
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.SideSize
import de.bixilon.minosoft.gui.rendering.models.block.state.render.BlockRender
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
class BuilderApply(
val applies: List<BlockStateApply>
@ -37,6 +42,32 @@ class BuilderApply(
if (static.isEmpty() && dynamic.isEmpty()) return null
TODO("Can not combine them yet")
val combined = static.combine()
if (dynamic.isEmpty()) return combined
return BuiltModel(combined, dynamic.toTypedArray())
}
private fun List<BakedModel>.combine(): BakedModel {
val faces: Array<MutableList<BakedFace>> = Array(Directions.SIZE) { mutableListOf() }
val sizes: Array<MutableList<SideSize.FaceSize>> = Array(Directions.SIZE) { mutableListOf() }
var particle: AbstractTexture? = null
for (model in this) {
if (particle == null) {
particle = model.particle
}
for (direction in Directions) {
faces[direction.ordinal] += model.faces[direction.ordinal]
sizes[direction.ordinal] += model.sizes[direction.ordinal].sizes
}
}
// TODO: sizes
return BakedModel(faces.compact(), emptyArray(), particle)
}
}

View File

@ -0,0 +1,40 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.models.block.state.builder
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.world.positions.BlockPosition
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedModel
import de.bixilon.minosoft.gui.rendering.models.block.state.render.BlockRender
import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh
import java.util.*
class BuiltModel(
// TODO: this fucks up the rendering order, because it mixes static models with dynamic ones
val model: BakedModel,
val dynamic: Array<BlockRender>,
) : BlockRender {
override fun render(position: BlockPosition, mesh: WorldMesh, random: Random?, state: BlockState, neighbours: Array<BlockState?>, light: ByteArray, tints: IntArray?): Boolean {
var rendered = model.render(position, mesh, random, state, neighbours, light, tints)
for (dynamic in this.dynamic) {
if (dynamic.render(position, mesh, random, state, neighbours, light, tints)) {
rendered = true
}
}
return rendered
}
}