#ifndef __cexport_bi__
#define __cexport_bi__

' Defines the C-API for the Assimp export interface

#include once "ctypes.bi"
#include once "cscene.bi"
#include once "cfileio.bi"

extern "C"

' Describes an file format which Assimp can export to.
' Use aiGetExportFormatCount() to learn how many export formats the current Assimp build supports and 
' aiGetExportFormatDescription() to retrieve a description of an export format option.
type aiExportFormatDesc
  ' a short string ID to uniquely identify the export format.
  ' Use this ID string to specify which file format you want to export to when calling aiExportScene().
  as const zstring ptr id
  ' A short description of the file format to present to users.
  ' Useful if you want to allow the user to select an export format.
  as const zstring ptr description
  ' Recommended file extension for the exported file in lower case. 
  as const zstring ptr fileExtension
end type

' Returns the number of export file formats available in the current Assimp build.
' Use aiGetExportFormatDescription() to retrieve infos of a specific export format.
declare function aiGetExportFormatCount() as size_t

' Returns a description of the nth export file format. 
' Use aiGetExportFormatCount() to learn how many export formats are supported.
' @param pIndex Index of the export format to retrieve information for.
' Valid range is 0 to aiGetExportFormatCount()
' @return A description of that specific export format. NULL if pIndex is out of range.
declare function aiGetExportFormatDescription(byval pIndex as size_t) as const aiExportFormatDesc ptr

' Create a modifiable copy of a scene.
' This is useful to import files via Assimp, change their topology and  export them again.
' Since the scene returned by the various importer functions is const, a modifiable copy is needed.
' @param pIn Valid scene to be copied
' @param pOut Receives a modifyable copy of the scene. Use aiFreeScene() to delete it again.
declare sub aiCopyScene(byval pIn as const aiScene ptr,byval pOut as aiScene ptr ptr)

' Frees a scene copy created using aiCopyScene() */
declare sub aiFreeScene(byval pIn as const aiScene ptr)

' Exports the given scene to a chosen file format and writes the result file(s) to disk.
' @param pScene The scene to export. Stays in possession of the caller, is not changed by the function.
' The scene is expected to conform to Assimp's Importer output format as specified in the data Data Structures Page.
' In short, this means the model data should use a right-handed coordinate systems, face winding should be counter-clockwise
' and the UV coordinate origin is assumed to be in the upper left. 
' If your input data uses different conventions, have a look at the last parameter.
' @param pFormatId ID string to specify to which format you want to export to. 
' Use aiGetExportFormatCount() / aiGetExportFormatDescription() to learn which export formats are available.
' @param pFileName Output file to write
' @param pIO custom IO implementation to be used. Use this if you use your own storage methods.
' If none is supplied, a default implementation using standard file IO is used.
' Note that aiExportSceneToBlob is provided as convenience function to export to memory buffers.
' @param Preprocessing Accepts any choice of the aiPostProcessing enumerated flags, 
' but in reality only a subset of them makes sense here.
' Specifying preprocessing flags is useful if the input scene does not conform to Assimp's default conventions 
' as specified in the data Data Structures Page.  In short, this means the geometry data should use a right-handed coordinate systems, face 
' winding should be counter-clockwise and the UV coordinate origin is assumed to be in the upper left.
' The aiProcess_MakeLeftHanded, aiProcess_FlipUVs and aiProcess_FlipWindingOrder flags are used in the import side to allow users
' to have those defaults automatically adapted to their conventions. Specifying those flags for exporting has the opposite effect, respectively.
' Some other of the aiPostProcessSteps enumerated values may be useful as well, but you'll need to try out what their effect on the exported file is.
' Many formats impose their own restrictions on the structure of the geometry stored therein, so some preprocessing may have little or no effect at all, 
' or may be redundant as exporters would apply them anyhow. A good example is triangulation - whilst you can enforce it by specifying 
' the aiProcess_Triangulate flag, most export formats support only triangulate data so they would run the step anyway.
' If assimp detects that the input scene was directly taken from the importer side of the library 
' (i.e. not copied using aiCopyScene and potetially modified afterwards), 
' any postprocessing steps already applied to the scene will not be applied again,
' unless they show non-idempotent behaviour (aiProcess_MakeLeftHanded, aiProcess_FlipUVs and aiProcess_FlipWindingOrder).
' @return a status code indicating the result of the export @note Use aiCopyScene() to get a modifiable copy of a previously imported scene.
declare function aiExportScene(byval pScene as const aiScene ptr , _
                               byval pFormatId as const zstring ptr, _ 
                               byval pFileName as const zstring ptr, _
                               byval Preprocessing as ulong) as aiReturn


' Exports the given scene to a chosen file format using custom IO logic supplied by you.
' @param pScene The scene to export. Stays in possession of the caller, is not changed by the function.
' @param pFormatId ID string to specify to which format you want to export to.
' Use aiGetExportFormatCount() / aiGetExportFormatDescription() to learn which export formats are available.
' @param pFileName Output file to write
' @param pIO custom IO implementation to be used. Use this if you use your own storage methods.
' If none is supplied, a default implementation using standard file IO is used.
' Note that aiExportSceneToBlob is provided as convenience function to export to memory buffers.
' @param Preprocessing Please see the documentation for aiExportScene
' @return a status code indicating the result of the export
' @note Include "caiFileIO.bi" for the definition of aiFileIO.
' @note Use aiCopyScene() to get a modifiable copy of a previously imported scene.
declare function aiExportSceneEx(byval pScene as const aiScene ptr, _
                                 byval pFormatId as const zstring ptr, _
                                 byval pFileName as const zstring ptr,  _
                                 byval pIO as aiFileIO ptr, _
                                 byval Preprocessing as ulong) as aiReturn


' Describes a blob of exported scene data. 
' Use aiExportSceneToBlob() to create a blob containing an exported scene. 
' The memory referred by this structure is owned by Assimp. Use aiReleaseExportedFile() to free its resources. 
' Don't try to free the memory on your side - it will crash for most build configurations due to conflicting heaps.
' Blobs can be nested - each blob may reference another blob, which may in turn reference another blob and so on.
' This is used when exporters write more than one output file for a given aiScene.
' See the remarks for aiExportDataBlob::name for more information.
type aiExportDataBlob 
  ' Size of the data in bytes
  as size_t size
  'The data. 
  as any ptr pData
  ' Name of the blob.
  ' An empty string always indicates the first (and primary) blob, which contains the actual file data.
  ' Any other blobs are auxiliary files produced by exporters (i.e. material files). 
  ' Existence of such files depends on the file format. Most formats don't split assets across multiple files.
  ' If used, blob names usually contain the file extension that should be used when writing the data to disc.
  as aiString name
  ' Pointer to the next blob in the chain or NULL if there is none.
  as aiExportDataBlob ptr pNext
end type


' Exports the given scene to a chosen file format. 
' Returns the exported data as a binary blob which you can write into a file or something.
' When you're done with the data, use aiReleaseExportBlob() to free the resources associated with the export. 
' @param pScene The scene to export. Stays in possession of the caller, is not changed by the function.
' @param pFormatId ID string to specify to which format you want to export to.
' Use aiGetExportFormatCount() / aiGetExportFormatDescription() to learn which export formats are available.
' @param pPreprocessing Please see the documentation for aiExportScene
' @return the exported data or NULL in case of error
declare function aiExportSceneToBlob(byval pScene as const aiScene ptr, _
                                     byval pFormatId as const zstring ptr, _
                                     byval Preprocessing as ulong) as const aiExportDataBlob ptr

' Releases the memory associated with the given exported data. 
' Use this function to free a data blob returned by aiExportScene().
' @param pData the data blob returned by aiExportSceneToBlob
declare sub aiReleaseExportBlob(byval pData as const aiExportDataBlob ptr)

end extern

#endif ' __cexport_bi__

