Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/importer/model.h @ 4588

Last change on this file since 4588 was 4579, checked in by bensch, 19 years ago

orxonox/trunk: array is now also a template

File size: 7.1 KB
Line 
1/*!
2  \file model.h
3  \brief Contains the Model Class that handles 3D-Models
4*/
5
6#ifndef _MODEL_H
7#define _MODEL_H
8
9#include "base_object.h"
10#include "material.h"
11#include "glincl.h"
12#include "array.h"
13
14
15// FORWARD DEFINITION //
16class Vector;
17template<class T> class Array;
18template<class T> class tList;
19
20//! an enumerator fot the different Model Types.
21/**
22   MODEL_DISPLAY_LIST means, that a DisplayList will be built out of the model. This model will be STATIC, meaning it cannot be changed after initialisation.
23   MODEL_VERTEX_ARRAY means, that a VertexArray will be built out of the model. This moel will be DYNAMIX, meaning that one can change the properties from outside of the model.
24 * \todo implement this stuff
25*/
26typedef enum MODEL_TYPE {MODEL_DISPLAY_LIST,
27                         MODEL_VERTEX_ARRAY};
28
29
30// definition of different modes for setting up Faces
31#define VERTEX 0       //!< If Faces are created WITH Vertex-Coordinate
32#define NORMAL 1       //!< If Faces are created WITH Normals (otherwise autocalculate)
33#define TEXCOORD 2     //!< If Faces are created WITH TextureCoordinate
34
35//! an enumerator for VERTEX_FORMAT
36typedef enum VERTEX_FORMAT { VERTEX_ONLY = VERTEX,
37                             VERTEX_NORMAL = NORMAL,
38                             VERTEX_TEXCOORD = TEXCOORD,
39                             VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD };
40
41////////////////////
42/// SUB-ELEMENTS ///
43////////////////////
44//! This is the placeholder of one Vertex beloning to a Face.
45class ModelFaceElement
46{
47 public:
48  ModelFaceElement();
49  ~ModelFaceElement();
50
51  int                 vertexNumber;         //!< The number of the Vertex out of the Array* vertices, this vertex points to.
52  int                 normalNumber;         //!< The number of the Normal out of the Array* normals, this vertex points to.
53  int                 texCoordNumber;       //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
54
55  ModelFaceElement*   next;                 //!< Point to the next FaceElement in this List.
56};
57
58//! This is the placeholder of a Face belonging to a Group of Faces.
59class ModelFace
60{
61 public:
62  ModelFace();
63  ~ModelFace();
64
65  unsigned int        vertexCount;     //!< The Count of vertices this Face has.
66  ModelFaceElement*   firstElem;       //!< Points to the first Vertex (FaceElement) of this Face.
67  Material*           material;        //!< The Material to use.
68
69  ModelFace*          next;            //!< Pointer to the next Face.
70};
71
72//! Group to handle multiple Models per obj-file.
73class ModelGroup
74{
75 public:
76  ModelGroup();
77  ~ModelGroup();
78
79  void cleanup();
80
81  char*        name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
82  GLubyte*     indices;        //!< The indices of the Groups. Needed for vertex-arrays
83  GLuint       listNumber;     //!< The number of the GL-List this Group gets.
84  ModelFace*   firstFace;      //!< The first Face in this group.
85  ModelFace*   currentFace;    //!< The current Face in this Group (the one we are currently working with.)
86  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...
87  int          faceCount;      //!< The Number of Faces this Group holds.
88
89  ModelGroup*  next;           //!< Pointer to the next Group.
90};
91
92/////////////
93/// MODEL ///
94/////////////
95
96//! Class that handles 3D-Models. it can also read them in and display them.
97class Model : public BaseObject
98{
99 public:
100  Model(const char* modelName = NULL, MODEL_TYPE type = MODEL_DISPLAY_LIST);
101  virtual ~Model(void);
102
103  void draw(void) const;
104  void draw(int groupNumber) const;
105  void draw(char* groupName) const;
106
107  /** \returns Count of the Models (Groups) in this File */
108  inline int getGroupCount(void) const { return this->groupCount; };
109
110  /** \returns a Pointer to the Vertex-Array, if it was deleted it returns NULL */
111  inline const GLfloat* getVertexArray(void) const { return this->vertices->getArray(); };
112  /** \returns the VertexCount of this Model */
113  inline unsigned int getVertexArrayCount(void) const { return this->vertexCount; };
114
115  /** \returns a Pointer to the Normals-Array, if it was deleted it returns NULL */
116  inline const GLfloat* getNormalsArray(void) const { return this->normals->getArray(); };
117  /** \returns the NormalsCount of this Model */
118  inline unsigned int getNormalsArrayCount(void) const { return this->normalCount; };
119
120  /** \returns a Pointer to the TexCoord-Array, if it was deleted it returns NULL */
121  inline const GLfloat* getTexCoordArray(void) const { return this->vTexture->getArray(); };
122  /** \returns the TexCoord-Count of this Model */
123  inline unsigned int getTexCoordArrayCount(void) const { return this->texCoordCount; };
124
125
126  Material* addMaterial(Material* material);
127  Material* addMaterial(const char* materialName);
128
129  bool addGroup(const char* groupString);
130  bool addVertex(const char* vertexString);
131  bool addVertex(float x, float y, float z);
132  bool addFace(const char* faceString);
133  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
134  bool addVertexNormal(const char* normalString);
135  bool addVertexNormal(float x, float y, float z);
136  bool addVertexTexture(const char* vTextureString);
137  bool addVertexTexture(float u, float v);
138  bool setMaterial(const char* mtlString);
139  bool setMaterial(Material* mtl);
140  void finalize(void);
141
142  /** \returns The number of Vertices of the Model */
143  inline int getVertexCount(void) const {return this->vertexCount;}
144  /** \returns The number of Normals of the Model */
145  inline int getNormalCount(void) const {return this->normalCount;}
146  /** \returns The number of Texture Coordinates of the Model*/
147  inline int getTexCoordCount(void) const {return this->texCoordCount;}
148
149 protected:
150  void cubeModel(void);
151
152  Material* findMaterialByName(const char* materialName);
153
154
155 protected:
156  float            scaleFactor;     //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation
157
158 private:
159  bool buildVertexNormals(void);
160
161  bool importToDisplayList(void);
162  bool addGLElement(ModelFaceElement* elem);
163
164  bool importToVertexArray(void);
165
166  bool deleteArrays(void);
167  bool cleanup(void);
168
169 private:
170  MODEL_TYPE       type;            //!< A type for the Model
171  bool             finalized;       //!< Sets the Object to be finalized.
172
173  unsigned int     vertexCount;     //!< A modelwide Counter for vertices.
174  unsigned int     normalCount;     //!< A modelwide Counter for the normals.
175  unsigned int     texCoordCount;   //!< A modelwide Counter for the texCoord.
176  Array<GLfloat>*  vertices;        //!< The Array that handles the Vertices.
177  Array<GLfloat>*  normals;         //!< The Array that handles the Normals.
178  Array<GLfloat>*  vTexture;        //!< The Array that handles the VertexTextureCoordinates.
179
180  ModelGroup*      firstGroup;      //!< The first of all groups.
181  ModelGroup*      currentGroup;    //!< The currentGroup. this is the one we will work with.
182  int              groupCount;      //!< The Count of Groups.
183
184  tList<Material>* materialList;    //!< A list for all the Materials in this Model
185};
186
187#endif
Note: See TracBrowser for help on using the repository browser.