Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4808 was 4806, checked in by patrick, 19 years ago

orxonox/trunk: the important interface functions are now implemented directly in abstract model.

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