You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

514 lines
21 KiB

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