cexport.h 13 KB

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