cimport.h 21 KB

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