Changeset 9829 in orxonox.OLD for branches/new_class_id/src/lib/graphics
- Timestamp:
- Sep 26, 2006, 1:09:35 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/graphics/importer
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/graphics/importer/Makefile.am
r9824 r9829 11 11 grid.cc \ 12 12 static_model.cc \ 13 static_model_data.cc \ 13 14 objModel.cc \ 14 15 primitive_model.cc \ … … 57 58 grid.h \ 58 59 static_model.h \ 60 static_model_data.h \ 59 61 objModel.h \ 60 62 primitive_model.h \ -
branches/new_class_id/src/lib/graphics/importer/static_model_data.cc
r9827 r9829 18 18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER 19 19 20 #include "static_model .h"20 #include "static_model_data.h" 21 21 22 22 #include "debug.h" … … 134 134 /// MODEL /// 135 135 ///////////// 136 ObjectListDefinition(StaticModel );136 ObjectListDefinition(StaticModelData); 137 137 138 138 /** … … 141 141 * assigns it a Name and a Type 142 142 */ 143 StaticModel ::StaticModel(const std::string& modelName)144 { 145 this->registerObject(this, StaticModel ::_objectList);143 StaticModelData::StaticModelData(const std::string& modelName) 144 { 145 this->registerObject(this, StaticModelData::_objectList); 146 146 PRINTF(4)("new 3D-Model is being created\n"); 147 147 this->setName(modelName); … … 162 162 * Looks if any from model allocated space is still in use, and if so deleted it. 163 163 */ 164 StaticModel ::~StaticModel()164 StaticModelData::~StaticModelData() 165 165 { 166 166 PRINTF(4)("Deleting Model "); … … 189 189 delete (*modMat); 190 190 } 191 192 // mark this stuff as beeing deleted193 this->pModelInfo.pVertices = NULL;194 this->pModelInfo.pNormals = NULL;195 this->pModelInfo.pTexCoor = NULL;196 191 } 197 192 … … 199 194 * @brief Finalizes an Object. This can be done outside of the Class. 200 195 */ 201 void StaticModel ::finalize()196 void StaticModelData::finalize() 202 197 { 203 198 // this creates the display List. … … 205 200 this->buildTriangleList(); 206 201 207 // write out the modelInfo data used for the collision detection!208 this->pModelInfo.pVertices = &this->vertices[0];209 this->pModelInfo.pNormals = &this->normals[0];210 this->pModelInfo.pTexCoor = &this->vTexture[0];211 212 202 this->finalized = true; 213 203 } … … 216 206 * @brief rebuild the Model from the Information we got. 217 207 */ 218 void StaticModel ::rebuild()208 void StaticModelData::rebuild() 219 209 { 220 210 PRINTF(3)("Rebuilding Model '%s'\n", this->getCName()); … … 230 220 * It does this by just calling the Lists that must have been created earlier. 231 221 */ 232 void StaticModel ::draw () const222 void StaticModelData::draw () const 233 223 { 234 224 PRINTF(4)("drawing the 3D-Models\n"); … … 249 239 * It does this by just calling the List that must have been created earlier. 250 240 */ 251 void StaticModel ::draw (int groupNumber) const241 void StaticModelData::draw (int groupNumber) const 252 242 { 253 243 if (unlikely(groupNumber >= this->groupCount)) … … 281 271 * It does this by just calling the List that must have been created earlier. 282 272 */ 283 void StaticModel ::draw (const std::string& groupName) const273 void StaticModelData::draw (const std::string& groupName) const 284 274 { 285 275 PRINTF(4)("drawing the requested 3D-Models if found.\n"); … … 310 300 * This will be applied at the end of the importing Process. 311 301 */ 312 bool StaticModel ::cleanup()302 bool StaticModelData::cleanup() 313 303 { 314 304 PRINTF(4)("cleaning up the 3D-Model to save Memory.\n"); … … 328 318 * with this option set the Materials will not be deleted with the Model. 329 319 */ 330 Material* StaticModel ::addMaterial(Material* material)320 Material* StaticModelData::addMaterial(Material* material) 331 321 { 332 322 if (material == NULL) … … 344 334 * @returns the added material 345 335 */ 346 Material* StaticModel ::addMaterial(const std::string& materialName)336 Material* StaticModelData::addMaterial(const std::string& materialName) 347 337 { 348 338 ModelMaterial* modMat = new ModelMaterial; … … 360 350 * @returns the Material if found, NULL otherwise 361 351 */ 362 Material* StaticModel ::findMaterialByName(const std::string& materialName)352 Material* StaticModelData::findMaterialByName(const std::string& materialName) 363 353 { 364 354 std::list<ModelMaterial*>::iterator modMat; … … 376 366 * With it you should be able to create Models with more than one SubModel inside 377 367 */ 378 bool StaticModel ::addGroup(const std::string& groupString)368 bool StaticModelData::addGroup(const std::string& groupString) 379 369 { 380 370 PRINTF(5)("Read Group: %s.\n", groupString.c_str()); … … 399 389 * If a vertex line is found this function will inject it into the vertex-Array 400 390 */ 401 bool StaticModel ::addVertex (const std::string& vertexString)391 bool StaticModelData::addVertex (const std::string& vertexString) 402 392 { 403 393 float subbuffer1; … … 408 398 this->vertices.push_back(subbuffer2*scaleFactor); 409 399 this->vertices.push_back(subbuffer3*scaleFactor); 410 this->pModelInfo.numVertices++;411 400 return true; 412 401 } … … 418 407 * @param z the Z-coordinate of the Vertex to add. 419 408 */ 420 bool StaticModel ::addVertex(float x, float y, float z)409 bool StaticModelData::addVertex(float x, float y, float z) 421 410 { 422 411 PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z); … … 424 413 this->vertices.push_back(y*scaleFactor); 425 414 this->vertices.push_back(z*scaleFactor); 426 this->pModelInfo.numVertices++;427 415 return true; 428 416 } … … 434 422 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 435 423 */ 436 bool StaticModel ::addVertexNormal (const std::string& normalString)424 bool StaticModelData::addVertexNormal (const std::string& normalString) 437 425 { 438 426 float subbuffer1; … … 443 431 this->normals.push_back(subbuffer2); 444 432 this->normals.push_back(subbuffer3); 445 this->pModelInfo.numNormals++;446 433 return true; 447 434 } … … 455 442 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 456 443 */ 457 bool StaticModel ::addVertexNormal(float x, float y, float z)444 bool StaticModelData::addVertexNormal(float x, float y, float z) 458 445 { 459 446 PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z); … … 461 448 this->normals.push_back(y); 462 449 this->normals.push_back(z); 463 this->pModelInfo.numNormals++;464 450 return true; 465 451 } … … 474 460 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !! 475 461 */ 476 bool StaticModel ::addVertexTexture (const std::string& vTextureString)462 bool StaticModelData::addVertexTexture (const std::string& vTextureString) 477 463 { 478 464 float subbuffer1; … … 481 467 this->vTexture.push_back(subbuffer1); 482 468 this->vTexture.push_back(1 - subbuffer2); 483 this->pModelInfo.numTexCoor++;484 469 return true; 485 470 } … … 493 478 * inject it into the TextureCoordinate-Array 494 479 */ 495 bool StaticModel ::addVertexTexture(float u, float v)480 bool StaticModelData::addVertexTexture(float u, float v) 496 481 { 497 482 PRINTF(5)("found vertex-Texture %f, %f\n", u, v); 498 483 this->vTexture.push_back(u); 499 484 this->vTexture.push_back(v); 500 this->pModelInfo.numTexCoor++;501 485 return true; 502 486 } … … 513 497 * @TODO make it std::string conform 514 498 */ 515 bool StaticModel ::addFace (const std::string& faceStringInput)499 bool StaticModelData::addFace (const std::string& faceStringInput) 516 500 { 517 501 const char* faceString = faceStringInput.c_str(); … … 571 555 * @param type The information Passed with each Vertex 572 556 */ 573 bool StaticModel ::addFace(int faceElemCount, VERTEX_FORMAT type, ...)557 bool StaticModelData::addFace(int faceElemCount, VERTEX_FORMAT type, ...) 574 558 { 575 559 if (this->currentGroup->faceCount > 0) … … 604 588 * @param matString the Material that will be set. 605 589 */ 606 bool StaticModel ::setMaterial(const std::string& matString)590 bool StaticModelData::setMaterial(const std::string& matString) 607 591 { 608 592 if (this->currentGroup->faceCount > 0) … … 620 604 * @param mtl the Material that will be set. 621 605 */ 622 bool StaticModel ::setMaterial(Material* mtl)606 bool StaticModelData::setMaterial(Material* mtl) 623 607 { 624 608 if (this->currentGroup->faceCount > 0) … … 641 625 * 4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array. 642 626 */ 643 bool StaticModel ::buildVertexNormals ()627 bool StaticModelData::buildVertexNormals () 644 628 { 645 629 PRINTF(4)("Normals are being calculated.\n"); … … 721 705 * reads and includes the Faces/Materials into the openGL state Machine 722 706 */ 723 bool StaticModel ::importToDisplayList()707 bool StaticModelData::importToDisplayList() 724 708 { 725 709 // finalize the Arrays … … 811 795 * builds an array of triangles, that can later on be used for obb separation and octree separation 812 796 */ 813 bool StaticModel ::buildTriangleList()814 { 815 if( unlikely( this->pModelInfo.pTriangles != NULL))797 bool StaticModelData::buildTriangleList() 798 { 799 if( unlikely(!this->triangles.empty())) 816 800 return true; 817 801 /* make sure, that all the arrays are finalized */ … … 823 807 ModelFace* tmpFace; //!< the temporary face referece 824 808 809 unsigned int numTriangles = 0; 825 810 bool warned = false; 826 827 this->pModelInfo.numTriangles = 0;828 811 829 812 /* count the number of triangles */ … … 836 819 { 837 820 /* if its a triangle just add it to the list */ 838 if( tmpFace->vertexCount == 3){ 839 ++this->pModelInfo.numTriangles; 821 if( tmpFace->vertexCount == 3) 822 { 823 ++numTriangles; 840 824 } /* if the polygon is a quad */ 841 else if( tmpFace->vertexCount == 4) { 842 this->pModelInfo.numTriangles += 2; 825 else if( tmpFace->vertexCount == 4) 826 { 827 numTriangles += 2; 843 828 } 844 else if( tmpFace->vertexCount > 4) { 845 if (!warned) { 829 else if( tmpFace->vertexCount > 4) 830 { 831 if (!warned) 832 { 846 833 PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getCName()); 847 834 warned = true; … … 853 840 } 854 841 855 PRINTF(3)("got %i triangles, %i vertices\n", this->pModelInfo.numTriangles, this->pModelInfo.numVertices);842 PRINTF(3)("got %i triangles, %i vertices\n", numTriangles, this->vertices.size()); 856 843 857 844 … … 859 846 860 847 /* allocate memory for the new triangle structures */ 861 if( (this->pModelInfo.pTriangles = new sTriangleExt[this->pModelInfo.numTriangles]) == NULL) 862 { 863 PRINTF(1)("Could not allocate memory for triangle list\n"); 864 return false; 865 } 848 this->triangles.reserve(numTriangles); 866 849 867 850 /* now iterate through all groups and build up the triangle list */ … … 879 862 for( int j = 0; j < 3; ++j) 880 863 { 881 this-> pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3 ;882 this-> pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3 ;883 this-> pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3 ;864 this->triangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3 ; 865 this->triangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3 ; 866 this->triangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3 ; 884 867 tmpElem = tmpElem->next; 885 868 … … 890 873 { 891 874 892 this-> pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;893 this-> pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;894 this-> pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;895 896 this-> pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;897 this-> pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;898 this-> pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;875 this->triangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3; 876 this->triangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3; 877 this->triangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3; 878 879 this->triangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3; 880 this->triangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3; 881 this->triangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3; 899 882 tmpElem = tmpElem->next; 900 883 901 this-> pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;902 this-> pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;903 this-> pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;884 this->triangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3; 885 this->triangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3; 886 this->triangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3; 904 887 tmpElem = tmpElem->next; 905 888 906 this-> pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;907 this-> pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;908 this-> pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;909 910 this-> pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;911 this-> pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;912 this-> pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;889 this->triangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3; 890 this->triangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3; 891 this->triangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3; 892 893 this->triangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3; 894 this->triangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3; 895 this->triangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3; 913 896 tmpElem = tmpElem->next; 914 897 915 this-> pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;916 this-> pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;917 this-> pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;898 this->triangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3; 899 this->triangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3; 900 this->triangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3; 918 901 919 902 index += 2; … … 937 920 merging this information, the face will be drawn. 938 921 */ 939 bool StaticModel ::addGLElement (ModelFaceElement* elem)922 bool StaticModelData::addGLElement (ModelFaceElement* elem) 940 923 { 941 924 PRINTF(5)("importing grafical Element to openGL.\n"); … … 943 926 if (elem->texCoordNumber > -1) 944 927 { 945 if (likely((unsigned int)elem->texCoordNumber < this-> pModelInfo.numTexCoor))928 if (likely((unsigned int)elem->texCoordNumber < this->vTexture.size())) 946 929 glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2); 947 930 else 948 931 PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n", 949 elem->texCoordNumber, this-> pModelInfo.numTexCoor);932 elem->texCoordNumber, this->vTexture.size()); 950 933 } 951 934 if (elem->normalNumber > -1) 952 935 { 953 if (likely((unsigned int)elem->normalNumber < this-> pModelInfo.numNormals))936 if (likely((unsigned int)elem->normalNumber < this->normals.size())) 954 937 glNormal3fv(&this->normals[0] + elem->normalNumber * 3); 955 938 else 956 939 PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete", 957 elem->normalNumber, this-> pModelInfo.numNormals);940 elem->normalNumber, this->normals.size()); 958 941 } 959 942 if (elem->vertexNumber > -1) 960 943 { 961 if (likely((unsigned int)elem->vertexNumber < this-> pModelInfo.numVertices))944 if (likely((unsigned int)elem->vertexNumber < this->vertices.size())) 962 945 glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3); 963 946 else 964 947 PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete", 965 elem->vertexNumber, this-> pModelInfo.numVertices);948 elem->vertexNumber, this->vertices.size()); 966 949 } 967 950 … … 974 957 This will inject a Cube, because this is the most basic model. 975 958 */ 976 void StaticModel ::cubeModel()959 void StaticModelData::cubeModel() 977 960 { 978 961 this->addVertex (-0.5, -0.5, 0.5); -
branches/new_class_id/src/lib/graphics/importer/static_model_data.h
r9827 r9829 90 90 * All the objects are rendered with glLists 91 91 */ 92 class StaticModel : public Model92 class StaticModelData : public BaseObject 93 93 { 94 ObjectListDeclaration(StaticModel );94 ObjectListDeclaration(StaticModelData); 95 95 public: 96 StaticModel (const std::string& modelName = "");97 virtual ~StaticModel ();96 StaticModelData(const std::string& modelName = ""); 97 virtual ~StaticModelData(); 98 98 99 99 virtual void draw() const; … … 153 153 std::vector<GLfloat> vTexture; //!< The Array that handles the VertexTextureCoordinates. 154 154 155 std::vector<sTriangleExt> triangles; //!< The Triangles if built. 156 155 157 ModelGroup* firstGroup; //!< The first of all groups. 156 158 ModelGroup* currentGroup; //!< The currentGroup. this is the one we will work with.
Note: See TracChangeset
for help on using the changeset viewer.