@@ -2286,38 +2286,28 @@ void UpdateModelAnimationBones(Model model, ModelAnimation anim, int frame)
2286
2286
}
2287
2287
}
2288
2288
2289
- // Update all bones and boneMatrices of first mesh with bones.
2290
- for (int boneId = 0 ; boneId < anim .boneCount ; boneId ++ )
2291
- {
2292
- Vector3 inTranslation = model .bindPose [boneId ].translation ;
2293
- Quaternion inRotation = model .bindPose [boneId ].rotation ;
2294
- Vector3 inScale = model .bindPose [boneId ].scale ;
2295
-
2296
- Vector3 outTranslation = anim .framePoses [frame ][boneId ].translation ;
2297
- Quaternion outRotation = anim .framePoses [frame ][boneId ].rotation ;
2298
- Vector3 outScale = anim .framePoses [frame ][boneId ].scale ;
2299
-
2300
- Quaternion invRotation = QuaternionInvert (inRotation );
2301
- Vector3 invTranslation = Vector3RotateByQuaternion (Vector3Negate (inTranslation ), invRotation );
2302
- Vector3 invScale = Vector3Divide ((Vector3 ){ 1.0f , 1.0f , 1.0f }, inScale );
2303
-
2304
- Vector3 boneTranslation = Vector3Add (Vector3RotateByQuaternion (
2305
- Vector3Multiply (outScale , invTranslation ), outRotation ), outTranslation );
2306
- Quaternion boneRotation = QuaternionMultiply (outRotation , invRotation );
2307
- Vector3 boneScale = Vector3Multiply (outScale , invScale );
2308
-
2309
- Matrix boneMatrix = MatrixMultiply (MatrixMultiply (
2310
- QuaternionToMatrix (boneRotation ),
2311
- MatrixTranslate (boneTranslation .x , boneTranslation .y , boneTranslation .z )),
2312
- MatrixScale (boneScale .x , boneScale .y , boneScale .z ));
2313
-
2314
- model .meshes [firstMeshWithBones ].boneMatrices [boneId ] = boneMatrix ;
2315
- }
2316
-
2317
- // Update remaining meshes with bones
2318
- // NOTE: Using deep copy because shallow copy results in double free with 'UnloadModel()'
2319
2289
if (firstMeshWithBones != -1 )
2320
2290
{
2291
+ // Update all bones and boneMatrices of first mesh with bones.
2292
+ for (int boneId = 0 ; boneId < anim .boneCount ; boneId ++ )
2293
+ {
2294
+ Transform * bindTransform = & model .bindPose [boneId ];
2295
+ Matrix bindMatrix = MatrixMultiply (MatrixMultiply (
2296
+ MatrixScale (bindTransform -> scale .x , bindTransform -> scale .y , bindTransform -> scale .z ),
2297
+ QuaternionToMatrix (bindTransform -> rotation )),
2298
+ MatrixTranslate (bindTransform -> translation .x , bindTransform -> translation .y , bindTransform -> translation .z ));
2299
+
2300
+ Transform * targetTransform = & anim .framePoses [frame ][boneId ];
2301
+ Matrix targetMatrix = MatrixMultiply (MatrixMultiply (
2302
+ MatrixScale (targetTransform -> scale .x , targetTransform -> scale .y , targetTransform -> scale .z ),
2303
+ QuaternionToMatrix (targetTransform -> rotation )),
2304
+ MatrixTranslate (targetTransform -> translation .x , targetTransform -> translation .y , targetTransform -> translation .z ));
2305
+
2306
+ model .meshes [firstMeshWithBones ].boneMatrices [boneId ] = MatrixMultiply (MatrixInvert (bindMatrix ), targetMatrix );
2307
+ }
2308
+
2309
+ // Update remaining meshes with bones
2310
+ // NOTE: Using deep copy because shallow copy results in double free with 'UnloadModel()'
2321
2311
for (int i = firstMeshWithBones + 1 ; i < model .meshCount ; i ++ )
2322
2312
{
2323
2313
if (model .meshes [i ].boneMatrices )
0 commit comments