assimp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2010, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file assimp.h
  35. * @brief Defines the C-API to the Open Asset Import Library.
  36. */
  37. #ifndef AI_ASSIMP_H_INC
  38. #define AI_ASSIMP_H_INC
  39. #include "aiTypes.h"
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. struct aiScene; // aiScene.h
  44. struct aiFileIO; // aiFileIO.h
  45. typedef void (*aiLogStreamCallback)(const char* /* message */, char* /* user */);
  46. // --------------------------------------------------------------------------------
  47. /** C-API: Represents a log stream. A log stream receives all log messages and
  48. * streams them _somewhere_.
  49. * @see aiGetPredefinedLogStream
  50. * @see aiAttachLogStream
  51. * @see aiDetachLogStream */
  52. // --------------------------------------------------------------------------------
  53. struct aiLogStream
  54. {
  55. /** callback to be called */
  56. aiLogStreamCallback callback;
  57. /** user data to be passed to the callback */
  58. char* user;
  59. };
  60. /** Our own C boolean type */
  61. typedef int aiBool;
  62. #define AI_FALSE 0
  63. #define AI_TRUE 1
  64. // --------------------------------------------------------------------------------
  65. /** Reads the given file and returns its content.
  66. *
  67. * If the call succeeds, the imported data is returned in an aiScene structure.
  68. * The data is intended to be read-only, it stays property of the ASSIMP
  69. * library and will be stable until aiReleaseImport() is called. After you're
  70. * done with it, call aiReleaseImport() to free the resources associated with
  71. * this file. If the import fails, NULL is returned instead. Call
  72. * aiGetErrorString() to retrieve a human-readable error text.
  73. * @param pFile Path and filename of the file to be imported,
  74. * expected to be a null-terminated c-string. NULL is not a valid value.
  75. * @param pFlags Optional post processing steps to be executed after
  76. * a successful import. Provide a bitwise combination of the
  77. * #aiPostProcessSteps flags.
  78. * @return Pointer to the imported data or NULL if the import failed.
  79. */
  80. ASSIMP_API const C_STRUCT aiScene* aiImportFile(
  81. const char* pFile,
  82. unsigned int pFlags);
  83. // --------------------------------------------------------------------------------
  84. /** Reads the given file using user-defined I/O functions and returns
  85. * its content.
  86. *
  87. * If the call succeeds, the imported data is returned in an aiScene structure.
  88. * The data is intended to be read-only, it stays property of the ASSIMP
  89. * library and will be stable until aiReleaseImport() is called. After you're
  90. * done with it, call aiReleaseImport() to free the resources associated with
  91. * this file. If the import fails, NULL is returned instead. Call
  92. * aiGetErrorString() to retrieve a human-readable error text.
  93. * @param pFile Path and filename of the file to be imported,
  94. * expected to be a null-terminated c-string. NULL is not a valid value.
  95. * @param pFlags Optional post processing steps to be executed after
  96. * a successful import. Provide a bitwise combination of the
  97. * #aiPostProcessSteps flags.
  98. * @param pFS aiFileIO structure. Will be used to open the model file itself
  99. * and any other files the loader needs to open.
  100. * @return Pointer to the imported data or NULL if the import failed.
  101. * @note Include <aiFileIO.h> for the definition of #aiFileIO.
  102. */
  103. ASSIMP_API const C_STRUCT aiScene* aiImportFileEx(
  104. const char* pFile,
  105. unsigned int pFlags,
  106. C_STRUCT aiFileIO* pFS);
  107. // --------------------------------------------------------------------------------
  108. /** Reads the given file from a given memory buffer,
  109. *
  110. * If the call succeeds, the contents of the file are returned as a pointer to an
  111. * aiScene object. The returned data is intended to be read-only, the importer keeps
  112. * ownership of the data and will destroy it upon destruction. If the import fails,
  113. * NULL is returned.
  114. * A human-readable error description can be retrieved by calling aiGetErrorString().
  115. * @param pBuffer Pointer to the file data
  116. * @param pLength Length of pBuffer, in bytes
  117. * @param pFlags Optional post processing steps to be executed after
  118. * a successful import. Provide a bitwise combination of the
  119. * #aiPostProcessSteps flags. If you wish to inspect the imported
  120. * scene first in order to fine-tune your post-processing setup,
  121. * consider to use #aiApplyPostProcessing().
  122. * @param pHint An additional hint to the library. If this is a non empty string,
  123. * the library looks for a loader to support the file extension specified by pHint
  124. * and passes the file to the first matching loader. If this loader is unable to
  125. * completely the request, the library continues and tries to determine the file
  126. * format on its own, a task that may or may not be successful.
  127. * Check the return value, and you'll know ...
  128. * @return A pointer to the imported data, NULL if the import failed.
  129. *
  130. * @note This is a straightforward way to decode models from memory buffers, but it
  131. * doesn't handle model formats spreading their data across multiple files or even
  132. * directories. Examples include OBJ or MD3, which outsource parts of their material
  133. * stuff into external scripts. If you need the full functionality, provide a custom
  134. * IOSystem to make Assimp find these files.
  135. */
  136. ASSIMP_API const C_STRUCT aiScene* aiImportFileFromMemory(
  137. const char* pBuffer,
  138. unsigned int pLength,
  139. unsigned int pFlags,
  140. const char* pHint);
  141. // --------------------------------------------------------------------------------
  142. /** Apply post-processing to an already-imported scene.
  143. *
  144. * This is strictly equivalent to calling #aiImportFile()/#aiImportFileEx with the
  145. * same flags. However, you can use this separate function to inspect the imported
  146. * scene first to fine-tune your post-processing setup.
  147. * @param pScene Scene to work on.
  148. * @param pFlags Provide a bitwise combination of the #aiPostProcessSteps flags.
  149. * @return A pointer to the post-processed data. Post processing is done in-place,
  150. * meaning this is still the same #aiScene which you passed for pScene. However,
  151. * _if_ post-processing failed, the scene could now be NULL. That's quite a rare
  152. * case, post processing steps are not really designed to 'fail'. To be exact,
  153. * the #aiProcess_ValidateDS flag is currently the only post processing step
  154. * which can actually cause the scene to be reset to NULL.
  155. */
  156. ASSIMP_API const C_STRUCT aiScene* aiApplyPostProcessing(
  157. const C_STRUCT aiScene* pScene,
  158. unsigned int pFlags);
  159. // --------------------------------------------------------------------------------
  160. /** Get one of the predefine log streams. This is the quick'n'easy solution to
  161. * access Assimp's log system. Attaching a log stream can slightly reduce Assimp's
  162. * overall import performance.
  163. *
  164. * Usage is rather simple (this will stream the log to a file, named log.txt, and
  165. * the stdout stream of the process:
  166. * @code
  167. * struct aiLogStream c;
  168. * c = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"log.txt");
  169. * aiAttachLogStream(&c);
  170. * c = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
  171. * aiAttachLogStream(&c);
  172. * @endcode
  173. *
  174. * @param pStreams One of the #aiDefaultLogStream enumerated values.
  175. * @param file Solely for the #aiDefaultLogStream_FILE flag: specifies the file to write to.
  176. * Pass NULL for all other flags.
  177. * @return The log stream. callback is set to NULL if something went wrong.
  178. */
  179. ASSIMP_API C_STRUCT aiLogStream aiGetPredefinedLogStream(
  180. C_ENUM aiDefaultLogStream pStreams,
  181. const char* file);
  182. // --------------------------------------------------------------------------------
  183. /** Attach a custom log stream to the libraries' logging system.
  184. *
  185. * Attaching a log stream can slightly reduce Assimp's overall import
  186. * performance. Multiple log-streams can be attached.
  187. * @param stream Describes the new log stream.
  188. * @note To ensure proepr destruction of the logging system, you need to manually
  189. * call aiDetachLogStream() on every single log stream you attach.
  190. * Alternatively (for the lazy folks) #aiDetachAllLogStreams is provided.
  191. */
  192. ASSIMP_API void aiAttachLogStream(
  193. const C_STRUCT aiLogStream* stream);
  194. // --------------------------------------------------------------------------------
  195. /** Enable verbose logging. Verbose logging includes debug-related stuff and
  196. * detailed import statistics. This can have severe impact on import performance
  197. * and memory consumption. However, it might be useful to find out why a file
  198. * didn't read correctly.
  199. * @param d AI_TRUE or AI_FALSE, your decision.
  200. */
  201. ASSIMP_API void aiEnableVerboseLogging(aiBool d);
  202. // --------------------------------------------------------------------------------
  203. /** Detach a custom log stream from the libraries' logging system.
  204. *
  205. * This is the counterpart of #aiAttachPredefinedLogStream. If you attached a stream,
  206. * don't forget to detach it again.
  207. * @param stream The log stream to be detached.
  208. * @return AI_SUCCESS if the log stream has been detached successfully.
  209. * @see aiDetachAllLogStreams
  210. */
  211. ASSIMP_API C_ENUM aiReturn aiDetachLogStream(
  212. const C_STRUCT aiLogStream* stream);
  213. // --------------------------------------------------------------------------------
  214. /** Detach all active log streams from the libraries' logging system.
  215. * This ensures that the logging system is terminated properly and all
  216. * resources allocated by it are actually freed. If you attached a stream,
  217. * don't forget to detach it again.
  218. * @see aiAttachLogStream
  219. * @see aiDetachLogStream
  220. */
  221. ASSIMP_API void aiDetachAllLogStreams(void);
  222. // --------------------------------------------------------------------------------
  223. /** Releases all resources associated with the given import process.
  224. *
  225. * Call this function after you're done with the imported data.
  226. * @param pScene The imported data to release. NULL is a valid value.
  227. */
  228. ASSIMP_API void aiReleaseImport(
  229. const C_STRUCT aiScene* pScene);
  230. // --------------------------------------------------------------------------------
  231. /** Returns the error text of the last failed import process.
  232. *
  233. * @return A textual description of the error that occurred at the last
  234. * import process. NULL if there was no error. There can't be an error if you
  235. * got a non-NULL #aiScene from #aiImportFile/#aiImportFileEx/#aiApplyPostProcessing.
  236. */
  237. ASSIMP_API const char* aiGetErrorString();
  238. // --------------------------------------------------------------------------------
  239. /** Returns whether a given file extension is supported by ASSIMP
  240. *
  241. * @param szExtension Extension for which the function queries support for.
  242. * Must include a leading dot '.'. Example: ".3ds", ".md3"
  243. * @return AI_TRUE if the file extension is supported.
  244. */
  245. ASSIMP_API aiBool aiIsExtensionSupported(
  246. const char* szExtension);
  247. // --------------------------------------------------------------------------------
  248. /** Get a list of all file extensions supported by ASSIMP.
  249. *
  250. * If a file extension is contained in the list this does, of course, not
  251. * mean that ASSIMP is able to load all files with this extension.
  252. * @param szOut String to receive the extension list.
  253. * Format of the list: "*.3ds;*.obj;*.dae". NULL is not a valid parameter.
  254. */
  255. ASSIMP_API void aiGetExtensionList(
  256. C_STRUCT aiString* szOut);
  257. // --------------------------------------------------------------------------------
  258. /** Get the storage required by an imported asset
  259. * @param pIn Input asset.
  260. * @param in Data structure to be filled.
  261. */
  262. ASSIMP_API void aiGetMemoryRequirements(
  263. const C_STRUCT aiScene* pIn,
  264. C_STRUCT aiMemoryInfo* in);
  265. // --------------------------------------------------------------------------------
  266. /** Set an integer property.
  267. *
  268. * This is the C-version of #Assimp::Importer::SetPropertyInteger(). In the C
  269. * interface, properties are always shared by all imports. It is not possible to
  270. * specify them per import.
  271. *
  272. * @param szName Name of the configuration property to be set. All supported
  273. * public properties are defined in the aiConfig.h header file (#AI_CONFIG_XXX).
  274. * @param value New value for the property
  275. */
  276. ASSIMP_API void aiSetImportPropertyInteger(
  277. const char* szName,
  278. int value);
  279. // --------------------------------------------------------------------------------
  280. /** Set a floating-point property.
  281. *
  282. * This is the C-version of #Assimp::Importer::SetPropertyFloat(). In the C
  283. * interface, properties are always shared by all imports. It is not possible to
  284. * specify them per import.
  285. *
  286. * @param szName Name of the configuration property to be set. All supported
  287. * public properties are defined in the aiConfig.h header file (#AI_CONFIG_XXX).
  288. * @param value New value for the property
  289. */
  290. ASSIMP_API void aiSetImportPropertyFloat(
  291. const char* szName,
  292. float value);
  293. // --------------------------------------------------------------------------------
  294. /** Set a string property.
  295. *
  296. * This is the C-version of #Assimp::Importer::SetPropertyString(). In the C
  297. * interface, properties are always shared by all imports. It is not possible to
  298. * specify them per import.
  299. *
  300. * @param szName Name of the configuration property to be set. All supported
  301. * public properties are defined in the aiConfig.h header file (#AI_CONFIG_XXX).
  302. * @param value New value for the property
  303. */
  304. ASSIMP_API void aiSetImportPropertyString(
  305. const char* szName,
  306. const C_STRUCT aiString* st);
  307. // --------------------------------------------------------------------------------
  308. /** Construct a quaternion from a 3x3 rotation matrix.
  309. * @param quat Receives the output quaternion.
  310. * @param mat Matrix to 'quaternionize'.
  311. * @see aiQuaternion(const aiMatrix3x3& pRotMatrix)
  312. */
  313. ASSIMP_API void aiCreateQuaternionFromMatrix(
  314. C_STRUCT aiQuaternion* quat,
  315. const C_STRUCT aiMatrix3x3* mat);
  316. // --------------------------------------------------------------------------------
  317. /** Decompose a transformation matrix into its rotational, translational and
  318. * scaling components.
  319. *
  320. * @param mat Matrix to decompose
  321. * @param scaling Receives the scaling component
  322. * @param rotation Receives the rotational component
  323. * @param position Receives the translational component.
  324. * @see aiMatrix4x4::Decompose (aiVector3D&, aiQuaternion&, aiVector3D&) const;
  325. */
  326. ASSIMP_API void aiDecomposeMatrix(
  327. const C_STRUCT aiMatrix4x4* mat,
  328. C_STRUCT aiVector3D* scaling,
  329. C_STRUCT aiQuaternion* rotation,
  330. C_STRUCT aiVector3D* position);
  331. // --------------------------------------------------------------------------------
  332. /** Transpose a 4x4 matrix.
  333. * @param mat Pointer to the matrix to be transposed
  334. */
  335. ASSIMP_API void aiTransposeMatrix4(
  336. C_STRUCT aiMatrix4x4* mat);
  337. // --------------------------------------------------------------------------------
  338. /** Transpose a 3x3 matrix.
  339. * @param mat Pointer to the matrix to be transposed
  340. */
  341. ASSIMP_API void aiTransposeMatrix3(
  342. C_STRUCT aiMatrix3x3* mat);
  343. // --------------------------------------------------------------------------------
  344. /** Transform a vector by a 3x3 matrix
  345. * @param vec Vector to be transformed.
  346. * @param mat Matrix to transform the vector with.
  347. */
  348. ASSIMP_API void aiTransformVecByMatrix3(
  349. C_STRUCT aiVector3D* vec,
  350. const C_STRUCT aiMatrix3x3* mat);
  351. // --------------------------------------------------------------------------------
  352. /** Transform a vector by a 4x4 matrix
  353. * @param vec Vector to be transformed.
  354. * @param mat Matrix to transform the vector with.
  355. */
  356. ASSIMP_API void aiTransformVecByMatrix4(
  357. C_STRUCT aiVector3D* vec,
  358. const C_STRUCT aiMatrix4x4* mat);
  359. // --------------------------------------------------------------------------------
  360. /** Multiply two 4x4 matrices.
  361. * @param dst First factor, receives result.
  362. * @param src Matrix to be multiplied with 'dst'.
  363. */
  364. ASSIMP_API void aiMultiplyMatrix4(
  365. C_STRUCT aiMatrix4x4* dst,
  366. const C_STRUCT aiMatrix4x4* src);
  367. // --------------------------------------------------------------------------------
  368. /** Multiply two 3x3 matrices.
  369. * @param dst First factor, receives result.
  370. * @param src Matrix to be multiplied with 'dst'.
  371. */
  372. ASSIMP_API void aiMultiplyMatrix3(
  373. C_STRUCT aiMatrix3x3* dst,
  374. const C_STRUCT aiMatrix3x3* src);
  375. // --------------------------------------------------------------------------------
  376. /** Get a 3x3 identity matrix.
  377. * @param mat Matrix to receive its personal identity
  378. */
  379. ASSIMP_API void aiIdentityMatrix3(
  380. C_STRUCT aiMatrix3x3* mat);
  381. // --------------------------------------------------------------------------------
  382. /** Get a 4x4 identity matrix.
  383. * @param mat Matrix to receive its personal identity
  384. */
  385. ASSIMP_API void aiIdentityMatrix4(
  386. C_STRUCT aiMatrix4x4* mat);
  387. #ifdef __cplusplus
  388. }
  389. #endif
  390. #endif // AI_ASSIMP_H_INC