Skip to content

Commit ae6d34a

Browse files
committed
Renamed some models examples for consistency
1 parent 542333b commit ae6d34a

15 files changed

Lines changed: 790 additions & 97 deletions

examples/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,10 @@ TEXT = \
657657
text/text_writing_anim
658658

659659
MODELS = \
660+
models/models_animation_blend_custom \
660661
models/models_animation_blending \
661-
models/models_animation_bone_blending \
662662
models/models_animation_gpu_skinning \
663-
models/models_loading_iqm \
663+
models/models_animation_timming \
664664
models/models_basic_voxel \
665665
models/models_billboard_rendering \
666666
models/models_bone_socket \
@@ -673,6 +673,7 @@ MODELS = \
673673
models/models_heightmap_rendering \
674674
models/models_loading \
675675
models/models_loading_gltf \
676+
models/models_loading_iqm \
676677
models/models_loading_m3d \
677678
models/models_loading_vox \
678679
models/models_mesh_generation \

examples/Makefile.Web

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,10 @@ TEXT = \
642642
text/text_writing_anim
643643

644644
MODELS = \
645+
models/models_animation_blend_custom \
645646
models/models_animation_blending \
646-
models/models_animation_bone_blending \
647647
models/models_animation_gpu_skinning \
648-
models/models_loading_iqm \
648+
models/models_animation_timming \
649649
models/models_basic_voxel \
650650
models/models_billboard_rendering \
651651
models/models_bone_socket \
@@ -658,6 +658,7 @@ MODELS = \
658658
models/models_heightmap_rendering \
659659
models/models_loading \
660660
models/models_loading_gltf \
661+
models/models_loading_iqm \
661662
models/models_loading_m3d \
662663
models/models_loading_vox \
663664
models/models_mesh_generation \
@@ -1199,15 +1200,15 @@ text/text_writing_anim: text/text_writing_anim.c
11991200
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
12001201

12011202
# Compile MODELS examples
1202-
models/models_animation_blending: models/models_animation_blending.c
1203+
models/models_animation_blend_custom: models/models_animation_blend_custom.c
12031204
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
1204-
--preload-file models/resources/models/gltf/robot.glb@resources/models/gltf/robot.glb \
1205+
--preload-file models/resources/models/gltf/greenman.glb@resources/models/gltf/greenman.glb \
12051206
--preload-file models/resources/shaders/glsl100/skinning.vs@resources/shaders/glsl100/skinning.vs \
12061207
--preload-file models/resources/shaders/glsl100/skinning.fs@resources/shaders/glsl100/skinning.fs
12071208

1208-
models/models_animation_bone_blending: models/models_animation_bone_blending.c
1209+
models/models_animation_blending: models/models_animation_blending.c
12091210
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
1210-
--preload-file models/resources/models/gltf/greenman.glb@resources/models/gltf/greenman.glb \
1211+
--preload-file models/resources/models/gltf/robot.glb@resources/models/gltf/robot.glb \
12111212
--preload-file models/resources/shaders/glsl100/skinning.vs@resources/shaders/glsl100/skinning.vs \
12121213
--preload-file models/resources/shaders/glsl100/skinning.fs@resources/shaders/glsl100/skinning.fs
12131214

@@ -1217,11 +1218,9 @@ models/models_animation_gpu_skinning: models/models_animation_gpu_skinning.c
12171218
--preload-file models/resources/shaders/glsl100/skinning.vs@resources/shaders/glsl100/skinning.vs \
12181219
--preload-file models/resources/shaders/glsl100/skinning.fs@resources/shaders/glsl100/skinning.fs
12191220

1220-
models/models_loading_iqm: models/models_loading_iqm.c
1221+
models/models_animation_timming: models/models_animation_timming.c
12211222
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
1222-
--preload-file models/resources/models/iqm/guy.iqm@resources/models/iqm/guy.iqm \
1223-
--preload-file models/resources/models/iqm/guytex.png@resources/models/iqm/guytex.png \
1224-
--preload-file models/resources/models/iqm/guyanim.iqm@resources/models/iqm/guyanim.iqm
1223+
--preload-file models/resources/models/gltf/robot.glb@resources/models/gltf/robot.glb
12251224

12261225
models/models_basic_voxel: models/models_basic_voxel.c
12271226
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
@@ -1276,6 +1275,12 @@ models/models_loading_gltf: models/models_loading_gltf.c
12761275
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
12771276
--preload-file models/resources/models/gltf/robot.glb@resources/models/gltf/robot.glb
12781277

1278+
models/models_loading_iqm: models/models_loading_iqm.c
1279+
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
1280+
--preload-file models/resources/models/iqm/guy.iqm@resources/models/iqm/guy.iqm \
1281+
--preload-file models/resources/models/iqm/guytex.png@resources/models/iqm/guytex.png \
1282+
--preload-file models/resources/models/iqm/guyanim.iqm@resources/models/iqm/guyanim.iqm
1283+
12791284
models/models_loading_m3d: models/models_loading_m3d.c
12801285
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
12811286
--preload-file models/resources/models/m3d/cesium_man.m3d@resources/models/m3d/cesium_man.m3d

examples/examples_list.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ models;models_basic_voxel;★★☆☆;5.5;5.5;2025;2025;"Tim Little";@timlittle
171171
models;models_rotating_cube;★☆☆☆;5.6-dev;5.6-dev;2025;2025;"Jopestpe";@jopestpe
172172
models;models_decals;★★★★;5.6-dev;5.6-dev;2025;2025;"JP Mortiboys";@themushroompirates
173173
models;models_directional_billboard;★★☆☆;5.6-dev;5.6;2025;2025;"Robin";@RobinsAviary
174-
models;models_animation_bone_blending;★★★★;5.5;5.5;2026;2026;"dmitrii-brand";@dmitrii-brand
174+
models;models_animation_blend_custom;★★★★;5.5;5.5;2026;2026;"dmitrii-brand";@dmitrii-brand
175175
models;models_animation_blending;☆☆☆☆;5.5;5.6-dev;2024;2024;"Kirandeep";@Kirandeep-Singh-Khehra
176+
models;models_animation_timming;★★☆☆;5.6;5.6;2026;2026;"Ramon Santamaria";@raysan5
176177
shaders;shaders_ascii_rendering;★★☆☆;5.5;5.6;2025;2025;"Maicon Santana";@maiconpintoabreu
177178
shaders;shaders_basic_lighting;★★★★;3.0;4.2;2019;2025;"Chris Camacho";@chriscamacho
178179
shaders;shaders_model_shader;★★☆☆;1.3;3.7;2014;2025;"Ramon Santamaria";@raysan5

examples/models/models_animation_bone_blending.c renamed to examples/models/models_animation_blend_custom.c

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************************
22
*
3-
* raylib [models] example - animation bone blending
3+
* raylib [models] example - animation blend custom
44
*
55
* Example complexity rating: [★★★★] 4/4
66
*
@@ -53,7 +53,7 @@ int main(void)
5353
const int screenWidth = 800;
5454
const int screenHeight = 450;
5555

56-
InitWindow(screenWidth, screenHeight, "raylib [models] example - animation bone blending");
56+
InitWindow(screenWidth, screenHeight, "raylib [models] example - animation blend custom");
5757

5858
// Define the camera to look into our 3d world
5959
Camera camera = { 0 };
@@ -80,7 +80,7 @@ int main(void)
8080
TraceLog(LOG_INFO, "Found %d animations:", animsCount);
8181
for (int i = 0; i < animsCount; i++)
8282
{
83-
TraceLog(LOG_INFO, " Animation %d: %s (%d frames)", i, modelAnimations[i].name, modelAnimations[i].frameCount);
83+
TraceLog(LOG_INFO, " Animation %d: %s (%d frames)", i, modelAnimations[i].name, modelAnimations[i].keyframeCount);
8484
}
8585

8686
// Use specific indices: walk/move = 2, attack = 3
@@ -118,8 +118,8 @@ int main(void)
118118
ModelAnimation anim1 = modelAnimations[animIndex1];
119119
ModelAnimation anim2 = modelAnimations[animIndex2];
120120

121-
animCurrentFrame1 = (animCurrentFrame1 + 1)%anim1.frameCount;
122-
animCurrentFrame2 = (animCurrentFrame2 + 1)%anim2.frameCount;
121+
animCurrentFrame1 = (animCurrentFrame1 + 1)%anim1.keyframeCount;
122+
animCurrentFrame2 = (animCurrentFrame2 + 1)%anim2.keyframeCount;
123123

124124
// Blend the two animations
125125
characterModel.transform = MatrixTranslate(position.x, position.y, position.z);
@@ -203,9 +203,9 @@ static void BlendModelAnimationsBones(Model *model, ModelAnimation *anim1, int f
203203
ModelAnimation *anim2, int frame2, float blendFactor, bool upperBodyBlend)
204204
{
205205
// Validate inputs
206-
if (anim1->boneCount == 0 || anim1->framePoses == NULL ||
207-
anim2->boneCount == 0 || anim2->framePoses == NULL ||
208-
model->boneCount == 0 || model->bindPose == NULL)
206+
if (anim1->boneCount == 0 || anim1->keyframePoses == NULL ||
207+
anim2->boneCount == 0 || anim2->keyframePoses == NULL ||
208+
model->skeleton.boneCount == 0 || model->skeleton.bindPose == NULL)
209209
{
210210
return;
211211
}
@@ -214,26 +214,13 @@ static void BlendModelAnimationsBones(Model *model, ModelAnimation *anim1, int f
214214
blendFactor = fminf(1.0f, fmaxf(0.0f, blendFactor));
215215

216216
// Ensure frame indices are valid
217-
if (frame1 >= anim1->frameCount) frame1 = anim1->frameCount - 1;
218-
if (frame2 >= anim2->frameCount) frame2 = anim2->frameCount - 1;
217+
if (frame1 >= anim1->keyframeCount) frame1 = anim1->keyframeCount - 1;
218+
if (frame2 >= anim2->keyframeCount) frame2 = anim2->keyframeCount - 1;
219219
if (frame1 < 0) frame1 = 0;
220220
if (frame2 < 0) frame2 = 0;
221221

222-
// Find first mesh with bones
223-
int firstMeshWithBones = -1;
224-
for (int i = 0; i < model->meshCount; i++)
225-
{
226-
if (model->meshes[i].boneMatrices)
227-
{
228-
firstMeshWithBones = i;
229-
break;
230-
}
231-
}
232-
233-
if (firstMeshWithBones == -1) return;
234-
235222
// Get bone count (use minimum of all to be safe)
236-
int boneCount = model->boneCount;
223+
int boneCount = model->skeleton.boneCount;
237224
if (anim1->boneCount < boneCount) boneCount = anim1->boneCount;
238225
if (anim2->boneCount < boneCount) boneCount = anim2->boneCount;
239226

@@ -246,7 +233,7 @@ static void BlendModelAnimationsBones(Model *model, ModelAnimation *anim1, int f
246233
// If upper body blending is enabled, use different blend factors for upper vs lower body
247234
if (upperBodyBlend)
248235
{
249-
const char *boneName = model->bones[boneId].name;
236+
const char *boneName = model->skeleton.bones[boneId].name;
250237
bool isUpperBody = IsUpperBodyBone(boneName);
251238

252239
// Upper body: use anim2 (attack), Lower body: use anim1 (walk)
@@ -256,12 +243,12 @@ static void BlendModelAnimationsBones(Model *model, ModelAnimation *anim1, int f
256243
}
257244

258245
// Get transforms from both animations
259-
Transform *bindTransform = &model->bindPose[boneId];
260-
Transform *anim1Transform = &anim1->framePoses[frame1][boneId];
261-
Transform *anim2Transform = &anim2->framePoses[frame2][boneId];
246+
Transform *bindTransform = &model->skeleton.bindPose[boneId];
247+
Transform *anim1Transform = &anim1->keyframePoses[frame1][boneId];
248+
Transform *anim2Transform = &anim2->keyframePoses[frame2][boneId];
262249

263250
// Blend the transforms
264-
Transform blended;
251+
Transform blended = { 0 };
265252
blended.translation = Vector3Lerp(anim1Transform->translation, anim2Transform->translation, boneBlendFactor);
266253
blended.rotation = QuaternionSlerp(anim1Transform->rotation, anim2Transform->rotation, boneBlendFactor);
267254
blended.scale = Vector3Lerp(anim1Transform->scale, anim2Transform->scale, boneBlendFactor);
@@ -279,18 +266,7 @@ static void BlendModelAnimationsBones(Model *model, ModelAnimation *anim1, int f
279266
MatrixTranslate(blended.translation.x, blended.translation.y, blended.translation.z));
280267

281268
// Calculate final bone matrix (similar to UpdateModelAnimationBones)
282-
model->meshes[firstMeshWithBones].boneMatrices[boneId] = MatrixMultiply(MatrixInvert(bindMatrix), blendedMatrix);
283-
}
284-
285-
// Copy bone matrices to remaining meshes
286-
for (int i = firstMeshWithBones + 1; i < model->meshCount; i++)
287-
{
288-
if (model->meshes[i].boneMatrices)
289-
{
290-
memcpy(model->meshes[i].boneMatrices,
291-
model->meshes[firstMeshWithBones].boneMatrices,
292-
model->meshes[i].boneCount*sizeof(model->meshes[i].boneMatrices[0]));
293-
}
269+
model->boneMatrices[boneId] = MatrixMultiply(MatrixInvert(bindMatrix), blendedMatrix);
294270
}
295271
}
296272

23.4 KB
Loading

examples/models/models_animation_blending.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* raylib [models] example - animation blending
44
*
5-
* Example complexity rating: [★★★☆] 3/4
5+
* Example complexity rating: [☆☆☆☆] 0/4
66
*
77
* Example originally created with raylib 5.5, last time updated with raylib 5.6-dev
88
*

examples/models/models_animation_gpu_skinning.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
*
99
* Example contributed by Daniel Holden (@orangeduck) and reviewed by Ramon Santamaria (@raysan5)
1010
*
11+
* WARNING: GPU skinning must be enabled in raylib with a compilation flag,
12+
* if not enabled, CPU skinning will be used instead
13+
* NOTE: Due to limitations in the Apple OpenGL driver, this feature does not work on MacOS
14+
*
1115
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
1216
* BSD-like license that allows static linking with closed source software
1317
*
1418
* Copyright (c) 2024-2025 Daniel Holden (@orangeduck)
1519
*
16-
* Note: Due to limitations in the Apple OpenGL driver, this feature does not work on MacOS
17-
*
1820
********************************************************************************************/
1921

2022
#include "raylib.h"
@@ -42,29 +44,29 @@ int main(void)
4244
// Define the camera to look into our 3d world
4345
Camera camera = { 0 };
4446
camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position
45-
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
47+
camera.target = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera looking at point
4648
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
4749
camera.fovy = 45.0f; // Camera field-of-view Y
4850
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
4951

5052
// Load gltf model
51-
Model characterModel = LoadModel("resources/models/gltf/greenman.glb"); // Load character model
53+
Model model = LoadModel("resources/models/gltf/greenman.glb"); // Load character model
54+
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
5255

5356
// Load skinning shader
57+
// WARNING: GPU skinning must be enabled in raylib with a compilation flag,
58+
// if not enabled, CPU skinning will be used instead
5459
Shader skinningShader = LoadShader(TextFormat("resources/shaders/glsl%i/skinning.vs", GLSL_VERSION),
5560
TextFormat("resources/shaders/glsl%i/skinning.fs", GLSL_VERSION));
56-
57-
characterModel.materials[1].shader = skinningShader;
61+
model.materials[1].shader = skinningShader;
5862

5963
// Load gltf model animations
60-
int animsCount = 0;
61-
unsigned int animIndex = 0;
62-
unsigned int animCurrentFrame = 0;
63-
ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/greenman.glb", &animsCount);
64-
65-
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
64+
int animCount = 0;
65+
ModelAnimation *anims = LoadModelAnimations("resources/models/gltf/greenman.glb", &animCount);
6666

67-
DisableCursor(); // Limit cursor to relative movement inside the window
67+
// Animation playing variables
68+
unsigned int animIndex = 0; // Current animation playing
69+
unsigned int animCurrentFrame = 0; // Current animation frame
6870

6971
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
7072
//--------------------------------------------------------------------------------------
@@ -74,17 +76,15 @@ int main(void)
7476
{
7577
// Update
7678
//----------------------------------------------------------------------------------
77-
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
79+
UpdateCamera(&camera, CAMERA_ORBITAL);
7880

7981
// Select current animation
80-
if (IsKeyPressed(KEY_T)) animIndex = (animIndex + 1)%animsCount;
81-
else if (IsKeyPressed(KEY_G)) animIndex = (animIndex + animsCount - 1)%animsCount;
82+
if (IsKeyPressed(KEY_RIGHT)) animIndex = (animIndex + 1)%animCount;
83+
else if (IsKeyPressed(KEY_LEFT)) animIndex = (animIndex + animCount - 1)%animCount;
8284

8385
// Update model animation
84-
ModelAnimation anim = modelAnimations[animIndex];
85-
animCurrentFrame = (animCurrentFrame + 1)%anim.frameCount;
86-
characterModel.transform = MatrixTranslate(position.x, position.y, position.z);
87-
UpdateModelAnimationBones(characterModel, anim, animCurrentFrame);
86+
animCurrentFrame = (animCurrentFrame + 1)%anims[animIndex].keyframeCount;
87+
UpdateModelAnimation(model, anims[animIndex], (float)animCurrentFrame);
8888
//----------------------------------------------------------------------------------
8989

9090
// Draw
@@ -95,23 +95,23 @@ int main(void)
9595

9696
BeginMode3D(camera);
9797

98-
// Draw character mesh, pose calculation is done in shader (GPU skinning)
99-
DrawMesh(characterModel.meshes[0], characterModel.materials[1], characterModel.transform);
98+
DrawModel(model, position, 1.0f, WHITE);
10099

101100
DrawGrid(10, 1.0f);
102101

103102
EndMode3D();
104103

105-
DrawText("Use the T/G to switch animation", 10, 10, 20, GRAY);
104+
DrawText(TextFormat("Current animation: %s", anims[animIndex].name), 10, 40, 20, MAROON);
105+
DrawText("Use the LEFT/RIGHT keys to switch animation", 10, 10, 20, GRAY);
106106

107107
EndDrawing();
108108
//----------------------------------------------------------------------------------
109109
}
110110

111111
// De-Initialization
112112
//--------------------------------------------------------------------------------------
113-
UnloadModelAnimations(modelAnimations, animsCount); // Unload model animation
114-
UnloadModel(characterModel); // Unload model and meshes/material
113+
UnloadModelAnimations(anims, animCount); // Unload model animation
114+
UnloadModel(model); // Unload model and meshes/material
115115
UnloadShader(skinningShader); // Unload GPU skinning shader
116116

117117
CloseWindow(); // Close window and OpenGL context

0 commit comments

Comments
 (0)