mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
fix fallback rgb reading, fix tests
That fixes weird looking grass (and a couple of other textures) in resource packs and 1.20.2
This commit is contained in:
parent
8838e480b1
commit
c3bf0f1de2
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.world.chunk.manager
|
|||||||
|
|
||||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||||
import de.bixilon.minosoft.data.registries.biomes.Biome
|
import de.bixilon.minosoft.data.registries.biomes.Biome
|
||||||
import de.bixilon.minosoft.data.registries.biomes.BiomePrecipitation
|
|
||||||
import de.bixilon.minosoft.data.registries.blocks.types.stone.StoneTest0
|
import de.bixilon.minosoft.data.registries.blocks.types.stone.StoneTest0
|
||||||
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
|
||||||
import de.bixilon.minosoft.data.world.biome.accessor.NoiseBiomeAccessor
|
import de.bixilon.minosoft.data.world.biome.accessor.NoiseBiomeAccessor
|
||||||
@ -438,7 +437,7 @@ class ChunkManagerTest {
|
|||||||
|
|
||||||
fun noiseBiomeCache() {
|
fun noiseBiomeCache() {
|
||||||
val manager = create()
|
val manager = create()
|
||||||
val biome = Biome(minosoft("test"), 0.0f, 0.0f, null, null, null, null, BiomePrecipitation.NONE)
|
val biome = Biome(minosoft("test"), 0.0f, 0.0f, null, null, null, null, null)
|
||||||
manager.world.cacheBiomeAccessor = NoiseBiomeAccessor(manager.world.connection, 0L)
|
manager.world.cacheBiomeAccessor = NoiseBiomeAccessor(manager.world.connection, 0L)
|
||||||
val source = SpatialBiomeArray(Array(1024) { biome })
|
val source = SpatialBiomeArray(Array(1024) { biome })
|
||||||
val matrix = manager.createMatrix(source)
|
val matrix = manager.createMatrix(source)
|
||||||
|
@ -18,6 +18,7 @@ import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
|||||||
import de.bixilon.minosoft.gui.rendering.chunk.mesh.ChunkMesh
|
import de.bixilon.minosoft.gui.rendering.chunk.mesh.ChunkMesh
|
||||||
import de.bixilon.minosoft.gui.rendering.chunk.mesh.SingleChunkMesh
|
import de.bixilon.minosoft.gui.rendering.chunk.mesh.SingleChunkMesh
|
||||||
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedFace
|
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedFace
|
||||||
|
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.Shades
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer
|
import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
|
||||||
@ -56,7 +57,7 @@ class BakedFaceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun mixed() {
|
fun mixed() {
|
||||||
val face = BakedFace(floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f), floatArrayOf(-1f, -2f, -3f, -4f, -5f, -6f, -7f, -8f), 1.0f, -1, null, texture())
|
val face = BakedFace(floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f), floatArrayOf(-1f, -2f, -3f, -4f, -5f, -6f, -7f, -8f), Shades.UP, -1, null, texture())
|
||||||
|
|
||||||
val mesh = mesh()
|
val mesh = mesh()
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ class BakedFaceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun blockSouth() {
|
fun blockSouth() {
|
||||||
val face = BakedFace(floatArrayOf(0f, 0f, 0f, 0f, 1f, 0f, 0f, 1f, 1f, 0f, 0f, 1f), floatArrayOf(0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f), 1.0f, -1, null, texture())
|
val face = BakedFace(floatArrayOf(0f, 0f, 0f, 0f, 1f, 0f, 0f, 1f, 1f, 0f, 0f, 1f), floatArrayOf(0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f), Shades.UP, -1, null, texture())
|
||||||
|
|
||||||
val mesh = mesh()
|
val mesh = mesh()
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ object BakedModelTestUtil {
|
|||||||
|
|
||||||
vertices?.let { assertMatches(face.positions, it, "Vertices mismatch") }
|
vertices?.let { assertMatches(face.positions, it, "Vertices mismatch") }
|
||||||
uv?.let { if (!face.uv.contentEquals(it)) throw AssertionError("UV mismatch, expected [${uv[0]}|${uv[1]}], but got [${face.uv[0]}|${face.uv[1]}]") } // printing the first element is fine, it is always clockwise
|
uv?.let { if (!face.uv.contentEquals(it)) throw AssertionError("UV mismatch, expected [${uv[0]}|${uv[1]}], but got [${face.uv[0]}|${face.uv[1]}]") } // printing the first element is fine, it is always clockwise
|
||||||
shade?.let { Assert.assertEquals(face.shade, it, "Shade mismatch") }
|
shade?.let { Assert.assertEquals(face.shade.shade, it, "Shade mismatch") }
|
||||||
texture?.toResourceLocation()?.texture()?.let { Assert.assertEquals(face.texture, it, "Texture mismatch") }
|
texture?.toResourceLocation()?.texture()?.let { Assert.assertEquals(face.texture, it, "Texture mismatch") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* 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.textures
|
||||||
|
|
||||||
|
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.TextureData
|
||||||
|
import org.testng.Assert.assertEquals
|
||||||
|
import org.testng.annotations.Test
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
@Test(groups = ["texture", "assets"])
|
||||||
|
class TextureReadingTest {
|
||||||
|
private val GRAY_GRAY = TextureReadingTest::class.java.getResourceAsStream("/texture_reading/gray_gray.png")!!.readAllBytes()
|
||||||
|
private val GRAY_RGB = TextureReadingTest::class.java.getResourceAsStream("/texture_reading/gray_rgb.png")!!.readAllBytes()
|
||||||
|
|
||||||
|
private val READ_1 = TextureUtil::class.java.getDeclaredMethod("readTexture1", InputStream::class.java).apply { isAccessible = true }
|
||||||
|
private val READ_2 = TextureUtil::class.java.getDeclaredMethod("readTexture2", InputStream::class.java).apply { isAccessible = true }
|
||||||
|
|
||||||
|
private fun TextureData.assertGray() {
|
||||||
|
assertEquals(size, Vec2i(16, 16))
|
||||||
|
|
||||||
|
assertEquals(buffer.get(0), 0x94.toByte())
|
||||||
|
assertEquals(buffer.get(1), 0x94.toByte())
|
||||||
|
assertEquals(buffer.get(2), 0x94.toByte())
|
||||||
|
assertEquals(buffer.get(3), 0xFF.toByte())
|
||||||
|
assertEquals(buffer.get(4), 0xC3.toByte())
|
||||||
|
assertEquals(buffer.get(128), 0xA3.toByte())
|
||||||
|
assertEquals(buffer.get(256), 0xA2.toByte())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `read rgb 1`() {
|
||||||
|
val texture = READ_1.invoke(TextureUtil, ByteArrayInputStream(GRAY_RGB)) as TextureData
|
||||||
|
texture.assertGray()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `read rgb 2`() {
|
||||||
|
val texture = READ_2.invoke(TextureUtil, ByteArrayInputStream(GRAY_RGB)) as TextureData
|
||||||
|
texture.assertGray()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false)
|
||||||
|
fun `read gray 1`() {
|
||||||
|
val texture = READ_1.invoke(TextureUtil, ByteArrayInputStream(GRAY_GRAY)) as TextureData
|
||||||
|
texture.assertGray()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `read gray 2`() {
|
||||||
|
val texture = READ_2.invoke(TextureUtil, ByteArrayInputStream(GRAY_GRAY)) as TextureData
|
||||||
|
texture.assertGray()
|
||||||
|
}
|
||||||
|
}
|
BIN
src/integration-test/resources/texture_reading/gray_gray.png
Normal file
BIN
src/integration-test/resources/texture_reading/gray_gray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 298 B |
BIN
src/integration-test/resources/texture_reading/gray_rgb.png
Normal file
BIN
src/integration-test/resources/texture_reading/gray_rgb.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 560 B |
@ -70,7 +70,7 @@ data class Biome(
|
|||||||
fogColor = fogColor,
|
fogColor = fogColor,
|
||||||
waterColor = waterColor,
|
waterColor = waterColor,
|
||||||
waterFogColor = waterFogColor,
|
waterFogColor = waterFogColor,
|
||||||
precipitation = data["precipitation"]?.let { BiomePrecipitation[it] },
|
precipitation = data["precipitation"]?.let { if (it is Int) BiomePrecipitation.getOrNull(it - 1) else BiomePrecipitation[it] },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,21 +43,30 @@ object TextureUtil {
|
|||||||
}!!
|
}!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun InputStream.readTexture1(): TextureData {
|
||||||
|
val decoder = PNGDecoder(this)
|
||||||
|
val data = BufferUtils.createByteBuffer(decoder.width * decoder.height * PNGDecoder.Format.RGBA.numComponents)
|
||||||
|
decoder.decode(data, decoder.width * PNGDecoder.Format.RGBA.numComponents, PNGDecoder.Format.RGBA)
|
||||||
|
|
||||||
|
return TextureData(Vec2i(decoder.width, decoder.height), data)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Other way of reading a texture if the first (preferred one) method does not work
|
|
||||||
* Only happens to some weird textures (seen in PureBDCraft)
|
|
||||||
* Ignores the alpha channel
|
|
||||||
*/
|
|
||||||
private fun InputStream.readTexture2(): TextureData {
|
private fun InputStream.readTexture2(): TextureData {
|
||||||
val image: BufferedImage = ImageIO.read(this)
|
val image: BufferedImage = ImageIO.read(this)
|
||||||
val rgb = image.getRGB(0, 0, image.width, image.height, null, 0, image.width)
|
|
||||||
|
|
||||||
val byteOutput = ByteArrayOutputStream()
|
val byteOutput = ByteArrayOutputStream()
|
||||||
val dataOutput = DataOutputStream(byteOutput)
|
val dataOutput = DataOutputStream(byteOutput)
|
||||||
|
|
||||||
for (color in rgb) {
|
val samples = if (image.raster.numBands == 3) intArrayOf(0, 1, 2) else intArrayOf(0, 0, 0)
|
||||||
dataOutput.writeInt((color shl 8) or 0xFF)
|
|
||||||
|
for (y in 0 until image.height) {
|
||||||
|
for (x in 0 until image.width) {
|
||||||
|
dataOutput.writeByte(image.raster.getSample(x, y, samples[0]))
|
||||||
|
dataOutput.writeByte(image.raster.getSample(x, y, samples[1]))
|
||||||
|
dataOutput.writeByte(image.raster.getSample(x, y, samples[2]))
|
||||||
|
val alpha = image.alphaRaster?.getSample(x, y, 0) ?: 0xFF
|
||||||
|
dataOutput.writeByte(alpha)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val buffer = MemoryUtil.memAlloc(byteOutput.size())
|
val buffer = MemoryUtil.memAlloc(byteOutput.size())
|
||||||
@ -68,11 +77,7 @@ object TextureUtil {
|
|||||||
|
|
||||||
fun InputStream.readTexture(): TextureData {
|
fun InputStream.readTexture(): TextureData {
|
||||||
return try {
|
return try {
|
||||||
val decoder = PNGDecoder(this)
|
readTexture1()
|
||||||
val data = BufferUtils.createByteBuffer(decoder.width * decoder.height * PNGDecoder.Format.RGBA.numComponents)
|
|
||||||
decoder.decode(data, decoder.width * PNGDecoder.Format.RGBA.numComponents, PNGDecoder.Format.RGBA)
|
|
||||||
|
|
||||||
TextureData(Vec2i(decoder.width, decoder.height), data)
|
|
||||||
} catch (exception: Throwable) {
|
} catch (exception: Throwable) {
|
||||||
this.reset()
|
this.reset()
|
||||||
readTexture2()
|
readTexture2()
|
||||||
|
@ -50,7 +50,7 @@ class GrassTintCalculator : TintProvider {
|
|||||||
|
|
||||||
fun getBlockColor(biome: Biome?): Int {
|
fun getBlockColor(biome: Biome?): Int {
|
||||||
if (biome == null) {
|
if (biome == null) {
|
||||||
return getColor(127, 127)
|
return getColor(127, 255)
|
||||||
}
|
}
|
||||||
val color = getColor(biome.colorMapPixelIndex)
|
val color = getColor(biome.colorMapPixelIndex)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user