Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/importer/model.h @ 3395

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

orxonox/trunk: adapted PRINTF/PRINT/COUT, now they should behave properly.

File size: 4.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 "../stdincl.h"
10
11#include "array.h"
12#include "material.h"
13#include "vector.h"
14
15using namespace std;
16
17
18
19//! Class that handles 3D-Models. it can also read them in and display them.
20class Model
21{
22 public:
23  Model ();
24  Model (char* fileName);
25  Model(char* fileName, float scaling);
26  ~Model ();
27 
28  void draw (void) const;
29  void draw (int groupNumber) const;
30  void draw (char* groupName) const;
31  int getGroupCount() const;
32
33 private:
34  //! This is the placeholder of one Vertex beloning to a Face.
35  struct FaceElement
36  {
37    int vertexNumber;    //!< The number of the Vertex out of the Array* vertices, this vertex points to.
38    int normalNumber;    //!< The number of the Normal out of the Array* normals, this vertex points to.
39    int texCoordNumber;  //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
40    FaceElement* next;   //!< Point to the next FaceElement in this List.
41  };
42
43  //! This is the placeholder of a Face belonging to a Group of Faces.
44  /**
45     \todo take Material to a call for itself.
46
47     This can also be a Material-Change switch.
48     That means if you want to change a Material inside of a group,
49     you can create an empty face and apply a material to it, and the Importer will cahnge Colors
50  */
51  struct Face
52  {
53    int vertexCount;        //!< The Count of vertices this Face has.
54    FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face.
55
56    char* materialString;   //!< The Name of the Material to which to Change.
57
58    Face* next;             //!< Pointer to the next Face.
59  }; 
60
61  //! Group to handle multiple Models per obj-file.
62  struct Group
63  {
64    char* name;         //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
65
66    GLuint listNumber;  //!< The number of the GL-List this Group gets.
67    Face* firstFace;    //!< The first Face in this group.
68    Face* currentFace;  //!< The current Face in this Group (the one we are currently working with.)
69    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...
70    int faceCount;      //!< The Number of Faces this Group holds.
71
72    Group* next;        //!< Pointer to the next Group.
73  };
74
75
76  Array* vertices;      //!< The Array that handles the Vertices.
77  int verticesCount;    //!< A global Counter for vertices.
78  Array* normals;       //!< The Array that handles the Normals.
79  Array* vTexture;      //!< The Array that handles the VertexTextureCoordinates.
80
81 
82  Group* firstGroup;    //!< The first of all groups.
83  Group* currentGroup;  //!< The currentGroup. this is the one we will work with.
84  int groupCount;       //!< The Count of Groups.
85
86  Material* material;   //!< Initial pointer to the Material. This can hold many materials, because Material can be added with Material::addMaterial(..)
87  float scaleFactor;    //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation
88
89  char* objPath;        //!< The Path where the obj and mtl-file are located.
90  char* objFileName;    //!< The Name of the obj-file.
91  char* mtlFileName;    //!< The Name of the mtl-file (parsed out of the obj-file)
92
93  bool initialize (void);
94  bool initGroup(Group* group);
95  bool initFace (Face* face);
96  bool cleanup(void);
97  bool cleanupGroup(Group* group);
98  bool cleanupFace(Face* face);
99  bool cleanupFaceElement(FaceElement* faceElem);
100
101  ///// readin ///
102  bool importFile (char* fileName);
103  bool readFromObjFile (void);
104 
105  bool readGroup (char* groupString);
106  bool readVertex (char* vertexString);
107  bool readFace (char* faceString);
108  bool readVertexNormal (char* normalString);
109  bool readVertexTexture (char* vTextureString);
110  bool readMtlLib (char* matFile);
111  bool readUseMtl (char* mtlString);
112
113  bool importToGL (void);
114  bool addGLElement (FaceElement* elem);
115
116  bool buildVertexNormals ();
117
118  void BoxModel (void);
119};
120
121#endif
Note: See TracBrowser for help on using the repository browser.