From 873bf31be3145d5695f9f13b7cb3eb688b6256e4 Mon Sep 17 00:00:00 2001 From: Le Juez Victor <90587919+Bigfoot71@users.noreply.github.com> Date: Tue, 24 Dec 2024 20:17:37 +0100 Subject: [PATCH] [rmodels] Fix normal transform in `UpdateModelAnimationBones` (#4634) * remove duplicate calculation of `invRotation` in `UpdateModelAnimationBones` * fix normal transform in `UpdateModelAnimation` --- src/rmodels.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index 0455ced2785d..c62267de4733 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -2296,13 +2296,12 @@ void UpdateModelAnimationBones(Model model, ModelAnimation anim, int frame) Quaternion outRotation = anim.framePoses[frame][boneId].rotation; Vector3 outScale = anim.framePoses[frame][boneId].scale; - Vector3 invTranslation = Vector3RotateByQuaternion(Vector3Negate(inTranslation), QuaternionInvert(inRotation)); 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); + Vector3 boneTranslation = Vector3Add(Vector3RotateByQuaternion( + Vector3Multiply(outScale, invTranslation), outRotation), outTranslation); Quaternion boneRotation = QuaternionMultiply(outRotation, invRotation); Vector3 boneScale = Vector3Multiply(outScale, invScale); @@ -2384,7 +2383,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame) if ((mesh.normals != NULL) && (mesh.animNormals != NULL )) { animNormal = (Vector3){ mesh.normals[vCounter], mesh.normals[vCounter + 1], mesh.normals[vCounter + 2] }; - animNormal = Vector3Transform(animNormal,model.meshes[m].boneMatrices[boneId]); + animNormal = Vector3Transform(animNormal, MatrixTranspose(MatrixInvert(model.meshes[m].boneMatrices[boneId]))); mesh.animNormals[vCounter] += animNormal.x*boneWeight; mesh.animNormals[vCounter + 1] += animNormal.y*boneWeight; mesh.animNormals[vCounter + 2] += animNormal.z*boneWeight;