/*===========================================================================
 *
 * File:	Df3dexpo.H
 * Author:	Dave Humphrey (uesp@m0use.net)
 * Created On:	July 5, 2001
 *
 * Implements export related routines for Daggerfall 3D objects.
 *
 *=========================================================================*/
#ifndef __DF3DEXPO_H
#define __DF3DEXPO_H


/*===========================================================================
 *
 * Begin Required Include Files
 *
 *=========================================================================*/
  #include "uesp/dagger/df3dobj.h"
  #include "file/file3ds.h"
  #include "file/dxffile.h"
/*===========================================================================
 *		End of Required Include Files
 *=========================================================================*/


/*===========================================================================
 *
 * Begin Definitions
 *
 *=========================================================================*/

	/* Conversion factors for points when exporting */
  #define DF3D_3DS_FACTOR ((float)256)
  #define DF3D_DXF_FACTOR ((float)256)

/*===========================================================================
 *		End of Definitions
 *=========================================================================*/


/*===========================================================================
 *
 * Begin Type Definitions
 *
 *=========================================================================*/

	/* Point/face callback data structure for 3DS exports */
  typedef struct {
    C3dsFile*		pFile3DS;	/* Pointer to the output file */
    const float*	pMeshMatrix;	/* Optional mesh matrix used to transform point */
    int			ObjectVersion;	/* Version of DF 3D object */
    int			PointIndex;	/* Used for exporting faces */
    const CDF3dObject*	pObject;	/* Pointer to the original 3d object */
   } df3dexport3ds_t;

	/* Point/face callback data structure for DXF exports */
  typedef struct {
    CDxfFile*    pFileDxf;		/* Pointer to the output file */
    df3dpoint_t* pPoints;		/* Point data array */
    const float* pMeshMatrix;		/* Optional mesh matrix used to transform point */
    int		 ObjectVersion;		/* Version of DF 3D object */
    int		 Layer;			/* Layer number for object */
   } df3dexportdxf_t;

	/* Used to convert XYZ point coordinates to DF UV coordinates */
  typedef struct {
    float UA, UB, UC, UD;
    float VA, VB, VC, VD;
   } df3duvmatrix_t;
  
/*===========================================================================
 *		End of Type Definitions
 *=========================================================================*/


/*===========================================================================
 *
 * Begin Function Prototypes
 *
 *=========================================================================*/

 	/* Local function prototypes */
  int l_ExportDFMaterialTo3DS (df3dface_t& DFFace, void* pData);
  int l_ExportDFMaterialGroupTo3DS (const df3dface_t& DFFace, void* pData);
  int l_ExportDFTexturePointTo3DS2 (const df3dface_t& DFFace, void* pData);
  int l_ExportDFTexVertTo3DS (const df3dface_t& DFFace, void* pData);
	
	/* Create a material/texture name from image indices */
  char* CreateDF3DSMaterialName (const int TextureIndex, const int ImageIndex);
  char* CreateDF3DSTextureName  (const int TextureIndex, const int ImageIndex);

	/* Calculate a face XYZ to texture UV coordinate transform matrices */
  boolean ComputeDFFaceTextureUVMatrix (df3duvmatrix_t& Matrix, const df3dface_t& Face, 
					const CDF3dObject& Object);

	/* Output materials to a 3DS file */
  boolean ExportDFMaterialsTo3DS      (C3dsFile& File3DS, const CDF3dObject& Object);
  int     ExportDFMaterialGroupsTo3DS (C3dsFile& File3DS, const CDF3dObject& Object);

	/* Export a 3D object to a 3DS file */
  boolean ExportDF3dObjectTo3DS  (const char* pFilename, const CDF3dObject& Object);
  boolean ExportDF3dObjectTo3DS  (C3dsFile& File3DS,     const CDF3dObject& Object, 
				  const float* pMeshMatrix = NULL, const char* pName = NULL);

	/* Export a 3D object to a DXF file */
  boolean ExportDF3dObjectToDXF (const char* pFilename, const CDF3dObject& Object);
  boolean ExportDF3dObjectToDXF (CDxfFile& FileDXF,     const CDF3dObject& Object, 
				 const float* pMeshMatrix = NULL, const int Layer = 2);

/*===========================================================================
 *		End of Function Prototypes
 *=========================================================================*/


#endif
/*===========================================================================
 *		End of File Df3dexpo.H
 *=========================================================================*/