diff --git a/examples/models/models_loading_gltf.c b/examples/models/models_loading_gltf.c index 750bd7be2..cf6510673 100644 --- a/examples/models/models_loading_gltf.c +++ b/examples/models/models_loading_gltf.c @@ -35,9 +35,10 @@ int main(void) // Loaf gltf model Model model = LoadModel("resources/models/gltf/robot.glb"); - unsigned int animationCount; - ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/robot.glb", &animationCount); - ModelAnimation anim = modelAnimations[0]; + unsigned int animsCount; + ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/robot.glb", &animsCount); + + unsigned int animIndex = 0; 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 //-------------------------------------------------------------------------------------- + unsigned int currentFrame = 0; + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // 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); - UpdateModelAnimation(model, anim, 2); //---------------------------------------------------------------------------------- // Draw @@ -68,6 +80,8 @@ int main(void) EndMode3D(); + DrawText("Use the up/down arrow keys to switch animation.", 10, 10, 20, WHITE); + EndDrawing(); //---------------------------------------------------------------------------------- } @@ -75,7 +89,7 @@ int main(void) // De-Initialization //-------------------------------------------------------------------------------------- UnloadModel(model); // Unload model and meshes/material - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/models/resources/models/gltf/robot.blend b/examples/models/resources/models/gltf/robot.blend index d3bdac237..efe43c5e5 100644 Binary files a/examples/models/resources/models/gltf/robot.blend and b/examples/models/resources/models/gltf/robot.blend differ diff --git a/examples/models/resources/models/gltf/robot.glb b/examples/models/resources/models/gltf/robot.glb index 73f5bf44e..549011e75 100644 Binary files a/examples/models/resources/models/gltf/robot.glb and b/examples/models/resources/models/gltf/robot.glb differ