fix some skeletal transformation bugs

This commit is contained in:
Moritz Zwerger 2023-10-19 19:18:28 +02:00
parent a23ec4c1c3
commit ecba02d533
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 7 additions and 11 deletions

View File

@ -172,8 +172,8 @@ object BlockProperties {
return Pair(property, property.parse(value)!!)
}
@Deprecated("not block specific")
private fun parseProperty(group: String, value: Any): Pair<BlockProperty<*>, Any> {
// TODO: block.properties
val properties = PROPERTIES[group] ?: throw IllegalArgumentException("Can not find group: $group, expected value $value")
var property: BlockProperty<*>? = null

View File

@ -48,7 +48,7 @@ class SkeletalManager(
prepareDraw()
shader.light = light
instance.transform.pack(uniformBuffer.buffer)
instance.transform.pack(uniformBuffer.buffer, instance.position)
uniformBuffer.upload(0 until instance.model.transformCount * Mat4.length)
instance.model.mesh.draw()

View File

@ -29,6 +29,7 @@ class SkeletalInstance(
val transform: TransformInstance,
) {
val animation = AnimationManager(this)
var position = Mat4()
var light = 0xFF
@ -47,11 +48,9 @@ class SkeletalInstance(
}
fun update(position: Vec3, rotation: Vec3) {
val matrix = Mat4()
this.position = Mat4()
.translateAssign(position)
.rotateRadAssign(rotation)
transform.value(matrix)
}
fun update(position: Vec3d, rotation: Vec3) {

View File

@ -25,9 +25,6 @@ class TransformInstance(
) {
val value = Mat4()
fun pack(buffer: FloatBuffer) {
pack(buffer, Mat4())
}
fun reset() {
this.value(Mat4.EMPTY_INSTANCE)
@ -37,8 +34,8 @@ class TransformInstance(
}
}
private fun pack(buffer: FloatBuffer, parent: Mat4) {
val value = value * parent
fun pack(buffer: FloatBuffer, parent: Mat4) {
val value = parent * value
val offset = this.id * Mat4.length
for (index in 0 until Mat4.length) {
buffer.put(offset + index, value.array[index])

View File

@ -59,7 +59,7 @@ object Vec3Util {
get() = this.floor
val Vec3.Companion.X: Vec3 get() = Vec3Util.X
val Vec3.Companion.Y: Vec3 get() = Vec3Util.X
val Vec3.Companion.Y: Vec3 get() = Vec3Util.Y
val Vec3.Companion.Z: Vec3 get() = Vec3Util.Z