cexport.h 12 KB

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