Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/graphics/importer/static_model_data.h @ 9830

Last change on this file since 9830 was 9830, checked in by bensch, 18 years ago

orxonox/new_class_id: Static Model splitted up into Data and Logic part

File size: 5.9 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/// SUB-ELEMENTS ///
31////////////////////
32//! This is the placeholder of one Vertex beloning to a Face.
33class ModelFaceElement
34{
35public:
36  ModelFaceElement();
37  ~ModelFaceElement();
38
39  int                 vertexNumber;         //!< The number of the Vertex out of the Array* vertices, this vertex points to.
40  int                 normalNumber;         //!< The number of the Normal out of the Array* normals, this vertex points to.
41  int                 texCoordNumber;       //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
42
43  ModelFaceElement*   next;                 //!< Point to the next FaceElement in this List.
44};
45
46//! This is the placeholder of a Face belonging to a Group of Faces.
47class ModelFace
48{
49public:
50  ModelFace();
51  ~ModelFace();
52
53  unsigned int        vertexCount;     //!< The Count of vertices this Face has.
54  ModelFaceElement*   firstElem;       //!< Points to the first Vertex (FaceElement) of this Face.
55  Material*           material;        //!< The Material to use.
56
57  ModelFace*          next;            //!< Pointer to the next Face.
58};
59
60//! Group to handle multiple Models per obj-file.
61class ModelGroup
62{
63public:
64  ModelGroup();
65  ~ModelGroup();
66
67  void cleanup();
68
69  std::string  name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function.
70  GLubyte*     indices;        //!< The indices of the Groups. Needed for vertex-arrays
71  GLuint       listNumber;     //!< The number of the GL-List this Group gets.
72  ModelFace*   firstFace;      //!< The first Face in this group.
73  ModelFace*   currentFace;    //!< The current Face in this Group (the one we are currently working with.)
74  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...
75  int          faceCount;      //!< The Number of Faces this Group holds.
76
77  ModelGroup*  next;           //!< Pointer to the next Group.
78};
79
80struct ModelMaterial
81{
82  Material* material;
83  bool external;
84};
85
86/////////////
87/// MODEL ///
88/////////////
89//! Class that handles static 3D-Models.
90/**
91 * it can also read them in and display them.
92 * All the objects are rendered with glLists
93 */
94class StaticModelData : public BaseObject
95{
96  ObjectListDeclaration(StaticModelData);
97  public:
98    typedef CountPointer<StaticModelData> Pointer;
99
100  public:
101  StaticModelData(const std::string& modelName = "");
102  virtual ~StaticModelData();
103
104  void draw() const;
105  void draw(int groupNumber) const;
106  void draw(const std::string& groupName) const;
107
108  void rebuild();
109
110  Material* addMaterial(Material* material);
111  Material* addMaterial(const std::string& materialName);
112
113  bool addGroup(const std::string& groupString);
114
115  void setScaleFactor(float scaleFactor) { this->scaleFactor = scaleFactor; };
116
117  bool addVertex(const std::string& vertexString);
118  bool addVertex(float x, float y, float z);
119
120  bool addFace(const std::string& faceString);
121  bool addFace(int faceElemCount, VERTEX_FORMAT type, va_list args);
122
123  bool addVertexNormal(const std::string& normalString);
124  bool addVertexNormal(float x, float y, float z);
125
126  bool addVertexTexture(const std::string& vTextureString);
127  bool addVertexTexture(float u, float v);
128
129  bool setMaterial(const std::string& mtlString);
130  bool setMaterial(Material* mtl);
131
132  void finalize();
133
134
135  const std::vector<GLfloat>& getVertices() const { return this->vertices; };
136  const std::vector<GLfloat>& getNormals() const { return this->normals; };
137  const std::vector<GLfloat>& getTexCoords() const { return this->vTexture; };
138  const std::vector<sTriangleExt>& getTriangles() const { return this->triangles; };
139  ///! HACK SOLUTION sTriangleExt should be const in the modelInfo.
140  sTriangleExt* getTrianglesExt() { return &this->triangles[0]; };
141
142  float getScaleFactor() const  { return scaleFactor; }
143
144protected:
145  Material* findMaterialByName(const std::string& materialName);
146
147private:
148  bool buildVertexNormals();
149
150  bool importToDisplayList();
151  bool buildTriangleList();
152
153  bool addGLElement(ModelFaceElement* elem);
154
155  bool cleanup();
156
157private:
158  bool                       finalized;       //!< Sets the Object to be finalized.
159
160  float                      scaleFactor;     //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation
161
162  unsigned int               faceCount;       //!< A modelwide Counter for the faces
163
164  std::vector<GLfloat>       vertices;        //!< The Array that handles the Vertices.
165  std::vector<GLfloat>       normals;         //!< The Array that handles the Normals.
166  std::vector<GLfloat>       vTexture;        //!< The Array that handles the VertexTextureCoordinates.
167
168  std::vector<sTriangleExt>  triangles;       //!< The Triangles if built.
169
170  ModelGroup*                firstGroup;      //!< The first of all groups.
171  ModelGroup*                currentGroup;    //!< The currentGroup. this is the one we will work with.
172  int                        groupCount;      //!< The Count of Groups.
173
174  std::list<ModelMaterial*>  materialList;    //!< A list for all the Materials in this Model
175};
176
177#endif /* _STATIC_MODEL_DATA_H */
Note: See TracBrowser for help on using the repository browser.