Subversion Repositories gelsvn

Rev

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