Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: material is now only dependent on tList<Material>* in model

File size: 4.5 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  tList<Material>* materialList;
97
98 protected:
99  float scaleFactor;    //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation
100
101  Material* findMaterialByName(const char* materialName);
102
103  void cubeModel(void);
104
105 public:
106  Model(const char* modelName = NULL);
107  virtual ~Model(void);
108
109  void setName(const char* name);
110  inline const char* getName() {return this->name;}
111 
112  void draw(void) const;
113  void draw(int groupNumber) const;
114  void draw(char* groupName) const;
115  int getGroupCount() const;
116
117  Material* addMaterial(Material* material);
118  Material* addMaterial(const char* materialName);
119
120  bool addGroup(const char* groupString);
121  bool addVertex(const char* vertexString);
122  bool addVertex(float x, float y, float z);
123  bool addFace(const char* faceString);
124  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
125  bool addVertexNormal(const char* normalString);
126  bool addVertexNormal(float x, float y, float z);
127  bool addVertexTexture(const char* vTextureString);
128  bool addVertexTexture(float u, float v);
129  bool setMaterial(const char* mtlString);
130  bool setMaterial(Material* mtl);
131  void finalize(void);
132};
133
134#endif
Note: See TracBrowser for help on using the repository browser.