Skip to content

Commit e89dc94

Browse files
Trung Nguyentjammer
authored andcommitted
- expose ModelAnimation.name -> string: to get name of animation.
- fixed asset path in example/model_animation.ml.
1 parent b42f17c commit e89dc94

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

examples/models/models_animation.ml

Lines changed: 10 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,13 +14,14 @@ 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;
@@ -34,10 +37,10 @@ let rec loop camera model anims frame_counter =
3437
| false ->
3538
let open Raylib in
3639
update_camera (addr camera) CameraMode.First_person;
40+
let anims0 = CArray.get anims 0 in
3741
let frame_counter =
3842
if is_key_down Key.Space then (
3943
let frame_counter = succ frame_counter in
40-
let anims0 = CArray.get anims 0 in
4144
update_model_animation model anims0 frame_counter;
4245
if frame_counter >= ModelAnimation.frame_count anims0 then 0
4346
else frame_counter)
@@ -57,14 +60,16 @@ let rec loop camera model anims frame_counter =
5760
CArray.iter
5861
(fun bone ->
5962
draw_cube (Transform.translation bone) 0.2 0.2 0.2 Color.red)
60-
(ModelAnimation.frame_poses_at (CArray.get anims 0) frame_counter);
63+
(ModelAnimation.frame_poses_at anims0 frame_counter);
6164
draw_grid 10 1.0;
6265

6366
end_mode_3d ();
6467

6568
draw_text "PRESS SPACE to PLAY MODEL ANIMATION" 10 10 20 Color.maroon;
6669
draw_text "(c) Guy IQM 3D model by @culacant" (width - 200) (height - 20)
6770
10 Color.gray;
71+
let anim_name = ModelAnimation.name anims0 in
72+
draw_text ("animation: " ^ anim_name) 10 32 20 Color.maroon;
6873
end_drawing ();
6974
loop camera model anims frame_counter
7075

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 -> string
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,10 @@ module ModelAnimation = struct
674674
let frame_count modelanimation =
675675
getf modelanimation ModelAnimation.frame_count
676676

677+
let name modelanimation =
678+
let ptr = Ctypes.CArray.start (getf modelanimation ModelAnimation.name) in
679+
Ctypes.string_from_ptr ptr ~length:32
680+
677681
let frame_poses_at anim index =
678682
let frame_count = getf anim ModelAnimation.frame_count in
679683
let poses =

0 commit comments

Comments
 (0)