Subversion Repositories gelsvn

Rev

Rev 89 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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