Changeset 3063 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Dec 3, 2004, 1:59:29 PM (20 years ago)
- Location:
- orxonox/trunk/importer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/importer/Makefile.in
r2991 r3063 429 429 430 430 431 # uncomment the following if bencoderrequires the math library431 # uncomment the following if orxonox requires the math library 432 432 #orxonox_LDADD=-lm 433 433 -
orxonox/trunk/importer/object.cc
r2995 r3063 70 70 glDeleteLists (walker->listNumber, 1); 71 71 Group* lastWalker = walker; 72 walker = walker->next Group;72 walker = walker->next; 73 73 delete lastWalker; 74 74 } … … 94 94 material = new Material(); 95 95 96 // glEnableClientState (GL_VERTEX_ARRAY); 97 // glEnableClientState (GL_NORMAL_ARRAY); 98 // glEnableClientState (GL_TEXTURE_COORD_ARRAY); 99 96 vertices = new Array(); 97 vTexture = new Array(); 98 normals = new Array(); 100 99 101 100 return true; … … 117 116 /** 118 117 \brief finalizes an Object. 119 This funcion is needed, to close the glList and all the other lists. 118 This funcion is needed, to close the glList and all the other lists. This will be applied at the end of the importing Process. 120 119 */ 121 120 bool Object::finalize(void) … … 124 123 printf("finalizing the 3D-Object\n"); 125 124 finalizeGroup (currentGroup); 125 126 importToGL (); 127 128 if (vertices != NULL) 129 delete vertices; 130 if (vTexture != NULL) 131 delete vTexture; 132 if (normals != NULL) 133 delete normals; 134 126 135 if (material != NULL) 127 136 delete material; … … 133 142 It does this by just calling the Lists that must have been created earlier. 134 143 */ 135 void Object::draw (void) 144 void Object::draw (void) const 136 145 { 137 146 if (verbose >=2) … … 143 152 printf ("Drawing object %s\n", walker->name); 144 153 glCallList (walker->listNumber); 145 walker = walker->next Group;154 walker = walker->next; 146 155 } 147 156 } … … 152 161 \param groupNumber The number of the group that will be displayed. 153 162 */ 154 void Object::draw (int groupNumber) 163 void Object::draw (int groupNumber) const 155 164 { 156 165 if (groupNumber >= groupCount) 157 166 { 158 if (verbose>= 2)167 if (verbose>=1) 159 168 printf ("You requested object number %i, but this File only contains of %i Objects.\n", groupNumber-1, groupCount); 160 169 return; … … 169 178 { 170 179 if (verbose >= 2) 171 printf ("Drawing object number % snamed %s\n", counter, walker->name);180 printf ("Drawing object number %i named %s\n", counter, walker->name); 172 181 glCallList (walker->listNumber); 173 182 return; 174 183 } 175 184 ++counter; 176 walker = walker->next Group;177 } 178 if (verbose >= 2)185 walker = walker->next; 186 } 187 if (verbose >= 1) 179 188 printf("Object number %i in %s not Found.\n", groupNumber, objFileName); 180 189 return; … … 183 192 184 193 /** 185 \brief Draws the Object with a specific group name194 \brief Draws the Object with a specific groupName 186 195 It does this by just calling the List that must have been created earlier. 187 196 \param groupName The name of the group that will be displayed. 188 197 */ 189 void Object::draw (char* groupName) 198 void Object::draw (char* groupName) const 190 199 { 191 200 if (verbose >=2) … … 201 210 return; 202 211 } 203 walker = walker->next Group;212 walker = walker->next; 204 213 } 205 214 if (verbose >= 2) … … 211 220 \returns Count of the Objects in this File 212 221 */ 213 int Object::getGroupCount (void) 222 int Object::getGroupCount (void) const 214 223 { 215 224 return groupCount; … … 226 235 group->faceMode = -1; 227 236 group->faceCount = 0; 228 group->nextGroup = NULL; 229 if ((group->listNumber = glGenLists(1)) == 0 ) 230 { 231 printf ("list could not be created for this Object\n"); 232 return false; 233 } 234 235 if (groupCount == 0) 236 { 237 group->firstVertex = 0; 238 group->firstNormal = 0; 239 group->firstVertexTexture = 0; 240 } 241 else 242 { 243 group->firstVertex = currentGroup->firstVertex + currentGroup->vertices->getCount()/3; 244 group->firstNormal = currentGroup->firstNormal + currentGroup->normals->getCount()/3; 245 group->firstVertexTexture = currentGroup->firstVertexTexture + currentGroup->vTexture->getCount()/2; 246 } 247 if (verbose >=2) 248 printf ("Creating new Arrays, with starting points v:%i, vt:%i, vn:%i .\n", group->firstVertex, group->firstVertexTexture, group->firstNormal); 249 group->vertices = new Array(); 250 group->normals = new Array(); 251 group->vTexture = new Array(); 252 253 glNewList (group->listNumber, GL_COMPILE); 237 group->next = NULL; 238 239 group->firstFace = new Face; 240 group->currentFace = group->firstFace; 254 241 } 255 242 … … 258 245 \param group the group to finalize. 259 246 */ 260 bool Object::finalizeGroup(Group* group) 247 bool Object::finalizeGroup(Group* group) // think it is not needed anymore 261 248 { 262 249 if (verbose >=2) 263 250 printf ("Finalize group %s.\n", group->name); 264 glEnd(); 265 glEndList(); 266 } 267 268 /** 269 \brief deletes the Arrays of the Group to save space. 270 \param group the group to delete the arrays from. 271 */ 272 bool Object::cleanupGroup(Group* group) 273 { 274 if (verbose >=2) 275 printf ("cleaning up group %s.\n", group->name); 276 277 delete group->vertices; 278 delete group->normals; 279 delete group->vTexture; 251 280 252 } 281 253 … … 316 288 } 317 289 318 else if (!strncmp(Buffer, "mtllib ", 6))290 else if (!strncmp(Buffer, "mtllib ", 7)) 319 291 { 320 292 readMtlLib (Buffer+7); 321 293 } 322 294 323 else if (!strncmp(Buffer, "usemtl ", 6))295 else if (!strncmp(Buffer, "usemtl ", 7)) 324 296 { 325 297 readUseMtl (Buffer+7); … … 327 299 328 300 // case VertexNormal 329 else if (!strncmp(Buffer, "vn ", 2))301 else if (!strncmp(Buffer, "vn ", 3)) 330 302 { 331 303 readVertexNormal(Buffer+3); … … 333 305 334 306 // case VertexTextureCoordinate 335 else if (!strncmp(Buffer, "vt ", 2))307 else if (!strncmp(Buffer, "vt ", 3)) 336 308 { 337 309 readVertexTexture(Buffer+3); 338 310 } 339 311 // case group 340 else if (!strncmp(Buffer, "g ", 1))312 else if (!strncmp(Buffer, "g ", 2)) 341 313 { 342 314 readGroup (Buffer+2); 343 315 } 344 else if (!strncmp(Buffer, "s ", 1))316 else if (!strncmp(Buffer, "s ", 2)) 345 317 { 346 318 if (verbose >= 1) 347 printf("smoothing groups not sup ortet yet. line: %s\n", Buffer);319 printf("smoothing groups not supportet yet. line: %s\n", Buffer); 348 320 } 349 321 } … … 360 332 bool Object::readVertex (char* vertexString) 361 333 { 362 readingVertices = true;363 334 char subbuffer1[20]; 364 335 char subbuffer2[20]; … … 367 338 if (verbose >= 3) 368 339 printf ("reading in a vertex: %s %s %s\n", subbuffer1, subbuffer2, subbuffer3); 369 currentGroup->vertices->addEntry(atof(subbuffer1)*scaleFactor, atof(subbuffer2)*scaleFactor, atof(subbuffer3)*scaleFactor);340 vertices->addEntry(atof(subbuffer1)*scaleFactor, atof(subbuffer2)*scaleFactor, atof(subbuffer3)*scaleFactor); 370 341 return true; 371 342 } … … 379 350 bool Object::readFace (char* faceString) 380 351 { 381 // finalize the Arrays; 382 if (readingVertices == true) 383 { 384 currentGroup->vertices->finalizeArray(); 385 // glVertexPointer(3, GL_FLOAT, 0, currentGroup->vertices->getArray()); 386 currentGroup->normals->finalizeArray(); 387 // glNormalPointer(GL_FLOAT, 0, currentGroup->normals->getArray()); 388 currentGroup->vTexture->finalizeArray(); 389 } 390 391 readingVertices = false; 392 currentGroup->faceCount++; 393 394 int elemCount = 0; 395 396 FaceElement* firstElem = new FaceElement; 397 FaceElement* tmpElem = firstElem; 398 399 352 if (currentGroup->faceCount >0) 353 currentGroup->currentFace = currentGroup->currentFace->next = new Face; 354 initFace (currentGroup->currentFace); 355 356 FaceElement* tmpElem = currentGroup->currentFace->firstElem = new FaceElement; 357 400 358 while(strcmp (faceString, "\0")) 401 359 { 402 if ( elemCount>0)360 if (currentGroup->currentFace->vertexCount>0) 403 361 tmpElem = tmpElem->next = new FaceElement; 404 362 tmpElem->next = NULL; 405 363 406 407 sscanf (faceString, "%s", tmpElem->value); 364 char* tmpValue = new char [50]; 365 sscanf (faceString, "%s", tmpValue); 366 tmpElem->value = new char [strlen(tmpValue)]; 367 strcpy (tmpElem->value, tmpValue); 368 369 delete tmpValue; ////// DANGEROUS could be wrong to do this (useless) ///// 408 370 faceString += strlen(tmpElem->value); 409 371 if (strcmp (faceString, "\0")) 410 372 faceString++; 411 elemCount++; 412 413 414 } 415 416 417 if (elemCount == 3) 418 { 419 if (currentGroup->faceMode != 3) 420 { 421 if (currentGroup->faceMode != -1) 422 glEnd(); 423 glBegin(GL_TRIANGLES); 424 } 425 426 currentGroup->faceMode = 3; 427 if (verbose >=3) 428 printf ("found triag.\n"); 429 } 430 431 else if (elemCount == 4) 432 { 433 if (currentGroup->faceMode != 4) 434 { 435 if (currentGroup->faceMode != -1) 436 glEnd(); 437 glBegin(GL_QUADS); 438 } 439 currentGroup->faceMode = 4; 440 if (verbose >=3 ) 441 printf ("found quad.\n"); 442 } 443 444 else if (elemCount > 4) 445 { 446 if (currentGroup->faceMode != -1) 447 glEnd(); 448 glBegin(GL_POLYGON); 449 if (verbose >=3) 450 printf ("Polygon with %i faces found.", elemCount); 451 currentGroup->faceMode = elemCount; 452 } 453 454 tmpElem = firstElem; 455 FaceElement* delElem; 456 while (tmpElem != NULL) 457 { 458 // printf ("%s\n", tmpElem->value); 459 addGLElement(tmpElem->value); 460 delElem = tmpElem; 461 tmpElem = tmpElem->next; 462 delete delElem; 463 } 464 373 currentGroup->currentFace->vertexCount++; 374 } 375 376 currentGroup->faceCount++; 465 377 } 466 378 … … 485 397 texture[0] = '\0'; 486 398 texture ++; 487 if (verbose>=3) 488 printf ("includeing texture #%i, and mapping it to group texture #%i, textureArray has %i entries.\n", atoi(texture), (atoi(texture)-1 - currentGroup->firstVertexTexture)*2, currentGroup->vTexture->getCount()); 489 glTexCoord2fv(currentGroup->vTexture->getArray()+(atoi(texture)-1 - currentGroup->firstVertexTexture)*2); 399 glTexCoord2fv(vTexture->getArray()+(atoi(texture)-1)*2); 490 400 491 401 char* normal; … … 495 405 normal ++; 496 406 //glArrayElement(atoi(vertex)-1); 497 glNormal3fv(currentGroup->normals->getArray() +(atoi(normal)-1 - currentGroup->firstNormal)*3); 498 } 499 } 500 if (verbose>=3) 501 printf ("includeing vertex #%i, and mapping it to group vertex #%i, vertexArray has %i entries.\n", atoi(vertex), (atoi(vertex)-1 - currentGroup->firstVertex)*3, currentGroup->vertices->getCount()); 502 glVertex3fv(currentGroup->vertices->getArray() +(atoi(vertex)-1 - currentGroup->firstVertex)*3); 407 glNormal3fv(normals->getArray() +(atoi(normal)-1)*3); 408 } 409 } 410 glVertex3fv(vertices->getArray() +(atoi(vertex)-1)*3); 503 411 504 412 } … … 511 419 bool Object::readVertexNormal (char* normalString) 512 420 { 513 readingVertices = true;514 421 char subbuffer1[20]; 515 422 char subbuffer2[20]; … … 518 425 if (verbose >=3 ) 519 426 printf("found vertex-Normal %s, %s, %s\n", subbuffer1,subbuffer2,subbuffer3); 520 currentGroup->normals->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));427 normals->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3)); 521 428 return true; 522 429 } … … 529 436 bool Object::readVertexTexture (char* vTextureString) 530 437 { 531 readingVertices = true;532 438 char subbuffer1[20]; 533 439 char subbuffer2[20]; … … 535 441 if (verbose >=3 ) 536 442 printf("found vertex-Texture %s, %s\n", subbuffer1,subbuffer2); 537 currentGroup->vTexture->addEntry(atof(subbuffer1));538 currentGroup->vTexture->addEntry(atof(subbuffer2));443 vTexture->addEntry(atof(subbuffer1)); 444 vTexture->addEntry(atof(subbuffer2)); 539 445 return true; 540 446 } … … 558 464 Group* newGroup = new Group; 559 465 finalizeGroup(currentGroup); 560 currentGroup->next Group= newGroup;466 currentGroup->next = newGroup; 561 467 initGroup(newGroup); 562 cleanupGroup(currentGroup); // deletes the arrays of the group; must be after initGroup.563 468 currentGroup = newGroup; // must be after init see initGroup for more info 564 469 } … … 566 471 ++groupCount; 567 472 473 } 474 475 476 bool Object::initFace (Face* face) 477 { 478 face->vertexCount = 0; 479 480 face->firstElem = NULL; 481 482 face->material = NULL; 483 484 face->next = NULL; 485 486 return true; 487 } 488 489 bool Object::importToGL (void) 490 { 491 492 // finalize the Arrays 493 vertices->finalizeArray(); 494 vTexture->finalizeArray(); 495 normals->finalizeArray(); 496 497 currentGroup = firstGroup; 498 499 while (currentGroup != NULL) 500 { 501 502 // creating a glList for the Group 503 if ((currentGroup->listNumber = glGenLists(1)) == 0) 504 { 505 printf ("list could not be created for this Object\n"); 506 return false; 507 } 508 glNewList (currentGroup->listNumber, GL_COMPILE); 509 510 // Putting Faces to GL 511 Face* tmpFace = currentGroup->firstFace; 512 while (tmpFace != NULL) 513 { 514 if (tmpFace->vertexCount == 3) 515 { 516 if (currentGroup->faceMode != 3) 517 { 518 if (currentGroup->faceMode != -1) 519 glEnd(); 520 glBegin(GL_TRIANGLES); 521 } 522 523 currentGroup->faceMode = 3; 524 if (verbose >=3) 525 printf ("found triag.\n"); 526 } 527 528 else if (tmpFace->vertexCount == 4) 529 { 530 if (currentGroup->faceMode != 4) 531 { 532 if (currentGroup->faceMode != -1) 533 glEnd(); 534 glBegin(GL_QUADS); 535 } 536 currentGroup->faceMode = 4; 537 if (verbose >=3 ) 538 printf ("found quad.\n"); 539 } 540 541 else if (tmpFace->vertexCount > 4) 542 { 543 if (currentGroup->faceMode != -1) 544 glEnd(); 545 glBegin(GL_POLYGON); 546 if (verbose >=3) 547 printf ("Polygon with %i faces found.", tmpFace->vertexCount); 548 currentGroup->faceMode = tmpFace->vertexCount; 549 } 550 551 FaceElement* tmpElem = tmpFace->firstElem; 552 FaceElement* delElem; 553 while (tmpElem != NULL) 554 { 555 // printf ("%s\n", tmpElem->value); 556 addGLElement(tmpElem->value); 557 delElem = tmpElem; 558 tmpElem = tmpElem->next; 559 delete delElem; 560 } 561 tmpFace = tmpFace->next; 562 } 563 glEnd(); 564 glEndList(); 565 currentGroup = currentGroup->next; 566 } 568 567 } 569 568 … … 595 594 596 595 // create new Material 597 if (!strncmp(Buffer, "newmtl ", 2))596 if (!strncmp(Buffer, "newmtl ", 7)) 598 597 { 599 598 tmpMat = tmpMat->addMaterial(Buffer+7); … … 601 600 } 602 601 // setting a illumMode 603 else if (!strncmp(Buffer, "illum ", 5))602 else if (!strncmp(Buffer, "illum ", 6)) 604 603 { 605 604 tmpMat->setIllum(Buffer+6); … … 607 606 } 608 607 // setting Diffuse Color 609 else if (!strncmp(Buffer, "Kd ", 2))608 else if (!strncmp(Buffer, "Kd ", 3)) 610 609 { 611 610 tmpMat->setDiffuse(Buffer+3); 612 611 } 613 612 // setting Ambient Color 614 else if (!strncmp(Buffer, "Ka ", 2))613 else if (!strncmp(Buffer, "Ka ", 3)) 615 614 { 616 615 tmpMat->setAmbient(Buffer+3); 617 616 } 618 617 // setting Specular Color 619 else if (!strncmp(Buffer, "Ks ", 2))618 else if (!strncmp(Buffer, "Ks ", 3)) 620 619 { 621 620 tmpMat->setSpecular(Buffer+3); 622 621 } 623 622 // setting The Specular Shininess 624 else if (!strncmp(Buffer, "Ns ", 2))623 else if (!strncmp(Buffer, "Ns ", 3)) 625 624 { 626 625 tmpMat->setShininess(Buffer+3); 627 626 } 628 627 // setting up transparency 629 else if (!strncmp(Buffer, "d ", 1))628 else if (!strncmp(Buffer, "d ", 2)) 630 629 { 631 630 tmpMat->setTransparency(Buffer+2); 632 631 } 633 else if (!strncpy(Buffer, "Tf ", 2))632 else if (!strncpy(Buffer, "Tf ", 3)) 634 633 { 635 634 tmpMat->setTransparency(Buffer+3); -
orxonox/trunk/importer/object.h
r2934 r3063 16 16 using namespace std; 17 17 18 extern int verbose; //!< fill be removed and added again as a verbose-class18 extern int verbose; //!< Will be removed and added again as a verbose-class. 19 19 20 20 21 struct FaceElement22 {23 char value[20];24 FaceElement* next;25 };26 21 27 22 //! Class that handles 3D-Objects. it can also read them in and display them. … … 37 32 bool initialize (void); 38 33 bool finalize(void); 39 void draw (void) ;40 void draw (int groupNumber) ;41 void draw (char* groupName) ;42 int getGroupCount() ;34 void draw (void) const; 35 void draw (int groupNumber) const; 36 void draw (char* groupName) const; 37 int getGroupCount() const; 43 38 44 39 private: 40 struct FaceElement 41 { 42 char* value; 43 FaceElement* next; 44 }; 45 46 //! Face 47 struct Face 48 { 49 int vertexCount; 50 51 FaceElement* firstElem; 52 53 char* material; 54 55 Face* next; 56 }; 57 45 58 //! Group to handle multiple Objects per obj-file 46 59 struct Group … … 49 62 50 63 GLuint listNumber; 51 Array* vertices; 52 int verticesCount; 53 Array* colors; 54 Array* normals; 55 Array* vTexture; 64 Face* firstFace; 65 Face* currentFace; 56 66 int faceMode; 57 67 int faceCount; 58 68 59 int firstVertex; 60 int firstNormal; 61 int firstVertexTexture; 69 Group* next; 70 }; 62 71 63 Group* nextGroup; 64 }; 72 73 Array* vertices; 74 int verticesCount; 75 Array* colors; 76 Array* normals; 77 Array* vTexture; 78 65 79 66 80 Group* firstGroup; //!< the first of all groups. 67 81 Group* currentGroup; //!< the currentGroup. this is the one we will work with. 68 82 int groupCount; 69 70 bool readingVertices;71 83 72 84 char* objFileName; … … 76 88 float scaleFactor; 77 89 90 char* objPath; 78 91 ifstream* OBJ_FILE; 79 92 ifstream* MTL_FILE; … … 81 94 bool initGroup(Group* group); 82 95 bool finalizeGroup (Group* group); 83 bool cleanupGroup(Group* group);84 96 85 97 … … 96 108 bool readUseMtl (char* mtlString); 97 109 110 bool initFace (Face* face); 111 bool importToGL (void); 98 112 bool addGLElement (char* elementString); 99 113
Note: See TracChangeset
for help on using the changeset viewer.