export.hpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. */
  87. void SetIOHandler( IOSystem* pIOHandler);
  88. // -------------------------------------------------------------------
  89. /** Retrieves the IO handler that is currently set.
  90. * You can use #IsDefaultIOHandler() to check whether the returned
  91. * interface is the default IO handler provided by ASSIMP. The default
  92. * handler is active as long the application doesn't supply its own
  93. * custom IO handler via #SetIOHandler().
  94. * @return A valid IOSystem interface, never NULL.
  95. */
  96. IOSystem* GetIOHandler() const;
  97. // -------------------------------------------------------------------
  98. /** Checks whether a default IO handler is active
  99. * A default handler is active as long the application doesn't
  100. * supply its own custom IO handler via #SetIOHandler().
  101. * @return true by default
  102. */
  103. bool IsDefaultIOHandler() const;
  104. // -------------------------------------------------------------------
  105. /** Exports the given scene to a chosen file format. Returns the exported
  106. * data as a binary blob which you can write into a file or something.
  107. * When you're done with the data, simply let the #Exporter instance go
  108. * out of scope to have it released automatically.
  109. * @param pScene The scene to export. Stays in possession of the caller,
  110. * is not changed by the function.
  111. * @param pFormatId ID string to specify to which format you want to
  112. * export to. Use
  113. * #GetExportFormatCount / #GetExportFormatDescription to learn which
  114. * export formats are available.
  115. * @return the exported data or NULL in case of error.
  116. * @note If the Exporter instance did already hold a blob from
  117. * a previous call to #ExportToBlob, it will be disposed.
  118. * Any IO handlers set via #SetIOHandler are ignored here.*/
  119. const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const char* pFormatId );
  120. inline const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const std::string& pFormatId );
  121. // -------------------------------------------------------------------
  122. /** Convenience function to export directly to a file. Use
  123. * #SetIOSystem to supply a custom IOSystem to gain fine-grained control
  124. * about the output data flow of the export process.
  125. * @param pBlob A data blob obtained from a previous call to #aiExportScene. Must not be NULL.
  126. * @param pPath Full target file name. Target must be accessible.
  127. * @return AI_SUCCESS if everything was fine. */
  128. aiReturn Export( const aiScene* pScene, const char* pFormatId, const char* pPath );
  129. inline aiReturn Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath );
  130. // -------------------------------------------------------------------
  131. /** Return the blob obtained from the last call to #ExportToBlob */
  132. const aiExportDataBlob* GetBlob() const;
  133. // -------------------------------------------------------------------
  134. /** Orphan the blob from the last call to #ExportToBlob. This means
  135. * the caller takes ownership and is thus responsible for calling
  136. * #aiReleaseExportData to free the data again. */
  137. const aiExportDataBlob* GetOrphanedBlob() const;
  138. // -------------------------------------------------------------------
  139. /** Returns the number of export file formats available in the current
  140. * Assimp build. Use #Exporter::GetExportFormatDescription to
  141. * retrieve infos of a specific export format */
  142. size_t GetExportFormatCount() const;
  143. // -------------------------------------------------------------------
  144. /** Returns a description of the nth export file format. Use #
  145. * #Exporter::GetExportFormatCount to learn how many export
  146. * formats are supported.
  147. * @param pIndex Index of the export format to retrieve information
  148. * for. Valid range is 0 to #Exporter::GetExportFormatCount
  149. * @return A description of that specific export format.
  150. * NULL if pIndex is out of range. */
  151. const aiExportFormatDesc* GetExportFormatDescription( size_t pIndex ) const;
  152. protected:
  153. // Just because we don't want you to know how we're hacking around.
  154. ExporterPimpl* pimpl;
  155. };
  156. // ----------------------------------------------------------------------------------
  157. inline const aiExportDataBlob* Exporter :: ExportToBlob( const aiScene* pScene, const std::string& pFormatId )
  158. {
  159. return ExportToBlob(pScene,pFormatId.c_str());
  160. }
  161. // ----------------------------------------------------------------------------------
  162. inline aiReturn Exporter :: Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath )
  163. {
  164. return Export(pScene,pFormatId.c_str(),pPath.c_str());
  165. }
  166. } // namespace Assimp
  167. #endif // ASSIMP_BUILD_NO_EXPORT
  168. #endif // AI_EXPORT_HPP_INC