////////////////////////////////////////////////////////////////////////////////
// MechWarrior3MechImporter.h
// MechWarrior 3 Mech and vehicle import
// Copyright Bjoern Ganster
// Developed since 2007
////////////////////////////////////////////////////////////////////////////////

#ifndef MechWarrior3Importer__H
#define MechWarrior3Importer__H

#include "MechWarrior3ZBD.h"
#include "Archive.h"
#include "FileCache.h"
#include "Matrix.h"
#include "MechWarrior3GameZArchive.h"
#include "Point3D.h"
#include "TextureCompiler.h"

class Texture;
class Mesh;

class MW3MechImporter {
public:
	// Constructor
	MW3MechImporter (bool piratesMoon);

	// Destructor
	~MW3MechImporter();

	void execute(const PathChar* zbdDir, const PathChar* outputDir, const PathChar* importXML);
private:
	MechWarrior3ZBD* m_mechLib, * m_textureLib;
	TextureCompiler* m_tc;
	BGCPString m_mechOutputDir;
	BGCPString m_targetPath;
	bool mPiratesMoon;
	MechWarrior3ZBD mMechLib;
	MW3GameZArchive mGameZ;

	// todo: store the texture filenames in the textures?
	vector<BGCPString> textureFNs;

	// Open mech geometry (recursive part)
	void extractNodes (MemoryBlock* flt, size_t& offset, Matrix m, RenderableObject& meshes);
	void extractNodes_PM (MemoryBlock* flt, size_t& offset, Matrix m, RenderableObject& meshes);

	// Open mech geometry
	void exportFLT (MemoryBlock* flt, RenderableObject& meshes);

	// Get texture if already loaded or load the texture and then return it ...
	ManagedTexture* getTexture(size_t textureNum, bool hasUVs);

	// Read texture coordinates
	void readTextureCoords(MemoryBlock* flt, Mesh* mesh, MeshPolygon* poly, size_t polyData, bool invertPolygons);

	// Import a single mech or vehicle
	void importSingle(XMLTreeConstIterator& xmlIter, const PathChar* outputDir);
};

#endif
