cexport.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 cexport.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 "types.h"
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. struct aiScene; // aiScene.h
  45. struct aiFileIO; // aiFileIO.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 modifiable 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 modifiable copy is needed.
  81. * @param pIn Valid scene to be copied
  82. * @param pOut Receives a modifyable copy of the scene. Use aiFreeScene() to
  83. * delete it again.
  84. */
  85. ASSIMP_API void aiCopyScene(const C_STRUCT aiScene* pIn,
  86. C_STRUCT aiScene** pOut);
  87. // --------------------------------------------------------------------------------
  88. /** Frees a scene copy created using aiCopyScene() */
  89. ASSIMP_API void aiFreeScene(const C_STRUCT aiScene* pIn);
  90. // --------------------------------------------------------------------------------
  91. /** Exports the given scene to a chosen file format and writes the result file(s) to disk.
  92. * @param pScene The scene to export. Stays in possession of the caller, is not changed by the function.
  93. * The scene is expected to conform to Assimp's Importer output format as specified
  94. * in the @link data Data Structures Page @endlink. In short, this means the model data
  95. * should use a right-handed coordinate systems, face winding should be counter-clockwise
  96. * and the UV coordinate origin is assumed to be in the upper left. If your input data
  97. * uses different conventions, have a look at the last parameter.
  98. * @param pFormatId ID string to specify to which format you want to export to. Use
  99. * aiGetExportFormatCount() / aiGetExportFormatDescription() to learn which export formats are available.
  100. * @param pFileName Output file to write
  101. * @param pIO custom IO implementation to be used. Use this if you use your own storage methods.
  102. * If none is supplied, a default implementation using standard file IO is used. Note that
  103. * #aiExportSceneToBlob is provided as convenience function to export to memory buffers.
  104. * @param pPreprocessing Accepts any choice of the #aiPostProcessing enumerated
  105. * flags, but in reality only a subset of them makes sense here. Specifying
  106. * 'preprocessing' flags is useful if the input scene does not conform to
  107. * Assimp's default conventions as specified in the @link data Data Structures Page @endlink.
  108. * In short, this means the geometry data should use a right-handed coordinate systems, face
  109. * winding should be counter-clockwise and the UV coordinate origin is assumed to be in
  110. * the upper left. The #aiProcess_MakeLeftHanded, #aiProcess_FlipUVs and
  111. * #aiProcess_FlipWindingOrder flags are used in the import side to allow users
  112. * to have those defaults automatically adapted to their conventions. Specifying those flags
  113. * for exporting has the opposite effect, respectively. Some other of the
  114. * #aiPostProcessSteps enumerated values may be useful as well, but you'll need
  115. * to try out what their effect on the exported file is. Many formats impose
  116. * their own restrictions on the structure of the geometry stored therein,
  117. * so some preprocessing may have little or no effect at all, or may be
  118. * redundant as exporters would apply them anyhow. A good example
  119. * is triangulation - whilst you can enforce it by specifying
  120. * the #aiProcess_Triangulate flag, most export formats support only
  121. * triangulate data so they would run the step anyway.
  122. *
  123. * If assimp detects that the input scene was directly taken from the importer side of
  124. * the library (i.e. not copied using aiCopyScene and potetially modified afterwards),
  125. * any postprocessing steps already applied to the scene will not be applied again, unless
  126. * they show non-idempotent behaviour (#aiProcess_MakeLeftHanded, #aiProcess_FlipUVs and
  127. * #aiProcess_FlipWindingOrder).
  128. * @return a status code indicating the result of the export
  129. * @note Use aiCopyScene() to get a modifiable copy of a previously
  130. * imported scene.
  131. */
  132. ASSIMP_API aiReturn aiExportScene( const C_STRUCT aiScene* pScene,
  133. const char* pFormatId,
  134. const char* pFileName,
  135. unsigned int pPreprocessing);
  136. // --------------------------------------------------------------------------------
  137. /** Exports the given scene to a chosen file format using custom IO logic supplied by you.
  138. * @param pScene The scene to export. Stays in possession of the caller, is not changed by the function.
  139. * @param pFormatId ID string to specify to which format you want to export to. Use
  140. * aiGetExportFormatCount() / aiGetExportFormatDescription() to learn which export formats are available.
  141. * @param pFileName Output file to write
  142. * @param pIO custom IO implementation to be used. Use this if you use your own storage methods.
  143. * If none is supplied, a default implementation using standard file IO is used. Note that
  144. * #aiExportSceneToBlob is provided as convenience function to export to memory buffers.
  145. * @param pPreprocessing Please see the documentation for #aiExportScene
  146. * @return a status code indicating the result of the export
  147. * @note Include <aiFileIO.h> for the definition of #aiFileIO.
  148. * @note Use aiCopyScene() to get a modifiable copy of a previously
  149. * imported scene.
  150. */
  151. ASSIMP_API aiReturn aiExportSceneEx( const C_STRUCT aiScene* pScene,
  152. const char* pFormatId,
  153. const char* pFileName,
  154. C_STRUCT aiFileIO* pIO,
  155. unsigned int pPreprocessing );
  156. // --------------------------------------------------------------------------------
  157. /** Describes a blob of exported scene data. Use #aiExportSceneToBlob() to create a blob containing an
  158. * exported scene. The memory referred by this structure is owned by Assimp. Use #aiReleaseExportedFile()
  159. * to free its resources. Don't try to free the memory on your side - it will crash for most build configurations
  160. * due to conflicting heaps.
  161. *
  162. * Blobs can be nested - each blob may reference another blob, which may in turn reference another blob and so on.
  163. * This is used when exporters write more than one output file for a given #aiScene. See the remarks for
  164. * #aiExportDataBlob::name for more information.
  165. */
  166. struct aiExportDataBlob
  167. {
  168. /// Size of the data in bytes
  169. size_t size;
  170. /// The data.
  171. void* data;
  172. /** Name of the blob. An empty string always
  173. indicates the first (and primary) blob,
  174. which contains the actual file data.
  175. Any other blobs are auxiliary files produced
  176. by exporters (i.e. material files). Existence
  177. of such files depends on the file format. Most
  178. formats don't split assets across multiple files.
  179. If used, blob names usually contain the file
  180. extension that should be used when writing
  181. the data to disc.
  182. */
  183. C_STRUCT aiString name;
  184. /** Pointer to the next blob in the chain or NULL if there is none. */
  185. C_STRUCT aiExportDataBlob * next;
  186. #ifdef __cplusplus
  187. /// Default constructor
  188. aiExportDataBlob() { size = 0; data = next = NULL; }
  189. /// Releases the data
  190. ~aiExportDataBlob() { delete [] static_cast<unsigned char*>( data ); delete next; }
  191. private:
  192. // no copying
  193. aiExportDataBlob(const aiExportDataBlob& );
  194. aiExportDataBlob& operator= (const aiExportDataBlob& );
  195. #endif // __cplusplus
  196. };
  197. // --------------------------------------------------------------------------------
  198. /** Exports the given scene to a chosen file format. Returns the exported data as a binary blob which
  199. * you can write into a file or something. When you're done with the data, use #aiReleaseExportBlob()
  200. * to free the resources associated with the export.
  201. * @param pScene The scene to export. Stays in possession of the caller, is not changed by the function.
  202. * @param pFormatId ID string to specify to which format you want to export to. Use
  203. * #aiGetExportFormatCount() / #aiGetExportFormatDescription() to learn which export formats are available.
  204. * @param pPreprocessing Please see the documentation for #aiExportScene
  205. * @return the exported data or NULL in case of error
  206. */
  207. ASSIMP_API const C_STRUCT aiExportDataBlob* aiExportSceneToBlob( const C_STRUCT aiScene* pScene, const char* pFormatId, unsigned int pPreprocessing );
  208. // --------------------------------------------------------------------------------
  209. /** Releases the memory associated with the given exported data. Use this function to free a data blob
  210. * returned by aiExportScene().
  211. * @param pData the data blob returned by #aiExportSceneToBlob
  212. */
  213. ASSIMP_API void aiReleaseExportBlob( const C_STRUCT aiExportDataBlob* pData );
  214. #ifdef __cplusplus
  215. }
  216. #endif
  217. #endif // ASSIMP_BUILD_NO_EXPORT
  218. #endif // AI_EXPORT_H_INC