diff options
| author | Hristo Stamenov <[email protected]> | 2021-03-14 13:09:31 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-03-14 12:09:31 +0100 |
| commit | f9b79403d1142d61ea0ed6f41456600bb06a7318 (patch) | |
| tree | 89482f2b6c8f4622aecd1154f9490f38fb07868d /examples/models/models_gltf_model.c | |
| parent | 01e28263be9869b28acae5cf1128472269626edb (diff) | |
| download | raylib-f9b79403d1142d61ea0ed6f41456600bb06a7318.tar.gz raylib-f9b79403d1142d61ea0ed6f41456600bb06a7318.zip | |
Improve gltf support (#1647)
* Implement a load values from accessor function.
Added some more value types for the different GLTF attributes.
Fixed crash when loading animated triangle.
* Split GLTF model loading into separate functions for readability.
* Fixed the already working models that I broke when introducing GLTFReadValue.
Improved the example for gltf models to be able to switch between a few models.
* Removed license from screen. It is pu inside a license file anyway.
* Small improvements on the naming of functions
Removed (*model). and replaced it with model->
Diffstat (limited to 'examples/models/models_gltf_model.c')
| -rw-r--r-- | examples/models/models_gltf_model.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/examples/models/models_gltf_model.c b/examples/models/models_gltf_model.c index c064e34f..2e9e8456 100644 --- a/examples/models/models_gltf_model.c +++ b/examples/models/models_gltf_model.c @@ -39,7 +39,18 @@ int main(void) camera.fovy = 45.0f; // Camera field-of-view Y camera.type = CAMERA_PERSPECTIVE; // Camera mode type - Model model = LoadModel("resources/gltf/Avocado.glb"); // Load the animated model mesh and + Model model[7]; + + model[0] = LoadModel("resources/gltf/raylib_32x32.glb"); + model[1] = LoadModel("resources/gltf/rigged_figure.glb"); + model[2] = LoadModel("resources/gltf/Avocado.glb"); + model[3] = LoadModel("resources/gltf/GearboxAssy.glb"); + model[4] = LoadModel("resources/gltf/BoxAnimated.glb"); + model[5] = LoadModel("resources/gltf/AnimatedTriangle.gltf"); + model[6] = LoadModel("resources/gltf/AnimatedMorphCube.glb"); + + int currentModel = 0; + int modelCount = 7; Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position @@ -54,23 +65,39 @@ int main(void) // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); + + if(IsKeyReleased(KEY_RIGHT)) + { + currentModel++; + if(currentModel == modelCount) + { + currentModel = 0; + } + } + + if(IsKeyReleased(KEY_LEFT)) + { + currentModel--; + if(currentModel < 0) + { + currentModel = modelCount - 1; + } + } // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(RAYWHITE); + ClearBackground(SKYBLUE); BeginMode3D(camera); - DrawModelEx(model, position, (Vector3){ 0.0f, 1.0f, 0.0f }, 180.0f, (Vector3){ 15.0f, 15.0f, 15.0f }, WHITE); + DrawModelEx(model[currentModel], position, (Vector3){ 0.0f, 1.0f, 0.0f }, 180.0f, (Vector3){ 2.0f, 2.0f, 2.0f }, WHITE); DrawGrid(10, 1.0f); // Draw a grid EndMode3D(); - DrawText("(cc0) Avocado by @Microsoft", screenWidth - 200, screenHeight - 20, 10, GRAY); - EndDrawing(); //---------------------------------------------------------------------------------- } @@ -78,7 +105,10 @@ int main(void) // De-Initialization //-------------------------------------------------------------------------------------- - UnloadModel(model); // Unload model + for(int i = 0; i < modelCount; i++) + { + UnloadModel(model[i]); // Unload model + } CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- |
