Merge branch 'master' into 13-10-25MSVC_Warnings

This commit is contained in:
Ray 2025-10-15 19:02:18 +02:00 committed by GitHub
commit 95fbcb728f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 38 deletions

View File

@ -3073,7 +3073,7 @@ unsigned int *ComputeSHA1(unsigned char *data, int dataSize)
hash[4] += e; hash[4] += e;
} }
free(msg); RL_FREE(msg);
return hash; return hash;
} }

View File

@ -2352,6 +2352,8 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
Mesh mesh = model.meshes[m]; Mesh mesh = model.meshes[m];
Vector3 animVertex = { 0 }; Vector3 animVertex = { 0 };
Vector3 animNormal = { 0 }; Vector3 animNormal = { 0 };
Matrix boneMatrix = { 0 };
Matrix InverseBoneMatrix = { 0 };
int boneId = 0; int boneId = 0;
int boneCounter = 0; int boneCounter = 0;
float boneWeight = 0.0; float boneWeight = 0.0;
@ -2361,6 +2363,18 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
// Skip if missing bone data, causes segfault without on some models // Skip if missing bone data, causes segfault without on some models
if ((mesh.boneWeights == NULL) || (mesh.boneIds == NULL)) continue; if ((mesh.boneWeights == NULL) || (mesh.boneIds == NULL)) continue;
// Iterates over 4 bones per vertex
for (int j = 0; j < 4; j++, boneCounter++)
{
boneWeight = mesh.boneWeights[boneCounter];
boneId = mesh.boneIds[boneCounter];
// Early stop when no transformation will be applied
if (boneWeight == 0.0f) continue;
boneMatrix = model.meshes[m].boneMatrices[boneId];
InverseBoneMatrix = MatrixTranspose(MatrixInvert(boneMatrix));
for (int vCounter = 0; vCounter < vValues; vCounter += 3) for (int vCounter = 0; vCounter < vValues; vCounter += 3)
{ {
mesh.animVertices[vCounter] = 0; mesh.animVertices[vCounter] = 0;
@ -2372,17 +2386,8 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
mesh.animNormals[vCounter + 1] = 0; mesh.animNormals[vCounter + 1] = 0;
mesh.animNormals[vCounter + 2] = 0; mesh.animNormals[vCounter + 2] = 0;
} }
// Iterates over 4 bones per vertex
for (int j = 0; j < 4; j++, boneCounter++)
{
boneWeight = mesh.boneWeights[boneCounter];
boneId = mesh.boneIds[boneCounter];
// Early stop when no transformation will be applied
if (boneWeight == 0.0f) continue;
animVertex = (Vector3){ mesh.vertices[vCounter], mesh.vertices[vCounter + 1], mesh.vertices[vCounter + 2] }; animVertex = (Vector3){ mesh.vertices[vCounter], mesh.vertices[vCounter + 1], mesh.vertices[vCounter + 2] };
animVertex = Vector3Transform(animVertex,model.meshes[m].boneMatrices[boneId]); animVertex = Vector3Transform(animVertex, boneMatrix);
mesh.animVertices[vCounter] += animVertex.x*boneWeight; mesh.animVertices[vCounter] += animVertex.x*boneWeight;
mesh.animVertices[vCounter+1] += animVertex.y*boneWeight; mesh.animVertices[vCounter+1] += animVertex.y*boneWeight;
mesh.animVertices[vCounter+2] += animVertex.z*boneWeight; mesh.animVertices[vCounter+2] += animVertex.z*boneWeight;
@ -2390,10 +2395,10 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
// Normals processing // Normals processing
// NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals) // NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
if ((mesh.normals != NULL) && (mesh.animNormals != NULL )) if ((mesh.normals != NULL) && (mesh.animNormals != NULL))
{ {
animNormal = (Vector3){ mesh.normals[vCounter], mesh.normals[vCounter + 1], mesh.normals[vCounter + 2] }; animNormal = (Vector3){ mesh.normals[vCounter], mesh.normals[vCounter + 1], mesh.normals[vCounter + 2] };
animNormal = Vector3Transform(animNormal, MatrixTranspose(MatrixInvert(model.meshes[m].boneMatrices[boneId]))); animNormal = Vector3Transform(animNormal, InverseBoneMatrix);
mesh.animNormals[vCounter] += animNormal.x*boneWeight; mesh.animNormals[vCounter] += animNormal.x*boneWeight;
mesh.animNormals[vCounter + 1] += animNormal.y*boneWeight; mesh.animNormals[vCounter + 1] += animNormal.y*boneWeight;
mesh.animNormals[vCounter + 2] += animNormal.z*boneWeight; mesh.animNormals[vCounter + 2] += animNormal.z*boneWeight;