Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: minor

File size: 5.1 KB
RevLine 
[2823]1/*!
[3360]2  \file model.h
3  \brief Contains the Model Class that handles 3D-Models
[2823]4*/
5
[3360]6#ifndef _MODEL_H
7#define _MODEL_H
[2773]8
[2776]9#include "material.h"
[3917]10#include "glincl.h"
[2748]11
[3427]12// FORWARD DEFINITION //
13class Array;
14class Vector;
[3910]15template<class T> class tList;
[3427]16
[3916]17//! an enumerator fot the different Model Types.
18/**
19   MODEL_DISPLAY_LIST means, that a DisplayList will be built out of the model. This model will be STATIC, meaning it cannot be changed after initialisation.
20   MODEL_VERTEX_ARRAY means, that a VertexArray will be built out of the model. This moel will be DYNAMIX, meaning that one can change the properties from outside of the model.
21*/
22typedef enum MODEL_TYPE {MODEL_DISPLAY_LIST,
23                         MODEL_VERTEX_ARRAY};
[3910]24
25
[3657]26// definition of different modes for setting up Faces
27#define VERTEX 0       //!< If Faces are created WITH Vertex-Coordinate
28#define NORMAL 1       //!< If Faces are created WITH Normals (otherwise autocalculate)
29#define TEXCOORD 2     //!< If Faces are created WITH TextureCoordinate
[3894]30//! an enumerator for VERTEX_FORMAT
[3916]31typedef enum VERTEX_FORMAT {VERTEX_ONLY = VERTEX,
[3894]32                    VERTEX_NORMAL = NORMAL,
33                    VERTEX_TEXCOORD = TEXCOORD,
[3895]34                    VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD};
[2842]35
[3360]36//! Class that handles 3D-Models. it can also read them in and display them.
37class Model
[2748]38{
[3910]39 private:
40  /////////////
41  // structs //
42  /////////////
[3186]43  //! This is the placeholder of one Vertex beloning to a Face.
[3396]44  struct FaceElement
[3063]45  {
[3186]46    int vertexNumber;    //!< The number of the Vertex out of the Array* vertices, this vertex points to.
47    int normalNumber;    //!< The number of the Normal out of the Array* normals, this vertex points to.
48    int texCoordNumber;  //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
49    FaceElement* next;   //!< Point to the next FaceElement in this List.
[3063]50  };
51
[3186]52  //! This is the placeholder of a Face belonging to a Group of Faces.
[3418]53  struct Face
[3063]54  {
[3186]55    int vertexCount;        //!< The Count of vertices this Face has.
56    FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face.
[3063]57
[3801]58    Material* material;     //!< The Material to use.
[3063]59
[3186]60    Face* next;             //!< Pointer to the next Face.
61  }; 
[3063]62
[3360]63  //! Group to handle multiple Models per obj-file.
[2850]64  struct Group
65  {
[3186]66    char* name;         //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
[2850]67
[3917]68    GLubyte* indices;   //!< The indices of the Groups. Needed for vertex-arrays
69    GLuint listNumber;  //!< The number of the GL-List this Group gets.
[3186]70    Face* firstFace;    //!< The first Face in this group.
71    Face* currentFace;  //!< The current Face in this Group (the one we are currently working with.)
72    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...
73    int faceCount;      //!< The Number of Faces this Group holds.
[2850]74
[3186]75    Group* next;        //!< Pointer to the next Group.
[3063]76  };
[2850]77
[3910]78  char* name;            //!< This is the name of the Model.
[3916]79  MODEL_TYPE type;
[3910]80  bool finalized;        //!< Sets the Object to be finalized.
[3063]81
[3186]82  Array* vertices;      //!< The Array that handles the Vertices.
83  int verticesCount;    //!< A global Counter for vertices.
84  Array* normals;       //!< The Array that handles the Normals.
85  Array* vTexture;      //!< The Array that handles the VertexTextureCoordinates.
[3063]86
[3186]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.
[2850]90
[3916]91  tList<Material>* materialList;
92 
93
[2850]94  bool initGroup(Group* group);
[3066]95  bool initFace (Face* face);
[3910]96
[3911]97  bool buildVertexNormals(void);
98
[3916]99  bool importToDisplayList(void);
[3911]100  bool addGLElement(FaceElement* elem);
101
[3916]102  bool importToVertexArray(void);
103
104  bool deleteArrays(void);
[3911]105  bool cleanup(void);
[3066]106  bool cleanupGroup(Group* group);
107  bool cleanupFace(Face* face);
[3068]108  bool cleanupFaceElement(FaceElement* faceElem);
[2850]109
[3910]110
111 protected:
112  float scaleFactor;    //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation
113
[3913]114  Material* findMaterialByName(const char* materialName);
115
[3910]116  void cubeModel(void);
117
[3398]118 public:
[3916]119  Model(const char* modelName = NULL, MODEL_TYPE type = MODEL_DISPLAY_LIST);
[3910]120  virtual ~Model(void);
121
122  void setName(const char* name);
123  inline const char* getName() {return this->name;}
124 
125  void draw(void) const;
126  void draw(int groupNumber) const;
127  void draw(char* groupName) const;
128  int getGroupCount() const;
129
[3913]130  Material* addMaterial(Material* material);
131  Material* addMaterial(const char* materialName);
132
[3894]133  bool addGroup(const char* groupString);
[3909]134  bool addVertex(const char* vertexString);
[3894]135  bool addVertex(float x, float y, float z);
[3909]136  bool addFace(const char* faceString);
[3895]137  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
[3909]138  bool addVertexNormal(const char* normalString);
[3894]139  bool addVertexNormal(float x, float y, float z);
[3909]140  bool addVertexTexture(const char* vTextureString);
[3894]141  bool addVertexTexture(float u, float v);
[3913]142  bool setMaterial(const char* mtlString);
143  bool setMaterial(Material* mtl);
[3398]144  void finalize(void);
[2748]145};
[2773]146
147#endif
Note: See TracBrowser for help on using the repository browser.