#ifndef __cimport_bi__
#define __cimport_bi__

' Defines the C-API to the Open Asset Import Library. 

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

extern "C"

type aiLogStreamCallback as sub (byval msg as const zstring ptr,byval user as any ptr)

' C-API: Represents a log stream. A log stream receives all log messages and  streams them _somewhere_.
' see aiGetPredefinedLogStream
' see aiAttachLogStream
' see aiDetachLogStream/
type aiLogStream
  ' callback to be called 
  as aiLogStreamCallback callback
  '  user data to be passed to the callback */
  as any ptr user
end type



'C-API: Represents an opaque set of settings to be used during importing.
' see  aiCreatePropertyStore
' see  aiReleasePropertyStore
' see  aiImportFileExWithProperties
' see  aiSetPropertylong
' see  aiSetPropertyFloat
' see  aiSetPropertyString
' see  aiSetPropertyMatrix

type aiPropertyStore 
  as ubyte sentinel
end type

' Our own C boolean type
type aiBool as long
#define AI_FALSE 0
#define AI_TRUE 1


' Reads the given file and returns its content.

' If the call succeeds, the imported data is returned in an aiScene structure. 
' The data is intended to be read-only, it stays property of the ASSIMP 
' library and will be stable until aiReleaseImport() is called. After you're 
' done with it, call aiReleaseImport() to free the resources associated with 
' this file. If the import fails, NULL is returned instead. Call 
' aiGetErrorString() to retrieve a human-readable error text.
' @param pFile Path and filename of the file to be imported, 
'   expected to be a null-terminated c-string. NULL is not a valid value.
' @param pFlags Optional post processing steps to be executed after 
'   a successful import. Provide a bitwise combination of the 
'   aiPostProcessSteps flags.
' @return Pointer to the imported data or NULL if the import failed. 

declare function aiImportFile(byval pFile as const zstring ptr,byval Flags as ulong) as const aiScene ptr

' Reads the given file using user-defined I/O functions and returns its content.

' If the call succeeds, the imported data is returned in an aiScene structure. 
' The data is intended to be read-only, it stays property of the ASSIMP 
' library and will be stable until aiReleaseImport() is called. After you're 
' done with it, call aiReleaseImport() to free the resources associated with 
' this file. If the import fails, NULL is returned instead. Call 
' aiGetErrorString() to retrieve a human-readable error text.
' @param pFile Path and filename of the file to be imported, 
'   expected to be a null-terminated c-string. NULL is not a valid value.
' @param pFlags Optional post processing steps to be executed after 
'   a successful import. Provide a bitwise combination of the
'   #aiPostProcessSteps flags.
' @param pFS aiFileIO structure. Will be used to open the model file itself
'   and any other files the loader needs to open.  Pass NULL to use the default
'   implementation.
' @return Pointer to the imported data or NULL if the import failed.  
' @note Include <aiFileIO.h> for the definition of #aiFileIO.
declare function aiImportFileEx(byval pFile as const zstring ptr, _
                                byval Flags as ulong, _
                                byval pFS as aiFileIO ptr) as const aiScene ptr

' Same as aiImportFileEx, but adds an extra parameter containing importer settings.
'
' @param pProps aiPropertyStore instance containing import settings. 
declare function aiImportFileExWithProperties(byval pFile as const zstring ptr, _
                                              byval Flags as ulong, _
                                              byval pFS as aiFileIO ptr, _
                                              byval pProps as const aiPropertyStore ptr) as const aiScene ptr


' Reads the given file from a given memory buffer,
' 
' If the call succeeds, the contents of the file are returned as a pointer to an aiScene object. 
' The returned data is intended to be read-only, the importer keeps ownership of the data 
' and will destroy it upon destruction. If the import fails, NULL is returned.
' A human-readable error description can be retrieved by calling aiGetErrorString(). 
' @param pBuffer Pointer to the file data
' @param pLength Length of pBuffer, in bytes
' @param pFlags Optional post processing steps to be executed after 
'   a successful import. Provide a bitwise combination of the 
'   aiPostProcessSteps flags. If you wish to inspect the imported
'   scene first in order to fine-tune your post-processing setup,
'   consider to use #aiApplyPostProcessing().
' @param pHint An additional hint to the library. If this is a non empty string,
'   the library looks for a loader to support the file extension specified by pHint
'   and passes the file to the first matching loader. If this loader is unable to 
'   completely the request, the library continues and tries to determine the file
'   format on its own, a task that may or may not be successful. 
'   Check the return value, and you'll know ...
' @return A pointer to the imported data, NULL if the import failed.

' @note This is a straightforward way to decode models from memory buffers, but it doesn't handle model formats 
' that spread their data across multiple files or even directories.
' Examples include OBJ or MD3, which outsource parts of their material info into external scripts. 
' If you need full functionality, provide a custom IOSystem to make Assimp find these files 
' and use the regular aiImportFileEx()/aiImportFileExWithProperties() API.

declare function aiImportFileFromMemory(byval pBuffer as const any ptr, _
                                        byval Length as ulong, _
                                        byval Flags as ulong, _
                                        byval pHint as const zstring ptr) as const aiScene ptr

' Same as #aiImportFileFromMemory, but adds an extra parameter containing importer settings.

' @param pProps aiPropertyStore instance containing import settings. 
' @see aiImportFileFromMemory

declare function aiImportFileFromMemoryWithProperties(byval pBuffer as const any ptr, _
                                                      byval Length as ulong, _
                                                      byval Flags as ulong, _
                                                      byval pHint as const zstring ptr, _
                                                      byval pProps as const aiPropertyStore ptr) as const aiScene ptr


' Apply post-processing to an already-imported scene.

' This is strictly equivalent to calling aiImportFile()/aiImportFileEx with the same flags. 
' However, you can use this separate function to inspect the imported scene first to 
' fine-tune your post-processing setup. 
' @param pScene Scene to work on.
' @param pFlags Provide a bitwise combination of the aiPostProcessSteps flags.
' @return A pointer to the post-processed data.
' Post processing is done in-place,  meaning this is still the same aiScene which you passed for pScene. 
' However, if post-processing failed, the scene could now be NULL. 
' That's quite a rare case, post processing steps are not really designed to 'fail'. 
' To be exact, the aiProcess_ValidateDS flag is currently the only post processing step 
' which can actually cause the scene to be reset to NULL.
declare function aiApplyPostProcessing(byval pScene as const aiScene ptr, _
                                       byval Flags as ulong) as const aiScene ptr


' Get one of the predefine log streams. 
' This is the quick'n'easy solution to access Assimp's log system. 
' Attaching a log stream can slightly reduce Assimp's  overall import performance. 

'  Usage is rather simple (this will stream the log to a file, named log.txt, and the stdout stream of the process:
' 
'   struct aiLogStream c;
'    c = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"log.txt");
'    aiAttachLogStream(&c);
'   c = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
'    aiAttachLogStream(&c);

'  @param pStreams One of the aiDefaultLogStream enumerated values. 
'  @param file Solely for the aiDefaultLogStream_FILE flag: specifies the file to write to.
'    Pass NULL for all other flags.
'  @return The log stream. callback is set to NULL if something went wrong.

declare function aiGetPredefinedLogStream(byval Streams as aiDefaultLogStream, _
                                          byval file as const zstring ptr) as aiLogStream

' Attach a custom log stream to the libraries' logging system.
' Attaching a log stream can slightly reduce Assimp's overall import performance. 
' Multiple log-streams can be attached. 
'  @param stream Describes the new log stream.
'  @note To ensure proepr destruction of the logging system, you need to manually
'    call aiDetachLogStream() on every single log stream you attach. 
'    Alternatively (for the lazy folks) #aiDetachAllLogStreams is provided.
declare sub aiAttachLogStream(byval stream as const aiLogStream ptr)

' Enable verbose logging. 
' Verbose logging includes debug-related stuff and detailed import statistics.
' This can have severe impact on import performance and memory consumption.
' However, it might be useful to find out why a file didn't read correctly.
'  @param d AI_TRUE or AI_FALSE, your decision.
declare sub aiEnableVerboseLogging(byval d as aiBool)

' Detach a custom log stream from the libraries' logging system.

' This is the counterpart of aiAttachPredefinedLogStream. 
' If you attached a stream,  don't forget to detach it again.
' @param stream The log stream to be detached.
' @return AI_SUCCESS if the log stream has been detached successfully.
' see  aiDetachAllLogStreams
declare function aiDetachLogStream(byval stream as const aiLogStream ptr) as aiReturn

' Detach all active log streams from the libraries' logging system.
' This ensures that the logging system is terminated properly and all
' resources allocated by it are actually freed.
' If you attached a stream, don't forget to detach it again.
' see  aiAttachLogStream
' see  aiDetachLogStream
declare sub aiDetachAllLogStreams()

' Releases all resources associated with the given import process.
' Call this function after you're done with the imported data.
' @param pScene The imported data to release. NULL is a valid value.
declare sub aiReleaseImport(byval pScene as const aiScene ptr)

' Returns the error text of the last failed import process. 
' @return A textual description of the error that occurred at the last
' import process. NULL if there was no error. There can't be an error if you
' got a non-NULL aiScene from aiImportFile/aiImportFileEx/aiApplyPostProcessing.
declare function aiGetErrorString() as const zstring ptr

' Returns whether a given file extension is supported by ASSIMP
' @param szExtension Extension for which the function queries support for.
' Must include a leading dot '.'. Example: ".3ds", ".md3"
' return AI_TRUE if the file extension is supported.
declare function  aiIsExtensionSupported(byval szExtension as const zstring ptr) as aiBool

' Get a list of all file extensions supported by ASSIMP.
' If a file extension is contained in the list this does, of course, not
' mean that ASSIMP is able to load all files with this extension.
' @param szOut String to receive the extension list.
' Format of the list: "*.3ds;*.obj;*.dae". NULL is not a valid parameter.
declare sub aiGetExtensionList(byval szOut as aiString ptr)

' Get the approximated storage required by an imported asset
' @param pIn Input asset.
' @param in Data structure to be filled. 
declare sub aiGetMemoryRequirements(byval pIn as const aiScene ptr,byval in as aiMemoryInfo ptr)

' Create an empty property store. Property stores are used to collect import settings.
' @return New property store. Property stores need to be manually destroyed using
' the aiReleasePropertyStore API function.
declare function aiCreatePropertyStore() as aiPropertyStore ptr

' Delete a property store.
' @param p Property store to be deleted.
declare sub aiReleasePropertyStore(byval p as aiPropertyStore ptr)

' Set an long property. 
' This is the C-version of Assimp::Importer::SetPropertylong(). 
' In the C interface, properties are always shared by all imports. 
' It is not possible to specify them per import.
' @param szName Name of the configuration property to be set. 
' All supported public properties are defined in the config.h header file (#AI_CONFIG_XXX).
' @param value New value for the property
declare sub aiSetImportPropertylong(byval store as aiPropertyStore ptr,byval szName as const zstring ptr,byval value as long)

' Set a floating-point property. 
declare sub aiSetImportPropertyFloat(byval store as aiPropertyStore ptr,byval szName as const zstring ptr,byval value as single)

' Set a string property. 
declare sub aiSetImportPropertyString(byval store as aiPropertyStore ptr,byval szName as const zstring ptr,byval st as const aiString ptr)

' Set a matrix property. 
declare sub aiSetImportPropertyMatrix(byval store as aiPropertyStore ptr,byval szName as const zstring ptr,byval mat as const aiMatrix4x4 ptr)

' Construct a quaternion from a 3x3 rotation matrix.
'  @param quat Receives the output quaternion.
'  @param mat Matrix to 'quaternionize'.
' see  aiQuaternion(const aiMatrix3x3& pRotMatrix)
declare sub aiCreateQuaternionFromMatrix(byval quat as aiQuaternion ptr,byval mat as const aiMatrix3x3 ptr)

' Decompose a transformation matrix into its rotational, translational and scaling components.
' @param mat Matrix to decompose
' @param scaling Receives the scaling component
' @param rotation Receives the rotational component
' @param position Receives the translational component.
' @see aiMatrix4x4::Decompose (aiVector3D&, aiQuaternion&, aiVector3D&) const;
declare sub aiDecomposeMatrix(byval mat as const aiMatrix4x4 ptr, _
                              byval scaling  as aiVector3D ptr, _
                              byval rotation as aiQuaternion ptr, _
                              byval position as aiVector3D ptr)

' Transpose a 4x4 matrix.
' @param mat Pointer to the matrix to be transposed
declare sub aiTransposeMatrix4(byval mar as aiMatrix4x4 ptr)

' Transpose a 3x3 matrix.
' @param mat Pointer to the matrix to be transposed
declare sub aiTransposeMatrix3(byval mat as aiMatrix3x3 ptr)

' Transform a vector by a 3x3 matrix
' @param vec Vector to be transformed.
'  @param mat Matrix to transform the vector with.
declare sub aiTransformVecByMatrix3(byval vec as aiVector3D ptr,byval mat as const aiMatrix3x3 ptr)

' Transform a vector by a 4x4 matrix
'  @param vec Vector to be transformed.
'  @param mat Matrix to transform the vector with.
declare sub aiTransformVecByMatrix4(byval vec as aiVector3D ptr,byval mat as const aiMatrix4x4 ptr)

' Multiply two 4x4 matrices.
' @param dst First factor, receives result.
' @param src Matrix to be multiplied with 'dst'.
declare sub aiMultiplyMatrix4(byval dst as aiMatrix4x4 ptr,byval src as const aiMatrix4x4 ptr)

' Multiply two 3x3 matrices.
' @param dst First factor, receives result.
' @param src Matrix to be multiplied with 'dst'.
declare sub aiMultiplyMatrix3(byval dst as aiMatrix3x3 ptr,byval src as const aiMatrix3x3 ptr)

' Get a 3x3 identity matrix.
' @param mat Matrix to receive its personal identity
declare sub aiIdentityMatrix3(byval mat as aiMatrix3x3 ptr)

' Get a 4x4 identity matrix.
' @param mat Matrix to receive its personal identity
declare sub aiIdentityMatrix4(byval mat as aiMatrix4x4 ptr)

' A function for creating a rotation matrix that rotates a vector called "from" 
' into another vector called "to".
' Input : from[3], to[3] which both must be *normalized* non-zero vectors
' Output: mtx[3][3] -- a 3x3 matrix in colum-major form
declare sub aiFromToMatrix(byval from as const aiVector3D ptr,byval to_ as const aiVector3D ptr,byval mout as aiMatrix3x3 ptr)

end extern


#endif ' __cimport_bi__
