Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: prepare for VertexArrays

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