assimp.h 18 KB

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