r3d_skeleton.odin 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* r3d_skeleton.odin -- R3D Skeleton 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 Stores bone information for skeletal animation.
  31. *
  32. * Contains the bone name and the index of its parent bone.
  33. */
  34. BoneInfo :: struct {
  35. name: [32]i8, ///< Bone name (max 31 characters + null terminator).
  36. parent: i32, ///< Index of the parent bone (-1 if root).
  37. }
  38. /**
  39. * @brief Represents a skeletal hierarchy used for skinning.
  40. *
  41. * Defines the bone structure, reference poses, and inverse bind matrices
  42. * required for skeletal animation. The skeleton provides both local and
  43. * global bind poses used during skinning and animation playback.
  44. */
  45. Skeleton :: struct {
  46. bones: [^]BoneInfo, ///< Array of bone descriptors defining the hierarchy and names.
  47. boneCount: i32, ///< Total number of bones in the skeleton.
  48. localBind: [^]rl.Matrix, ///< Bind pose matrices relative to parent
  49. modelBind: [^]rl.Matrix, ///< Bind pose matrices in model/global space
  50. invBind: [^]rl.Matrix, ///< Inverse bind matrices (model space) for skinning
  51. rootBind: [16]f32, ///< Root correction if local bind is not identity
  52. skinTexture: u32, ///< rl.Texture ID that contains the bind pose for GPU skinning. This is a 1D rl.Texture RGBA16F 4*boneCount.
  53. }
  54. @(default_calling_convention="c", link_prefix="R3D_")
  55. foreign lib {
  56. /**
  57. * @brief Loads a skeleton hierarchy from a 3D model file.
  58. *
  59. * Skeletons are automatically loaded when importing a model,
  60. * but can be loaded manually for advanced use cases.
  61. *
  62. * @param filePath Path to the model file containing the skeleton data.
  63. * @return Return the loaded R3D_Skeleton.
  64. */
  65. LoadSkeleton :: proc(filePath: cstring) -> Skeleton ---
  66. /**
  67. * @brief Loads a skeleton hierarchy from memory data.
  68. *
  69. * Allows manual loading of skeletons directly from a memory buffer.
  70. * Typically used for advanced or custom asset loading workflows.
  71. *
  72. * @param data Pointer to the memory buffer containing skeleton data.
  73. * @param size Size of the memory buffer in bytes.
  74. * @param hint Optional format hint (can be NULL).
  75. * @return Return the loaded R3D_Skeleton.
  76. */
  77. LoadSkeletonFromMemory :: proc(data: rawptr, size: u32, hint: cstring) -> Skeleton ---
  78. /**
  79. * @brief Loads a skeleton hierarchy from an existing importer.
  80. *
  81. * Extracts the skeleton data from a previously loaded importer instance.
  82. *
  83. * @param importer Importer instance to extract the skeleton from.
  84. * @return Return the loaded R3D_Skeleton.
  85. */
  86. LoadSkeletonFromImporter :: proc(importer: ^Importer) -> Skeleton ---
  87. /**
  88. * @brief Frees the memory allocated for a skeleton.
  89. *
  90. * @param skeleton R3D_Skeleton to destroy.
  91. */
  92. UnloadSkeleton :: proc(skeleton: Skeleton) ---
  93. /**
  94. * @brief Check if a skeleton is valid.
  95. *
  96. * Returns true if atleast the texBindPose is greater than zero.
  97. *
  98. * @param skeleton The skeleton to check.
  99. * @return true if valid, false otherwise.
  100. */
  101. IsSkeletonValid :: proc(skeleton: Skeleton) -> bool ---
  102. /**
  103. * @brief Returns the index of the bone with the given name.
  104. *
  105. * @param skeleton Skeleton to search in.
  106. * @param boneName Name of the bone to find.
  107. * @return Index of the bone, or a negative value if not found.
  108. */
  109. GetSkeletonBoneIndex :: proc(skeleton: Skeleton, boneName: cstring) -> i32 ---
  110. /**
  111. * @brief Returns a pointer to the bone with the given name.
  112. *
  113. * @param skeleton Skeleton to search in.
  114. * @param boneName Name of the bone to find.
  115. * @return Pointer to the bone, or NULL if not found.
  116. */
  117. GetSkeletonBone :: proc(skeleton: Skeleton, boneName: cstring) -> ^BoneInfo ---
  118. }