Changeset 6031 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- Dec 10, 2005, 11:18:19 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/static_model.cc
r6022 r6031 32 32 //////////////////// 33 33 /** 34 * creates a new ModelFaceElement35 */34 * @brief creates a new ModelFaceElement 35 */ 36 36 ModelFaceElement::ModelFaceElement() 37 37 { … … 44 44 45 45 /** 46 * destroys a ModelFaceElement47 */46 * @brief destroys a ModelFaceElement 47 */ 48 48 ModelFaceElement::~ModelFaceElement() 49 49 { … … 53 53 54 54 /** 55 * creates a new ModelFace56 */55 * @brief creates a new ModelFace 56 */ 57 57 ModelFace::ModelFace() 58 58 { … … 81 81 82 82 /** 83 * Creates a new ModelGroup84 */83 * @brief Creates a new ModelGroup 84 */ 85 85 ModelGroup::ModelGroup() 86 86 { … … 97 97 98 98 /** 99 * deletes a ModelGroup100 */99 * @brief deletes a ModelGroup 100 */ 101 101 ModelGroup::~ModelGroup() 102 102 { … … 118 118 119 119 /** 120 * cleans up a ModelGroup121 122 123 */120 * @brief cleans up a ModelGroup 121 * 122 * actually does the same as the delete Operator, but does not delete the predecessing group 123 */ 124 124 void ModelGroup::cleanup() 125 125 { … … 137 137 ///////////// 138 138 /** 139 * Creates a 3D-Model.140 141 142 */143 StaticModel::StaticModel(const char* modelName , MODEL_TYPE type)139 * @brief Creates a 3D-Model. 140 * 141 * assigns it a Name and a Type 142 */ 143 StaticModel::StaticModel(const char* modelName) 144 144 { 145 145 this->setClassID(CL_MODEL, "Model"); 146 146 PRINTF(4)("new 3D-Model is being created\n"); 147 147 this->setName(modelName); 148 this->type = type;149 148 150 149 this->finalized = false; 150 151 151 // setting the start group; 152 152 this->currentGroup = this->firstGroup = new ModelGroup; 153 153 this->groupCount = 0; 154 this->vertexCount = 0;155 this->normalCount = 0;156 this->texCoordCount = 0;157 154 this->faceCount = 0; 158 this->triangleCount = 0; 159 this->triangles = NULL; 160 161 this->scaleFactor = 1; 162 163 this->vertices = new tArray<GLfloat>(); 164 this->vTexture = new tArray<GLfloat>(); 165 this->normals = new tArray<GLfloat>(); 166 167 if (this->type == MODEL_VERTEX_ARRAY) 168 glEnableClientState(GL_VERTEX_ARRAY | GL_NORMAL_ARRAY | GL_TEXTURE_COORD_ARRAY); 169 } 170 171 /** 172 * deletes an Model. 173 174 Looks if any from model allocated space is still in use, and if so deleted it. 175 */ 155 156 this->scaleFactor = 1.0f; 157 } 158 159 /** 160 * @brief deletes an Model. 161 * 162 * Looks if any from model allocated space is still in use, and if so deleted it. 163 */ 176 164 StaticModel::~StaticModel() 177 165 { … … 190 178 delete this->firstGroup; 191 179 192 // deleting Arrays (if not allready done by finalize)193 this->deleteArrays();194 195 180 // deleting the MaterialList 196 181 PRINTF(5)("Deleting Materials.\n"); … … 207 192 208 193 /** 209 * Finalizes an Object. This can be done outside of the Class.210 */194 * @brief Finalizes an Object. This can be done outside of the Class. 195 */ 211 196 void StaticModel::finalize() 212 197 { … … 215 200 this->buildTriangleList(); 216 201 217 // deletes everything we allocated. 218 //if (this->type == MODEL_DISPLAY_LIST) 219 //this->deleteArrays(); 220 // this->cleanup(); 221 222 /* load the ModelInfo */ 223 this->pModelInfo.numVertices = this->vertexCount; 224 this->pModelInfo.pVertices = this->vertices->getArray(); 225 this->pModelInfo.numTriangles = this->triangleCount; 226 this->pModelInfo.pTriangles = this->triangles; 227 this->pModelInfo.numNormals = this->normalCount; 228 this->pModelInfo.pNormals = this->normals->getArray(); 229 this->pModelInfo.numTexCoor = this->vTexture->getCount(); 230 this->pModelInfo.pTexCoor = this->vTexture->getArray(); 202 this->pModelInfo.pVertices = this->vertices.getArray(); 203 this->pModelInfo.pNormals = this->normals.getArray(); 204 this->pModelInfo.pTexCoor = this->vTexture.getArray(); 231 205 232 206 this->finalized = true; … … 234 208 235 209 /** 236 * rebuild the Model from the Information we got.210 * @brief rebuild the Model from the Information we got. 237 211 */ 238 212 void StaticModel::rebuild() … … 240 214 PRINTF(3)("Rebuilding Model '%s'\n", this->getName()); 241 215 this->finalize(); 242 243 216 } 244 217 … … 252 225 void StaticModel::draw () const 253 226 { 254 255 227 PRINTF(4)("drawing the 3D-Models\n"); 256 228 ModelGroup* tmpGroup = this->firstGroup; … … 262 234 } 263 235 264 265 /*const GLfloat* pVertices = NULL;266 const GLfloat* pNorm = NULL;267 268 glBegin(GL_TRIANGLES);269 for( int i = 0; i < this->triangleCount; ++i)270 {236 /* 237 const GLfloat* pVertices = NULL; 238 const GLfloat* pNorm = NULL; 239 240 glBegin(GL_TRIANGLES); 241 for( int i = 0; i < this->triangleCount; ++i) 242 { 271 243 //printf("int i = %i\n", i); 272 244 pNorm = &this->normals->getArray()[this->triangles[i].indexToNormals[0]]; … … 285 257 glVertex3f(pVertices[0], pVertices[1], pVertices[2]); 286 258 287 } 288 glEnd();*/ 289 } 290 291 /** 292 * Draws the Model number groupNumber 259 } 260 glEnd(); 261 */ 262 } 263 264 265 /** 266 * @brief Draws the Model number groupNumber 293 267 * @param groupNumber The number of the group that will be displayed. 294 295 296 */268 * 269 * It does this by just calling the List that must have been created earlier. 270 */ 297 271 void StaticModel::draw (int groupNumber) const 298 272 { 299 if ( groupNumber >= this->groupCount)273 if (unlikely(groupNumber >= this->groupCount)) 300 274 { 301 275 PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount); … … 318 292 PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getName()); 319 293 return; 320 321 } 322 323 /** 324 * Draws the Model with a specific groupName294 } 295 296 297 /** 298 * @brief Draws the Model with a specific groupName 325 299 * @param groupName The name of the group that will be displayed. 326 327 328 */300 * 301 * It does this by just calling the List that must have been created earlier. 302 */ 329 303 void StaticModel::draw (char* groupName) const 330 304 { … … 348 322 // INIT // 349 323 ////////// 350 /** 351 * deletes all the arrays 352 */ 353 bool StaticModel::deleteArrays() 354 { 355 if (this->vertices) 356 delete this->vertices; 357 if (this->vTexture) 358 delete this->vTexture; 359 if (this->normals) 360 delete this->normals; 361 if (this->triangles) 362 delete[] this->triangles; 363 364 this->vertices = NULL; 365 this->vTexture = NULL; 366 this->normals = NULL; 367 this->triangles = NULL; 368 this->triangleCount = 0; 369 } 370 371 /** 372 * finalizes an Model. 324 325 /** 326 * @brief finalizes an Model. 327 * 373 328 * This funcion is needed, to delete all the Lists, and arrays that are no more 374 329 * needed because they are already imported into openGL. … … 386 341 ////////// 387 342 /** 388 * adds a new Material to the Material List343 * @brief adds a new Material to the Material List 389 344 * @param material the Material to add 390 345 * @returns the added material … … 405 360 406 361 /** 407 * adds a new Material to the Material List362 * @brief adds a new Material to the Material List 408 363 * @param materialName the name of the Material to add 409 364 * @returns the added material 410 */365 */ 411 366 Material* StaticModel::addMaterial(const char* materialName) 412 367 { … … 421 376 422 377 /** 423 * finds a Material by its name and returns it378 * @brief finds a Material by its name and returns it 424 379 * @param materialName the Name of the material to search for. 425 380 * @returns the Material if found, NULL otherwise 426 */381 */ 427 382 Material* StaticModel::findMaterialByName(const char* materialName) 428 383 { … … 435 390 436 391 /** 437 * parses a group String392 * @brief parses a group String 438 393 * @param groupString the new Group to create 439 440 441 442 */394 * 395 * This function initializes a new Group. 396 * With it you should be able to create Models with more than one SubModel inside 397 */ 443 398 bool StaticModel::addGroup(const char* groupString) 444 399 { … … 459 414 460 415 /** 461 * parses a vertex-String416 * @brief parses a vertex-String 462 417 * @param vertexString The String that will be parsed. 463 464 If a vertex line is found this function will inject it into the vertex-Array465 */418 * 419 * If a vertex line is found this function will inject it into the vertex-Array 420 */ 466 421 bool StaticModel::addVertex (const char* vertexString) 467 422 { … … 470 425 float subbuffer3; 471 426 sscanf (vertexString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 472 this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor); 473 this->vertexCount++; 427 this->vertices.addEntry(subbuffer1*scaleFactor, 428 subbuffer2*scaleFactor, 429 subbuffer3*scaleFactor); 430 this->pModelInfo.numVertices++; 474 431 return true; 475 432 } 476 433 477 434 /** 478 * parses a vertex-String435 * @brief parses a vertex-String 479 436 * @param x the X-coordinate of the Vertex to add. 480 437 * @param y the Y-coordinate of the Vertex to add. 481 438 * @param z the Z-coordinate of the Vertex to add. 482 483 */ 439 */ 484 440 bool StaticModel::addVertex(float x, float y, float z) 485 441 { 486 442 PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z); 487 this->vertices->addEntry(x*scaleFactor, y*scaleFactor, z*scaleFactor); 488 this->vertexCount++; 443 this->vertices.addEntry(x*scaleFactor, 444 y*scaleFactor, 445 z*scaleFactor); 446 this->pModelInfo.numVertices++; 489 447 return true; 490 448 } 491 449 492 450 /** 493 * parses a vertexNormal-String451 * @brief parses a vertexNormal-String 494 452 * @param normalString The String that will be parsed. 495 496 497 */453 * 454 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 455 */ 498 456 bool StaticModel::addVertexNormal (const char* normalString) 499 457 { … … 502 460 float subbuffer3; 503 461 sscanf (normalString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 504 this->normals ->addEntry(subbuffer1, subbuffer2, subbuffer3);505 this-> normalCount++;462 this->normals.addEntry(subbuffer1, subbuffer2, subbuffer3); 463 this->pModelInfo.numNormals++; 506 464 return true; 507 465 } 508 466 509 467 /** 510 * adds a VertexNormal.468 * @brief adds a VertexNormal. 511 469 * @param x The x coordinate of the Normal. 512 470 * @param y The y coordinate of the Normal. 513 471 * @param z The z coordinate of the Normal. 514 515 516 */472 * 473 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 474 */ 517 475 bool StaticModel::addVertexNormal(float x, float y, float z) 518 476 { 519 477 PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z); 520 this->normals ->addEntry(x, y, z);521 this-> normalCount++;478 this->normals.addEntry(x, y, z); 479 this->pModelInfo.numNormals++; 522 480 return true; 523 481 } 524 482 525 483 /** 526 * parses a vertexTextureCoordinate-String484 * @brief parses a vertexTextureCoordinate-String 527 485 * @param vTextureString The String that will be parsed. 528 529 530 531 532 533 */486 * 487 * If a vertexTextureCoordinate line is found, 488 * this function will inject it into the vertexTexture-Array 489 * 490 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !! 491 */ 534 492 bool StaticModel::addVertexTexture (const char* vTextureString) 535 493 { … … 537 495 float subbuffer2; 538 496 sscanf (vTextureString, "%f %f", &subbuffer1, &subbuffer2); 539 this->vTexture ->addEntry(subbuffer1);540 this->vTexture ->addEntry(1 - subbuffer2);541 this-> texCoordCount++;497 this->vTexture.addEntry(subbuffer1); 498 this->vTexture.addEntry(1 - subbuffer2); 499 this->pModelInfo.numTexCoor++; 542 500 return true; 543 501 } 544 502 545 503 /** 546 * adds a Texture Coordinate504 * @brief adds a Texture Coordinate 547 505 * @param u The u coordinate of the TextureCoordinate. 548 506 * @param v The y coordinate of the TextureCoordinate. 549 550 If a TextureCoordinate line is found this function will inject it into the TextureCoordinate-Array 551 */ 507 * 508 * If a TextureCoordinate line is found this function will 509 * inject it into the TextureCoordinate-Array 510 */ 552 511 bool StaticModel::addVertexTexture(float u, float v) 553 512 { 554 513 PRINTF(5)("found vertex-Texture %f, %f\n", u, v); 555 this->vTexture ->addEntry(u);556 this->vTexture ->addEntry(v);557 this-> texCoordCount++;514 this->vTexture.addEntry(u); 515 this->vTexture.addEntry(v); 516 this->pModelInfo.numTexCoor++; 558 517 return true; 559 518 } 560 519 561 520 /** 562 * parses a face-string521 * @brief parses a face-string 563 522 * @param faceString The String that will be parsed. 564 565 If a face line is found this function will add it to the glList. 566 567 String is different from the argument addFace, in this that the first Vertex/Normal/Texcoord is 1 instead of 0 568 */ 523 * 524 * If a face line is found this function will add it to the glList. 525 * 526 * String is different from the argument addFace, 527 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0 528 */ 569 529 bool StaticModel::addFace (const char* faceString) 570 530 { … … 613 573 this->currentGroup->currentFace->vertexCount++; 614 574 } 615 575 616 576 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2; 617 577 this->faceCount += this->currentGroup->currentFace->vertexCount -2; … … 619 579 620 580 /** 621 * adds a new Face581 * @brief adds a new Face 622 582 * @param faceElemCount the number of Vertices to add to the Face. 623 583 * @param type The information Passed with each Vertex … … 663 623 664 624 if (this->currentGroup->faceCount == 0) 665 this->currentGroup->faceCount 625 this->currentGroup->faceCount++; 666 626 } 667 627 … … 678 638 679 639 if (this->currentGroup->faceCount == 0) 680 this->currentGroup->faceCount 681 } 682 683 /** 684 * A routine that is able to create normals.685 686 687 688 689 690 691 */640 this->currentGroup->faceCount++; 641 } 642 643 /** 644 * @brief A routine that is able to create normals. 645 * 646 * The algorithm does the following: 647 * 1. It calculates creates Vectors for each normale, and sets them to zero. 648 * 2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements 649 * 3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal. 650 * 4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array. 651 */ 692 652 bool StaticModel::buildVertexNormals () 693 653 { 694 654 PRINTF(4)("Normals are being calculated.\n"); 695 655 696 Vector* normArray = new Vector [vertices ->getCount()/3];697 for (int i=0; i<vertices ->getCount()/3;i++)656 Vector* normArray = new Vector [vertices.getCount()/3]; 657 for (int i=0; i<vertices.getCount()/3;i++) 698 658 normArray[i] = Vector(.0,.0,.0); 699 659 … … 705 665 706 666 ModelGroup* tmpGroup = firstGroup; 707 while (tmpGroup )667 while (tmpGroup != NULL) 708 668 { 709 669 ModelFace* tmpFace = tmpGroup->firstFace; 710 while (tmpFace )670 while (tmpFace != NULL) 711 671 { 712 if (tmpFace->firstElem )672 if (tmpFace->firstElem != NULL) 713 673 { 714 674 ModelFaceElement* firstElem = tmpFace->firstElem; … … 718 678 ModelFaceElement* lastElem; 719 679 // 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. 720 while (curElem )680 while (curElem != NULL) 721 681 { 722 682 prevElem = curElem; … … 732 692 curElem->normalNumber = curElem->vertexNumber; 733 693 734 curV = Vector (vertices->getArray()[curElem->vertexNumber*3], vertices->getArray()[curElem->vertexNumber*3+1], vertices->getArray()[curElem->vertexNumber*3+2]); 735 prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV; 736 nextV = Vector (vertices->getArray()[nextElem->vertexNumber*3], vertices->getArray()[nextElem->vertexNumber*3+1], vertices->getArray()[nextElem->vertexNumber*3+2]) - curV; 694 curV = Vector (this->vertices.getArray()[curElem->vertexNumber*3], 695 this->vertices.getArray()[curElem->vertexNumber*3+1], 696 this->vertices.getArray()[curElem->vertexNumber*3+2]); 697 698 prevV = Vector (this->vertices.getArray()[prevElem->vertexNumber*3], 699 this->vertices.getArray()[prevElem->vertexNumber*3+1], 700 this->vertices.getArray()[prevElem->vertexNumber*3+2]) - curV; 701 702 nextV = Vector (this->vertices.getArray()[nextElem->vertexNumber*3], 703 this->vertices.getArray()[nextElem->vertexNumber*3+1], 704 this->vertices.getArray()[nextElem->vertexNumber*3+2]) - curV; 737 705 normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV); 738 706 … … 746 714 } 747 715 748 for (int i=0; i < vertices->getCount()/3;i++)716 for (int i=0; i < this->vertices.getCount()/3;i++) 749 717 { 750 718 normArray[i].normalize(); … … 754 722 755 723 } 756 delete []normArray;724 delete[] normArray; 757 725 } 758 726 … … 766 734 { 767 735 // finalize the Arrays 768 this->vertices ->finalizeArray();769 this->vTexture ->finalizeArray();770 if (normals ->getCount() == 0) // vertices-Array must be built for this736 this->vertices.finalizeArray(); 737 this->vTexture.finalizeArray(); 738 if (normals.getCount() == 0) // vertices-Array must be built for this 771 739 this->buildVertexNormals(); 772 this->normals ->finalizeArray();740 this->normals.finalizeArray(); 773 741 774 742 this->currentGroup = this->firstGroup; … … 852 820 } 853 821 854 /**855 * reads and includes the Faces/Materials into the openGL state Machine856 */857 bool StaticModel::importToVertexArray()858 {859 // finalize the Arrays860 this->vertices->finalizeArray();861 this->vTexture->finalizeArray();862 if (normals->getCount() == 0) // vertices-Array must be built for this863 this->buildVertexNormals();864 this->normals->finalizeArray();865 866 this->currentGroup = this->firstGroup;867 glVertexPointer(3, GL_FLOAT, 0, this->vertices->getArray());868 glNormalPointer(3, 0, this->normals->getArray());869 glTexCoordPointer(2, GL_FLOAT, 0, this->vTexture->getArray());870 }871 872 873 822 874 823 /** … … 877 826 bool StaticModel::buildTriangleList() 878 827 { 879 if( unlikely(this-> triangles != NULL))828 if( unlikely(this->pModelInfo.pTriangles != NULL)) 880 829 return true; 881 830 /* make sure, that all the arrays are finalized */ 882 if( unlikely(!this->vertices ->isFinalized()))883 this->vertices ->finalizeArray();884 if( unlikely(!this->vTexture ->isFinalized()))885 this->vTexture ->finalizeArray();886 if( normals ->getCount() == 0) // vertices-Array must be built for this831 if( unlikely(!this->vertices.isFinalized())) 832 this->vertices.finalizeArray(); 833 if( unlikely(!this->vTexture.isFinalized())) 834 this->vTexture.finalizeArray(); 835 if( normals.getCount() == 0) // vertices-Array must be built for this 887 836 this->buildVertexNormals(); 888 if( unlikely(!this->normals ->isFinalized()))889 this->normals ->finalizeArray();837 if( unlikely(!this->normals.isFinalized())) 838 this->normals.finalizeArray(); 890 839 891 840 … … 896 845 /* count the number of triangles */ 897 846 /* now iterate through all groups and build up the triangle list */ 898 this->triangleCount = 0;899 847 this->currentGroup = this->firstGroup; 900 848 while( this->currentGroup != NULL) … … 907 855 if( tmpFace->vertexCount == 3) 908 856 { 909 ++this-> triangleCount;857 ++this->pModelInfo.numTriangles; 910 858 } /* if the polygon is a quad */ 911 859 else if( tmpFace->vertexCount == 4) 912 860 { 913 this-> triangleCount+= 2;861 this->pModelInfo.numTriangles += 2; 914 862 } 915 863 else if( tmpFace->vertexCount > 4) … … 923 871 } 924 872 925 PRINTF(3)("got %i triangles, %i vertices\n", this-> triangleCount, this->vertexCount);873 PRINTF(3)("got %i triangles, %i vertices\n", this->pModelInfo.numTriangles, this->pModelInfo.numVertices); 926 874 927 875 … … 929 877 930 878 /* allocate memory for the new triangle structures */ 931 if( (this-> triangles = new sTriangleExt[this->triangleCount]) == NULL)879 if( (this->pModelInfo.pTriangles = new sTriangleExt[this->pModelInfo.numTriangles]) == NULL) 932 880 { 933 881 PRINTF(1)("Could not allocate memory for triangle list\n"); … … 950 898 for( int j = 0; j < 3; ++j) 951 899 { 952 this-> triangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3;953 this-> triangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3;954 this-> triangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3;900 this->pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3; 901 this->pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3; 902 this->pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3; 955 903 tmpElem = tmpElem->next; 956 904 } … … 960 908 { 961 909 962 this-> triangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;963 this-> triangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;964 this-> triangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;965 966 this-> triangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;967 this-> triangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;968 this-> triangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;910 this->pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3; 911 this->pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3; 912 this->pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3; 913 914 this->pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3; 915 this->pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3; 916 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3; 969 917 tmpElem = tmpElem->next; 970 918 971 this-> triangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;972 this-> triangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;973 this-> triangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;919 this->pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3; 920 this->pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3; 921 this->pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3; 974 922 tmpElem = tmpElem->next; 975 923 976 this-> triangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;977 this-> triangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;978 this-> triangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;979 980 this-> triangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;981 this-> triangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;982 this-> triangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;924 this->pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3; 925 this->pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3; 926 this->pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3; 927 928 this->pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3; 929 this->pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3; 930 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3; 983 931 tmpElem = tmpElem->next; 984 932 985 this-> triangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;986 this-> triangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;987 this-> triangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;933 this->pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3; 934 this->pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3; 935 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3; 988 936 989 937 index += 2; … … 1013 961 if (elem->texCoordNumber != -1) 1014 962 { 1015 if (likely(elem->texCoordNumber < this-> texCoordCount))1016 glTexCoord2fv(this->vTexture ->getArray() + elem->texCoordNumber * 2);963 if (likely(elem->texCoordNumber < this->pModelInfo.numTexCoor)) 964 glTexCoord2fv(this->vTexture.getArray() + elem->texCoordNumber * 2); 1017 965 else 1018 966 PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n", 1019 elem->texCoordNumber, this-> texCoordCount);967 elem->texCoordNumber, this->pModelInfo.numTexCoor); 1020 968 } 1021 969 if (elem->normalNumber != -1) 1022 970 { 1023 if (likely(elem->normalNumber < this-> normalCount))1024 glNormal3fv(this->normals ->getArray() + elem->normalNumber * 3);971 if (likely(elem->normalNumber < this->pModelInfo.numNormals)) 972 glNormal3fv(this->normals.getArray() + elem->normalNumber * 3); 1025 973 else 1026 974 PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete", 1027 elem->normalNumber, this-> normalCount);975 elem->normalNumber, this->pModelInfo.numNormals); 1028 976 } 1029 977 if (elem->vertexNumber != -1) 1030 978 { 1031 if (likely(elem->vertexNumber < this-> vertexCount))1032 glVertex3fv(this->vertices ->getArray() + elem->vertexNumber * 3);979 if (likely(elem->vertexNumber < this->pModelInfo.numVertices)) 980 glVertex3fv(this->vertices.getArray() + elem->vertexNumber * 3); 1033 981 else 1034 982 PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete", 1035 elem->vertexNumber, this-> vertexCount);983 elem->vertexNumber, this->pModelInfo.numVertices); 1036 984 } 1037 985 -
trunk/src/lib/graphics/importer/static_model.h
r6022 r6031 16 16 // FORWARD DECLARATION // 17 17 template<class T> class tArray; 18 19 20 //! an enumerator fot the different Model Types.21 /**22 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.23 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.24 * @todo implement this stuff25 */26 typedef enum MODEL_TYPE {27 MODEL_DISPLAY_LIST,28 MODEL_VERTEX_ARRAY29 };30 31 18 32 19 // definition of different modes for setting up Faces … … 111 98 { 112 99 public: 113 StaticModel(const char* modelName = NULL , MODEL_TYPE type = MODEL_DISPLAY_LIST);100 StaticModel(const char* modelName = NULL); 114 101 virtual ~StaticModel(); 115 102 … … 120 107 void rebuild(); 121 108 122 /** @returns Count of the Models (Groups) in this File */123 inline int getGroupCount() const { return this->groupCount; };124 125 /** @returns a Pointer to the Vertex-Array, if it was deleted it returns NULL */126 inline const GLfloat* getVertexArray() const { return this->vertices->getArray(); };127 /** @returns the VertexCount of this Model */128 inline unsigned int getVertexCount() const { return this->vertexCount; };129 130 /** @returns a Pointer to the Normals-Array, if it was deleted it returns NULL */131 inline const GLfloat* getNormalsArray() const { return this->normals->getArray(); };132 /** @returns the NormalsCount of this Model */133 inline unsigned int getNormalsCount() const { return this->normalCount; };134 135 /** @returns a Pointer to the TexCoord-Array, if it was deleted it returns NULL */136 inline const GLfloat* getTexCoordArray() const { return this->vTexture->getArray(); };137 /** @returns the TexCoord-Count of this Model */138 inline unsigned int getTexCoordCount() const { return this->texCoordCount; };139 140 /** @returns the Count of Faces of this Model */141 inline unsigned int getFaceCount() const { return this->faceCount; };142 143 144 109 Material* addMaterial(Material* material); 145 110 Material* addMaterial(const char* materialName); 146 111 147 112 bool addGroup(const char* groupString); 113 148 114 bool addVertex(const char* vertexString); 149 115 bool addVertex(float x, float y, float z); 116 150 117 bool addFace(const char* faceString); 151 118 bool addFace(int faceElemCount, VERTEX_FORMAT type, ...); 119 152 120 bool addVertexNormal(const char* normalString); 153 121 bool addVertexNormal(float x, float y, float z); 122 154 123 bool addVertexTexture(const char* vTextureString); 155 124 bool addVertexTexture(float u, float v); 125 156 126 bool setMaterial(const char* mtlString); 157 127 bool setMaterial(Material* mtl); 128 158 129 void finalize(); 159 130 … … 163 134 164 135 Material* findMaterialByName(const char* materialName); 165 166 136 167 137 protected: … … 173 143 bool importToDisplayList(); 174 144 bool buildTriangleList(); 145 175 146 bool addGLElement(ModelFaceElement* elem); 176 147 177 bool importToVertexArray();178 179 bool deleteArrays();180 148 bool cleanup(); 181 149 182 150 private: 183 MODEL_TYPE type; //!< A type for the Model184 151 bool finalized; //!< Sets the Object to be finalized. 185 152 186 unsigned int vertexCount; //!< A modelwide Counter for vertices.187 unsigned int normalCount; //!< A modelwide Counter for the normals.188 unsigned int texCoordCount; //!< A modelwide Counter for the texCoord.189 153 unsigned int faceCount; //!< A modelwide Counter for the faces 190 unsigned int triangleCount; //!< Number of triangles >= faceCount 191 tArray<GLfloat>* vertices; //!< The Array that handles the Vertices. 192 tArray<GLfloat>* normals; //!< The Array that handles the Normals. 193 tArray<GLfloat>* vTexture; //!< The Array that handles the VertexTextureCoordinates. 194 sTriangleExt* triangles; //!< The Array of triangles in the model.h style 154 155 tArray<GLfloat> vertices; //!< The Array that handles the Vertices. 156 tArray<GLfloat> normals; //!< The Array that handles the Normals. 157 tArray<GLfloat> vTexture; //!< The Array that handles the VertexTextureCoordinates. 195 158 196 159 ModelGroup* firstGroup; //!< The first of all groups.
Note: See TracChangeset
for help on using the changeset viewer.