mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 18:34:56 -04:00
builder apply (multipart): combine model to built one
This commit is contained in:
parent
6cd22eed73
commit
6bf89cf3f5
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user