r3d_animation.odin 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* r3d_animation.odin -- R3D Animation Module.
  2. *
  3. * Copyright (c) 2025-2026 Le Juez Victor
  4. *
  5. * This software is provided 'as-is', without any express or implied warranty.
  6. * For conditions of distribution and use, see accompanying LICENSE file.
  7. */
  8. package r3d
  9. import rl "vendor:raylib"
  10. when ODIN_OS == .Windows {
  11. foreign import lib {
  12. "windows/libr3d.a",
  13. "system:raylib",
  14. "system:assimp",
  15. }
  16. } else when ODIN_OS == .Linux {
  17. foreign import lib {
  18. "linux/libr3d.a",
  19. "system:raylib",
  20. "system:assimp",
  21. }
  22. } else when ODIN_OS == .Darwin {
  23. foreign import lib {
  24. "darwin/libr3d.a",
  25. "system:raylib",
  26. "system:assimp",
  27. }
  28. }
  29. /**
  30. * @brief Animation track storing keyframe times and values.
  31. *
  32. * Represents a single animated property (translation, rotation or scale).
  33. * Keys are sampled by time and interpolated at runtime.
  34. */
  35. AnimationTrack :: struct {
  36. times: [^]f32, ///< Keyframe times (sorted, in animation ticks).
  37. values: [^]f32, ///< Keyframe values (rl.Vector3 or rl.Quaternion).
  38. count: i32, ///< Number of keyframes.
  39. }
  40. /**
  41. * @brief Animation channel controlling a single bone.
  42. *
  43. * Contains animation tracks for translation, rotation and scale.
  44. * The sampled tracks are combined to produce the bone local transform.
  45. */
  46. AnimationChannel :: struct {
  47. translation: AnimationTrack, ///< Translation track (rl.Vector3).
  48. rotation: AnimationTrack, ///< Rotation track (rl.Quaternion).
  49. scale: AnimationTrack, ///< Scale track (rl.Vector3).
  50. boneIndex: i32, ///< Index of the affected bone.
  51. }
  52. /**
  53. * @brief Represents a skeletal animation for a model.
  54. *
  55. * Contains all animation channels required to animate a skeleton.
  56. * Each channel corresponds to one bone and defines its transformation
  57. * (translation, rotation, scale) over time.
  58. */
  59. Animation :: struct {
  60. channels: [^]AnimationChannel, ///< Array of animation channels, one per animated bone.
  61. channelCount: i32, ///< Total number of channels in this animation.
  62. ticksPerSecond: f32, ///< Playback rate; number of animation ticks per second.
  63. duration: f32, ///< Total length of the animation, in ticks.
  64. boneCount: i32, ///< Number of bones in the target skeleton.
  65. name: [32]i8, ///< Animation name (null-terminated string).
  66. }
  67. /**
  68. * @brief Represents a collection of skeletal animations sharing the same skeleton.
  69. *
  70. * Holds multiple animations that can be applied to compatible models or skeletons.
  71. * Typically loaded together from a single 3D model file (e.g., GLTF, FBX) containing several animation clips.
  72. */
  73. AnimationLib :: struct {
  74. animations: ^Animation, ///< Array of animations included in this library.
  75. count: i32, ///< Number of animations contained in the library.
  76. }
  77. @(default_calling_convention="c", link_prefix="R3D_")
  78. foreign lib {
  79. /**
  80. * @brief Loads animations from a model file.
  81. * @param filePath Path to the model file containing animations.
  82. * @param targetFrameRate Desired frame rate (FPS) for sampling the animations.
  83. * @return Pointer to an array of R3D_Animation, or NULL on failure.
  84. * @note Free the returned array using R3D_UnloadAnimationLib().
  85. */
  86. LoadAnimationLib :: proc(filePath: cstring) -> AnimationLib ---
  87. /**
  88. * @brief Loads animations from memory data.
  89. * @param data Pointer to memory buffer containing model animation data.
  90. * @param size Size of the buffer in bytes.
  91. * @param hint Hint on the model format (can be NULL).
  92. * @param targetFrameRate Desired frame rate (FPS) for sampling the animations.
  93. * @return Pointer to an array of R3D_Animation, or NULL on failure.
  94. * @note Free the returned array using R3D_UnloadAnimationLib().
  95. */
  96. LoadAnimationLibFromMemory :: proc(data: rawptr, size: u32, hint: cstring) -> AnimationLib ---
  97. /**
  98. * @brief Loads animations from an existing importer.
  99. * @param importer Importer instance containing animation data.
  100. * @return Pointer to an array of R3D_Animation, or NULL on failure.
  101. * @note Free the returned array using R3D_UnloadAnimationLib().
  102. */
  103. LoadAnimationLibFromImporter :: proc(importer: ^Importer) -> AnimationLib ---
  104. /**
  105. * @brief Releases all resources associated with an animation library.
  106. * @param animLib Animation library to unload.
  107. */
  108. UnloadAnimationLib :: proc(animLib: AnimationLib) ---
  109. /**
  110. * @brief Returns the index of an animation by name.
  111. * @param animLib Animation library to search.
  112. * @param name Name of the animation (case-sensitive).
  113. * @return Zero-based index if found, or -1 if not found.
  114. */
  115. GetAnimationIndex :: proc(animLib: AnimationLib, name: cstring) -> i32 ---
  116. /**
  117. * @brief Retrieves an animation by name.
  118. * @param animLib Animation library to search.
  119. * @param name Name of the animation (case-sensitive).
  120. * @return Pointer to the animation, or NULL if not found.
  121. */
  122. GetAnimation :: proc(animLib: AnimationLib, name: cstring) -> ^Animation ---
  123. }