#ifndef DESTINY3D_EXPORTER_HPP
#define DESTINY3D_EXPORTER_HPP

#define WIN32_LEAN_AND_MEAN

#define FLEXPORTER_API
#include <FlexporterSDK_IceCore.h>
#include <FlexporterSDK.h>
#include <FLX_CropValues.h>

#define USING_DESTINY3D
#define DESTINY3D_STATIC_LINK
#include "deGlobalTypes.hpp"
#include "deWorld.hpp"
#include "deArray.hpp"
#include "deList.hpp"
#include "deMesh.hpp"

class IdeSceneABT;
class IdeBitmapProxy;
class IdeRenderTexture;
class IdeSceneRoom;
class IdeSurface;

class Destiny3DFormat : public ExportFormat
{
public:
	// constructor, destructor
	Destiny3DFormat();
	virtual ~Destiny3DFormat();

	// Exporter init
	override(ExportFormat)	bool	Init				(bool motion);
	
	// Main scene info
	override(ExportFormat)	bool	SetSceneInfo		(const MainDescriptor& maininfo);
	
	// Export loop
	override(ExportFormat)	bool	ExportCamera		(const CameraDescriptor& camera);
	override(ExportFormat)	bool	ExportController	(const ControllerDescriptor& controller);
	override(ExportFormat)	bool	ExportHelper		(const HelperDescriptor& helper);
	override(ExportFormat)	bool	ExportLight			(const LightDescriptor& light);
	override(ExportFormat)	bool	ExportMaterial		(const MaterialDescriptor& material);
	override(ExportFormat)	bool	ExportMesh			(const MeshDescriptor& mesh);
	override(ExportFormat)	bool	ExportMotion		(const MotionDescriptor& motion);
	override(ExportFormat)	bool	ExportShape			(const ShapeDescriptor& shape);
	override(ExportFormat)	bool	ExportTexture		(const TextureDescriptor& texture);
	override(ExportFormat)	bool	ExportSpaceWarp		(const SpaceWarpDescriptor& space_warp);
	
	// End of export notification
	override(ExportFormat)	bool	EndExport			(const StatsDescriptor& stats);

	// About box
	override(CustomFormat)	void	About				();
	
private:
	struct FlexPortBase
	{
		sdword ObjectID;
		char* Name;
	};
	struct FlexPortTexture : public FlexPortBase
	{
		TextureTransform	Transform;
		UVWSource			SourceUVW;
		udword				MapChannel;
		long				AddressU, AddressV;
		IdeBitmapProxy*		BitmapProxy;
	};
	struct FlexPortMaterial : public FlexPortBase
	{
		TextureTransform	Transform;

		deColor				AmbientColor;
		deColor				DiffuseColor;
		deColor				SpecularColor;
		deColor				EmissiveColor;
		
		sdword				DiffuseMapID;
		sdword				OpacityMapID;
		sdword				BumpMapID;
		IdeSurface*			FinalSurface;
	};
	struct MeshMaterialInfo
	{
		sdword MatID;
		udword NumVerts;
		udword NumFaces;
	};
	struct FlexPortMeshData
	{
		MeshMaterialInfo Material;
		deMeshVertexData Vertices;
		deMeshIndexData  Indices;
	};
	struct FlexPortInstanceMesh : public FlexPortBase
	{
		sdword			ThisID;
		sdword			MasterID;
		NakedPRS		Position;
		deTArray<FlexPortMeshData>*MeshData;
	};
	bool							m_EngineInited;
	bool							m_IsMotionFile;
	deWorldID						m_WorldID;
	deTArray<FlexPortTexture>		m_Textures;
	deTArray<FlexPortMaterial>		m_Materials;
	deTArray<FlexPortInstanceMesh>	m_Meshes;
	deTList<FlexPortInstanceMesh>	m_InstanceMeshes;
	IdeRenderTexture*				m_NullTexture;
	IdeSceneRoom*					m_SceneRoom;
	IdeSceneABT*					m_ABT;

	typedef deTArray<FlexPortTexture>::iterator TexIterator;
	typedef deTArray<FlexPortMaterial>::iterator MatIterator;
	typedef deTArray<FlexPortInstanceMesh>::iterator MeshIterator;
};

static inline deColor Make_deColor(const NakedPoint& pt)
{
	deColor color;
	color.r = pt.r;
	color.g = pt.g;
	color.b = pt.b;
	color.a = 0;
	return color;
}

#endif