update models/models_loading_gltf.c to play gltf animation

Updated the .blend file to use weights rather than bone parents so it
fits into the framework. Exported with weights to the .glb file.
This commit is contained in:
nc 2022-12-30 21:16:13 -05:00
parent 4aa5796993
commit 1289a892b0
3 changed files with 19 additions and 5 deletions

View File

@ -35,9 +35,10 @@ int main(void)
// Loaf gltf model // Loaf gltf model
Model model = LoadModel("resources/models/gltf/robot.glb"); Model model = LoadModel("resources/models/gltf/robot.glb");
unsigned int animationCount; unsigned int animsCount;
ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/robot.glb", &animationCount); ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/robot.glb", &animsCount);
ModelAnimation anim = modelAnimations[0];
unsigned int animIndex = 0;
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
@ -46,13 +47,24 @@ int main(void)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
unsigned int currentFrame = 0;
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
ModelAnimation anim = modelAnimations[animIndex];
if(IsKeyPressed(KEY_UP)) {
animIndex = (animIndex + 1) % animsCount;
}
if(IsKeyPressed(KEY_DOWN)) {
animIndex = (animIndex + animsCount - 1) % animsCount;
}
currentFrame = (currentFrame + 1) % anim.frameCount;
UpdateModelAnimation(model, anim, currentFrame);
UpdateCamera(&camera); UpdateCamera(&camera);
UpdateModelAnimation(model, anim, 2);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -68,6 +80,8 @@ int main(void)
EndMode3D(); EndMode3D();
DrawText("Use the up/down arrow keys to switch animation.", 10, 10, 20, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }