export.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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.h
  35. * @brief Defines the C-API for the Assimp export interface
  36. */
  37. #ifndef AI_EXPORT_H_INC
  38. #define AI_EXPORT_H_INC
  39. #ifndef ASSIMP_BUILD_NO_EXPORT
  40. #include "aiTypes.h"
  41. #ifdef __cplusplus
  42. #include <boost/noncopyable.hpp>
  43. extern "C" {
  44. #endif
  45. struct aiScene; // aiScene.h
  46. // --------------------------------------------------------------------------------
  47. /** Describes an file format which Assimp can export to. Use #aiGetExportFormatCount() to
  48. * learn how many export formats the current Assimp build supports and #aiGetExportFormatDescription()
  49. * to retrieve a description of an export format option.
  50. */
  51. struct aiExportFormatDesc
  52. {
  53. /// a short string ID to uniquely identify the export format. Use this ID string to
  54. /// specify which file format you want to export to when calling #aiExportScene().
  55. /// Example: "dae" or "obj"
  56. const char* id;
  57. /// A short description of the file format to present to users. Useful if you want
  58. /// to allow the user to select an export format.
  59. const char* description;
  60. /// Recommended file extension for the exported file in lower case.
  61. const char* fileExtension;
  62. };
  63. // --------------------------------------------------------------------------------
  64. /** Returns the number of export file formats available in the current Assimp build.
  65. * Use aiGetExportFormatDescription() to retrieve infos of a specific export format.
  66. */
  67. ASSIMP_API size_t aiGetExportFormatCount(void);
  68. // --------------------------------------------------------------------------------
  69. /** Returns a description of the nth export file format. Use #aiGetExportFormatCount()
  70. * to learn how many export formats are supported.
  71. * @param pIndex Index of the export format to retrieve information for. Valid range is
  72. * 0 to #aiGetExportFormatCount()
  73. * @return A description of that specific export format. NULL if pIndex is out of range.
  74. */
  75. ASSIMP_API const C_STRUCT aiExportFormatDesc* aiGetExportFormatDescription( size_t pIndex);
  76. // --------------------------------------------------------------------------------
  77. /** Create a modifyable copy of a scene.
  78. * This is useful to import files via Assimp, change their topology and
  79. * export them again. Since the scene returned by the various importer functions
  80. * is const, a modifyable copy is needed.
  81. * @param pIn Valid scene to be copied
  82. * @param pOut User-allocated scene to be filled.
  83. */
  84. ASSIMP_API void aiCopyScene(const C_STRUCT aiScene* pIn, C_STRUCT aiScene** pOut);
  85. // --------------------------------------------------------------------------------
  86. /** Exports the given scene to a chosen file format and writes the result file(s) to disk.
  87. * @param pScene The scene to export. Stays in possession of the caller, is not changed by the function.
  88. * The scene is expected to conform to Assimp's Importer output format as specified
  89. * in the @link data Data Structures Page @endlink. In short, this means the model data
  90. * should use a right-handed coordinate systems, face winding should be counter-clockwise
  91. * and the UV coordinate origin is assumed to be in the upper left. If your input data
  92. * uses different conventions, have a look at the last parameter.
  93. * @param pFormatId ID string to specify to which format you want to export to. Use
  94. * aiGetExportFormatCount() / aiGetExportFormatDescription() to learn which export formats are available.
  95. * @param pFileName Output file to write
  96. * @param pIO custom IO implementation to be used. Use this if you use your own storage methods.
  97. * If none is supplied, a default implementation using standard file IO is used. Note that
  98. * #aiExportSceneToBlob is provided as convenience function to export to memory buffers.
  99. * @param pPreprocessing Accepts any choice of the #aiPostProcessing enumerated
  100. * flags, but in reality only a subset of them makes sense here. Specifying
  101. * 'preprocessing' flags is useful if the input scene does not conform to
  102. * Assimp's default conventions as specified in the @link data Data Structures Page @endlink.
  103. * In short, this means the geometry data should use a right-handed coordinate systems, face
  104. * winding should be counter-clockwise and the UV coordinate origin is assumed to be in
  105. * the upper left. The #aiProcess_MakeLeftHanded, #aiProcess_FlipUVs and
  106. * #aiProcess_FlipWindingOrder flags are used in the import side to allow users
  107. * to have those defaults automatically adapted to their conventions. Specifying those flags
  108. * for exporting has the opposite effect, respectively. Some other of the
  109. * #aiPostProcessSteps enumerated values may be useful as well, but you'll need
  110. * to try out what their effect on the exported file is. Many formats impose
  111. * their own restrictions on the structure of the geometry stored therein,
  112. * so some preprocessing may have little or no effect at all, or may be
  113. * redundant as exporters would apply them anyhow. A good example
  114. * is triangulation - whilst you can enforce it by specifying
  115. * the #aiProcess_Triangulate flag, most export formats support only
  116. * triangulate data so they would run the step anyway.
  117. * @return a status code indicating the result of the export
  118. */
  119. ASSIMP_API aiReturn aiExportScene( const C_STRUCT aiScene* pScene, const char* pFormatId, const char* pFileName, unsigned int pPreprocessing);
  120. // --------------------------------------------------------------------------------
  121. /** Exports the given scene to a chosen file format using custom IO logic supplied by you.
  122. * @param pScene The scene to export. Stays in possession of the caller, is not changed by the function.
  123. * @param pFormatId ID string to specify to which format you want to export to. Use
  124. * aiGetExportFormatCount() / aiGetExportFormatDescription() to learn which export formats are available.
  125. * @param pFileName Output file to write
  126. * @param pIO custom IO implementation to be used. Use this if you use your own storage methods.
  127. * If none is supplied, a default implementation using standard file IO is used. Note that
  128. * #aiExportSceneToBlob is provided as convienience function to export to memory buffers.
  129. * @param pPreprocessing Please see the documentation for #aiExportScene
  130. * @return a status code indicating the result of the export
  131. */
  132. ASSIMP_API aiReturn aiExportSceneEx( const C_STRUCT aiScene* pScene, const char* pFormatId, const char* pFileName, C_STRUCT aiFileIO* pIO, unsigned int pPreprocessing );
  133. // --------------------------------------------------------------------------------
  134. /** Describes a blob of exported scene data. Use #aiExportSceneToBlob() to create a blob containing an
  135. * exported scene. The memory referred by this structure is owned by Assimp. Use #aiReleaseExportedFile()
  136. * to free its resources. Don't try to free the memory on your side - it will crash for most build configurations
  137. * due to conflicting heaps.
  138. *
  139. * Blobs can be nested - each blob may reference another blob, which may in turn reference another blob and so on.
  140. * This is used when exporters write more than one output file for a given #aiScene. See the remarks for
  141. * #aiExportDataBlob::name for more information.
  142. */
  143. struct aiExportDataBlob
  144. #ifdef __cplusplus
  145. : public boost::noncopyable
  146. #endif // __cplusplus
  147. {
  148. /// Size of the data in bytes
  149. size_t size;
  150. /// The data.
  151. void* data;
  152. /** Name of the blob. An empty string always
  153. indicates the first (and primary) blob,
  154. which contains the actual file data.
  155. Any other blobs are auxiliary files produced
  156. by exporters (i.e. material files). Existence
  157. of such files depends on the file format. Most
  158. formats don't split assets across multiple files.
  159. If used, blob names usually contain the file
  160. extension that should be used when writing
  161. the data to disc.
  162. */
  163. aiString name;
  164. /** Pointer to the next blob in the chain or NULL if there is none. */
  165. aiExportDataBlob * next;
  166. #ifdef __cplusplus
  167. /// Default constructor
  168. aiExportDataBlob() { size = 0; data = next = NULL; }
  169. /// Releases the data
  170. ~aiExportDataBlob() { delete static_cast<char*>( data ); delete next; }
  171. #endif // __cplusplus
  172. };
  173. // --------------------------------------------------------------------------------
  174. /** Exports the given scene to a chosen file format. Returns the exported data as a binary blob which
  175. * you can write into a file or something. When you're done with the data, use #aiReleaseExportBlob()
  176. * to free the resources associated with the export.
  177. * @param pScene The scene to export. Stays in possession of the caller, is not changed by the function.
  178. * @param pFormatId ID string to specify to which format you want to export to. Use
  179. * #aiGetExportFormatCount() / #aiGetExportFormatDescription() to learn which export formats are available.
  180. * @param pPreprocessing Please see the documentation for #aiExportScene
  181. * @return the exported data or NULL in case of error
  182. */
  183. ASSIMP_API const C_STRUCT aiExportDataBlob* aiExportSceneToBlob( const C_STRUCT aiScene* pScene, const char* pFormatId, unsigned int pPreprocessing );
  184. // --------------------------------------------------------------------------------
  185. /** Releases the memory associated with the given exported data. Use this function to free a data blob
  186. * returned by aiExportScene().
  187. * @param pData the data blob returned by #aiExportSceneToBlob
  188. */
  189. ASSIMP_API C_STRUCT void aiReleaseExportBlob( const C_STRUCT aiExportDataBlob* pData );
  190. #ifdef __cplusplus
  191. }
  192. #endif
  193. #endif // ASSIMP_BUILD_NO_EXPORT
  194. #endif // AI_EXPORT_H_INC