1
1
/*******************************************************************************************
2
2
*
3
- * raylib [models] example - Load IQM 3d model with animations and play them
3
+ * raylib [models] example - Load 3d model with animations and play them
4
4
*
5
- * This example has been created using raylib 2.0 (www.raylib.com)
5
+ * This example has been created using raylib 2.5 (www.raylib.com)
6
6
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
7
7
*
8
- * Copyright (c) 2018 @culacant and @raysan5
8
+ * Copyright (c) 2019 Ramon Santamaria (@raysan5) and @culacant
9
9
*
10
10
********************************************************************************************/
11
11
12
12
#include "raylib.h"
13
13
14
- #define RIQM_IMPLEMENTATION
15
- #include "riqm.h"
16
-
17
14
int main ()
18
15
{
19
16
// Initialization
20
17
//--------------------------------------------------------------------------------------
21
18
int screenWidth = 800 ;
22
19
int screenHeight = 450 ;
23
20
24
- InitWindow (screenWidth , screenHeight , "raylib [models] example - iqm animation" );
21
+ InitWindow (screenWidth , screenHeight , "raylib [models] example - model animation" );
25
22
26
23
// Define the camera to look into our 3d world
27
24
Camera camera = { 0 };
@@ -31,26 +28,25 @@ int main()
31
28
camera .fovy = 45.0f ; // Camera field-of-view Y
32
29
camera .type = CAMERA_PERSPECTIVE ; // Camera mode type
33
30
34
- // Load the animated model mesh and basic data
35
- AnimatedModel model = LoadAnimatedModel ("resources/guy.iqm" );
36
31
37
- // Load model texture and set material
38
- // NOTE: There is only 1 mesh and 1 material (both at index 0), thats what the 2 0's are
39
- model = AnimatedModelAddTexture (model , "resources/guytex.png" ); // REPLACE!
40
- model = SetMeshMaterial (model , 0 , 0 ); // REPLACE!
32
+ Model model = LoadModel ("resources/guy/guy.iqm" ); // Load the animated model mesh and basic data
33
+ Texture2D texture = LoadTexture ("resources/guy/guytex.png" ); // Load model texture and set material
34
+ SetMaterialTexture (& model .materials [0 ], MAP_DIFFUSE , texture ); // Set model material map texture
35
+
36
+ Vector3 position = { 0.0f , 0.0f , 0.0f }; // Set model position
41
37
42
38
// Load animation data
43
- Animation anim = LoadAnimationFromIQM ( "resources/guyanim.iqm" ) ;
44
-
39
+ int animsCount = 0 ;
40
+ ModelAnimation * anims = LoadModelAnimations ( "resources/guy/guyanim.iqm" , & animsCount );
45
41
int animFrameCounter = 0 ;
46
42
47
- SetCameraMode (camera , CAMERA_FREE ); // Set free camera mode
43
+ SetCameraMode (camera , CAMERA_FREE ); // Set free camera mode
48
44
49
- SetTargetFPS (60 ); // Set our game to run at 60 frames-per-second
45
+ SetTargetFPS (60 ); // Set our game to run at 60 frames-per-second
50
46
//--------------------------------------------------------------------------------------
51
47
52
48
// Main game loop
53
- while (!WindowShouldClose ()) // Detect window close button or ESC key
49
+ while (!WindowShouldClose ()) // Detect window close button or ESC key
54
50
{
55
51
// Update
56
52
//----------------------------------------------------------------------------------
@@ -60,7 +56,8 @@ int main()
60
56
if (IsKeyDown (KEY_SPACE ))
61
57
{
62
58
animFrameCounter ++ ;
63
- AnimateModel (model , anim , animFrameCounter ); // Animate the model with animation data and frame
59
+ UpdateModelAnimation (model , anims [0 ], animFrameCounter );
60
+ if (animFrameCounter >= anims [0 ].frameCount ) animFrameCounter = 0 ;
64
61
}
65
62
//----------------------------------------------------------------------------------
66
63
@@ -72,14 +69,18 @@ int main()
72
69
73
70
BeginMode3D (camera );
74
71
75
- DrawAnimatedModel (model , Vector3Zero (), 1.0f , WHITE ); // Draw animated model
72
+ DrawModelEx (model , position , (Vector3 ){ 1.0f , 0.0f , 0.0f }, -90.0f , (Vector3 ){ 1.0f , 1.0f , 1.0f }, WHITE );
73
+
74
+ for (int i = 0 ; i < model .boneCount ; i ++ )
75
+ {
76
+ DrawCube (anims [0 ].framePoses [animFrameCounter ][i ].translation , 0.2f , 0.2f , 0.2f , RED );
77
+ }
76
78
77
79
DrawGrid (10 , 1.0f ); // Draw a grid
78
80
79
81
EndMode3D ();
80
-
81
- DrawText ("PRESS SPACE to PLAY IQM MODEL ANIMATION" , 10 , 10 , 20 , MAROON );
82
82
83
+ DrawText ("PRESS SPACE to PLAY MODEL ANIMATION" , 10 , 10 , 20 , MAROON );
83
84
DrawText ("(c) Guy IQM 3D model by @culacant" , screenWidth - 200 , screenHeight - 20 , 10 , GRAY );
84
85
85
86
EndDrawing ();
@@ -88,8 +89,10 @@ int main()
88
89
89
90
// De-Initialization
90
91
//--------------------------------------------------------------------------------------
91
- UnloadAnimation (anim ); // Unload animation data
92
- UnloadAnimatedModel (model ); // Unload animated model
92
+ // Unload model animations data
93
+ for (int i = 0 ; i < animsCount ; i ++ ) UnloadModelAnimation (anims [i ]);
94
+
95
+ UnloadModel (model ); // Unload model
93
96
94
97
CloseWindow (); // Close window and OpenGL context
95
98
//--------------------------------------------------------------------------------------
0 commit comments