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