Importer.hpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2025, 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 Importer.hpp
  35. * @brief Defines the C++-API to the Open Asset Import Library.
  36. */
  37. #pragma once
  38. #ifndef AI_ASSIMP_HPP_INC
  39. #define AI_ASSIMP_HPP_INC
  40. #ifdef __GNUC__
  41. #pragma GCC system_header
  42. #endif
  43. #ifndef __cplusplus
  44. #error This header requires C++ to be used. Use assimp.h for plain C.
  45. #endif // __cplusplus
  46. // Public ASSIMP data structures
  47. #include <assimp/types.h>
  48. #include <exception>
  49. #include <vector>
  50. namespace Assimp {
  51. // =======================================================================
  52. // Public interface to Assimp
  53. class Importer;
  54. class IOStream;
  55. class IOSystem;
  56. class ProgressHandler;
  57. // =======================================================================
  58. // Plugin development
  59. //
  60. // Include the following headers for the declarations:
  61. // BaseImporter.h
  62. // BaseProcess.h
  63. class BaseImporter;
  64. class BaseProcess;
  65. class SharedPostProcessInfo;
  66. class BatchLoader;
  67. // =======================================================================
  68. // Holy stuff, only for members of the high council of the Jedi.
  69. class ImporterPimpl;
  70. } // namespace Assimp
  71. #define AI_PROPERTY_WAS_NOT_EXISTING 0xffffffff
  72. struct aiScene;
  73. // importerdesc.h
  74. struct aiImporterDesc;
  75. /** @namespace Assimp Assimp's CPP-API and all internal APIs */
  76. namespace Assimp {
  77. // ----------------------------------------------------------------------------------
  78. /** CPP-API: The Importer class forms an C++ interface to the functionality of the
  79. * Open Asset Import Library.
  80. *
  81. * Create an object of this class and call ReadFile() to import a file.
  82. * If the import succeeds, the function returns a pointer to the imported data.
  83. * The data remains property of the object, it is intended to be accessed
  84. * read-only. The imported data will be destroyed along with the Importer
  85. * object. If the import fails, ReadFile() returns a nullptr pointer. In this
  86. * case you can retrieve a human-readable error description be calling
  87. * GetErrorString(). You can call ReadFile() multiple times with a single Importer
  88. * instance. Actually, constructing Importer objects involves quite many
  89. * allocations and may take some time, so it's better to reuse them as often as
  90. * possible.
  91. *
  92. * If you want to let assimp deal with OutOfMemory-exception make sure that
  93. * ASSIMP_CATCH_GLOBAL_EXCEPTIONS is set.
  94. * If this is not the case you need to catch the exception by yourself.
  95. *
  96. * If you need the Importer to do custom file handling to access the files,
  97. * implement IOSystem and IOStream and supply an instance of your custom
  98. * IOSystem implementation by calling SetIOHandler() before calling ReadFile().
  99. * If you do not assign a custom IO handler, a default handler using the
  100. * standard C++ IO logic will be used.
  101. *
  102. * @note One Importer instance is not thread-safe. If you use multiple
  103. * threads for loading, each thread should maintain its own Importer instance.
  104. */
  105. class ASSIMP_API Importer {
  106. public:
  107. /**
  108. * @brief The upper limit for hints.
  109. */
  110. static const unsigned int MaxLenHint = 200;
  111. public:
  112. // -------------------------------------------------------------------
  113. /** Constructor. Creates an empty importer object.
  114. *
  115. * Call ReadFile() to start the import process. The configuration
  116. * property table is initially empty.
  117. */
  118. Importer();
  119. // -------------------------------------------------------------------
  120. /** Copy constructor.
  121. *
  122. * This copies the configuration properties of another Importer.
  123. * If this Importer owns a scene it won't be copied.
  124. * Call ReadFile() to start the import process.
  125. */
  126. Importer(const Importer &other) = delete;
  127. // -------------------------------------------------------------------
  128. /** Assignment operator has been deleted
  129. */
  130. Importer &operator=(const Importer &) = delete;
  131. // -------------------------------------------------------------------
  132. /** Destructor. The object kept ownership of the imported data,
  133. * which now will be destroyed along with the object.
  134. */
  135. ~Importer();
  136. // -------------------------------------------------------------------
  137. /** Registers a new loader.
  138. *
  139. * @param pImp Importer to be added. The Importer instance takes
  140. * ownership of the pointer, so it will be automatically deleted
  141. * with the Importer instance.
  142. * @return AI_SUCCESS if the loader has been added. The registration
  143. * fails if there is already a loader for a specific file extension.
  144. */
  145. aiReturn RegisterLoader(BaseImporter *pImp);
  146. // -------------------------------------------------------------------
  147. /** Unregisters a loader.
  148. *
  149. * @param pImp Importer to be unregistered.
  150. * @return AI_SUCCESS if the loader has been removed. The function
  151. * fails if the loader is currently in use (this could happen
  152. * if the #Importer instance is used by more than one thread) or
  153. * if it has not yet been registered.
  154. */
  155. aiReturn UnregisterLoader(BaseImporter *pImp);
  156. // -------------------------------------------------------------------
  157. /** Registers a new post-process step.
  158. *
  159. * At the moment, there's a small limitation: new post processing
  160. * steps are added to end of the list, or in other words, executed
  161. * last, after all built-in steps.
  162. * @param pImp Post-process step to be added. The Importer instance
  163. * takes ownership of the pointer, so it will be automatically
  164. * deleted with the Importer instance.
  165. * @return AI_SUCCESS if the step has been added correctly.
  166. */
  167. aiReturn RegisterPPStep(BaseProcess *pImp);
  168. // -------------------------------------------------------------------
  169. /** Unregisters a post-process step.
  170. *
  171. * @param pImp Step to be unregistered.
  172. * @return AI_SUCCESS if the step has been removed. The function
  173. * fails if the step is currently in use (this could happen
  174. * if the #Importer instance is used by more than one thread) or
  175. * if it has not yet been registered.
  176. */
  177. aiReturn UnregisterPPStep(BaseProcess *pImp);
  178. // -------------------------------------------------------------------
  179. /** Set an integer configuration property.
  180. * @param szName Name of the property. All supported properties
  181. * are defined in the aiConfig.g header (all constants share the
  182. * prefix AI_CONFIG_XXX and are simple strings).
  183. * @param iValue New value of the property
  184. * @return true if the property was set before. The new value replaces
  185. * the previous value in this case.
  186. * @note Property of different types (float, int, string ..) are kept
  187. * on different stacks, so calling SetPropertyInteger() for a
  188. * floating-point property has no effect - the loader will call
  189. * GetPropertyFloat() to read the property, but it won't be there.
  190. */
  191. bool SetPropertyInteger(const char *szName, int iValue);
  192. // -------------------------------------------------------------------
  193. /** Set a boolean configuration property. Boolean properties
  194. * are stored on the integer stack internally so it's possible
  195. * to set them via #SetPropertyBool and query them with
  196. * #GetPropertyBool and vice versa.
  197. * @see SetPropertyInteger()
  198. */
  199. bool SetPropertyBool(const char *szName, bool value) {
  200. return SetPropertyInteger(szName, value);
  201. }
  202. // -------------------------------------------------------------------
  203. /** Set a floating-point configuration property.
  204. * @see SetPropertyInteger()
  205. */
  206. bool SetPropertyFloat(const char *szName, ai_real fValue);
  207. // -------------------------------------------------------------------
  208. /** Set a string configuration property.
  209. * @see SetPropertyInteger()
  210. */
  211. bool SetPropertyString(const char *szName, const std::string &sValue);
  212. // -------------------------------------------------------------------
  213. /** Set a matrix configuration property.
  214. * @see SetPropertyInteger()
  215. */
  216. bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue);
  217. // -------------------------------------------------------------------
  218. /** Set a pointer configuration property.
  219. * @see SetPropertyInteger()
  220. */
  221. bool SetPropertyPointer(const char *szName, void *sValue);
  222. // -------------------------------------------------------------------
  223. /** Get a configuration property.
  224. * @param szName Name of the property. All supported properties
  225. * are defined in the aiConfig.g header (all constants share the
  226. * prefix AI_CONFIG_XXX).
  227. * @param iErrorReturn Value that is returned if the property
  228. * is not found.
  229. * @return Current value of the property
  230. * @note Property of different types (float, int, string ..) are kept
  231. * on different lists, so calling SetPropertyInteger() for a
  232. * floating-point property has no effect - the loader will call
  233. * GetPropertyFloat() to read the property, but it won't be there.
  234. */
  235. int GetPropertyInteger(const char *szName,
  236. int iErrorReturn = 0xffffffff) const;
  237. // -------------------------------------------------------------------
  238. /** Get a boolean configuration property. Boolean properties
  239. * are stored on the integer stack internally so it's possible
  240. * to set them via #SetPropertyBool and query them with
  241. * #GetPropertyBool and vice versa.
  242. * @see GetPropertyInteger()
  243. */
  244. bool GetPropertyBool(const char *szName, bool bErrorReturn = false) const {
  245. return GetPropertyInteger(szName, bErrorReturn) != 0;
  246. }
  247. // -------------------------------------------------------------------
  248. /** Get a floating-point configuration property
  249. * @see GetPropertyInteger()
  250. */
  251. ai_real GetPropertyFloat(const char *szName,
  252. ai_real fErrorReturn = 10e10) const;
  253. // -------------------------------------------------------------------
  254. /** Get a string configuration property
  255. *
  256. * The return value remains valid until the property is modified.
  257. * @see GetPropertyInteger()
  258. */
  259. std::string GetPropertyString(const char *szName,
  260. const std::string &sErrorReturn = std::string()) const;
  261. // -------------------------------------------------------------------
  262. /** Get a matrix configuration property
  263. *
  264. * The return value remains valid until the property is modified.
  265. * @see GetPropertyInteger()
  266. */
  267. aiMatrix4x4 GetPropertyMatrix(const char *szName,
  268. const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const;
  269. // -------------------------------------------------------------------
  270. /** Get a pointer configuration property
  271. *
  272. * The return value remains valid until the property is modified.
  273. * @see GetPropertyInteger()
  274. */
  275. void* GetPropertyPointer(const char *szName,
  276. void *sErrorReturn = nullptr) const;
  277. // -------------------------------------------------------------------
  278. /** Supplies a custom IO handler to the importer to use to open and
  279. * access files. If you need the importer to use custom IO logic to
  280. * access the files, you need to provide a custom implementation of
  281. * IOSystem and IOFile to the importer. Then create an instance of
  282. * your custom IOSystem implementation and supply it by this function.
  283. *
  284. * The Importer takes ownership of the object and will destroy it
  285. * afterwards. The previously assigned handler will be deleted.
  286. * Pass nullptr to take again ownership of your IOSystem and reset Assimp
  287. * to use its default implementation.
  288. *
  289. * @param pIOHandler The IO handler to be used in all file accesses
  290. * of the Importer.
  291. */
  292. void SetIOHandler(IOSystem *pIOHandler);
  293. // -------------------------------------------------------------------
  294. /** Retrieves the IO handler that is currently set.
  295. * You can use #IsDefaultIOHandler() to check whether the returned
  296. * interface is the default IO handler provided by ASSIMP. The default
  297. * handler is active as long the application doesn't supply its own
  298. * custom IO handler via #SetIOHandler().
  299. * @return A valid IOSystem interface, never nullptr.
  300. */
  301. IOSystem *GetIOHandler() const;
  302. // -------------------------------------------------------------------
  303. /** Checks whether a default IO handler is active
  304. * A default handler is active as long the application doesn't
  305. * supply its own custom IO handler via #SetIOHandler().
  306. * @return true by default
  307. */
  308. bool IsDefaultIOHandler() const;
  309. // -------------------------------------------------------------------
  310. /** Supplies a custom progress handler to the importer. This
  311. * interface exposes an #Update() callback, which is called
  312. * more or less periodically (please don't sue us if it
  313. * isn't as periodically as you'd like it to have ...).
  314. * This can be used to implement progress bars and loading
  315. * timeouts.
  316. * @param pHandler Progress callback interface. Pass nullptr to
  317. * disable progress reporting.
  318. * @note Progress handlers can be used to abort the loading
  319. * at almost any time.*/
  320. void SetProgressHandler(ProgressHandler *pHandler);
  321. // -------------------------------------------------------------------
  322. /** Retrieves the progress handler that is currently set.
  323. * You can use #IsDefaultProgressHandler() to check whether the returned
  324. * interface is the default handler provided by ASSIMP. The default
  325. * handler is active as long the application doesn't supply its own
  326. * custom handler via #SetProgressHandler().
  327. * @return A valid ProgressHandler interface, never nullptr.
  328. */
  329. ProgressHandler *GetProgressHandler() const;
  330. // -------------------------------------------------------------------
  331. /** Checks whether a default progress handler is active
  332. * A default handler is active as long the application doesn't
  333. * supply its own custom progress handler via #SetProgressHandler().
  334. * @return true by default
  335. */
  336. bool IsDefaultProgressHandler() const;
  337. // -------------------------------------------------------------------
  338. /** @brief Check whether a given set of post-processing flags
  339. * is supported.
  340. *
  341. * Some flags are mutually exclusive, others are probably
  342. * not available because your excluded them from your
  343. * Assimp builds. Calling this function is recommended if
  344. * you're unsure.
  345. *
  346. * @param pFlags Bitwise combination of the aiPostProcess flags.
  347. * @return true if this flag combination is fine.
  348. */
  349. bool ValidateFlags(unsigned int pFlags) const;
  350. // -------------------------------------------------------------------
  351. /** Reads the given file and returns its contents if successful.
  352. *
  353. * If the call succeeds, the contents of the file are returned as a
  354. * pointer to an aiScene object. The returned data is intended to be
  355. * read-only, the importer object keeps ownership of the data and will
  356. * destroy it upon destruction. If the import fails, nullptr is returned.
  357. * A human-readable error description can be retrieved by calling
  358. * GetErrorString(). The previous scene will be deleted during this call.
  359. * @param pFile Path and filename to the file to be imported.
  360. * @param pFlags Optional post processing steps to be executed after
  361. * a successful import. Provide a bitwise combination of the
  362. * #aiPostProcessSteps flags. If you wish to inspect the imported
  363. * scene first in order to fine-tune your post-processing setup,
  364. * consider to use #ApplyPostProcessing().
  365. * @return A pointer to the imported data, nullptr if the import failed.
  366. * The pointer to the scene remains in possession of the Importer
  367. * instance. Use GetOrphanedScene() to take ownership of it.
  368. *
  369. * @note Assimp is able to determine the file format of a file
  370. * automatically.
  371. */
  372. const aiScene *ReadFile(
  373. const char *pFile,
  374. unsigned int pFlags);
  375. // -------------------------------------------------------------------
  376. /** Reads the given file from a memory buffer and returns its
  377. * contents if successful.
  378. *
  379. * If the call succeeds, the contents of the file are returned as a
  380. * pointer to an aiScene object. The returned data is intended to be
  381. * read-only, the importer object keeps ownership of the data and will
  382. * destroy it upon destruction. If the import fails, nullptr is returned.
  383. * A human-readable error description can be retrieved by calling
  384. * GetErrorString(). The previous scene will be deleted during this call.
  385. * Calling this method doesn't affect the active IOSystem.
  386. * @param pBuffer Pointer to the file data
  387. * @param pLength Length of pBuffer, in bytes
  388. * @param pFlags Optional post processing steps to be executed after
  389. * a successful import. Provide a bitwise combination of the
  390. * #aiPostProcessSteps flags. If you wish to inspect the imported
  391. * scene first in order to fine-tune your post-processing setup,
  392. * consider to use #ApplyPostProcessing().
  393. * @param pHint An additional hint to the library. If this is a non
  394. * empty string, the library looks for a loader to support
  395. * the file extension specified by pHint and passes the file to
  396. * the first matching loader. If this loader is unable to completely
  397. * the request, the library continues and tries to determine the
  398. * file format on its own, a task that may or may not be successful.
  399. * Check the return value, and you'll know ...
  400. * @return A pointer to the imported data, nullptr if the import failed.
  401. * The pointer to the scene remains in possession of the Importer
  402. * instance. Use GetOrphanedScene() to take ownership of it.
  403. *
  404. * @note This is a straightforward way to decode models from memory
  405. * buffers, but it doesn't handle model formats that spread their
  406. * data across multiple files or even directories. Examples include
  407. * OBJ or MD3, which outsource parts of their material info into
  408. * external scripts. If you need full functionality, provide
  409. * a custom IOSystem to make Assimp find these files and use
  410. * the regular ReadFile() API.
  411. */
  412. const aiScene *ReadFileFromMemory(
  413. const void *pBuffer,
  414. size_t pLength,
  415. unsigned int pFlags,
  416. const char *pHint = "");
  417. // -------------------------------------------------------------------
  418. /** Apply post-processing to an already-imported scene.
  419. *
  420. * This is strictly equivalent to calling #ReadFile() with the same
  421. * flags. However, you can use this separate function to inspect
  422. * the imported scene first to fine-tune your post-processing setup.
  423. * @param pFlags Provide a bitwise combination of the
  424. * #aiPostProcessSteps flags.
  425. * @return A pointer to the post-processed data. This is still the
  426. * same as the pointer returned by #ReadFile(). However, if
  427. * post-processing fails, the scene could now be nullptr.
  428. * That's quite a rare case, post processing steps are not really
  429. * designed to 'fail'. To be exact, the #aiProcess_ValidateDS
  430. * flag is currently the only post processing step which can actually
  431. * cause the scene to be reset to nullptr.
  432. *
  433. * @note The method does nothing if no scene is currently bound
  434. * to the #Importer instance. */
  435. const aiScene *ApplyPostProcessing(unsigned int pFlags);
  436. const aiScene *ApplyCustomizedPostProcessing(BaseProcess *rootProcess, bool requestValidation);
  437. // -------------------------------------------------------------------
  438. /** @brief Reads the given file and returns its contents if successful.
  439. *
  440. * This function is provided for backward compatibility.
  441. * See the const char* version for detailed docs.
  442. * @see ReadFile(const char*, pFlags) */
  443. const aiScene *ReadFile(
  444. const std::string &pFile,
  445. unsigned int pFlags);
  446. // -------------------------------------------------------------------
  447. /** Frees the current scene.
  448. *
  449. * The function does nothing if no scene has previously been
  450. * read via ReadFile(). FreeScene() is called automatically by the
  451. * destructor and ReadFile() itself. */
  452. void FreeScene();
  453. // -------------------------------------------------------------------
  454. /** Returns an error description of an error that occurred in ReadFile().
  455. *
  456. * Returns an empty string if no error occurred.
  457. * @return A description of the last error, an empty string if no
  458. * error occurred. The string is never nullptr.
  459. *
  460. * @note The returned function remains valid until one of the
  461. * following methods is called: #ReadFile(), #FreeScene(). */
  462. const char *GetErrorString() const;
  463. // -------------------------------------------------------------------
  464. /** Returns an exception if one occurred during import.
  465. *
  466. * @return The last exception which occurred.
  467. *
  468. * @note The returned value remains valid until one of the
  469. * following methods is called: #ReadFile(), #FreeScene(). */
  470. const std::exception_ptr& GetException() const;
  471. // -------------------------------------------------------------------
  472. /** Returns the scene loaded by the last successful call to ReadFile()
  473. *
  474. * @return Current scene or nullptr if there is currently no scene loaded */
  475. const aiScene *GetScene() const;
  476. // -------------------------------------------------------------------
  477. /** Returns the scene loaded by the last successful call to ReadFile()
  478. * and releases the scene from the ownership of the Importer
  479. * instance. The application is now responsible for deleting the
  480. * scene. Any further calls to GetScene() or GetOrphanedScene()
  481. * will return nullptr - until a new scene has been loaded via ReadFile().
  482. *
  483. * @return Current scene or nullptr if there is currently no scene loaded
  484. * @note Use this method with maximal caution, and only if you have to.
  485. * By design, aiScene's are exclusively maintained, allocated and
  486. * deallocated by Assimp and no one else. The reasoning behind this
  487. * is the golden rule that deallocations should always be done
  488. * by the module that did the original allocation because heaps
  489. * are not necessarily shared. GetOrphanedScene() enforces you
  490. * to delete the returned scene by yourself, but this will only
  491. * be fine if and only if you're using the same heap as assimp.
  492. * On Windows, it's typically fine provided everything is linked
  493. * against the multithreaded-dll version of the runtime library.
  494. * It will work as well for static linkage with Assimp.*/
  495. aiScene *GetOrphanedScene();
  496. // -------------------------------------------------------------------
  497. /** Returns whether a given file extension is supported by ASSIMP.
  498. *
  499. * @param szExtension Extension to be checked.
  500. * Must include a trailing dot '.'. Example: ".3ds", ".md3".
  501. * Cases-insensitive.
  502. * @return true if the extension is supported, false otherwise */
  503. bool IsExtensionSupported(const char *szExtension) const;
  504. // -------------------------------------------------------------------
  505. /** @brief Returns whether a given file extension is supported by ASSIMP.
  506. *
  507. * This function is provided for backward compatibility.
  508. * See the const char* version for detailed and up-to-date docs.
  509. * @see IsExtensionSupported(const char*) */
  510. inline bool IsExtensionSupported(const std::string &szExtension) const;
  511. // -------------------------------------------------------------------
  512. /** Get a full list of all file extensions supported by ASSIMP.
  513. *
  514. * If a file extension is contained in the list this does of course not
  515. * mean that ASSIMP is able to load all files with this extension ---
  516. * it simply means there is an importer loaded which claims to handle
  517. * files with this file extension.
  518. * @param szOut String to receive the extension list.
  519. * Format of the list: "*.3ds;*.obj;*.dae". This is useful for
  520. * use with the WinAPI call GetOpenFileName(Ex). */
  521. void GetExtensionList(aiString &szOut) const;
  522. // -------------------------------------------------------------------
  523. /** @brief Get a full list of all file extensions supported by ASSIMP.
  524. *
  525. * This function is provided for backward compatibility.
  526. * See the aiString version for detailed and up-to-date docs.
  527. * @see GetExtensionList(aiString&)*/
  528. inline void GetExtensionList(std::string &szOut) const;
  529. // -------------------------------------------------------------------
  530. /** Get the number of importers currently registered with Assimp. */
  531. size_t GetImporterCount() const;
  532. // -------------------------------------------------------------------
  533. /** Get meta data for the importer corresponding to a specific index..
  534. *
  535. * For the declaration of #aiImporterDesc, include <assimp/importerdesc.h>.
  536. * @param index Index to query, must be within [0,GetImporterCount())
  537. * @return Importer meta data structure, nullptr if the index does not
  538. * exist or if the importer doesn't offer meta information (
  539. * importers may do this at the cost of being hated by their peers).*/
  540. const aiImporterDesc *GetImporterInfo(size_t index) const;
  541. // -------------------------------------------------------------------
  542. /** Find the importer corresponding to a specific index.
  543. *
  544. * @param index Index to query, must be within [0,GetImporterCount())
  545. * @return Importer instance. nullptr if the index does not
  546. * exist. */
  547. BaseImporter *GetImporter(size_t index) const;
  548. // -------------------------------------------------------------------
  549. /** Find the importer corresponding to a specific file extension.
  550. *
  551. * This is quite similar to #IsExtensionSupported except a
  552. * BaseImporter instance is returned.
  553. * @param szExtension Extension to check for. The following formats
  554. * are recognized (BAH being the file extension): "BAH" (comparison
  555. * is case-insensitive), ".bah", "*.bah" (wild card and dot
  556. * characters at the beginning of the extension are skipped).
  557. * @return nullptr if no importer is found*/
  558. BaseImporter *GetImporter(const char *szExtension) const;
  559. // -------------------------------------------------------------------
  560. /** Find the importer index corresponding to a specific file extension.
  561. *
  562. * @param szExtension Extension to check for. The following formats
  563. * are recognized (BAH being the file extension): "BAH" (comparison
  564. * is case-insensitive), ".bah", "*.bah" (wild card and dot
  565. * characters at the beginning of the extension are skipped).
  566. * @return (size_t)-1 if no importer is found */
  567. size_t GetImporterIndex(const char *szExtension) const;
  568. // -------------------------------------------------------------------
  569. /** Returns the storage allocated by ASSIMP to hold the scene data
  570. * in memory.
  571. *
  572. * This refers to the currently loaded file, see #ReadFile().
  573. * @param in Data structure to be filled.
  574. * @note The returned memory statistics refer to the actual
  575. * size of the use data of the aiScene. Heap-related overhead
  576. * is (naturally) not included.*/
  577. void GetMemoryRequirements(aiMemoryInfo &in) const;
  578. // -------------------------------------------------------------------
  579. /** Enables "extra verbose" mode.
  580. *
  581. * 'Extra verbose' means the data structure is validated after *every*
  582. * single post processing step to make sure everyone modifies the data
  583. * structure in a well-defined manner. This is a debug feature and not
  584. * intended for use in production environments. */
  585. void SetExtraVerbose(bool bDo);
  586. // -------------------------------------------------------------------
  587. /** Private, do not use. */
  588. ImporterPimpl *Pimpl() { return pimpl; }
  589. const ImporterPimpl *Pimpl() const { return pimpl; }
  590. protected:
  591. // Just because we don't want you to know how we're hacking around.
  592. ImporterPimpl *pimpl;
  593. }; //! class Importer
  594. // ----------------------------------------------------------------------------
  595. // For compatibility, the interface of some functions taking a std::string was
  596. // changed to const char* to avoid crashes between binary incompatible STL
  597. // versions. This code her is inlined, so it shouldn't cause any problems.
  598. // ----------------------------------------------------------------------------
  599. // ----------------------------------------------------------------------------
  600. AI_FORCE_INLINE const aiScene *Importer::ReadFile(const std::string &pFile, unsigned int pFlags) {
  601. return ReadFile(pFile.c_str(), pFlags);
  602. }
  603. // ----------------------------------------------------------------------------
  604. AI_FORCE_INLINE void Importer::GetExtensionList(std::string &szOut) const {
  605. aiString s;
  606. GetExtensionList(s);
  607. szOut = s.data;
  608. }
  609. // ----------------------------------------------------------------------------
  610. AI_FORCE_INLINE bool Importer::IsExtensionSupported(const std::string &szExtension) const {
  611. return IsExtensionSupported(szExtension.c_str());
  612. }
  613. } // namespace Assimp
  614. #endif // AI_ASSIMP_HPP_INC