export.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2011, 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 export.hpp
  35. * @brief Defines the CPP-API for the Assimp export interface
  36. */
  37. #ifndef AI_EXPORT_HPP_INC
  38. #define AI_EXPORT_HPP_INC
  39. #ifndef ASSIMP_BUILD_NO_EXPORT
  40. #include "export.h"
  41. namespace Assimp {
  42. class ExporterPimpl;
  43. // ----------------------------------------------------------------------------------
  44. /** CPP-API: The Exporter class forms an C++ interface to the export functionality
  45. * of the Open Asset Import Library. Note that the export interface is available
  46. * only if Assimp has been built with ASSIMP_BUILD_NO_EXPORT not defined.
  47. *
  48. * The interface is modelled after the importer interface and mostly
  49. * symmetric. The same rules for threading etc. apply.
  50. *
  51. * In a nutshell, there are two export interfaces: #Export, which writes the
  52. * output file(s) either to the regular file system or to a user-supplied
  53. * #IOSystem, and #ExportToBlob which returns a linked list of memory
  54. * buffers (blob), each referring to one output file (in most cases
  55. * there will be only one output file of course, but this extra complexity is
  56. * needed since Assimp aims at supporting a wide range of file formats).
  57. *
  58. * #ExportToBlob is especially useful if you intend to work
  59. * with the data in-memory.
  60. */
  61. class ASSIMP_API Exporter
  62. // TODO: causes good ol' base class has no dll interface warning
  63. //#ifdef __cplusplus
  64. // : public boost::noncopyable
  65. //#endif // __cplusplus
  66. {
  67. public:
  68. Exporter();
  69. ~Exporter();
  70. public:
  71. // -------------------------------------------------------------------
  72. /** Supplies a custom IO handler to the exporter to use to open and
  73. * access files.
  74. *
  75. * If you need #Export to use custom IO logic to access the files,
  76. * you need to supply a custom implementation of IOSystem and
  77. * IOFile to the exporter.
  78. *
  79. * #Exporter takes ownership of the object and will destroy it
  80. * afterwards. The previously assigned handler will be deleted.
  81. * Pass NULL to take again ownership of your IOSystem and reset Assimp
  82. * to use its default implementation, which uses plain file IO.
  83. *
  84. * @param pIOHandler The IO handler to be used in all file accesses
  85. * of the Importer. */
  86. void SetIOHandler( IOSystem* pIOHandler);
  87. // -------------------------------------------------------------------
  88. /** Retrieves the IO handler that is currently set.
  89. * You can use #IsDefaultIOHandler() to check whether the returned
  90. * interface is the default IO handler provided by ASSIMP. The default
  91. * handler is active as long the application doesn't supply its own
  92. * custom IO handler via #SetIOHandler().
  93. * @return A valid IOSystem interface, never NULL. */
  94. IOSystem* GetIOHandler() const;
  95. // -------------------------------------------------------------------
  96. /** Checks whether a default IO handler is active
  97. * A default handler is active as long the application doesn't
  98. * supply its own custom IO handler via #SetIOHandler().
  99. * @return true by default */
  100. bool IsDefaultIOHandler() const;
  101. // -------------------------------------------------------------------
  102. /** Exports the given scene to a chosen file format. Returns the exported
  103. * data as a binary blob which you can write into a file or something.
  104. * When you're done with the data, simply let the #Exporter instance go
  105. * out of scope to have it released automatically.
  106. * @param pScene The scene to export. Stays in possession of the caller,
  107. * is not changed by the function.
  108. * @param pFormatId ID string to specify to which format you want to
  109. * export to. Use
  110. * #GetExportFormatCount / #GetExportFormatDescription to learn which
  111. * export formats are available.
  112. * @param pPreprocessing See the documentation for #Export
  113. * @return the exported data or NULL in case of error.
  114. * @note If the Exporter instance did already hold a blob from
  115. * a previous call to #ExportToBlob, it will be disposed.
  116. * Any IO handlers set via #SetIOHandler are ignored here.*/
  117. const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const char* pFormatId, unsigned int pPreprocessing = 0u );
  118. inline const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const std::string& pFormatId, unsigned int pPreprocessing = 0u );
  119. // -------------------------------------------------------------------
  120. /** Convenience function to export directly to a file. Use
  121. * #SetIOSystem to supply a custom IOSystem to gain fine-grained control
  122. * about the output data flow of the export process.
  123. * @param pBlob A data blob obtained from a previous call to #aiExportScene. Must not be NULL.
  124. * @param pPath Full target file name. Target must be accessible.
  125. * @param pPreprocessing Accepts any choice of the #aiPostProcessing enumerated
  126. * flags, but in reality only a subset of them makes sense here. Specifying
  127. * 'preprocessing' flags is useful if the input scene does not conform to
  128. * Assimp's default conventions as specified in the @link data Data Structures Page @endlink.
  129. * In short, this means the geometry data should use a right-handed coordinate systems, face
  130. * winding should be counter-clockwise and the UV coordinate origin is assumed to be in
  131. * the upper left. The #aiProcess_MakeLeftHanded, #aiProcess_FlipUVs and
  132. * #aiProcess_FlipWindingOrder flags are used in the import side to allow users
  133. * to have those defaults automatically adapted to their conventions. Specifying those flags
  134. * for exporting has the opposite effect, respectively. Some other of the
  135. * #aiPostProcessSteps enumerated values may be useful as well, but you'll need
  136. * to try out what their effect on the exported file is. Many formats impose
  137. * their own restrictions on the structure of the geometry stored therein,
  138. * so some preprocessing may have little or no effect at all, or may be
  139. * redundant as exporters would apply them anyhow. A good example
  140. * is triangulation - whilst you can enforce it by specifying
  141. * the #aiProcess_Triangulate flag, most export formats support only
  142. * triangulate data so they would run the step even if it wasn't requested.
  143. * @return AI_SUCCESS if everything was fine. */
  144. aiReturn Export( const aiScene* pScene, const char* pFormatId, const char* pPath, unsigned int pPreprocessing = 0u);
  145. inline aiReturn Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath, unsigned int pPreprocessing = 0u);
  146. // -------------------------------------------------------------------
  147. /** Returns an error description of an error that occurred in #Export
  148. * or #ExportToBlob
  149. *
  150. * Returns an empty string if no error occurred.
  151. * @return A description of the last error, an empty string if no
  152. * error occurred. The string is never NULL.
  153. *
  154. * @note The returned function remains valid until one of the
  155. * following methods is called: #Export, #ExportToBlob, #FreeBlob */
  156. const char* GetErrorString() const;
  157. // -------------------------------------------------------------------
  158. /** Return the blob obtained from the last call to #ExportToBlob */
  159. const aiExportDataBlob* GetBlob() const;
  160. // -------------------------------------------------------------------
  161. /** Orphan the blob from the last call to #ExportToBlob. This means
  162. * the caller takes ownership and is thus responsible for calling
  163. * the C API function #aiReleaseExportBlob to release it. */
  164. const aiExportDataBlob* GetOrphanedBlob() const;
  165. // -------------------------------------------------------------------
  166. /** Frees the current blob.
  167. *
  168. * The function does nothing if no blob has previously been
  169. * previously produced via #ExportToBlob. #FreeBlob is called
  170. * automatically by the destructor. The only reason to call
  171. * it manually would be to reclain as much storage as possible
  172. * without giving up the #Exporter instance yet. */
  173. void FreeBlob( );
  174. // -------------------------------------------------------------------
  175. /** Returns the number of export file formats available in the current
  176. * Assimp build. Use #Exporter::GetExportFormatDescription to
  177. * retrieve infos of a specific export format */
  178. size_t GetExportFormatCount() const;
  179. // -------------------------------------------------------------------
  180. /** Returns a description of the nth export file format. Use #
  181. * #Exporter::GetExportFormatCount to learn how many export
  182. * formats are supported.
  183. * @param pIndex Index of the export format to retrieve information
  184. * for. Valid range is 0 to #Exporter::GetExportFormatCount
  185. * @return A description of that specific export format.
  186. * NULL if pIndex is out of range. */
  187. const aiExportFormatDesc* GetExportFormatDescription( size_t pIndex ) const;
  188. protected:
  189. // Just because we don't want you to know how we're hacking around.
  190. ExporterPimpl* pimpl;
  191. };
  192. // ----------------------------------------------------------------------------------
  193. inline const aiExportDataBlob* Exporter :: ExportToBlob( const aiScene* pScene, const std::string& pFormatId,unsigned int pPreprocessing )
  194. {
  195. return ExportToBlob(pScene,pFormatId.c_str(),pPreprocessing);
  196. }
  197. // ----------------------------------------------------------------------------------
  198. inline aiReturn Exporter :: Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath, unsigned int pPreprocessing )
  199. {
  200. return Export(pScene,pFormatId.c_str(),pPath.c_str(),pPreprocessing);
  201. }
  202. } // namespace Assimp
  203. #endif // ASSIMP_BUILD_NO_EXPORT
  204. #endif // AI_EXPORT_HPP_INC