assimp.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /** @file Defines the CPP-API to the Asset Import Library. */
  2. #ifndef AI_ASSIMP_HPP_INC
  3. #define AI_ASSIMP_HPP_INC
  4. #ifndef __cplusplus
  5. #error This header requires C++ to be used.
  6. #endif
  7. #include <string>
  8. #include <vector>
  9. struct aiScene;
  10. namespace Assimp
  11. {
  12. class BaseImporter;
  13. class BaseProcess;
  14. class IOStream;
  15. class IOSystem;
  16. // ---------------------------------------------------------------------------
  17. /** The Importer class forms an C++ interface to the functionality of the
  18. * Asset Import library.
  19. *
  20. * Create an object of this class and call ReadFile() to import a file.
  21. * If the import succeeds, the function returns a pointer to the imported data.
  22. * The data remains property of the object, it is intended to be accessed
  23. * read-only. The imported data will be destroyed along with the Importer
  24. * object. If the import failes, ReadFile() returns a NULL pointer. In this
  25. * case you can retrieve a human-readable error description be calling
  26. * GetErrorString().
  27. *
  28. * If you need the Importer to do custom file handling to access the files,
  29. * implement IOSystem and IOStream and supply an instance of your custom IOSystem
  30. * implementation by calling SetIOHandler() before calling ReadFile(). If you
  31. * do not assign a custion IO handler, a default handler using the standard C++
  32. * IO logic will be used.
  33. */
  34. class Importer
  35. {
  36. public:
  37. // -------------------------------------------------------------------
  38. /** Constructor. Creates an empty importer object.
  39. *
  40. * Call ReadFile() to start the import process.
  41. */
  42. Importer();
  43. // -------------------------------------------------------------------
  44. /** Destructor. The object kept ownership of the imported data,
  45. * which now will be destroyed along with the object.
  46. */
  47. ~Importer();
  48. // -------------------------------------------------------------------
  49. /** Supplies a custom IO handler to the importer to open and access files.
  50. * If you need the importer to use custion IO logic to access the files,
  51. * you need to provide a custom implementation of IOSystem and IOFile
  52. * to the importer. Then create an instance of your custion IOSystem
  53. * implementation and supply it by this function.
  54. *
  55. * The Importer takes ownership of the object and will destroy it afterwards.
  56. * The previously assigned handler will be deleted.
  57. *
  58. * @param pIOHandler The IO handler to be used in all file accesses of the Importer.
  59. */
  60. void SetIOHandler( IOSystem* pIOHandler);
  61. // -------------------------------------------------------------------
  62. /** Reads the given file and returns its contents if successful.
  63. *
  64. * If the call succeeds, the contents of the file are returned as a
  65. * pointer to an aiScene object. The returned data is intended to be
  66. * read-only, the importer object keeps ownership of the data and will
  67. * destroy it upon destruction. If the import failes, NULL is returned.
  68. * A human-readable error description can be retrieved by calling
  69. * GetErrorString().
  70. * @param pFile Path and filename to the file to be imported.
  71. * @param pFlags Optional post processing steps to be executed after
  72. * a successful import. Provide a bitwise combination of the #aiPostProcessSteps
  73. * flags.
  74. * @return A pointer to the imported data, NULL if the import failed.
  75. */
  76. const aiScene* ReadFile( const std::string& pFile, unsigned int pFlags);
  77. // -------------------------------------------------------------------
  78. /** Returns an error description of an error that occured in ReadFile().
  79. *
  80. * Returns an empty string if no error occured.
  81. * @return A description of the last error, an empty string if no
  82. * error occured.
  83. */
  84. inline const std::string& GetErrorString() const
  85. { return mErrorString; }
  86. private:
  87. /** Empty copy constructor. */
  88. Importer(const Importer &other);
  89. protected:
  90. /** IO handler to use for all file accesses. */
  91. IOSystem* mIOHandler;
  92. /** Format-specific importer worker objects -
  93. * one for each format we can read. */
  94. std::vector<BaseImporter*> mImporter;
  95. /** Post processing steps we can apply at the imported data. */
  96. std::vector<BaseProcess*> mPostProcessingSteps;
  97. /** The imported data, if ReadFile() was successful,
  98. * NULL otherwise. */
  99. aiScene* mScene;
  100. /** The error description, if there was one. */
  101. std::string mErrorString;
  102. };
  103. } // End of namespace Assimp
  104. #endif // AI_ASSIMP_HPP_INC