skeletal: don't inherit all rotations

This commit is contained in:
Moritz Zwerger 2023-11-08 21:09:59 +01:00
parent ed451f7b85
commit 252dd3e1e8
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 7 additions and 18 deletions

View File

@ -14,7 +14,6 @@
package de.bixilon.minosoft.gui.rendering.skeletal.baked
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kutil.collections.CollectionUtil.extend
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.gui.rendering.models.block.element.ModelElement.Companion.BLOCK_SIZE
import de.bixilon.minosoft.gui.rendering.skeletal.mesh.AbstractSkeletalMesh
@ -28,7 +27,7 @@ data class SkeletalBakeContext(
val inflate: Float = 0.0f,
val texture: ResourceLocation? = null,
val transform: BakedSkeletalTransform,
val rotations: List<SkeletalRotation> = emptyList(),
val rotation: SkeletalRotation? = null,
val textures: Map<ResourceLocation, SkeletalTextureInstance>,
val consumer: AbstractSkeletalMesh,
@ -38,9 +37,9 @@ data class SkeletalBakeContext(
val offset = this.offset + (element.offset / BLOCK_SIZE)
val inflate = this.inflate + element.inflate
val texture = element.texture ?: texture
val rotations = if (element.rotation != null) this.rotations.extend(element.rotation.apply(offset, element.from, element.to)) else this.rotations
val rotation = element.rotation ?: this.rotation
val transform = element.transform?.let { transform.children[element.transform] ?: throw IllegalArgumentException("Can not find transform ${element.transform}") } ?: transform
return copy(offset = offset, inflate = inflate, texture = texture, transform = transform, rotations = rotations)
return copy(offset = offset, inflate = inflate, texture = texture, transform = transform, rotation = rotation)
}
}

View File

@ -13,7 +13,6 @@
package de.bixilon.minosoft.gui.rendering.skeletal.model.elements
import de.bixilon.kotlinglm.GLM
import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.minosoft.data.direction.Directions
@ -22,6 +21,7 @@ import de.bixilon.minosoft.gui.rendering.models.block.element.ModelElement.Compa
import de.bixilon.minosoft.gui.rendering.models.block.element.face.FaceUV
import de.bixilon.minosoft.gui.rendering.models.util.CuboidUtil
import de.bixilon.minosoft.gui.rendering.skeletal.baked.SkeletalBakeContext
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.rad
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.rotateAssign
data class SkeletalFace(
@ -47,10 +47,10 @@ data class SkeletalFace(
val normal = Vec3(direction.vector)
for (rotation in context.rotations) {
val origin = rotation.origin!!
if (context.rotation != null) {
val origin = context.rotation.origin ?: ((to + from) / 2.0f)
val rad = -GLM.radians(rotation.value)
val rad = -context.rotation.value.rad
val vec = Vec3(0, positions)
normal.rotateAssign(rad)

View File

@ -14,7 +14,6 @@
package de.bixilon.minosoft.gui.rendering.skeletal.model.elements
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
data class SkeletalRotation(
@ -23,15 +22,6 @@ data class SkeletalRotation(
val rescale: Boolean = false,
) {
fun apply(offset: Vec3, from: Vec3, to: Vec3): SkeletalRotation {
var origin = this.origin
if (origin == null) {
origin = ((to + from) / 2.0f / BLOCK_SIZE) + offset
}
return SkeletalRotation(value, origin, rescale)
}
companion object {
val EMPTY = SkeletalRotation(Vec3.EMPTY, Vec3.EMPTY, false)
}