Subversion Repositories gelsvn

Rev

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

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