From b4f1ff9a00e1dab70fbcb667beae623fdcf948be Mon Sep 17 00:00:00 2001 From: "d.isakov" Date: Wed, 16 Apr 2025 07:49:26 +0200 Subject: [PATCH] #4888 fix UpdateModelAnimationBones scale transform --- src/rmodels.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index 73dba6aa7..2653760cd 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -2289,29 +2289,19 @@ void UpdateModelAnimationBones(Model model, ModelAnimation anim, int frame) // Update all bones and boneMatrices of first mesh with bones. for (int boneId = 0; boneId < anim.boneCount; boneId++) { - Vector3 inTranslation = model.bindPose[boneId].translation; - Quaternion inRotation = model.bindPose[boneId].rotation; - Vector3 inScale = model.bindPose[boneId].scale; + Transform *bindTransform = &model.bindPose[boneId]; + Matrix bindMatrix = MatrixMultiply(MatrixMultiply( + MatrixScale(bindTransform->scale.x, bindTransform->scale.y, bindTransform->scale.z), + QuaternionToMatrix(bindTransform->rotation)), + MatrixTranslate(bindTransform->translation.x, bindTransform->translation.y, bindTransform->translation.z)); - Vector3 outTranslation = anim.framePoses[frame][boneId].translation; - Quaternion outRotation = anim.framePoses[frame][boneId].rotation; - Vector3 outScale = anim.framePoses[frame][boneId].scale; + Transform *targetTransform = &anim.framePoses[frame][boneId]; + Matrix targetMatrix = MatrixMultiply(MatrixMultiply( + MatrixScale(targetTransform->scale.x, targetTransform->scale.y, targetTransform->scale.z), + QuaternionToMatrix(targetTransform->rotation)), + MatrixTranslate(targetTransform->translation.x, targetTransform->translation.y, targetTransform->translation.z)); - Quaternion invRotation = QuaternionInvert(inRotation); - Vector3 invTranslation = Vector3RotateByQuaternion(Vector3Negate(inTranslation), invRotation); - Vector3 invScale = Vector3Divide((Vector3){ 1.0f, 1.0f, 1.0f }, inScale); - - Vector3 boneTranslation = Vector3Add(Vector3RotateByQuaternion( - Vector3Multiply(outScale, invTranslation), outRotation), outTranslation); - Quaternion boneRotation = QuaternionMultiply(outRotation, invRotation); - Vector3 boneScale = Vector3Multiply(outScale, invScale); - - Matrix boneMatrix = MatrixMultiply(MatrixMultiply( - QuaternionToMatrix(boneRotation), - MatrixTranslate(boneTranslation.x, boneTranslation.y, boneTranslation.z)), - MatrixScale(boneScale.x, boneScale.y, boneScale.z)); - - model.meshes[firstMeshWithBones].boneMatrices[boneId] = boneMatrix; + model.meshes[firstMeshWithBones].boneMatrices[boneId] = MatrixMultiply(MatrixInvert(bindMatrix), targetMatrix); } // Update remaining meshes with bones