Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/md2_loader/src/lib/graphics/importer/model.h @ 4157

Last change on this file since 4157 was 4139, checked in by patrick, 19 years ago

orxonox/branches/md2_loader: merged trunk into branche using: svn merge ../trunk/ md2_loader -r 4063:HEAD

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