Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5319 was 5304, checked in by bensch, 20 years ago

orxonox/trunk: so, ResourceManager now operates on BaseObjects. If this is better, i do not know, but at least it is more intuitive, i think

File size: 7.2 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
[4793]9#include "abstract_model.h"
[4577]10#include "base_object.h"
[2776]11#include "material.h"
[3917]12#include "glincl.h"
[4577]13#include "array.h"
[2748]14
[4577]15
[3427]16// FORWARD DEFINITION //
17class Vector;
[4579]18template<class T> class Array;
[3910]19template<class T> class tList;
[3427]20
[4793]21
[3916]22//! an enumerator fot the different Model Types.
23/**
24   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.
25   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.
[4836]26 * @todo implement this stuff
[3916]27*/
[4830]28typedef enum MODEL_TYPE {
29  MODEL_DISPLAY_LIST,
30  MODEL_VERTEX_ARRAY
31};
[3910]32
33
[3657]34// definition of different modes for setting up Faces
35#define VERTEX 0       //!< If Faces are created WITH Vertex-Coordinate
36#define NORMAL 1       //!< If Faces are created WITH Normals (otherwise autocalculate)
37#define TEXCOORD 2     //!< If Faces are created WITH TextureCoordinate
[4468]38
[3894]39//! an enumerator for VERTEX_FORMAT
[4830]40typedef enum VERTEX_FORMAT {
41  VERTEX_ONLY = VERTEX,
42  VERTEX_NORMAL = NORMAL,
43  VERTEX_TEXCOORD = TEXCOORD,
44  VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD
45};
[2842]46
[4022]47////////////////////
48/// SUB-ELEMENTS ///
49////////////////////
50//! This is the placeholder of one Vertex beloning to a Face.
51class ModelFaceElement
[2748]52{
[4022]53 public:
54  ModelFaceElement();
55  ~ModelFaceElement();
[3063]56
[4577]57  int                 vertexNumber;         //!< The number of the Vertex out of the Array* vertices, this vertex points to.
58  int                 normalNumber;         //!< The number of the Normal out of the Array* normals, this vertex points to.
59  int                 texCoordNumber;       //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
[4468]60
[4577]61  ModelFaceElement*   next;                 //!< Point to the next FaceElement in this List.
[4022]62};
[3063]63
[4022]64//! This is the placeholder of a Face belonging to a Group of Faces.
65class ModelFace
66{
67 public:
68  ModelFace();
69  ~ModelFace();
[4577]70
71  unsigned int        vertexCount;     //!< The Count of vertices this Face has.
[4468]72  ModelFaceElement*   firstElem;       //!< Points to the first Vertex (FaceElement) of this Face.
73  Material*           material;        //!< The Material to use.
[4577]74
[4468]75  ModelFace*          next;            //!< Pointer to the next Face.
[4577]76};
[3063]77
[4022]78//! Group to handle multiple Models per obj-file.
79class ModelGroup
80{
81 public:
82  ModelGroup();
83  ~ModelGroup();
[2850]84
[4022]85  void cleanup();
[2850]86
[4468]87  char*        name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
88  GLubyte*     indices;        //!< The indices of the Groups. Needed for vertex-arrays
89  GLuint       listNumber;     //!< The number of the GL-List this Group gets.
90  ModelFace*   firstFace;      //!< The first Face in this group.
91  ModelFace*   currentFace;    //!< The current Face in this Group (the one we are currently working with.)
[4836]92  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...
[4468]93  int          faceCount;      //!< The Number of Faces this Group holds.
[4577]94
[4468]95  ModelGroup*  next;           //!< Pointer to the next Group.
[4022]96};
[2850]97
[5304]98struct ModelMaterial
99{
100  Material* material;
101  bool external;
102};
103
[4022]104/////////////
105/// MODEL ///
106/////////////
107//! Class that handles 3D-Models. it can also read them in and display them.
[4806]108class Model : public AbstractModel
[4022]109{
[3398]110 public:
[3916]111  Model(const char* modelName = NULL, MODEL_TYPE type = MODEL_DISPLAY_LIST);
[4746]112  virtual ~Model();
[3910]113
[4746]114  void draw() const;
[3910]115  void draw(int groupNumber) const;
116  void draw(char* groupName) const;
117
[4836]118  /** @returns Count of the Models (Groups) in this File */
[4746]119  inline int getGroupCount() const { return this->groupCount; };
[4038]120
[4836]121  /** @returns a Pointer to the Vertex-Array, if it was deleted it returns NULL */
[4746]122  inline const GLfloat* getVertexArray() const { return this->vertices->getArray(); };
[4836]123  /** @returns the VertexCount of this Model */
[4746]124  inline unsigned int getVertexCount() const { return this->vertexCount; };
[4577]125
[4836]126  /** @returns a Pointer to the Normals-Array, if it was deleted it returns NULL */
[4746]127  inline const GLfloat* getNormalsArray() const { return this->normals->getArray(); };
[4836]128  /** @returns the NormalsCount of this Model */
[4746]129  inline unsigned int getNormalsCount() const { return this->normalCount; };
[4577]130
[4836]131  /** @returns a Pointer to the TexCoord-Array, if it was deleted it returns NULL */
[4746]132  inline const GLfloat* getTexCoordArray() const { return this->vTexture->getArray(); };
[4836]133  /** @returns the TexCoord-Count of this Model */
[4746]134  inline unsigned int getTexCoordCount() const { return this->texCoordCount; };
[4577]135
[4836]136  /** @returns the Count of Faces of this Model */
[4678]137  inline unsigned int getFaceCount() const { return this->faceCount; };
[4577]138
[4678]139
[3913]140  Material* addMaterial(Material* material);
141  Material* addMaterial(const char* materialName);
142
[3894]143  bool addGroup(const char* groupString);
[3909]144  bool addVertex(const char* vertexString);
[3894]145  bool addVertex(float x, float y, float z);
[3909]146  bool addFace(const char* faceString);
[3895]147  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
[3909]148  bool addVertexNormal(const char* normalString);
[3894]149  bool addVertexNormal(float x, float y, float z);
[3909]150  bool addVertexTexture(const char* vTextureString);
[3894]151  bool addVertexTexture(float u, float v);
[3913]152  bool setMaterial(const char* mtlString);
153  bool setMaterial(Material* mtl);
[4746]154  void finalize();
[4106]155
[4468]156
157 protected:
[4746]158  void cubeModel();
[4468]159
160  Material* findMaterialByName(const char* materialName);
161
[4529]162
163 protected:
[4836]164  float            scaleFactor;     //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation
[4529]165
[4468]166 private:
[4746]167  bool buildVertexNormals();
[4468]168
[4746]169  bool importToDisplayList();
[4791]170  bool buildTriangleList();
[4468]171  bool addGLElement(ModelFaceElement* elem);
172
[4746]173  bool importToVertexArray();
[4468]174
[4746]175  bool deleteArrays();
176  bool cleanup();
[4468]177
178 private:
[5304]179  MODEL_TYPE             type;            //!< A type for the Model
180  bool                   finalized;       //!< Sets the Object to be finalized.
[4468]181
[5304]182  unsigned int           vertexCount;     //!< A modelwide Counter for vertices.
183  unsigned int           normalCount;     //!< A modelwide Counter for the normals.
184  unsigned int           texCoordCount;   //!< A modelwide Counter for the texCoord.
185  unsigned int           faceCount;       //!< A modelwide Counter for the faces
186  unsigned int           triangleCount;   //!< Number of triangles >= faceCount
187  Array<GLfloat>*        vertices;        //!< The Array that handles the Vertices.
188  Array<GLfloat>*        normals;         //!< The Array that handles the Normals.
189  Array<GLfloat>*        vTexture;        //!< The Array that handles the VertexTextureCoordinates.
190  sTriangleExt*          triangles;       //!< The Array of triangles in the abstract_model.h style
[4468]191
[5304]192  ModelGroup*            firstGroup;      //!< The first of all groups.
193  ModelGroup*            currentGroup;    //!< The currentGroup. this is the one we will work with.
194  int                    groupCount;      //!< The Count of Groups.
[4468]195
[5304]196  tList<ModelMaterial>*  materialList;    //!< A list for all the Materials in this Model
[2748]197};
[2773]198
199#endif
Note: See TracBrowser for help on using the repository browser.