/* 
 * 
 * Confidential Information of Telekinesys Research Limited (t/a Havok).  Not for disclosure or distribution without Havok's
 * prior written consent.This software contains code, techniques and know-how which is confidential and proprietary to Havok.
 * Level 2 and Level 3 source code contains trade secrets of Havok. Havok Software (C) Copyright 1999-2008 Telekinesys Research Limited t/a Havok. All Rights Reserved. Use of this software is subject to the terms of an end user license agreement.
 * 
 */

#ifndef HK_GRAPHICS_BRIDGE_ASSET_CONV_H
#define HK_GRAPHICS_BRIDGE_ASSET_CONV_H

/// A collection of asset conversion utilities
class hkgAssetConverter
{
	public:

		enum ConvertMask
		{
			CONVERT_ALL = 0,
			NO_MESHES = 1,
			NO_LIGHTS = 2,
			NO_MATERIALS = 4,
			NO_TEXTURES = 8,
			NO_CAMERAS = 16,
			NO_SHADOW_CAST = 32,
			NO_VERTEX_COLORS = 64
		};

		struct Mapping
		{
			HKG_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( Mapping );

			Mapping() : m_origObject(HK_NULL), m_hkgObject(HK_NULL) { }
			const void* m_origObject; //The original object from the toolchain e.g. hkxCamera
			hkgReferencedObject* m_hkgObject; //The runtime graphics object we build e.g. hkgCamera
		};

		struct NodeMapping
		{
			HKG_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( Mapping);

			NodeMapping() : m_origNode(HK_NULL), m_hkgObject(HK_NULL) { }
			const class hkxNode* m_origNode; //The original node from the toolchain
			hkgReferencedObject* m_hkgObject; //The runtime graphics object we build e.g. hkgCamera
		};

		struct SkinPaletteMap
		{
			HKG_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( SkinPaletteMap);

			SkinPaletteMap() : m_skin(HK_NULL) { }
			class hkgDisplayObject* m_skin;
			hkArray< class hkgBlendMatrixSet* > m_palettes;
		};

		struct IndexMapping
		{
			hkInt16* m_mapping;
			hkInt32 m_numMapping;
		};

		struct MaterialCache
		{
			HKG_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( MaterialCache);

			MaterialCache() : m_manager(HK_NULL), m_supportsShaders(false) { }
			~MaterialCache();
			class hkgMaterialManager* m_manager;
			bool m_supportsShaders;
			hkgArray<Mapping> m_materials;	
			hkgArray<Mapping> m_textures;
		};

		struct MeshConvertOptions
		{
			HKG_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( MeshConvertOptions);

			MeshConvertOptions() : enableLighting(true), allowMaterialSharing(true), allowTextureMipmaps(true),
								   allowTextureCompression(false), allowHardwareSkinning(true), convMask(CONVERT_ALL) { }
			hkBool enableLighting;
			hkBool allowMaterialSharing;
			hkBool allowTextureMipmaps;
			hkBool allowTextureCompression;
			hkBool allowHardwareSkinning;
			ConvertMask convMask;
		};

		/// materialIndicesToClean - an array of material pointers that need to be cleaned up.
		/// The caller of this function is responsible for cleaning the materials up, if necessary
		static class hkgDisplayObject* HK_CALL convertMesh( const class hkxMesh* mesh, class hkgDisplayContext* context, 
											  const hkMatrix4& worldTransform, const MeshConvertOptions& options,
											  hkBool& wasSkin, MaterialCache& materialCache, hkgArray<Mapping>& meshCache,
											  hkgArray<Mapping>& skinVertexBufferCache, hkgArray<hkgMaterial*>& materialIndicesToClean);

		static int HK_CALL convertMaterial( const class hkxMaterial* material, hkgDisplayContext* context, MaterialCache& materialCache,
											hkBool allowSharing, hkBool doMipmaps, hkBool doCompression  );

		static int HK_CALL convertTexture(  const class hkxTextureInplace* texture, hkgDisplayContext* context,
											MaterialCache& materialCache, hkBool allowSharing, hkBool doMipmaps, hkBool doCompression   );

		static int HK_CALL convertTexture(  const class hkxTextureFile* texture, hkgDisplayContext* context, MaterialCache& materialCache,
											hkBool allowSharing, hkBool doMipmaps, hkBool doCompression   );

		static class hkgLight* HK_CALL convertLight( const class hkxLight* l, class hkgLightManager* manager );

		static class hkgCamera* HK_CALL convertCamera( const class hkxCamera* camera, const char* name );

		static SkinPaletteMap* HK_CALL setupHardwareSkin( hkgDisplayContext* context, hkgDisplayObject* dispObj, 
								IndexMapping* mappings, hkInt32 numMappings, 
								hkInt16 fullPaletteSize, hkBool allowCulling);

		static void HK_CALL updateSkin( hkgDisplayObject* dispObj, 
								hkArray< hkTransform >& matrixPalletes, hkArray< hkgBlendMatrixSet* >& graphicsPalettes, 
								const hkTransform& skinTransform, const class hkAabb* pLocalAabb = HK_NULL);

		// Search for the index of an object to retreive the display object.
		static int HK_CALL findMapping( const hkgArray<Mapping>& inList, const void* original);
		static int HK_CALL findMapping( const hkgArray<SkinPaletteMap*>& inList, const void* original);

	protected:

			// A dscription of the vertex format for our graphics library
		static class hkxVertexFormat* HK_CALL constructVertexFormat(class hkgVertexSet* v);
};

#endif // HK_GRAPHICS_BRIDGE_ASSET_CONV_H

/*
* Havok SDK - NO SOURCE PC DOWNLOAD, BUILD(#20080529)
*
* Confidential Information of Havok.  (C) Copyright 1999-2008 
* Telekinesys Research Limited t/a Havok. All Rights Reserved. The Havok
* Logo, and the Havok buzzsaw logo are trademarks of Havok.  Title, ownership
* rights, and intellectual property rights in the Havok software remain in
* Havok and/or its suppliers.
*
* Use of this software for evaluation purposes is subject to and indicates 
* acceptance of the End User licence Agreement for this product. A copy of 
* the license is included with this software and is also available at
* www.havok.com/tryhavok
*
*/
