Blame view

stim/visualization/obj/obj_material.h 1.76 KB
5db14a38   David Mayerich   added materials t...
1
2
3
4
  #ifndef OBJ_MATERIAL_H
  #define OBJ_MATERIAL_H
  
  #include <sstream>
5a58238a   David Mayerich   fixed linux compa...
5
  #include <cstring>
5db14a38   David Mayerich   added materials t...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  
  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
5a58238a   David Mayerich   fixed linux compa...
29
30
31
  		std::memset(ka, 0, sizeof(T) * 3);
  		std::memset(kd, 0, sizeof(T) * 3);
  		std::memset(ks, 0, sizeof(T) * 3);
5db14a38   David Mayerich   added materials t...
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  		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