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.
 
 
 
 
 
 

316 lines
14 KiB

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