Subversion Repositories gelsvn

Rev

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

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