Changeset 4022 in orxonox.OLD for orxonox/trunk/src/lib/graphics/importer
- Timestamp:
- May 3, 2005, 1:35:22 AM (20 years ago)
- Location:
- orxonox/trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/importer/model.cc
r4020 r4022 27 27 using namespace std; 28 28 29 ////////////////// 30 // DE-CONSTRUCT // 31 ////////////////// 32 /** 33 \brief Creates a 3D-Model. and assigns it a Name. 29 30 //////////////////// 31 /// SUB-Elements /// 32 //////////////////// 33 ModelFaceElement::ModelFaceElement() 34 { 35 } 36 37 ModelFaceElement::~ModelFaceElement() 38 { 39 if (this->next != NULL) 40 delete this->next; 41 } 42 43 ModelFace::ModelFace() 44 { 45 this->vertexCount = 0; 46 47 this->firstElem = NULL; 48 49 this->material = NULL; 50 51 this->next = NULL; 52 53 } 54 55 ModelFace::~ModelFace() 56 { 57 PRINTF(5)("Cleaning up Face\n"); 58 59 if (this->firstElem != NULL) 60 { 61 delete this->firstElem; 62 } 63 64 if (this->next != NULL) 65 { 66 delete this->next; 67 } 68 69 } 70 71 ModelGroup::ModelGroup() 72 { 73 PRINTF(4)("Adding new Group\n"); 74 this->name = ""; 75 this->faceMode = -1; 76 this->faceCount = 0; 77 this->next = NULL; 78 79 this->firstFace = new ModelFace; 80 this->currentFace = this->firstFace; 81 } 82 83 ModelGroup::~ModelGroup() 84 { 85 PRINTF(5)("Cleaning up group\n"); 86 if (this->firstFace != NULL) 87 { 88 delete this->firstFace; 89 } 90 91 if (this->next !=NULL) 92 delete this->next; 93 } 94 95 void ModelGroup::cleanup(void) 96 { 97 if (this->firstFace) 98 delete this->firstFace; 99 this->firstFace = NULL; 100 if (this->next) 101 this->next->cleanup(); 102 } 103 104 105 ///////////// 106 /// MODEL /// 107 ///////////// 108 /** 109 \brief Creates a 3D-Model. 110 111 assigns it a Name and a Type 34 112 */ 35 113 Model::Model(const char* modelName, MODEL_TYPE type) … … 42 120 this->finalized = false; 43 121 // setting the start group; 44 this->firstGroup = new Group; 45 this->currentGroup = this->firstGroup; 122 this->currentGroup = this->firstGroup = new ModelGroup; 46 123 this->groupCount = 0; 47 124 48 this->initGroup (this->currentGroup);49 125 this->scaleFactor = 1; 50 126 … … 76 152 77 153 PRINTF(5)("Deleting display Lists.\n"); 78 Group* walker = this->firstGroup;154 ModelGroup* walker = this->firstGroup; 79 155 while (walker != NULL) 80 156 { 81 157 glDeleteLists (walker->listNumber, 1); 82 Group* delWalker = walker;158 ModelGroup* delWalker = walker; 83 159 walker = walker->next; 84 160 delete delWalker; … … 128 204 { 129 205 PRINTF(4)("drawing the 3D-Models\n"); 130 Group* walker = this->firstGroup;206 ModelGroup* walker = this->firstGroup; 131 207 while (walker != NULL) 132 208 { … … 151 227 } 152 228 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 153 Group* walker = this->firstGroup;229 ModelGroup* walker = this->firstGroup; 154 230 int counter = 0; 155 231 while (walker != NULL) … … 178 254 { 179 255 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 180 Group* walker = this->firstGroup;256 ModelGroup* walker = this->firstGroup; 181 257 while (walker != NULL) 182 258 { … … 210 286 void Model::setName(const char* name) 211 287 { 212 if (this->name) 288 if (this->name) 213 289 delete []this->name; 214 290 if (name) … … 219 295 else 220 296 this->name = NULL; 221 }222 223 /**224 \brief initializes a new Group model225 \param group the group that should be initialized.226 \todo Maybe Group should be a Class, because it does a lot of stuff227 228 */229 bool Model::initGroup(Group* group)230 {231 PRINTF(4)("Adding new Group\n");232 group->name = "";233 group->faceMode = -1;234 group->faceCount = 0;235 group->next = NULL;236 237 group->firstFace = new Face;238 this->initFace (group->firstFace);239 group->currentFace = group->firstFace;240 }241 242 /**243 \brief initializes a new Face. (sets default Values)244 \param face The face to initialize245 */246 bool Model::initFace (Face* face)247 {248 face->vertexCount = 0;249 250 face->firstElem = NULL;251 252 face->material = NULL;253 254 face->next = NULL;255 256 return true;257 297 } 258 298 … … 280 320 { 281 321 PRINTF(4)("cleaning up the 3D-Model to save Memory.\n"); 282 this-> cleanupGroup(this->firstGroup);322 this->firstGroup->cleanup(); 283 323 return true; 284 324 } 285 325 286 /** 287 \brief Cleans up all groups starting from group. 288 \param group the first Group to clean 289 */ 290 bool Model::cleanupGroup (Group* group) 291 { 292 PRINTF(5)("Cleaning up group\n"); 293 if (group->firstFace != NULL) 294 { 295 cleanupFace (group->firstFace); 296 delete group->firstFace; 297 } 298 299 if (group->next !=NULL) 300 cleanupGroup (group->next); 301 return true; 302 } 303 304 /** 305 \brief Cleans up all Faces starting from face until NULL is reached. 306 \param face the first face to clean. 307 */ 308 bool Model::cleanupFace (Face* face) 309 { 310 PRINTF(5)("Cleaning up Face\n"); 311 312 if (face->firstElem != NULL) 313 { 314 this->cleanupFaceElement(face->firstElem); 315 delete face->firstElem; 316 } 317 318 if (face->next != NULL) 319 { 320 this->cleanupFace (face->next); 321 delete face->next; 322 } 323 } 324 325 /** 326 \brief Cleans up all FaceElements starting from faceElem. 327 \param faceElem the first FaceElement to clean. 328 */ 329 bool Model::cleanupFaceElement(FaceElement* faceElem) 330 { 331 if (faceElem->next != NULL) 332 { 333 this->cleanupFaceElement (faceElem->next); 334 delete faceElem->next; 335 } 336 } 326 337 327 338 328 ////////// … … 395 385 396 386 This function initializes a new Group. 397 With it you should be able to import .obj-files with more than one Models inside.387 With it you should be able to create Models with more than one SubModel inside 398 388 */ 399 389 bool Model::addGroup (const char* groupString) 400 390 { 401 391 PRINTF(5)("Read Group: %s.\n", groupString); 402 if (this->groupCount != 0 && this->currentGroup->faceCount >0)392 if (this->groupCount != 0 && this->currentGroup->faceCount > 0) 403 393 { 404 394 // finalizeGroup(currentGroup); 405 this->currentGroup = this->currentGroup->next = new Group; 406 this->initGroup(this->currentGroup); 395 this->currentGroup = this->currentGroup->next = new ModelGroup; 407 396 } 408 397 // setting the group name if not default. … … 518 507 { 519 508 if (this->currentGroup->faceCount >0) 520 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 521 this->initFace (this->currentGroup->currentFace); 522 523 FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement; 509 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 510 511 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement; 524 512 tmpElem->next = NULL; 525 513 while(strcmp (faceString, "\0")) 526 514 { 527 515 if (this->currentGroup->currentFace->vertexCount>0) 528 tmpElem = tmpElem->next = new FaceElement;516 tmpElem = tmpElem->next = new ModelFaceElement; 529 517 tmpElem->next = NULL; 530 518 … … 579 567 bool Model::addFace(int faceElemCount, VERTEX_FORMAT type, ...) 580 568 { 581 if (this->currentGroup->faceCount > 0) 582 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 583 this->initFace (this->currentGroup->currentFace); 584 585 FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement; 569 if (this->currentGroup->faceCount > 0) 570 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 571 572 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement; 586 573 tmpElem->next = NULL; 587 574 … … 592 579 { 593 580 if (this->currentGroup->currentFace->vertexCount>0) 594 tmpElem = tmpElem->next = newFaceElement;581 tmpElem = tmpElem->next = new ModelFaceElement; 595 582 tmpElem->next = NULL; 596 583 … … 614 601 { 615 602 if (this->currentGroup->faceCount > 0) 616 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 617 this->initFace (this->currentGroup->currentFace); 603 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 618 604 619 605 this->currentGroup->currentFace->material = this->findMaterialByName(matString); … … 630 616 { 631 617 if (this->currentGroup->faceCount > 0) 632 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 633 this->initFace (this->currentGroup->currentFace); 618 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 634 619 635 620 this->currentGroup->currentFace->material = mtl; … … 662 647 Vector curV; 663 648 664 Group* tmpGroup = firstGroup;649 ModelGroup* tmpGroup = firstGroup; 665 650 while (tmpGroup) 666 651 { 667 Face* tmpFace = tmpGroup->firstFace;652 ModelFace* tmpFace = tmpGroup->firstFace; 668 653 while (tmpFace) 669 654 { 670 655 if (tmpFace->firstElem) 671 656 { 672 FaceElement* firstElem = tmpFace->firstElem;673 FaceElement* prevElem;674 FaceElement* curElem = firstElem;675 FaceElement* nextElem;676 FaceElement* lastElem;657 ModelFaceElement* firstElem = tmpFace->firstElem; 658 ModelFaceElement* prevElem; 659 ModelFaceElement* curElem = firstElem; 660 ModelFaceElement* nextElem; 661 ModelFaceElement* lastElem; 677 662 // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop. 678 663 while (curElem) … … 744 729 745 730 // Putting Faces to GL 746 Face* tmpFace = this->currentGroup->firstFace;731 ModelFace* tmpFace = this->currentGroup->firstFace; 747 732 while (tmpFace != NULL) 748 733 { … … 794 779 } 795 780 796 FaceElement* tmpElem = tmpFace->firstElem;781 ModelFaceElement* tmpElem = tmpFace->firstElem; 797 782 while (tmpElem != NULL) 798 783 { … … 841 826 merging this information, the face will be drawn. 842 827 */ 843 bool Model::addGLElement ( FaceElement* elem)828 bool Model::addGLElement (ModelFaceElement* elem) 844 829 { 845 830 PRINTF(5)("importing grafical Element to openGL.\n"); -
orxonox/trunk/src/lib/graphics/importer/model.h
r3917 r4022 34 34 VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD}; 35 35 36 //////////////////// 37 /// SUB-ELEMENTS /// 38 //////////////////// 39 //! This is the placeholder of one Vertex beloning to a Face. 40 class ModelFaceElement 41 { 42 public: 43 ModelFaceElement(); 44 ~ModelFaceElement(); 45 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 ModelFaceElement* next; //!< Point to the next FaceElement in this List. 50 }; 51 52 //! This is the placeholder of a Face belonging to a Group of Faces. 53 class ModelFace 54 { 55 public: 56 ModelFace(); 57 ~ModelFace(); 58 59 int vertexCount; //!< The Count of vertices this Face has. 60 ModelFaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. 61 62 Material* material; //!< The Material to use. 63 64 ModelFace* next; //!< Pointer to the next Face. 65 }; 66 67 //! Group to handle multiple Models per obj-file. 68 class ModelGroup 69 { 70 public: 71 ModelGroup(); 72 ~ModelGroup(); 73 74 void cleanup(); 75 76 char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function. 77 78 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 79 GLuint listNumber; //!< The number of the GL-List this Group gets. 80 ModelFace* firstFace; //!< The first Face in this group. 81 ModelFace* currentFace; //!< The current Face in this Group (the one we are currently working with.) 82 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... 83 int faceCount; //!< The Number of Faces this Group holds. 84 85 ModelGroup* next; //!< Pointer to the next Group. 86 }; 87 88 ///////////// 89 /// MODEL /// 90 ///////////// 91 36 92 //! Class that handles 3D-Models. it can also read them in and display them. 37 93 class Model 38 94 { 39 95 private: 40 /////////////41 // structs //42 /////////////43 //! This is the placeholder of one Vertex beloning to a Face.44 struct FaceElement45 {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.50 };51 96 52 //! This is the placeholder of a Face belonging to a Group of Faces. 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. 97 char* name; //!< This is the name of the Model. 98 MODEL_TYPE type; 99 bool finalized; //!< Sets the Object to be finalized. 57 100 58 Material* material; //!< The Material to use. 101 Array* vertices; //!< The Array that handles the Vertices. 102 int verticesCount; //!< A global Counter for vertices. 103 Array* normals; //!< The Array that handles the Normals. 104 Array* vTexture; //!< The Array that handles the VertexTextureCoordinates. 59 105 60 Face* next; //!< Pointer to the next Face. 61 }; 106 ModelGroup* firstGroup; //!< The first of all groups. 107 ModelGroup* currentGroup; //!< The currentGroup. this is the one we will work with. 108 int groupCount; //!< The Count of Groups. 62 109 63 //! Group to handle multiple Models 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 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 69 GLuint listNumber; //!< The number of the GL-List this Group gets. 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. 74 75 Group* next; //!< Pointer to the next Group. 76 }; 77 78 char* name; //!< This is the name of the Model. 79 MODEL_TYPE type; 80 bool finalized; //!< Sets the Object to be finalized. 81 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. 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 tList<Material>* materialList; 110 tList<Material>* materialList;//!< A list for all the Materials in this Model 92 111 93 94 bool initGroup(Group* group);95 bool initFace (Face* face);96 97 112 bool buildVertexNormals(void); 98 113 99 114 bool importToDisplayList(void); 100 bool addGLElement( FaceElement* elem);115 bool addGLElement(ModelFaceElement* elem); 101 116 102 117 bool importToVertexArray(void); … … 104 119 bool deleteArrays(void); 105 120 bool cleanup(void); 106 bool cleanupGroup(Group* group);107 bool cleanupFace(Face* face);108 bool cleanupFaceElement(FaceElement* faceElem);109 121 110 122
Note: See TracChangeset
for help on using the changeset viewer.