Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/static_model_data.h

Last change on this file was 10161, checked in by patrick, 17 years ago

fixed the compile bug

File size: 5.3 KB
RevLine 
[2823]1/*!
[6021]2 * @file static_model.h
3 * @brief Contains the Model Class that handles Static 3D-Models rendered with glList's
4 */
[2823]5
[9830]6#ifndef _STATIC_MODEL_DATA_H
7#define _STATIC_MODEL_DATA_H
[2773]8
[6021]9#include "model.h"
[5701]10
[2776]11#include "material.h"
[6423]12#include <vector>
[9830]13#include "count_pointer.h"
[2748]14
[9830]15
[3657]16// definition of different modes for setting up Faces
17#define VERTEX 0       //!< If Faces are created WITH Vertex-Coordinate
18#define NORMAL 1       //!< If Faces are created WITH Normals (otherwise autocalculate)
19#define TEXCOORD 2     //!< If Faces are created WITH TextureCoordinate
[4468]20
[3894]21//! an enumerator for VERTEX_FORMAT
[4830]22typedef enum VERTEX_FORMAT {
23  VERTEX_ONLY = VERTEX,
24  VERTEX_NORMAL = NORMAL,
25  VERTEX_TEXCOORD = TEXCOORD,
26  VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD
27};
[2842]28
[3063]29
[4468]30
[4022]31/////////////
32/// MODEL ///
33/////////////
[6021]34//! Class that handles static 3D-Models.
35/**
36 * it can also read them in and display them.
37 * All the objects are rendered with glLists
38 */
[9829]39class StaticModelData : public BaseObject
[4022]40{
[9829]41  ObjectListDeclaration(StaticModelData);
[10141]42
[10161]43public:
[10141]44  ////////////////////
45  /// SUB-ELEMENTS ///
46  ////////////////////
47  //! This is the placeholder of one Vertex beloning to a Face.
48  class FaceElement
49  {
[9684]50  public:
[10141]51    FaceElement();
[9830]52
[10141]53    int                 vertexNumber;         //!< The number of the Vertex out of the Array* vertices, this vertex points to.
54    int                 normalNumber;         //!< The number of the Normal out of the Array* normals, this vertex points to.
55    int                 texCoordNumber;       //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
56  };
57
58  //! This is the placeholder of a Face belonging to a Group of Faces.
59  class Face
60  {
[9830]61  public:
[10141]62    Face();
63
64    std::vector<FaceElement>  _elements; //!< Elements of the Face.
65    Material*                 _material;        //!< The Material to use.
66  };
67
68  //! Group to handle multiple Models per obj-file.
69  class Group
70  {
71  public:
72    Group();
73    ~Group();
74
75    //! Compares the name with the groups name.
76    bool operator==(const std::string& name) const { return this->name == name; };
77    void cleanup();
78
79    std::string  name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function.
80    GLubyte*     indices;        //!< The indices of the Groups. Needed for vertex-arrays
81    GLuint       listNumber;     //!< The number of the GL-List this Group gets.
82    int          faceMode;       //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material,  3 for triangle, 4 for Quad, 5+ for Poly @todo ENUM...
83
84    std::vector<Face> _faces;    //!< Faces.
85  };
86
87  public:
88  typedef CountPointer<StaticModelData> Pointer;
89
90public:
[9829]91  StaticModelData(const std::string& modelName = "");
92  virtual ~StaticModelData();
[3910]93
[9830]94  void draw() const;
[10141]95  void draw(unsigned int groupNumber) const;
[7221]96  void draw(const std::string& groupName) const;
[3910]97
[5790]98  void rebuild();
99
[10141]100  Material* addMaterial(const Material& material);
[7221]101  Material* addMaterial(const std::string& materialName);
[3913]102
[7221]103  bool addGroup(const std::string& groupString);
[6031]104
[9830]105  void setScaleFactor(float scaleFactor) { this->scaleFactor = scaleFactor; };
106
[7221]107  bool addVertex(const std::string& vertexString);
[3894]108  bool addVertex(float x, float y, float z);
[6031]109
[7221]110  bool addFace(const std::string& faceString);
[9830]111  bool addFace(int faceElemCount, VERTEX_FORMAT type, va_list args);
[6031]112
[7221]113  bool addVertexNormal(const std::string& normalString);
[3894]114  bool addVertexNormal(float x, float y, float z);
[6031]115
[7221]116  bool addVertexTexture(const std::string& vTextureString);
[3894]117  bool addVertexTexture(float u, float v);
[6031]118
[7221]119  bool setMaterial(const std::string& mtlString);
[3913]120  bool setMaterial(Material* mtl);
[6031]121
[4746]122  void finalize();
[4106]123
[4468]124
[9830]125  const std::vector<GLfloat>& getVertices() const { return this->vertices; };
126  const std::vector<GLfloat>& getNormals() const { return this->normals; };
127  const std::vector<GLfloat>& getTexCoords() const { return this->vTexture; };
128  const std::vector<sTriangleExt>& getTriangles() const { return this->triangles; };
129  ///! HACK SOLUTION sTriangleExt should be const in the modelInfo.
130  sTriangleExt* getTrianglesExt() { return &this->triangles[0]; };
[10147]131  const std::vector<Group>& getGroups() { return this->_modelGroups; }
[4468]132
[9830]133  float getScaleFactor() const  { return scaleFactor; }
134
135protected:
[7221]136  Material* findMaterialByName(const std::string& materialName);
[4468]137
[9830]138private:
[4746]139  bool buildVertexNormals();
[4468]140
[4746]141  bool importToDisplayList();
[4791]142  bool buildTriangleList();
[6031]143
[10141]144  bool addGLElement(const StaticModelData::FaceElement& elem);
[4468]145
[4746]146  bool cleanup();
[4468]147
[9830]148private:
[5774]149  bool                       finalized;       //!< Sets the Object to be finalized.
[4468]150
[9830]151  float                      scaleFactor;     //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation
152
[5774]153  unsigned int               faceCount;       //!< A modelwide Counter for the faces
[4468]154
[6423]155  std::vector<GLfloat>       vertices;        //!< The Array that handles the Vertices.
156  std::vector<GLfloat>       normals;         //!< The Array that handles the Normals.
157  std::vector<GLfloat>       vTexture;        //!< The Array that handles the VertexTextureCoordinates.
[6031]158
[9829]159  std::vector<sTriangleExt>  triangles;       //!< The Triangles if built.
160
[4468]161
[10141]162  std::vector<Group>         _modelGroups;
163
164  std::list<Material>        materialList;    //!< A list for all the Materials in this Model
[2748]165};
[2773]166
[9830]167#endif /* _STATIC_MODEL_DATA_H */
Note: See TracBrowser for help on using the repository browser.