Skip to content

Commit 0e59563

Browse files
Trung NguyenTrung Nguyen
authored andcommitted
expose ModelAnimation.name -> string: to get name of animation.
1 parent 53a9847 commit 0e59563

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

examples/models/models_animation.ml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
let width = 800
22
let height = 450
33
let position = Raylib.Vector3.create 0.0 0.0 0.0
4+
let asset_path (filename: string) =
5+
Raylib.get_application_directory() ^ filename
46

57
let setup () =
68
let open Raylib in
@@ -12,17 +14,20 @@ let setup () =
1214
(Vector3.create 0.0 1.0 0.0)
1315
45.0 CameraProjection.Perspective
1416
in
15-
let model = load_model "resources/guy/guy.iqm" in
16-
let texture = load_texture "resources/guy/guytex.png" in
17+
let path = asset_path("") in
18+
let model = load_model (path ^ "./resources/guy/guy.iqm") in
19+
let texture = load_texture (path ^ "./resources/guy/guytex.png") in
1720
set_material_texture
1821
(CArray.get (Model.materials model) 0 |> addr)
1922
MaterialMapIndex.Albedo texture;
2023

21-
let anims = load_model_animations "resources/guy/guyanim.iqm" in
24+
let anims = load_model_animations (path ^ "./resources/guy/guyanim.iqm") in
2225

2326
disable_cursor ();
2427
set_target_fps 60;
2528
(camera, model, anims)
29+
let implode_char_list (l : char list) : string =
30+
l |> List.to_seq |> String.of_seq
2631

2732
let rec loop camera model anims frame_counter =
2833
match Raylib.window_should_close () with
@@ -34,10 +39,10 @@ let rec loop camera model anims frame_counter =
3439
| false ->
3540
let open Raylib in
3641
update_camera (addr camera) CameraMode.First_person;
42+
let anims0 = CArray.get anims 0 in
3743
let frame_counter =
3844
if is_key_down Key.Space then (
3945
let frame_counter = succ frame_counter in
40-
let anims0 = CArray.get anims 0 in
4146
update_model_animation model anims0 frame_counter;
4247
if frame_counter >= ModelAnimation.frame_count anims0 then 0
4348
else frame_counter)
@@ -57,14 +62,16 @@ let rec loop camera model anims frame_counter =
5762
CArray.iter
5863
(fun bone ->
5964
draw_cube (Transform.translation bone) 0.2 0.2 0.2 Color.red)
60-
(ModelAnimation.frame_poses_at (CArray.get anims 0) frame_counter);
65+
(ModelAnimation.frame_poses_at anims0 frame_counter);
6166
draw_grid 10 1.0;
6267

6368
end_mode_3d ();
6469

6570
draw_text "PRESS SPACE to PLAY MODEL ANIMATION" 10 10 20 Color.maroon;
6671
draw_text "(c) Guy IQM 3D model by @culacant" (width - 200) (height - 20)
6772
10 Color.gray;
73+
let anim_name = implode_char_list (CArray.to_list (ModelAnimation.name anims0)) in
74+
draw_text ("animation: " ^ anim_name) 10 32 20 Color.maroon;
6875
end_drawing ();
6976
loop camera model anims frame_counter
7077

src/raylib/raylib.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,8 @@ module ModelAnimation : sig
11371137

11381138
val frame_count : t -> int
11391139

1140+
val name : t -> char CArray.t
1141+
11401142
val frame_poses_at : t -> int -> Transform.t CArray.t
11411143
(** Poses array by frame *)
11421144

src/raylib/raylib_types.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ module ModelAnimation = struct
674674
let frame_count modelanimation =
675675
getf modelanimation ModelAnimation.frame_count
676676

677+
let name modelanimation =
678+
getf modelanimation ModelAnimation.name
679+
677680
let frame_poses_at anim index =
678681
let frame_count = getf anim ModelAnimation.frame_count in
679682
let poses =

0 commit comments

Comments
 (0)