Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Made the Model-class externalizable
meaning:

  1. There is now a possibility to initialize a Model without adding default vertex info
  2. Then you can add your vertices
  3. Then you can add any other model-specific stuff, like normals/texcoords/Faces
  4. For the time-being Materials have to be handled externaly, but this will change.

PATRICK: if you read this, you should be able, to implement this into the loading-screen, look at src/importer/framework.cc→main and then the big table.

with this aproach the Developer is farther away from OpenGL and closer to logic.

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