rendering: fix multipart rendering, allow file: urls in pixlyzer url

This commit is contained in:
Bixilon 2021-04-09 00:44:58 +02:00
parent 1c0e1acb2e
commit b72f40e01a
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 90 additions and 19 deletions

View File

@ -66,11 +66,13 @@ interface FileAssetsManager : AssetsManager {
return verifyAssetHash(hash, true) return verifyAssetHash(hash, true)
} }
fun downloadAsset(url: String, hash: String, compress: Boolean) { fun downloadAsset(url: String, hash: String, compress: Boolean, checkURL: Boolean = true) {
if (verifyAssetHash(hash, compress)) { if (verifyAssetHash(hash, compress)) {
return return
} }
if (checkURL) {
Util.checkURL(url) Util.checkURL(url)
}
Log.debug("Downloading %s -> %s", url, hash) Log.debug("Downloading %s -> %s", url, hash)
if (compress) { if (compress) {
Util.downloadFileAsGz(url, getAssetDiskPath(hash)) Util.downloadFileAsGz(url, getAssetDiskPath(hash))

View File

@ -127,7 +127,7 @@ class MinecraftAssetsManager(
"hashPrefix" to hash.substring(0, 2), "hashPrefix" to hash.substring(0, 2),
"fullHash" to hash "fullHash" to hash
) )
), hash, false) ), hash, compress = false, checkURL = false)
} }
else -> { else -> {
} }

View File

@ -13,7 +13,6 @@
package de.bixilon.minosoft.data.mappings.blocks package de.bixilon.minosoft.data.mappings.blocks
import com.google.gson.JsonArray import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.google.gson.JsonPrimitive import com.google.gson.JsonPrimitive
import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.Minosoft
@ -28,6 +27,7 @@ import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockLikeRenderer import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockLikeRenderer
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockRenderer import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockRenderer
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.FluidRenderer import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.FluidRenderer
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.MultipartRenderer
import glm_.vec3.Vec3i import glm_.vec3.Vec3i
import java.util.* import java.util.*
import kotlin.random.Random import kotlin.random.Random
@ -36,7 +36,7 @@ data class BlockState(
val owner: Block, val owner: Block,
val properties: Map<BlockProperties, Any> = mapOf(), val properties: Map<BlockProperties, Any> = mapOf(),
val rotation: BlockRotations = BlockRotations.NONE, val rotation: BlockRotations = BlockRotations.NONE,
val renders: MutableList<BlockLikeRenderer> = mutableListOf(), val renderers: MutableList<BlockLikeRenderer> = mutableListOf(),
val tintColor: RGBColor? = null, val tintColor: RGBColor? = null,
val material: Material, val material: Material,
val collisionShape: VoxelShape, val collisionShape: VoxelShape,
@ -109,11 +109,11 @@ data class BlockState(
} }
fun getBlockRenderer(blockPosition: Vec3i): BlockLikeRenderer { fun getBlockRenderer(blockPosition: Vec3i): BlockLikeRenderer {
if (Minosoft.getConfig().config.game.other.antiMoirePattern && renders.size > 1) { if (Minosoft.getConfig().config.game.other.antiMoirePattern && renderers.size > 1) {
// ToDo: Support weight attribute // ToDo: Support weight attribute
return renders.random(Random(blockPosition.hashCode())) return renderers.random(Random(blockPosition.hashCode()))
} }
return renders[0] return renderers[0]
} }
@ -133,22 +133,31 @@ data class BlockState(
val renders: MutableList<BlockLikeRenderer> = mutableListOf() val renders: MutableList<BlockLikeRenderer> = mutableListOf()
fun addBlockModel(json: JsonElement) { data["render"]?.let {
when (json) { when (it) {
is JsonArray -> { is JsonArray -> {
for (model in json) { for (model in it) {
addBlockModel(model) when (model) {
is JsonObject -> {
addBlockModel(model, renders, models)
}
is JsonArray -> {
val modelList: MutableList<BlockLikeRenderer> = mutableListOf()
for (singleModel in model) {
check(singleModel is JsonObject)
addBlockModel(singleModel, modelList, models)
}
renders.add(MultipartRenderer(modelList.toList()))
}
}
} }
} }
is JsonObject -> { is JsonObject -> {
addBlockModel(json, renders, models) addBlockModel(it, renders, models)
} }
else -> error("Not a render json!") else -> error("Not a render json!")
} }
} }
data["render"]?.let {
addBlockModel(it)
}
val tintColor: RGBColor? = data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) } ?: owner.tintColor val tintColor: RGBColor? = data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) } ?: owner.tintColor
@ -173,7 +182,7 @@ data class BlockState(
owner = owner, owner = owner,
properties = properties.toMap(), properties = properties.toMap(),
rotation = rotation, rotation = rotation,
renders = renders, renderers = renders,
tintColor = tintColor, tintColor = tintColor,
material = material, material = material,
collisionShape = collision, collisionShape = collision,

View File

@ -116,7 +116,7 @@ class WorldRenderer(
renderWindow.textures.animator.use(chunkShader, "AnimatedDataBuffer") renderWindow.textures.animator.use(chunkShader, "AnimatedDataBuffer")
for (block in connection.version.mapping.blockStateIdMap.values) { for (block in connection.version.mapping.blockStateIdMap.values) {
for (model in block.renders) { for (model in block.renderers) {
model.postInit() model.postInit()
} }
} }
@ -143,7 +143,7 @@ class WorldRenderer(
val textureMap: MutableMap<String, Texture> = ConcurrentHashMap() val textureMap: MutableMap<String, Texture> = ConcurrentHashMap()
for (block in blocks) { for (block in blocks) {
for (model in block.renders) { for (model in block.renderers) {
model.resolveTextures(textures, textureMap) model.resolveTextures(textures, textureMap)
} }
} }

View File

@ -0,0 +1,60 @@
/*
* Minosoft
* Copyright (C) 2021 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.chunk.models.renderable
import de.bixilon.minosoft.data.Directions
import de.bixilon.minosoft.data.mappings.blocks.BlockState
import de.bixilon.minosoft.data.world.World
import de.bixilon.minosoft.data.world.light.LightAccessor
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.chunk.ChunkMeshCollection
import de.bixilon.minosoft.gui.rendering.chunk.models.FaceSize
import de.bixilon.minosoft.gui.rendering.textures.Texture
import glm_.vec3.Vec3i
class MultipartRenderer(
val models: List<BlockLikeRenderer>,
) : BlockLikeRenderer {
override val faceBorderSizes: Array<Array<FaceSize>?>
override val transparentFaces: BooleanArray = BooleanArray(Directions.DIRECTIONS.size)
init {
val faceBorderSizes: MutableList<Array<FaceSize>?> = mutableListOf()
for (model in models) {
for (size in model.faceBorderSizes) {
faceBorderSizes.add(size)
}
for ((index, direction) in model.transparentFaces.withIndex()) {
if (direction) {
transparentFaces[index] = true
}
}
}
this.faceBorderSizes = faceBorderSizes.toTypedArray()
}
override fun render(blockState: BlockState, lightAccessor: LightAccessor, renderWindow: RenderWindow, blockPosition: Vec3i, meshCollection: ChunkMeshCollection, neighbourBlocks: Array<BlockState?>, world: World) {
for (model in models) {
model.render(blockState, lightAccessor, renderWindow, blockPosition, meshCollection, neighbourBlocks, world)
}
}
override fun resolveTextures(indexed: MutableList<Texture>, textureMap: MutableMap<String, Texture>) {
for (model in models) {
model.resolveTextures(indexed, textureMap)
}
}
}