Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: importer: functionality improvement

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