Subversion Repositories gelsvn

Rev

Rev 89 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#ifndef __MINI_MESH_H
#define __MINI_MESH_H

#include "IndexedFaceSet.h"
#include "Material.h"
#include "Texmap.h"

namespace Geometry
{


        /** \brief A Triangle Mesh struct. 

            This struct contains three indexed face sets,
                        one for geometry, textures, and normals. It also contains a vector
                        of materials and a vector of texture maps.

                        A number of functions are defined allowing for rendering of the
                        triangle mesh. */
        struct TriMesh 
        {
                // ------- DATA -------

                /// Name of model
                std::string name;
                
                /// Indexed face set for the actual geometry
                IndexedFaceSet geometry;

                /// Indexed face set for the normals
                IndexedFaceSet normals;

                /// Indexed face set for the texture coordinates.
                IndexedFaceSet texcoords;

                /// Material indices for all faces
                std::vector<int> mat_idx;

                /// Texture indices for all faces
                std::vector<int> tex_idx;

                /// Vector of materials
                std::vector<Material> materials;

                /// Vector of texture maps.
                std::vector<Texmap> texmaps;

                // -------- FUNCTIONS -----------

                /// Get an axis aligned bounding box for the model.
                void get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const;

                /// Get a bounding sphere for the model.
                void get_bsphere(CGLA::Vec3f& c, float& r) const;

                /// Returns true if at least one normal has been defined.
                bool has_normals() const 
                {
                        return normals.no_faces()>0;
                }
                
                /// Find a material from its name
                int find_material(const std::string&) const;

                /// Find a texture map from its name
                int find_texmap(const std::string&) const;
                
                /// Compute normals for the mesh. Does not check if there are normals.
                void compute_normals();

                /// Initialize textures
                void gl_init_textures();

                /// Use material corresponding to idx
                void TriMesh::gl_set_material(int idx);
                
                /// Draw the mesh using OpenGL.
                void gl_draw();
        };


}
#endif