wide, small skin tests

This commit is contained in:
Moritz Zwerger 2023-12-05 23:46:50 +01:00
parent acb3bd3b02
commit 901b2a029c
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 38 additions and 19 deletions

View File

@ -15,15 +15,17 @@ package de.bixilon.minosoft.gui.rendering.system.base.texture.skin
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.TextureData
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.buffer.TextureBuffer
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.readTexture
import de.bixilon.minosoft.test.IT
import org.testng.Assert.assertEquals
import org.testng.Assert.*
import org.testng.annotations.Test
@Test(groups = ["rendering", "textures"], enabled = false) // TODO: flip skin correctly
class SkinManagerTest {
val skin = IT.OBJENESIS.newInstance(SkinManager::class.java)
val readSkin = SkinManager::class.java.getDeclaredMethod("readSkin", ByteArray::class.java).apply { isAccessible = true }
val isReallyWide = SkinManager::class.java.getDeclaredMethod("isReallyWide", TextureBuffer::class.java).apply { isAccessible = true }
private fun ByteArray.readSkin(): TextureData {
@ -44,4 +46,13 @@ class SkinManagerTest {
assertEquals(old.buffer.data, expected.data)
}
fun `check if skin is really wide on a slim skin`() {
val slim = SkinManager::class.java.getResourceAsStream("/skins/5065405b55a729be5a442832b895d4352b3fdcc61c8c57f4b8abad64344194d3.png")!!.readAllBytes().readSkin()
assertFalse(isReallyWide.invoke(SkinManager, slim) as Boolean)
}
fun `check if skin is really wide on a wide skin`() {
val slim = SkinManager::class.java.getResourceAsStream("/skins/182f56f61cb8ec6e8938a5b7b515d209be55bb91e9969ba7bf9521293834cda2.png")!!.readAllBytes().readSkin()
assertTrue(isReallyWide.invoke(SkinManager, slim) as Boolean)
}
}

View File

@ -38,6 +38,7 @@ open class PlayerTexture(
url.checkWeb()
}
@JsonIgnore
fun getHash(): String {
when (url.host) {
"textures.minecraft.net" -> {

View File

@ -32,8 +32,7 @@ import de.bixilon.minosoft.gui.rendering.skeletal.mesh.SkeletalMeshBuilder
import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTexture
import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTextureListener
import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTextureState
import de.bixilon.minosoft.gui.rendering.system.base.texture.skin.PlayerSkin
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.isBlack
import de.bixilon.minosoft.gui.rendering.system.base.texture.skin.SkinManager.Companion.isReallyWide
import de.bixilon.minosoft.gui.rendering.util.mat.mat4.Mat4Util.translateYAssign
open class PlayerRenderer<E : PlayerEntity>(renderer: EntitiesRenderer, entity: E) : LivingEntityRenderer<E>(renderer, entity), DynamicTextureListener {
@ -113,22 +112,6 @@ open class PlayerRenderer<E : PlayerEntity>(renderer: EntitiesRenderer, entity:
return renderer.context.models.skeletal[name]
}
private fun PlayerSkin.isReallyWide(): Boolean {
val data = this.texture.data?.buffer ?: return true
// check if normal pixel is not black
if (data[40, 16].isBlack()) return true // left arm slim
if (data[32, 48].isBlack()) return true // right arm slim
if (!data[52, 20].isBlack()) return true // left arm wide
if (!data[53, 31].isBlack()) return true // left arm wide
if (!data[44, 52].isBlack()) return true // right arm wide
if (!data[45, 63].isBlack()) return true // right arm wide
return false
}
override fun onDynamicTextureChange(texture: DynamicTexture): Boolean {
if (texture.state != DynamicTextureState.LOADED) return false
this.skin = texture

View File

@ -25,6 +25,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.buffer.RGBA8Buffer
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.buffer.TextureBuffer
import de.bixilon.minosoft.gui.rendering.system.base.texture.skin.vanilla.DefaultSkinProvider
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.isBlack
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.readTexture
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY_INSTANCE
import java.io.ByteArrayInputStream
@ -94,4 +95,27 @@ class SkinManager(private val textures: TextureManager) {
else -> throw IllegalSkinError("Can not detect skin format: ${data.size}")
}
}
companion object {
fun PlayerSkin.isReallyWide(): Boolean {
val data = this.texture.data?.buffer ?: return true
return data.isReallyWide()
}
private fun TextureBuffer.isReallyWide(): Boolean {
// check if normal pixel is not black
if (this[40, 16].isBlack()) return true // left arm slim
if (this[32, 48].isBlack()) return true // right arm slim
if (!this[52, 20].isBlack()) return true // left arm wide
if (!this[53, 31].isBlack()) return true // left arm wide
if (!this[44, 52].isBlack()) return true // right arm wide
if (!this[45, 63].isBlack()) return true // right arm wide
return false
}
}
}