Changeset 4022 in orxonox.OLD for orxonox/trunk/src/lib/graphics/importer/model.cc
- Timestamp:
- May 3, 2005, 1:35:22 AM (20 years ago)
- File:
-
- 1 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");
Note: See TracChangeset
for help on using the changeset viewer.