/*
 * $Id: mtlparser.h,v 1.0 2011-04-22 22:50:29 sedlad1 Exp $
 *
 * Description  : One line description of file.
 * Author       : David Sedlacek <david.sedlacek@fel.cvut.cz>
 *
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __MTLPARSER__H__
#define __MTLPARSER__H__

#include "scene.h"
#include "textparser.h"

namespace VRUT
{
	class Module;

	///Class for parsing MTL files
	class MTLParser
	{
	private:
		///Input stream
		wxInputStream * inputStream;
		///Scene container ID to be built
		SCENE_ID sceneID;
		///Path to scene resources, can be archive filename
		wxString fileName;
		///Path to scene resources, can be archive filename
		wxString scenePath;
		///Parent module's interface
		Module * module;

		///current material name
		wxString materialName;
		///current material node
		Material * material;
		///current node name
		wxString nodeName;
		///material library
		wxString materialLib;
		///Texture cache (to omit multiple loading of the same texture)
		std::set<wxString> addImageCache;

		///Parse indices
		bool parseIndices(TextParser &textParser, GeometryTriangles *geoTri, GeometryTriangles::PRIMITIVE_TYPE primType, std::vector<Vector3> &v,
			std::vector<GeometryTriangles::TexCoord> &vt, std::vector<Vector3> &vn);

		///Create GeometryNode, Geometry and Material
		void createNodeGeometryMaterial(Scene *scene, GeometryTriangles *geoTri, NODE_ID rootID, const wxString &nodeName, const wxString &materialName, const bool optimize);

		///Parse file
		bool parseFile();

	public:
		///Class constructor
		///\param[in] _inputStream Stream to read data from
		///\param[in] _sceneID Scene ID
		///\param[in] _scenePath Path to scene resources (can be an archive filename)
		///\param[in] _module Parent module with messaging interface
		MTLParser(wxInputStream * _inputStream, SCENE_ID _sceneID, const wxString _scenePath, Module * _module);
		///Class destructor
		~MTLParser();

		///Parse OBJ stream and build scene graph
		///\param[in] rootID ID of node that will be root of imported scene
		///\return \c true if successful
		bool Parse(const NODE_ID &rootID);
	};
}

#endif
