Subversion Repositories gelsvn

Rev

Rev 89 | Rev 178 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 89 Rev 136
1
#ifndef __MINI_MESH_H
1
#ifndef __MINI_MESH_H
2
#define __MINI_MESH_H
2
#define __MINI_MESH_H
3
 
3
 
4
#include "IndexedFaceSet.h"
4
#include "IndexedFaceSet.h"
5
#include "Material.h"
5
#include "Material.h"
6
#include "Texmap.h"
6
#include "Texmap.h"
7
 
7
 
8
namespace Geometry
8
namespace Geometry
9
{
9
{
10
 
10
 
11
 
11
 
12
	/** \brief A Triangle Mesh struct. 
12
	/** \brief A Triangle Mesh struct. 
13
 
13
 
14
	    This struct contains three indexed face sets,
14
	    This struct contains three indexed face sets,
15
			one for geometry, textures, and normals. It also contains a vector
15
			one for geometry, textures, and normals. It also contains a vector
16
			of materials and a vector of texture maps.
16
			of materials and a vector of texture maps.
17
 
17
 
18
			A number of functions are defined allowing for rendering of the
18
			A number of functions are defined allowing for rendering of the
19
			triangle mesh. */
19
			triangle mesh. */
20
	struct TriMesh 
20
	struct TriMesh 
21
	{
21
	{
22
		// ------- DATA -------
22
		// ------- DATA -------
23
 
23
 
24
		/// Name of model
24
		/// Name of model
25
		std::string name;
25
		std::string name;
26
		
26
		
27
		/// Indexed face set for the actual geometry
27
		/// Indexed face set for the actual geometry
28
		IndexedFaceSet geometry;
28
		IndexedFaceSet geometry;
29
 
29
 
30
		/// Indexed face set for the normals
30
		/// Indexed face set for the normals
31
		IndexedFaceSet normals;
31
		IndexedFaceSet normals;
32
 
32
 
33
		/// Indexed face set for the texture coordinates.
33
		/// Indexed face set for the texture coordinates.
34
		IndexedFaceSet texcoords;
34
		IndexedFaceSet texcoords;
35
 
35
 
36
		/// Material indices for all faces
36
		/// Material indices for all faces
37
		std::vector<int> mat_idx;
37
		std::vector<int> mat_idx;
38
 
38
 
39
		/// Texture indices for all faces
39
		/// Texture indices for all faces
40
		std::vector<int> tex_idx;
40
		std::vector<int> tex_idx;
41
 
41
 
42
		/// Vector of materials
42
		/// Vector of materials
43
		std::vector<Material> materials;
43
		std::vector<Material> materials;
44
 
44
 
45
		/// Vector of texture maps.
45
		/// Vector of texture maps.
46
		std::vector<Texmap> texmaps;
46
		std::vector<Texmap> texmaps;
47
 
47
 
48
		// -------- FUNCTIONS -----------
48
		// -------- FUNCTIONS -----------
49
 
49
 
50
		/// Get an axis aligned bounding box for the model.
50
		/// Get an axis aligned bounding box for the model.
51
		void get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const;
51
		void get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const;
52
 
52
 
53
		/// Get a bounding sphere for the model.
53
		/// Get a bounding sphere for the model.
54
		void get_bsphere(CGLA::Vec3f& c, float& r) const;
54
		void get_bsphere(CGLA::Vec3f& c, float& r) const;
55
 
55
 
56
		/// Returns true if at least one normal has been defined.
56
		/// Returns true if at least one normal has been defined.
57
		bool has_normals() const 
57
		bool has_normals() const 
58
		{
58
		{
59
			return normals.no_faces()>0;
59
			return normals.no_faces()>0;
60
		}
60
		}
61
		
61
		
62
		/// Find a material from its name
62
		/// Find a material from its name
63
		int find_material(const std::string&) const;
63
		int find_material(const std::string&) const;
64
 
64
 
65
		/// Find a texture map from its name
65
		/// Find a texture map from its name
66
		int find_texmap(const std::string&) const;
66
		int find_texmap(const std::string&) const;
67
		
67
		
68
		/// Compute normals for the mesh. Does not check if there are normals.
68
		/// Compute normals for the mesh. Does not check if there are normals.
69
		void compute_normals();
69
		void compute_normals();
70
 
70
 
71
		/// Initialize textures
71
		/// Initialize textures
72
		void gl_init_textures();
72
		void gl_init_textures();
73
 
73
 
74
		/// Use material corresponding to idx
74
		/// Use material corresponding to idx
75
		void TriMesh::gl_set_material(int idx);
75
		void TriMesh::gl_set_material(size_t idx);
76
		
76
		
77
		/// Draw the mesh using OpenGL.
77
		/// Draw the mesh using OpenGL.
78
		void gl_draw();
78
		void gl_draw();
79
	};
79
	};
80
 
80
 
81
 
81
 
82
}
82
}
83
#endif
83
#endif
84
 
84