Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/importer/object.h @ 3196

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

orxonox/trunk: moved importer into the Trunk, now no merging is needed anymore.

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