From 6ff0b03629bec6452d4576e1ffdc91864ef7db03 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 24 Oct 2024 12:46:02 +0200 Subject: [PATCH] REVIEWED: `UpdateModelAnimationBoneMatrices()` comments --- examples/models/models_gpu_skinning.c | 11 ++++++----- src/raylib.h | 4 ++-- src/rmodels.c | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/models/models_gpu_skinning.c b/examples/models/models_gpu_skinning.c index 6868a62d3fd5..7e81b0d82d42 100644 --- a/examples/models/models_gpu_skinning.c +++ b/examples/models/models_gpu_skinning.c @@ -93,10 +93,11 @@ int main(void) BeginMode3D(camera); - // Draw character + // Draw character mesh, pose calculation is done in shader (GPU skinning) DrawMesh(characterModel.meshes[0], characterModel.materials[1], characterModel.transform); DrawGrid(10, 1.0f); + EndMode3D(); DrawText("Use the T/G to switch animation", 10, 10, 20, GRAY); @@ -107,11 +108,11 @@ int main(void) // De-Initialization //-------------------------------------------------------------------------------------- - UnloadModelAnimations(modelAnimations, animsCount); - UnloadModel(characterModel); // Unload character model and meshes/material - UnloadShader(skinningShader); + UnloadModelAnimations(modelAnimations, animsCount); // Unload model animation + UnloadModel(characterModel); // Unload model and meshes/material + UnloadShader(skinningShader); // Unload GPU skinning shader - CloseWindow(); // Close window and OpenGL context + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; diff --git a/src/raylib.h b/src/raylib.h index bc7bc372cd1a..c9d9f6e54717 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1601,11 +1601,11 @@ RLAPI void SetModelMeshMaterial(Model *model, int meshId, int materialId); // Model animations loading/unloading functions RLAPI ModelAnimation *LoadModelAnimations(const char *fileName, int *animCount); // Load model animations from file -RLAPI void UpdateModelAnimation(Model model, ModelAnimation anim, int frame); // Update model animation pose +RLAPI void UpdateModelAnimation(Model model, ModelAnimation anim, int frame); // Update model animation pose (CPU) +RLAPI void UpdateModelAnimationBoneMatrices(Model model, ModelAnimation anim, int frame); // Update model animation mesh bone matrices (GPU skinning) RLAPI void UnloadModelAnimation(ModelAnimation anim); // Unload animation data RLAPI void UnloadModelAnimations(ModelAnimation *animations, int animCount); // Unload animation array data RLAPI bool IsModelAnimationValid(Model model, ModelAnimation anim); // Check model animation skeleton match -RLAPI void UpdateModelAnimationBoneMatrices(Model model, ModelAnimation anim, int frame); // Update model animation mesh bone matrices (Note GPU skinning does not work on Mac) // Collision detection functions RLAPI bool CheckCollisionSpheres(Vector3 center1, float radius1, Vector3 center2, float radius2); // Check collision between two spheres diff --git a/src/rmodels.c b/src/rmodels.c index 30130d9e0947..ed15d96586c5 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -2364,6 +2364,9 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame) } } +// Update model animated bones transform matrices for a given frame +// NOTE: Updated data is not uploaded to GPU but kept at model.meshes[i].boneMatrices[boneId], +// to be uploaded to shader at drawing, in case GPU skinning is enabled void UpdateModelAnimationBoneMatrices(Model model, ModelAnimation anim, int frame) { if ((anim.frameCount > 0) && (anim.bones != NULL) && (anim.framePoses != NULL))