obj_material.h 1.76 KB
#ifndef OBJ_MATERIAL_H
#define OBJ_MATERIAL_H

#include <sstream>
#include <cstring>

namespace stim {

template<typename T>
struct obj_material {
	std::string name;			//material name
	T ka[3];				//ambient color
	T kd[3];				//diffuse color
	T ks[3];				//specular color
	T ns;					//specular exponent

	int illum;					//illumination model

	std::string tex_ka;			//ambient texture
	std::string tex_kd;			//diffuse texture
	std::string tex_ks;			//specular texture
	std::string tex_ns;			//texture map for the specular exponent
	std::string tex_alpha;		//texture map for the alpha component
	std::string tex_bump;		//bump map
	std::string tex_disp;		//displacement map
	std::string tex_decal;		//stencil decal

	obj_material() {			//constructor
		std::memset(ka, 0, sizeof(T) * 3);
		std::memset(kd, 0, sizeof(T) * 3);
		std::memset(ks, 0, sizeof(T) * 3);
		ns = 10;
		illum = 2;

	}
	std::string str() {
		std::stringstream ss;
		ss << "newmtl " << name << std::endl;
		ss << "Ka " << ka[0] << " " << ka[1] << " " << ka[2] << std::endl;
		ss << "Kd " << kd[0] << " " << kd[1] << " " << kd[2] << std::endl;
		ss << "Ks " << ks[0] << " " << ks[1] << " " << ks[2] << std::endl;
		ss << "Ns " << ns << std::endl;
		ss << "illum " << illum << std::endl;
		if (tex_ka != "") ss << "map_Ka " << tex_ka << std::endl;
		if (tex_kd != "") ss << "map_Kd " << tex_kd << std::endl;
		if (tex_ks != "") ss << "map_Ks " << tex_ks << std::endl;
		if (tex_ns != "") ss << "map_Ns " << tex_ns << std::endl;
		if (tex_alpha != "") ss << "map_d " << tex_alpha << std::endl;
		if (tex_bump != "") ss << "bump " << tex_bump << std::endl;
		if (tex_disp != "") ss << "disp " << tex_disp << std::endl;
		if (tex_decal != "") ss << "decal " << tex_decal << std::endl;
		return ss.str();
	}
};

}				//end namespace stim

#endif