mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 18:34:56 -04:00
skeletal rotation fixes and improvements, improve player model
This commit is contained in:
parent
978c2f06ad
commit
b6b0a82ca9
@ -23,6 +23,7 @@
|
|||||||
"transform": "head",
|
"transform": "head",
|
||||||
"offset": [0, 5, 0],
|
"offset": [0, 5, 0],
|
||||||
"from": [-5, 0, -5],
|
"from": [-5, 0, -5],
|
||||||
|
"rotation": [0, 0, 180],
|
||||||
"to": [5, 10, 5],
|
"to": [5, 10, 5],
|
||||||
"uv": [10, 0],
|
"uv": [10, 0],
|
||||||
"faces": "all"
|
"faces": "all"
|
||||||
|
@ -47,7 +47,8 @@ class PlayerModelMesh(context: RenderContext, initialCacheSize: Int = 1000) : Ab
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun String.getSkinPart(): SkinParts? = when (this) {
|
private fun String.getSkinPart(): SkinParts? = when (this) {
|
||||||
"body.head.hat" -> SkinParts.HAT
|
"head.hat" -> SkinParts.HAT
|
||||||
|
"body.jacket" -> SkinParts.JACKET
|
||||||
// TODO
|
// TODO
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,14 @@ import de.bixilon.minosoft.gui.rendering.skeletal.mesh.AbstractSkeletalMesh
|
|||||||
import de.bixilon.minosoft.gui.rendering.skeletal.model.textures.SkeletalTextureInstance
|
import de.bixilon.minosoft.gui.rendering.skeletal.model.textures.SkeletalTextureInstance
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY
|
||||||
import de.bixilon.minosoft.util.json.SkeletalFaceDeserializer
|
import de.bixilon.minosoft.util.json.SkeletalFaceDeserializer
|
||||||
|
import de.bixilon.minosoft.util.json.SkeletalRotationDeserializer
|
||||||
|
|
||||||
data class SkeletalElement(
|
data class SkeletalElement(
|
||||||
val from: Vec3,
|
val from: Vec3,
|
||||||
val to: Vec3,
|
val to: Vec3,
|
||||||
val offset: Vec3 = Vec3.EMPTY,
|
val offset: Vec3 = Vec3.EMPTY,
|
||||||
val rotation: SkeletalRotation? = null,
|
@JsonDeserialize(using = SkeletalRotationDeserializer::class) val rotation: SkeletalRotation? = null,
|
||||||
val inflate: Float = 0.0f,
|
val inflate: Float = 0.0f,
|
||||||
val enabled: Boolean = true,
|
|
||||||
val texture: ResourceLocation? = null,
|
val texture: ResourceLocation? = null,
|
||||||
val uv: Vec2i? = null,
|
val uv: Vec2i? = null,
|
||||||
val transform: String? = null,
|
val transform: String? = null,
|
||||||
@ -41,14 +41,11 @@ data class SkeletalElement(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
fun bake(consumer: AbstractSkeletalMesh, textures: Map<ResourceLocation, SkeletalTextureInstance>, transform: BakedSkeletalTransform, path: String) {
|
fun bake(consumer: AbstractSkeletalMesh, textures: Map<ResourceLocation, SkeletalTextureInstance>, transform: BakedSkeletalTransform, path: String) {
|
||||||
if (!enabled) return
|
|
||||||
|
|
||||||
val context = SkeletalBakeContext(transform = transform, textures = textures, consumer = consumer)
|
val context = SkeletalBakeContext(transform = transform, textures = textures, consumer = consumer)
|
||||||
return bake(context, path)
|
return bake(context, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bake(context: SkeletalBakeContext, path: String) {
|
private fun bake(context: SkeletalBakeContext, path: String) {
|
||||||
if (!enabled) return
|
|
||||||
val context = context.copy(this)
|
val context = context.copy(this)
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ data class SkeletalFace(
|
|||||||
val normal = Vec3(direction.vector)
|
val normal = Vec3(direction.vector)
|
||||||
|
|
||||||
for (rotation in context.rotations) {
|
for (rotation in context.rotations) {
|
||||||
val origin = rotation.origin!! / BLOCK_SIZE
|
val origin = rotation.origin!!
|
||||||
|
|
||||||
val rad = -GLM.radians(rotation.value)
|
val rad = -GLM.radians(rotation.value)
|
||||||
val vec = Vec3(0, positions)
|
val vec = Vec3(0, positions)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.skeletal.model.elements
|
package de.bixilon.minosoft.gui.rendering.skeletal.model.elements
|
||||||
|
|
||||||
import de.bixilon.kotlinglm.vec3.Vec3
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
|
import de.bixilon.minosoft.gui.rendering.models.block.element.ModelElement.Companion.BLOCK_SIZE
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY
|
||||||
|
|
||||||
data class SkeletalRotation(
|
data class SkeletalRotation(
|
||||||
@ -23,7 +24,10 @@ data class SkeletalRotation(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
fun apply(offset: Vec3, from: Vec3, to: Vec3): SkeletalRotation {
|
fun apply(offset: Vec3, from: Vec3, to: Vec3): SkeletalRotation {
|
||||||
val origin = (this.origin ?: ((to + from) / 2.0f)) + offset
|
var origin = this.origin
|
||||||
|
if (origin == null) {
|
||||||
|
origin = ((to + from) / 2.0f / BLOCK_SIZE) + offset
|
||||||
|
}
|
||||||
|
|
||||||
return SkeletalRotation(value, origin, rescale)
|
return SkeletalRotation(value, origin, rescale)
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,7 @@ object SkeletalFaceDeserializer : StdDeserializer<Map<Directions, SkeletalFace>>
|
|||||||
|
|
||||||
override fun deserialize(parser: JsonParser, context: DeserializationContext?): Map<Directions, SkeletalFace> {
|
override fun deserialize(parser: JsonParser, context: DeserializationContext?): Map<Directions, SkeletalFace> {
|
||||||
val codec = parser.codec
|
val codec = parser.codec
|
||||||
val next = parser.currentToken
|
when (parser.currentToken) {
|
||||||
when (next) {
|
|
||||||
JsonToken.START_OBJECT -> return codec.readValue(parser, MAP)
|
JsonToken.START_OBJECT -> return codec.readValue(parser, MAP)
|
||||||
JsonToken.START_ARRAY -> {
|
JsonToken.START_ARRAY -> {
|
||||||
val directions: Array<Directions> = codec.readValue(parser, Array<Directions>::class.java)
|
val directions: Array<Directions> = codec.readValue(parser, Array<Directions>::class.java)
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.util.json
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser
|
||||||
|
import com.fasterxml.jackson.core.JsonToken
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext
|
||||||
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
|
import de.bixilon.minosoft.gui.rendering.skeletal.model.elements.SkeletalRotation
|
||||||
|
|
||||||
|
object SkeletalRotationDeserializer : StdDeserializer<SkeletalRotation>(SkeletalRotation::class.java) {
|
||||||
|
|
||||||
|
override fun deserialize(parser: JsonParser, context: DeserializationContext?): SkeletalRotation {
|
||||||
|
return when (parser.currentToken) {
|
||||||
|
JsonToken.START_OBJECT -> parser.readValueAs(SkeletalRotation::class.java)
|
||||||
|
JsonToken.START_ARRAY -> {
|
||||||
|
val rotation = parser.readValueAs(FloatArray::class.java)
|
||||||
|
if (rotation.size != 3) throw IllegalArgumentException("Invalid count of components: ${rotation.size}")
|
||||||
|
SkeletalRotation(Vec3(0, rotation))
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> throw IllegalArgumentException("Can not skeletal rotation: $parser")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,9 +5,7 @@
|
|||||||
"to": [8, 8, 8],
|
"to": [8, 8, 8],
|
||||||
"texture": "minecraft:shulker",
|
"texture": "minecraft:shulker",
|
||||||
"uv": [0, 28],
|
"uv": [0, 28],
|
||||||
"rotation": {
|
"rotation": [0, 0, 180],
|
||||||
"value": [0, 0, 180]
|
|
||||||
},
|
|
||||||
"faces": "all"
|
"faces": "all"
|
||||||
},
|
},
|
||||||
"lid": {
|
"lid": {
|
||||||
@ -15,9 +13,7 @@
|
|||||||
"from": [-8, 4, -8],
|
"from": [-8, 4, -8],
|
||||||
"to": [8, 16, 8],
|
"to": [8, 16, 8],
|
||||||
"texture": "minecraft:shulker",
|
"texture": "minecraft:shulker",
|
||||||
"rotation": {
|
"rotation": [0, 0, 180],
|
||||||
"value": [0, 0, 180]
|
|
||||||
},
|
|
||||||
"uv": [0, 0],
|
"uv": [0, 0],
|
||||||
"faces": "all"
|
"faces": "all"
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,30 @@
|
|||||||
{
|
{
|
||||||
"elements": {
|
"elements": {
|
||||||
"body": {
|
"body": {
|
||||||
"from": [-4, 12, -2],
|
"offset": [0, 12, 0],
|
||||||
"to": [4, 24, 2],
|
"from": [-4, 0, -2],
|
||||||
|
"to": [4, 12, 2],
|
||||||
"texture": "minecraft:skin",
|
"texture": "minecraft:skin",
|
||||||
"uv": [16, 16],
|
"uv": [16, 16],
|
||||||
|
"rotation": [180, 0, 0],
|
||||||
"faces": "all",
|
"faces": "all",
|
||||||
"children": {
|
"children": {
|
||||||
|
"jacket": {
|
||||||
|
"from": [-4, 0, -2],
|
||||||
|
"to": [4, 12, 2],
|
||||||
|
"inflate": 0.25,
|
||||||
|
"uv": [16, 32],
|
||||||
|
"faces": "all"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"head": {
|
"head": {
|
||||||
"offset": [0, 24, 0],
|
"offset": [0, 24, 0],
|
||||||
"from": [-4, 0, -4],
|
"from": [-4, 0, -4],
|
||||||
"to": [4, 8, 4],
|
"to": [4, 8, 4],
|
||||||
"uv": [0, 0],
|
"uv": [0, 0],
|
||||||
|
"rotation": [180, 0, 0],
|
||||||
|
"texture": "minecraft:skin",
|
||||||
"transform": "head",
|
"transform": "head",
|
||||||
"faces": "all",
|
"faces": "all",
|
||||||
"children": {
|
"children": {
|
||||||
@ -24,8 +37,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"transforms": {
|
"transforms": {
|
||||||
"head": {
|
"head": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user