// Obj - obj-format objects
//
// Copyright (C) 2015 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vamos is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vamos. If not, see <http://www.gnu.org/licenses/>.
#ifndef _MODEL_H_
#define _MODEL_H_
#include "../geometry/Three_Vector.h"
#include <GL/gl.h>
#include <assimp/scene.h>
#include <assimp/Importer.hpp>
#include <boost/filesystem.hpp>
#include <exception>
#include <string>
#include <map>
namespace fs = boost::filesystem;
class aiMaterial;
class aiNode;
namespace Vamos_Media
{
class Model_Exception : public std::exception
{
public:
Model_Exception (std::string message) : m_message (message) {};
virtual ~Model_Exception () throw () {};
virtual const char* what () const throw () { return m_message.c_str (); }
private:
std::string m_message;
};
class Model_Cant_Convert_Image : Model_Exception
{
public:
Model_Cant_Convert_Image (std::string path)
: Model_Exception ("Can't convert image in file '" + path + "'")
{}
};
class Model_Cant_Load_Image : Model_Exception
{
public:
Model_Cant_Load_Image (std::string path)
: Model_Exception ("Can't load image from file '" + path + "'")
{}
};
class Model
{
public:
Model (const std::string& file,
double scale,
const Vamos_Geometry::Three_Vector& translation,
const Vamos_Geometry::Three_Vector& rotation,
bool two_sided = false);
~Model ();
/// Render the object in a display list.
/// @return the display list.
GLuint build ();
private:
boost::filesystem::path m_file;
void load_textures ();
void render (const aiNode* nd);
void apply_material (const aiMaterial& material);
Assimp::Importer m_importer;
const aiScene* mp_object;
GLuint* mp_texture_ids;
std::map <std::string, GLuint*> m_texture_id_map;
double m_scale;
Vamos_Geometry::Three_Vector m_translation;
Vamos_Geometry::Three_Vector m_rotation;
bool m_two_sided;
};
}
#endif // not _MODEL_H_