r3d_model.odin 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* r3d_model.odin -- R3D Model 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 Represents a complete 3D model with meshes and materials.
  31. *
  32. * Contains multiple meshes and their associated materials, along with animation and bounding information.
  33. */
  34. Model :: struct {
  35. meshes: [^]Mesh, ///< Array of meshes composing the model.
  36. meshData: [^]MeshData, ///< Array of meshes data in RAM (optional, can be NULL).
  37. materials: [^]Material, ///< Array of materials used by the model.
  38. meshMaterials: [^]i32, ///< Array of material indices, one per mesh.
  39. meshCount: i32, ///< Number of meshes.
  40. materialCount: i32, ///< Number of materials.
  41. aabb: rl.BoundingBox, ///< Axis-Aligned Bounding Box encompassing the whole model.
  42. skeleton: Skeleton, ///< Skeleton hierarchy and bind pose used for skinning (NULL if non-skinned).
  43. }
  44. @(default_calling_convention="c", link_prefix="R3D_")
  45. foreign lib {
  46. /**
  47. * @brief Load a 3D model from a file.
  48. *
  49. * Loads a 3D model from the specified file path. Supports various 3D file formats
  50. * and automatically parses meshes, materials, and texture references.
  51. *
  52. * @param filePath Path to the 3D model file to load.
  53. *
  54. * @return Loaded model structure containing meshes and materials.
  55. */
  56. LoadModel :: proc(filePath: cstring) -> Model ---
  57. /**
  58. * @brief Load a 3D model from a file with import flags.
  59. *
  60. * Extended version of R3D_LoadModel() allowing control over the import
  61. * process through additional flags.
  62. *
  63. * @param filePath Path to the 3D model file to load.
  64. * @param flags Importer behavior flags.
  65. *
  66. * @return Loaded model structure containing meshes and materials.
  67. */
  68. LoadModelEx :: proc(filePath: cstring, flags: ImportFlags) -> Model ---
  69. /**
  70. * @brief Load a 3D model from memory buffer.
  71. *
  72. * Loads a 3D model from a memory buffer containing the file data.
  73. * Useful for loading models from embedded resources or network streams.
  74. *
  75. * @param data Pointer to the memory buffer containing the model data.
  76. * @param size Size of the data buffer in bytes.
  77. * @param hint Hint on the model format (can be NULL).
  78. *
  79. * @return Loaded model structure containing meshes and materials.
  80. *
  81. * @note External dependencies (e.g., textures or linked resources) are not supported.
  82. * The model data must be fully self-contained. Use embedded formats like .glb to ensure compatibility.
  83. */
  84. LoadModelFromMemory :: proc(data: rawptr, size: u32, hint: cstring) -> Model ---
  85. /**
  86. * @brief Load a 3D model from a memory buffer with import flags.
  87. *
  88. * Extended version of R3D_LoadModelFromMemory() allowing control over
  89. * the import process through additional flags.
  90. *
  91. * @param data Pointer to the memory buffer containing the model data.
  92. * @param size Size of the data buffer in bytes.
  93. * @param hint Hint on the model format (can be NULL).
  94. * @param flags Importer behavior flags.
  95. *
  96. * @return Loaded model structure containing meshes and materials.
  97. *
  98. * @note External dependencies (e.g., textures or linked resources) are not supported.
  99. * The model data must be fully self-contained.
  100. */
  101. LoadModelFromMemoryEx :: proc(data: rawptr, size: u32, hint: cstring, flags: ImportFlags) -> Model ---
  102. /**
  103. * @brief Load a 3D model from an existing importer.
  104. *
  105. * Creates a model from a previously loaded importer instance.
  106. * This avoids re-importing the source file.
  107. *
  108. * @param importer Importer instance to extract the model from.
  109. *
  110. * @return Loaded model structure containing meshes and materials.
  111. */
  112. LoadModelFromImporter :: proc(importer: ^Importer) -> Model ---
  113. /**
  114. * @brief Unload a model and optionally its materials.
  115. *
  116. * Frees all memory associated with a model, including its meshes.
  117. * Materials can be optionally unloaded as well.
  118. *
  119. * @param model The model to be unloaded.
  120. * @param unloadMaterials If true, also unloads all materials associated with the model.
  121. * Set to false if textures are still being used elsewhere to avoid freeing shared resources.
  122. */
  123. UnloadModel :: proc(model: Model, unloadMaterials: bool) ---
  124. }