Help end child hunger

ResModel Lib Header

Prev: Header Next: Header
/** ----------------------------------------------------------
 * \class VSResModelLib
 * Lighthouse3D
 * VSResModelLib - Very Simple Resource Model Library
 * \version 0.3
 *		Updated the lib to use Assimp 3.0
 * \version 0.2.1
 *		Added the possibility of setting colors per model and per mesh
 * \version 0.2.0
 *		Added cubemap textures
 *		Added the possibility to reuse textures	
 *		Loader gets tangent and bitangent attributes
 * version 0.1.0
 *		Initial Release
 * This lib provides an interface for Assimp to load and render 3D models
 *  and performs simple resource managment 
 * This lib requires the following classes from VSL:
 * (
 * VSResourceLib
 * VSMathLib 
 * VSLogLib
 * VSShaderLib
 * and the following third party libs:
 * GLEW (,
 * Assimp (
 * Full documentation at 

#ifndef __VSResModelLib__
#define __VSResModelLib__

#ifdef _WIN32
#pragma comment(lib,"assimp.lib")

#include <string>
#include <vector>
#include <map>
#include <fstream>

#include <GL/glew.h>

// Assimp include files. These three are usually needed.
//#include <assimp/assimp.hpp>	
//#include <assimp/aiPostProcess.h>
//#include <assimp/aiScene.h>

#include "assimp/Importer.hpp"	//OO version Header!
#include "assimp/PostProcess.h"
#include "assimp/Scene.h"

#include "vsResourceLib.h"

class VSResModelLib : public VSResourceLib{



	virtual void clone(VSResourceLib *res);
	/** implementation of the superclass abstract method
	  * \param filename the model's filename
	virtual bool load(std::string filename);
	/// implementation of the superclass abstract method
	virtual void render();
	/// set a color component for all meshes
	void setColor(VSResourceLib::MaterialSemantics m, float *values);
	/// set a color component for a particular mesh
	void setColor(unsigned int mesh, VSResourceLib::MaterialSemantics m, float *values);


	/// load and set a texture for the object
	virtual void addTexture(unsigned int unit, std::string filename);
	/// load and set a cubemap texture for a object
	virtual void addCubeMapTexture(unsigned int unit, 
									std::string posX, std::string negX, 
									std::string posY, std::string negY, 
									std::string posZ, std::string negZ);
	/// set an existing texture ID for a texture unit
	virtual void setTexture(unsigned int unit, unsigned int textureID,
							GLenum textureType = GL_TEXTURE_2D);


	// A model can be made of many meshes. Each is stored
	// in the following structure
	struct MyMesh{
		GLuint vao;
		GLuint texUnits[MAX_TEXTURES];
		GLuint texTypes[MAX_TEXTURES];
		GLuint uniformBlockIndex;
		float transform[16];
		int numIndices;
		unsigned int type;
		struct Material mat;
		unsigned int *indexes;
		float *positions;
		float *normals;

	struct HalfEdge {
		GLuint vertex;
		struct HalfEdge *next;
		struct HalfEdge *twin;

	/// the mesh collection
	std::vector<struct MyMesh> mMyMeshes;
	/// aux pre processed mesh collection
	std::vector<struct MyMesh> pMyMeshesAux;

	// the global Assimp scene object
	const aiScene* pScene;

	bool pUseAdjacency;


	// images / texture
	// map image filenames to textureIds
	// pointer to texture Array
	std::map<std::string, GLuint> pTextureIdMap;	

	bool loadTextures(const aiScene *scene, std::string prefix);
	void genVAOsAndUniformBuffer(const aiScene *sc);
	void recursive_walk_for_matrices(const aiScene *sc, 
						const aiNode* nd);

	void get_bounding_box_for_node (const struct aiNode* nd, 
						aiVector3D* min, 
						aiVector3D* max);

	void color4_to_float4(const aiColor4D *c, float f[4]);
	void set_float4(float f[4], float a, float b, float c, float d);




Prev: Header Next: Header

Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2014 Suffusion theme by Sayontan Sinha