Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10233 was 10161, checked in by patrick, 18 years ago

fixed the compile bug

File size: 5.3 KB
Line 
1/*!
2 * @file static_model.h
3 * @brief Contains the Model Class that handles Static 3D-Models rendered with glList's
4 */
5
6#ifndef _STATIC_MODEL_DATA_H
7#define _STATIC_MODEL_DATA_H
8
9#include "model.h"
10
11#include "material.h"
12#include <vector>
13#include "count_pointer.h"
14
15
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
20
21//! an enumerator for VERTEX_FORMAT
22typedef enum VERTEX_FORMAT {
23  VERTEX_ONLY = VERTEX,
24  VERTEX_NORMAL = NORMAL,
25  VERTEX_TEXCOORD = TEXCOORD,
26  VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD
27};
28
29
30
31/////////////
32/// MODEL ///
33/////////////
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 */
39class StaticModelData : public BaseObject
40{
41  ObjectListDeclaration(StaticModelData);
42
43public:
44  ////////////////////
45  /// SUB-ELEMENTS ///
46  ////////////////////
47  //! This is the placeholder of one Vertex beloning to a Face.
48  class FaceElement
49  {
50  public:
51    FaceElement();
52
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  {
61  public:
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:
91  StaticModelData(const std::string& modelName = "");
92  virtual ~StaticModelData();
93
94  void draw() const;
95  void draw(unsigned int groupNumber) const;
96  void draw(const std::string& groupName) const;
97
98  void rebuild();
99
100  Material* addMaterial(const Material& material);
101  Material* addMaterial(const std::string& materialName);
102
103  bool addGroup(const std::string& groupString);
104
105  void setScaleFactor(float scaleFactor) { this->scaleFactor = scaleFactor; };
106
107  bool addVertex(const std::string& vertexString);
108  bool addVertex(float x, float y, float z);
109
110  bool addFace(const std::string& faceString);
111  bool addFace(int faceElemCount, VERTEX_FORMAT type, va_list args);
112
113  bool addVertexNormal(const std::string& normalString);
114  bool addVertexNormal(float x, float y, float z);
115
116  bool addVertexTexture(const std::string& vTextureString);
117  bool addVertexTexture(float u, float v);
118
119  bool setMaterial(const std::string& mtlString);
120  bool setMaterial(Material* mtl);
121
122  void finalize();
123
124
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]; };
131  const std::vector<Group>& getGroups() { return this->_modelGroups; }
132
133  float getScaleFactor() const  { return scaleFactor; }
134
135protected:
136  Material* findMaterialByName(const std::string& materialName);
137
138private:
139  bool buildVertexNormals();
140
141  bool importToDisplayList();
142  bool buildTriangleList();
143
144  bool addGLElement(const StaticModelData::FaceElement& elem);
145
146  bool cleanup();
147
148private:
149  bool                       finalized;       //!< Sets the Object to be finalized.
150
151  float                      scaleFactor;     //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation
152
153  unsigned int               faceCount;       //!< A modelwide Counter for the faces
154
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.
158
159  std::vector<sTriangleExt>  triangles;       //!< The Triangles if built.
160
161
162  std::vector<Group>         _modelGroups;
163
164  std::list<Material>        materialList;    //!< A list for all the Materials in this Model
165};
166
167#endif /* _STATIC_MODEL_DATA_H */
Note: See TracBrowser for help on using the repository browser.