Changeset 9869 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 29 edited
- 8 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/Makefile.am
r8724 r9869 4 4 noinst_LIBRARIES = libORXimporter.a libtc.a 5 5 6 libORXimporter_a_SOURCES = model.cc \ 7 interactive_model.cc \ 8 md_model_structure.cc \ 9 vertex_array_model.cc \ 10 grid.cc \ 11 static_model.cc \ 12 objModel.cc \ 13 primitive_model.cc \ 14 height_map.cc \ 15 bsp_manager.cc \ 16 bsp_file.cc \ 17 bsp_tree_node.cc \ 18 bsp_tree_leaf.cc \ 19 \ 20 material.cc \ 21 texture.cc \ 22 texture_data.cc \ 23 texture_sequence.cc \ 24 media_container.cc \ 25 movie_player.cc \ 26 \ 27 bsp_manager.cc \ 28 bsp_file.cc \ 29 bsp_tree_node.cc \ 30 bsp_tree_leaf.cc \ 31 \ 32 md2/md2Model.cc \ 33 \ 34 md3/md3_model.cc \ 35 md3/md3_animation.cc \ 36 md3/md3_animation_cfg.cc \ 37 md3/md3_bone_frame.cc \ 38 md3/md3_mesh.cc \ 39 md3/md3_data.cc \ 40 md3/md3_tag.cc 6 libORXimporter_a_SOURCES = \ 7 model.cc \ 8 interactive_model.cc \ 9 md_model_structure.cc \ 10 vertex_array_model.cc \ 11 grid.cc \ 12 static_model.cc \ 13 static_model_data.cc \ 14 objModel.cc \ 15 resource_obj.cc \ 16 primitive_model.cc \ 17 height_map.cc \ 18 bsp_manager.cc \ 19 bsp_file.cc \ 20 bsp_tree_node.cc \ 21 bsp_tree_leaf.cc \ 22 \ 23 material.cc \ 24 texture.cc \ 25 texture_data.cc \ 26 resource_texture.cc \ 27 texture_sequence.cc \ 28 media_container.cc \ 29 movie_player.cc \ 30 \ 31 bsp_manager.cc \ 32 bsp_file.cc \ 33 bsp_tree_node.cc \ 34 bsp_tree_leaf.cc \ 35 \ 36 md2/md2Model.cc \ 37 md2/resource_md2.cc 38 # \ 39 md3/md3_model.cc \ 40 md3/md3_animation.cc \ 41 md3/md3_animation_cfg.cc \ 42 md3/md3_bone_frame.cc \ 43 md3/md3_mesh.cc \ 44 md3/md3_data.cc \ 45 md3/md3_tag.cc 41 46 42 47 … … 54 59 grid.h \ 55 60 static_model.h \ 61 static_model_data.h \ 56 62 objModel.h \ 63 resource_obj.h \ 57 64 primitive_model.h \ 58 65 anorms.h \ … … 63 70 texture.h \ 64 71 texture_data.h \ 72 resource_texture.h \ 65 73 texture_sequence.h \ 66 74 \ … … 74 82 \ 75 83 md2/md2Model.h \ 84 md2/resource_md2.h \ 76 85 \ 77 86 md3/md3_model.h \ -
trunk/src/lib/graphics/importer/bsp_file.cc
r9406 r9869 466 466 PRINTF(4)("BSP FILE: Name %s . \n", fileName); 467 467 468 absFileName = Resource Manager::getFullName(fileName);468 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 469 469 470 470 if(File(absFileName).exists()) { … … 481 481 strncat (fileName, ext, strlen(fileName)); 482 482 483 absFileName = Resource Manager::getFullName(fileName);483 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 484 484 485 485 if(File(absFileName).exists()) { … … 496 496 strncat (fileName, ext, strlen(fileName)); 497 497 498 absFileName = Resource Manager::getFullName(fileName);498 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 499 499 500 500 if(File(absFileName).exists()) { … … 511 511 strncat (fileName, ext, strlen(fileName)); 512 512 513 absFileName = Resource Manager::getFullName(fileName);513 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 514 514 515 515 if(File(absFileName).exists()) { … … 524 524 strcpy(ext, ".TGA"); 525 525 strncat (fileName, ext, strlen(fileName)); 526 absFileName = Resource Manager::getFullName(fileName);526 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 527 527 528 528 if(File(absFileName).exists()/*stat( absFileName.c_str() , &results) == 0*/) { … … 537 537 strcpy(ext, ".jpg"); 538 538 strncat (fileName, ext, strlen(fileName)); 539 absFileName = Resource Manager::getFullName(fileName);539 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 540 540 if(File(absFileName).exists()) { 541 541 PRINTF(4)("BSP FILE: gefunden . \n"); … … 551 551 strcpy(ext, ".JPG"); 552 552 strncat (fileName, ext, strlen(fileName)); 553 absFileName = Resource Manager::getFullName(fileName);553 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 554 554 if(File(absFileName).exists()) { 555 555 PRINTF(4)("BSP FILE: gefunden . \n"); … … 566 566 strcpy(ext, ".bmp"); 567 567 strncat (fileName, ext, strlen(fileName)); 568 absFileName = Resource Manager::getFullName(fileName);568 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 569 569 570 570 if(File(absFileName).exists()) { … … 580 580 strcpy(ext, ".BMP"); 581 581 strncat (fileName, ext, strlen(fileName)); 582 absFileName = Resource Manager::getFullName(fileName);582 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 583 583 584 584 if(File(absFileName).exists()) { … … 611 611 this->testSurf = NULL; 612 612 613 this->testSurf = IMG_Load(Resource Manager::getFullName(mat).c_str());613 this->testSurf = IMG_Load(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(mat).c_str()); 614 614 if(this->testSurf != NULL) { 615 615 if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; -
trunk/src/lib/graphics/importer/bsp_manager.cc
r9235 r9869 33 33 #include "world_entities/player.h" 34 34 #include "world_entities/playable.h" 35 #include "util/loading/resource_manager.h" 35 36 36 // STL Containers 37 37 #include <vector> … … 41 41 #include "world_entity.h" 42 42 43 #include "util/loading/resource_manager.h" 43 44 #include "util/loading/load_param.h" 44 45 #include "util/loading/factory.h" … … 91 92 this->bspFile = new BspFile(); 92 93 this->bspFile->scale = scale; 93 if(this->bspFile->read(Resource Manager::getFullName(fileName).c_str()) == -1)94 if(this->bspFile->read(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName).c_str()) == -1) 94 95 return -1; 95 96 … … 1376 1377 if( this->outputFraction == 1.0f) // No collision Detected 1377 1378 { 1378 if( this->outputAllSolid ) 1379 if( this->outputAllSolid ) 1379 1380 { 1380 1381 this->collPlane = new plane; -
trunk/src/lib/graphics/importer/height_map.cc
r8316 r9869 22 22 #include "p_node.h" 23 23 #include "state.h" 24 #include "util/loading/resource_manager.h"25 24 #include "debug.h" 26 25 … … 327 326 328 327 328 ObjectListDefinition(HeightMap); 329 329 330 330 … … 413 413 void HeightMap::init(const std::string& heightMapName) 414 414 { 415 this-> setClassID(CL_HEIGHT_MAP, "HeightMap");415 this->registerObject(this, HeightMap::_objectList); 416 416 417 417 this->shiftX = 0; -
trunk/src/lib/graphics/importer/height_map.h
r7526 r9869 29 29 30 30 class SDL_Surface; 31 class Vector;32 31 class Material; 33 class PNode;34 32 class Texture; 35 33 class HeightMap; … … 70 68 71 69 70 72 71 //!< the height map representation itself 73 72 class HeightMap : public VertexArrayModel 74 73 { 74 ObjectListDeclaration(HeightMap); 75 75 friend class Tile; 76 76 -
trunk/src/lib/graphics/importer/interactive_model.cc
r9406 r9869 22 22 23 23 24 ObjectListDefinition(InteractiveModel); 25 24 26 /** 25 27 * standard constructor … … 28 30 InteractiveModel::InteractiveModel() 29 31 { 30 this-> setClassID(CL_INTERACTIVE_MODEL, "InteractiveModel");32 this->registerObject(this, InteractiveModel::_objectList); 31 33 } 32 34 -
trunk/src/lib/graphics/importer/interactive_model.h
r9003 r9869 30 30 class InteractiveModel : public Model 31 31 { 32 ObjectListDeclaration(InteractiveModel); 32 33 public: 33 34 InteractiveModel(); … … 38 39 virtual void setAnimation(int animNum, int playbackMode = 0) = 0; 39 40 virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback) {} 40 virtual int getAnimation() = 0;41 virtual int getAnimation() const = 0; 41 42 42 43 virtual bool isAnimationFinished() { return false; } -
trunk/src/lib/graphics/importer/material.cc
r9406 r9869 25 25 #include "loading/load_param.h" 26 26 27 #include "util/loading/resource_manager.h" 27 #include "resource_texture.h" 28 29 ObjectListDefinition(Material); 28 30 29 31 /** … … 33 35 Material::Material (const std::string& mtlName) 34 36 { 35 this-> setClassID(CL_MATERIAL, "Material");37 this->registerObject(this, Material::_objectList); 36 38 37 39 this->setIllum(3); … … 90 92 PRINTF(5)("delete Material %s.\n", this->getCName()); 91 93 92 if (this->ambientTexture != NULL)93 ResourceManager::getInstance()->unload(this->ambientTexture);94 if (this->specularTexture != NULL)95 ResourceManager::getInstance()->unload(this->specularTexture);96 97 94 if (this == Material::selectedMaterial) 98 95 Material::selectedMaterial = NULL; … … 101 98 102 99 const Material* Material::selectedMaterial = NULL; 103 104 105 /// TODO FIX THIS106 // Material& Material::operator=(const Material& m)107 // {108 // this->setIllum(m.illumModel);109 // this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]);110 // this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]);111 // this->setSpecular(m.specular[0],m.specular[1],m.specular[2]);112 // this->setShininess(m.shininess);113 // this->setTransparency(m.transparency);114 //115 // if (this->diffuseTexture != NULL)116 // ResourceManager::getInstance()->unload(this->diffuseTexture);117 // if (m.diffuseTexture != NULL)118 // this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);119 // this->ambientTexture = NULL; /// FIXME120 // this->specularTexture = NULL; /// FIXME121 //122 // this->setName(m.getName());123 // }124 125 126 100 127 101 /** … … 288 262 289 263 290 291 /**292 * @brief Adds a Texture Path to the List of already existing Paths293 * @param pathName The Path to add.294 */295 void Material::addTexturePath(const std::string& pathName)296 {297 ResourceManager::getInstance()->addImageDir(pathName);298 }299 300 // MAPPING //301 302 303 264 /** 304 265 * @brief Sets the Diffuse map of this Texture. … … 322 283 * @param textureNumber The Texture-Number from 0 to GL_MAX_TEXTURE_UNITS 323 284 */ 324 void Material::setDiffuseMap(const TextureData Pointer& textureDataPointer, unsigned int textureNumber)285 void Material::setDiffuseMap(const TextureData::Pointer& textureDataPointer, unsigned int textureNumber) 325 286 { 326 287 assert(textureNumber < Material::getMaxTextureUnits()); … … 349 310 if (!dMap.empty()) 350 311 { 351 Texture* tex = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target)); 352 if (tex != NULL) 353 this->textures[textureNumber] = *tex; 312 this->textures[textureNumber] = ResourceTexture(dMap); 313 //dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target)); 314 /* if (tex != NULL) 315 this->textures[textureNumber] = tex; 354 316 else 355 this->textures[textureNumber] = Texture(); 317 this->textures[textureNumber] = Texture();*/ 356 318 } 357 319 else -
trunk/src/lib/graphics/importer/material.h
r8761 r9869 24 24 class Material : public BaseObject 25 25 { 26 ObjectListDeclaration(Material); 26 27 public: 27 28 Material (const std::string& mtlName = ""); 28 29 virtual ~Material (); 29 30 31 Material& operator=(const Material& material); 32 30 33 void loadParams(const TiXmlElement* root); 31 32 Material& operator=(const Material& material);33 34 34 35 bool select () const; … … 53 54 // MAPPING // 54 55 void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0); 55 void setDiffuseMap(const TextureData Pointer& texturePointer, unsigned int textureNumber = 0);56 void setDiffuseMap(const TextureData::Pointer& texturePointer, unsigned int textureNumber = 0); 56 57 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 57 58 void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); … … 65 66 66 67 const Texture& diffuseTexture(unsigned int i = 0) const { return this->textures[i]; }; 67 68 static void addTexturePath(const std::string& pathName);69 68 70 69 static const std::string& blendFuncToString(GLenum blendFunc); -
trunk/src/lib/graphics/importer/md2/md2Model.cc
r9406 r9869 19 19 20 20 #include "debug.h" 21 #include " util/loading/resource_manager.h"22 23 24 21 #include "resource_md2.h" 22 23 24 ObjectListDefinition(MD2Model); 25 25 26 26 //! the model anorms 27 27 sVec3D MD2Model::anorms[NUM_VERTEX_NORMALS] = { 28 29 };28 #include "anorms.h" 29 }; 30 30 31 31 //! anormal dots, no idea of how this shall work, but it does 32 32 float MD2Model::anormsDots[SHADEDOT_QUANT][256] = { 33 34 };33 #include "anormtab.h" 34 }; 35 35 36 36 … … 42 42 sAnim MD2Model::animationList[22] = 43 43 { 44 // begin, end, fps, interruptable44 // begin, end, fps, interruptable 45 45 { 0, 39, 9, 1 }, //!< STAND 46 46 { 40, 45, 10, 1 }, //!< RUN … … 73 73 ********************************************************************************/ 74 74 75 MD2Model::MD2Model() 76 : data(new MD2Data()) 77 { 78 this->init(); 79 } 80 81 #include "resource_md2.h" 75 82 /** 76 83 \brief simple constructor initializing all variables 77 84 */ 78 85 MD2Model::MD2Model(const std::string& modelFileName, const std::string& skinFileName, float scale) 79 { 80 this->setClassID(CL_MD2_MODEL, "MD2Model"); 81 /* this creates the data container via ressource manager */ 82 if (!modelFileName.empty()) 83 this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale); 84 if( unlikely(this->data == NULL)) 85 PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n"); 86 86 : data(new MD2Data()) 87 { 88 this->init(); 87 89 this->scaleFactor = scale; 88 this->animationSpeed = 1.0f; 89 90 shadeDots = MD2Model::anormsDots[0]; 91 /* set the animation stat mannualy */ 92 this->animationState.type = STAND; 93 this->animationState.numPlays = 1; 94 this->setAnimation(STAND); 95 96 this->debug(); 97 98 //write the modelinfo information 90 91 this->data = ResourceMD2(modelFileName, skinFileName, scale).data; 92 rebuildInfo(); 93 94 //this->debug(); 95 } 96 97 MD2Model::MD2Model(const MD2Model& model) 98 : data(model.data) 99 { 100 this->init(); 101 this->rebuildInfo(); 102 } 103 104 MD2Model& MD2Model::operator=(const MD2Model& md2model) 105 { 106 this->data = md2model.data; 107 this->rebuildInfo(); 108 return *this; 109 } 110 111 void MD2Model::rebuildInfo() 112 { 113 //write the modelinfo information 99 114 this->pModelInfo.numVertices = this->data->numVertices; 100 115 this->pModelInfo.numTriangles = this->data->numTriangles; … … 107 122 108 123 // triangle conversion 124 if (this->pModelInfo.pTriangles != NULL) 125 delete[] this->pModelInfo.pTriangles; 109 126 this->pModelInfo.pTriangles = new sTriangleExt[this->data->numTriangles]; 110 127 for( int i = 0; i < this->data->numTriangles; i++) … … 118 135 this->pModelInfo.pTriangles[i].indexToTexCoor[2] = this->data->pTriangles[i].indexToTexCoor[2]; 119 136 } 137 } 138 139 bool MD2Model::load(const std::string& modelFileName, const std::string& skinFileName, float scale) 140 { 141 this->data = MD2Data::Pointer(new MD2Data(modelFileName, skinFileName, scale)); 142 this->rebuildInfo(); 120 143 } 121 144 … … 132 155 this->pModelInfo.pTexCoor = NULL; 133 156 this->pModelInfo.pTriangles = NULL; 134 135 ResourceManager::getInstance()->unload(this->data); 136 } 137 157 } 158 159 160 void MD2Model::init() 161 { 162 this->registerObject(this, MD2Model::_objectList); 163 /* this creates the data container via ressource manager */ 164 if( unlikely(this->data.isNull())) 165 PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n"); 166 167 this->scaleFactor = 1.0f; 168 this->animationSpeed = 1.0f; 169 170 shadeDots = MD2Model::anormsDots[0]; 171 /* set the animation stat mannualy */ 172 this->animationState.type = STAND; 173 this->animationState.numPlays = 1; 174 this->setAnimation(STAND); 175 } 138 176 139 177 /** … … 153 191 154 192 for( int i = 0; i < this->data->numVertices; ++i) 155 156 157 158 159 193 { 194 this->verticesList[i][0] = currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0]); 195 this->verticesList[i][1] = currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1]); 196 this->verticesList[i][2] = currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2]); 197 } 160 198 } 161 199 … … 259 297 /* draw the triangles */ 260 298 while( int i = *(pCommands++)) /* strange looking while loop for maximum performance */ 299 { 300 if( i < 0) 261 301 { 262 if( i < 0) 263 { 264 glBegin(GL_TRIANGLE_FAN); 265 i = -i; 266 } 267 else 268 { 269 glBegin(GL_TRIANGLE_STRIP); 270 } 271 272 for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */ 273 { 274 glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] ); 275 glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]); 276 glVertex3fv(this->verticesList[pCommands[2]]); 277 } 278 glEnd(); 279 302 glBegin(GL_TRIANGLE_FAN); 303 i = -i; 280 304 } 305 else 306 { 307 glBegin(GL_TRIANGLE_STRIP); 308 } 309 310 for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */ 311 { 312 glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] ); 313 glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]); 314 glVertex3fv(this->verticesList[pCommands[2]]); 315 } 316 glEnd(); 317 318 } 281 319 glDisable(GL_CULL_FACE); 282 320 glPopAttrib(); … … 289 327 int* pCommands = this->data->pGLCommands; 290 328 /* some face culling stuff */ 291 // glPushAttrib(GL_POLYGON_BIT);292 // glFrontFace(GL_CW);293 // glEnable(GL_CULL_FACE);294 // glCullFace(GL_BACK);295 //296 // this->processLighting();297 // this->interpolate(/*this->verticesList*/);329 // glPushAttrib(GL_POLYGON_BIT); 330 // glFrontFace(GL_CW); 331 // glEnable(GL_CULL_FACE); 332 // glCullFace(GL_BACK); 333 // 334 // this->processLighting(); 335 // this->interpolate(/*this->verticesList*/); 298 336 this->data->material.select(); 299 337 … … 337 375 338 376 if( this->animationState.localTime - this->animationState.lastTime > (1.0f / this->animationState.fps)) 377 { 378 this->animationState.currentFrame = this->animationState.nextFrame; 379 this->animationState.nextFrame++; 380 381 if( this->animationState.nextFrame > this->animationState.endFrame ) 339 382 { 340 this->animationState.currentFrame = this->animationState.nextFrame; 341 this->animationState.nextFrame++; 342 343 if( this->animationState.nextFrame > this->animationState.endFrame ) 383 if( this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 344 384 { 345 if( this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 346 { 347 this->animationState.nextFrame = this->animationState.startFrame; 348 this->animationState.numPlays++; 349 } 350 else 351 { 352 this->animationState.nextFrame = this->animationState.endFrame; 353 } 385 this->animationState.nextFrame = this->animationState.startFrame; 386 this->animationState.numPlays++; 354 387 } 355 this->animationState.lastTime = this->animationState.localTime; 388 else 389 { 390 this->animationState.nextFrame = this->animationState.endFrame; 391 } 356 392 } 357 358 // if( this->animationState.currentFrame > (this->data->numFrames - 1) ) 359 // this->animationState.currentFrame = 0; 360 361 // if( (this->animationState.nextFrame > (this->data->numFrames - 1)) && this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 362 // this->animationState.nextFrame = 0; 393 this->animationState.lastTime = this->animationState.localTime; 394 } 395 396 // if( this->animationState.currentFrame > (this->data->numFrames - 1) ) 397 // this->animationState.currentFrame = 0; 398 399 // if( (this->animationState.nextFrame > (this->data->numFrames - 1)) && this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 400 // this->animationState.nextFrame = 0; 363 401 364 402 this->animationState.interpolationState = this->animationState.fps * 365 (this->animationState.localTime - this->animationState.lastTime);403 (this->animationState.localTime - this->animationState.lastTime); 366 404 } 367 405 … … 390 428 PRINT(0)("= Number of Frames: \t%i\n", this->data->header->numFrames); 391 429 PRINT(0)("= Height, Width:\t%i, %i\n", this->data->header->skinHeight, this->data->header->skinWidth); 392 PRINT(0)("= Pointer to the data object: %p\n", this->data);430 //PRINT(0)("= Pointer to the data object: %p\n", this->data); 393 431 PRINT(0)("===================================================\n\n"); 394 432 } … … 399 437 ********************************************************************************/ 400 438 439 MD2Data::MD2Data() 440 { 441 this->init(); 442 } 443 401 444 /** 402 445 \brief simple constructor … … 404 447 MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale) 405 448 { 406 scale *= 0.1f; 407 449 this->init(); 450 this->scaleFactor = scale * .1; 451 452 this->loadModel(modelFileName); 453 this->loadSkin(skinFileName); 454 } 455 456 void MD2Data::init() 457 { 458 this->scaleFactor = 1.0; 408 459 this->pVertices = NULL; 409 460 this->pGLCommands = NULL; 410 461 this->pLightNormals = NULL; 411 462 this->pTexCoor = NULL; 463 this->header = NULL; 412 464 413 465 this->numFrames = 0; … … 415 467 this->numGLCommands = 0; 416 468 this->numTexCoor = 0; 417 418 // this->scaleFactor = 1.0f; 419 this->scaleFactor = scale; 420 421 this->fileName = ""; 422 this->skinFileName = ""; 423 this->loadModel(modelFileName); 424 this->loadSkin(skinFileName); 425 } 426 469 } 427 470 428 471 /** … … 462 505 pFile = fopen(fileName.c_str(), "rb"); 463 506 if( unlikely(!pFile)) 464 465 466 467 507 { 508 PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n"); 509 return false; 510 } 468 511 this->header = new MD2Header; 469 512 fread(this->header, 1, sizeof(MD2Header), pFile); 470 513 /* check for the header version: make sure its a md2 file :) */ 471 514 if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT)) 472 473 474 475 515 { 516 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str()); 517 return false; 518 } 476 519 477 520 this->fileName =fileName; … … 506 549 507 550 for(int i = 0; i < this->numFrames; ++i) 551 { 552 frame = (sFrame*)(buffer + this->header->frameSize * i); 553 pVertex = this->pVertices + this->numVertices * i; 554 pNormals = this->pLightNormals + this->numVertices * i; 555 556 for(int j = 0; j < this->numVertices; ++j) 508 557 { 509 frame = (sFrame*)(buffer + this->header->frameSize * i); 510 pVertex = this->pVertices + this->numVertices * i; 511 pNormals = this->pLightNormals + this->numVertices * i; 512 513 for(int j = 0; j < this->numVertices; ++j) 514 { 515 /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)... */ 516 pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor; 517 pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor; 518 pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor; 519 520 //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]); 521 522 pNormals[j] = frame->pVertices[j].lightNormalIndex; 523 } 558 /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)... */ 559 pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor; 560 pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor; 561 pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor; 562 563 //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]); 564 565 pNormals[j] = frame->pVertices[j].lightNormalIndex; 524 566 } 525 PRINTF(4)("Finished loading the md2 file\n"); 567 } 568 PRINTF(4)("Finished loading the md2 file\n"); 526 569 527 570 delete [] buffer; … … 538 581 { 539 582 if( fileName.empty()) 540 541 542 543 583 { 584 this->skinFileName = ""; 585 return false; 586 } 544 587 545 588 this->skinFileName = fileName; -
trunk/src/lib/graphics/importer/md2/md2Model.h
r9235 r9869 20 20 21 21 #include "base_object.h" 22 #include "count_pointer.h" 22 23 23 24 #include "interactive_model.h" … … 45 46 struct MD2Header 46 47 { 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 48 int ident; //!< This is used to identify the file 49 int version; //!< The version number of the file (Must be 8) 50 51 int skinWidth; //!< The skin width in pixels 52 int skinHeight; //!< The skin height in pixels 53 int frameSize; //!< The size in bytes the frames are 54 55 int numSkins; //!< The number of skins associated with the model 56 int numVertices; //!< The number of vertices (constant for each frame) 57 int numTexCoords; //!< The number of texture coordinates 58 int numTriangles; //!< The number of faces (polygons) 59 int numGlCommands; //!< The number of gl commands 60 int numFrames; //!< The number of animation frames 61 62 int offsetSkins; //!< The offset in the file for the skin data 63 int offsetTexCoords; //!< The offset in the file for the texture data 64 int offsetTriangles; //!< The offset in the file for the face data 65 int offsetFrames; //!< The offset in the file for the frames data 66 int offsetGlCommands; //!< The offset in the file for the gl commands data 67 int offsetEnd; //!< The end of the file offset 67 68 }; 68 69 … … 70 71 //! animation names enumeration 71 72 typedef enum MD2animType 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 73 { 74 STAND, //0 75 RUN, //1 76 ATTACK, //2 77 PAIN_A, //3 78 PAIN_B, //4 79 PAIN_C, //5 80 JUMP, //6 81 FLIP, //7 82 SALUTE, //8 83 FALLBACK, //9 84 WAVE, //10 85 POINT, //11 86 CROUCH_STAND, 87 CROUCH_WALK, 88 CROUCH_ATTACK, 89 CROUCH_PAIN, 90 CROUCH_DEATH, 91 DEATH_FALLBACK, 92 DEATH_FALLFORWARD, 93 DEATH_FALLBACKSLOW, 94 BOOM, 95 WALK, 96 97 MAX_ANIMATIONS 98 }; 98 99 99 100 … … 116 117 class MD2Data : public BaseObject 117 118 { 118 public: 119 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 119 public: 120 typedef CountPointer<MD2Data> Pointer; 121 public: 122 MD2Data(); 123 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 120 124 virtual ~MD2Data(); 121 125 122 private: 123 bool loadModel(const std::string& fileName); 124 bool loadSkin(const std::string& fileName = ""); 125 126 public: 126 private: 127 void init(); 128 bool loadModel(const std::string& fileName); 129 bool loadSkin(const std::string& fileName = ""); 130 131 public: 127 132 int numFrames; //!< number of frames 128 133 int numVertices; //!< number of vertices … … 148 153 149 154 //! This is a MD2 Model class 150 class MD2Model : public InteractiveModel { 151 152 public: 155 class MD2Model : public InteractiveModel 156 { 157 ObjectListDeclaration(MD2Model); 158 public: 159 MD2Model(); 153 160 MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f); 161 MD2Model(const MD2Model& model); 154 162 virtual ~MD2Model(); 163 164 MD2Model& operator=(const MD2Model& md2model); 165 166 bool load(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f); 155 167 156 168 virtual void draw() const; … … 160 172 virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback); 161 173 /** returns the current animation @returns animation type */ 162 inline int MD2Model::getAnimation(){ return this->animationState.type; }174 inline int getAnimation() const { return this->animationState.type; } 163 175 virtual void setAnimationSpeed(float speed) { this->animationSpeed = speed; } 164 virtual bool isAnimationFinished(){ return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }176 virtual bool isAnimationFinished() const { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; } 165 177 /** scales the current model @param scaleFactor: the factor [0..1] to use for scaling */ 166 178 void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;} 167 179 180 181 void acquireData(const MD2Data::Pointer& data) { this->data = data; rebuildInfo(); }; 182 const MD2Data::Pointer& dataPointer() const { return this->data; }; 168 183 virtual void tick(float dtS); 169 184 void debug(); … … 171 186 172 187 private: 188 void init(); 189 void rebuildInfo(); 190 173 191 void animate(float time); 174 192 void processLighting(); … … 177 195 178 196 179 197 public: 180 198 /* these variables are static, because they are all the same for every model */ 181 static sVec3D anorms[NUM_VERTEX_NORMALS]; //!< the anormals182 static float anormsDots[SHADEDOT_QUANT][256]; //!< the anormals dot products183 static sAnim animationList[22]; //!< the anomation list184 185 float* shadeDots;186 187 MD2Data* data;//!< the md2 data pointer188 189 190 float scaleFactor; //!< the scale factor (individual)191 float animationSpeed; //!< the speed of the animation (factor for the time)192 sAnimState animationState; //!< animation state of the model193 sVec3D verticesList[MD2_MAX_VERTICES]; //!< place to temp sav the vert199 static sVec3D anorms[NUM_VERTEX_NORMALS]; //!< the anormals 200 static float anormsDots[SHADEDOT_QUANT][256]; //!< the anormals dot products 201 static sAnim animationList[22]; //!< the anomation list 202 //! again one of these strange id software parts 203 float* shadeDots; 204 205 CountPointer<MD2Data> data; //!< the md2 data pointer 206 207 private: 208 float scaleFactor; //!< the scale factor (individual) 209 float animationSpeed; //!< the speed of the animation (factor for the time) 210 sAnimState animationState; //!< animation state of the model 211 sVec3D verticesList[MD2_MAX_VERTICES]; //!< place to temp sav the vert 194 212 }; 195 213 -
trunk/src/lib/graphics/importer/md3/md3_model.h
r8724 r9869 45 45 46 46 virtual void setAnimation(int animNum, int playbackMode = 0) {} 47 virtual int getAnimation() { return 0;}47 virtual int getAnimation() const { return 0;} 48 48 49 49 virtual void tick(float dt); -
trunk/src/lib/graphics/importer/media_container.cc
r8316 r9869 26 26 27 27 #include "util/loading/resource_manager.h" 28 29 28 /* header for debug output */ 30 29 #include "debug.h" 31 30 31 ObjectListDefinition(MediaContainer); 32 32 33 33 /** … … 37 37 { 38 38 // set the class id for the base object 39 this-> setClassID(CL_MEDIA_CONTAINER, "MediaContainer");39 this->registerObject(this, MediaContainer::_objectList); 40 40 41 41 fps = 0; … … 91 91 return false; 92 92 // check whether file exists 93 if(!Resource Manager::isInDataDir(filename))93 if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename)) 94 94 { 95 95 PRINTF(1)("Could not find %s\n", filename.c_str()); … … 101 101 102 102 // Open video file 103 if (av_open_input_file(&format_context, Resource Manager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )104 { 105 PRINTF(1)("Could not open %s\n", Resource Manager::getFullName(filename).c_str());103 if (av_open_input_file(&format_context, Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str(), NULL, 0, NULL) !=0 ) 104 { 105 PRINTF(1)("Could not open %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 106 106 return false; 107 107 } … … 110 110 if (av_find_stream_info(format_context) < 0) 111 111 { 112 PRINTF(1)("Could not find stream information in %s\n", Resource Manager::getFullName(filename).c_str());112 PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 113 113 return false; 114 114 } … … 119 119 if(video_stream == -1) 120 120 { 121 PRINTF(1)("Could not find a video stream in %s\n", Resource Manager::getFullName(filename).c_str());121 PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 122 122 return false; 123 123 } -
trunk/src/lib/graphics/importer/media_container.h
r7221 r9869 24 24 class MediaContainer : public TextureSequence 25 25 { 26 26 ObjectListDeclaration(MediaContainer); 27 27 private: 28 28 -
trunk/src/lib/graphics/importer/model.cc
r9406 r9869 20 20 #include "glincl.h" 21 21 22 22 ObjectListDefinition(Model); 23 23 24 24 /** … … 28 28 Model::Model() 29 29 { 30 this-> setClassID(CL_MODEL, "Model");30 this->registerObject(this, Model::_objectList); 31 31 this->pModelInfo.numVertices = 0; 32 32 this->pModelInfo.numTriangles = 0; -
trunk/src/lib/graphics/importer/model.h
r8035 r9869 54 54 //! This class defines the basic components of a model 55 55 class Model : virtual public BaseObject { 56 ObjectListDeclaration(Model); 56 57 57 58 public: -
trunk/src/lib/graphics/importer/movie_player.cc
r7221 r9869 24 24 // include your own header 25 25 #include "movie_player.h" 26 27 26 #include "util/loading/resource_manager.h" 28 27 … … 30 29 #include "debug.h" 31 30 31 ObjectListDefinition(MoviePlayer); 32 32 33 33 MoviePlayer::MoviePlayer(const std::string& filename) 34 34 { 35 35 // set the class id for the base object 36 this->setClassID(CL_MOVIE_PLAYER, "MoviePlayer"); 37 36 this->registerObject(this, MoviePlayer::_objectList); 38 37 status = STOP; 39 38 timer = 0; … … 90 89 return false; 91 90 // check whether file exists 92 if(!Resource Manager::isInDataDir(filename))91 if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename)) 93 92 { 94 93 PRINTF(1)("Could not find %s\n", filename.c_str()); … … 100 99 101 100 // Open video file 102 if (av_open_input_file(&format_context, Resource Manager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )103 { 104 PRINTF(1)("Could not open %s\n", Resource Manager::getFullName(filename).c_str());101 if (av_open_input_file(&format_context, Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str(), NULL, 0, NULL) !=0 ) 102 { 103 PRINTF(1)("Could not open %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 105 104 return false; 106 105 } … … 109 108 if (av_find_stream_info(format_context) < 0) 110 109 { 111 PRINTF(1)("Could not find stream information in %s\n", Resource Manager::getFullName(filename).c_str());110 PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 112 111 return false; 113 112 } … … 118 117 if(video_stream == -1) 119 118 { 120 PRINTF(1)("Could not find a video stream in %s\n", Resource Manager::getFullName(filename).c_str());119 PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 121 120 return false; 122 121 } -
trunk/src/lib/graphics/importer/movie_player.h
r7221 r9869 31 31 class MoviePlayer : public BaseObject 32 32 { 33 ObjectListDeclaration(MoviePlayer); 33 34 34 35 private: -
trunk/src/lib/graphics/importer/objModel.cc
r8369 r9869 18 18 #include "objModel.h" 19 19 20 #include <stdio.h>21 20 #include <string.h> 22 #include <stdlib.h>21 #include "loading/resource_manager.h" 23 22 24 23 #define PARSELINELENGTH 8192 … … 27 26 #include "compiler.h" 28 27 28 ObjectListDefinition(OBJModel); 29 29 /** 30 30 * @brief Crates a 3D-Model, loads in a File and scales it. … … 35 35 : StaticModel(fileName) 36 36 { 37 this-> setClassID(CL_OBJ_MODEL, "OBJModel");37 this->registerObject(this, OBJModel::_objectList); 38 38 39 39 this->objPath = "./"; 40 40 41 this->s caleFactor = scaling;41 this->setScaleFactor(scaling); 42 42 43 43 this->importFile (fileName); … … 77 77 else 78 78 this->objPath = "./"; 79 Material::addTexturePath(this->objPath);79 Resources::ResourceManager::getInstance()->addResourcePath("Texture", this->objPath); 80 80 81 81 this->readFromObjFile (fileName); -
trunk/src/lib/graphics/importer/objModel.h
r8369 r9869 12 12 class OBJModel : public StaticModel 13 13 { 14 public: 15 OBJModel(const std::string& fileName, float scaling = 1.0); 14 ObjectListDeclaration(OBJModel); 15 public: 16 OBJModel(const std::string& fileName, float scaling = 1.0); 16 17 virtual ~OBJModel(); 17 18 18 19 private: 19 20 ///// readin ///// 20 21 22 21 bool importFile (const std::string& fileName); 22 bool readFromObjFile (const std::string& fileName); 23 bool readMtlLib (const std::string& matFile); 23 24 24 25 26 27 28 29 30 25 private: 26 void setIllum (Material* material, const char* illum); 27 void setDiffuse (Material* material, const char* rgb); 28 void setAmbient (Material* material, const char* rgb); 29 void setSpecular (Material* material, const char* rgb); 30 void setShininess (Material* material, const char* shini); 31 void setTransparency (Material* material, const char* trans); 31 32 32 33 33 private: 34 std::string objPath; //!< The Path where the obj and mtl-file are located. 34 35 }; 35 36 -
trunk/src/lib/graphics/importer/static_model.cc
r9406 r9869 26 26 27 27 28 ////////////////////29 /// SUB-Elements ///30 ////////////////////31 /**32 * @brief creates a new ModelFaceElement33 */34 ModelFaceElement::ModelFaceElement()35 {36 this->vertexNumber = -1;37 this->normalNumber = -1;38 this->texCoordNumber = -1;39 40 this->next = NULL;41 }42 43 /**44 * @brief destroys a ModelFaceElement45 */46 ModelFaceElement::~ModelFaceElement()47 {48 if (this->next)49 delete this->next;50 }51 52 /**53 * @brief creates a new ModelFace54 */55 ModelFace::ModelFace()56 {57 this->vertexCount = 0;58 59 this->firstElem = NULL;60 61 this->material = NULL;62 63 this->next = NULL;64 }65 66 /**67 * deletes a ModelFace68 */69 ModelFace::~ModelFace()70 {71 PRINTF(5)("Cleaning up Face\n");72 73 if (this->firstElem != NULL)74 delete this->firstElem;75 76 if (this->next != NULL)77 delete this->next;78 }79 80 /**81 * @brief Creates a new ModelGroup82 */83 ModelGroup::ModelGroup()84 {85 PRINTF(4)("Adding new Group\n");86 this->name = "";87 this->faceMode = -1;88 this->faceCount = 0;89 this->next = NULL;90 this->listNumber = 0;91 this->indices = NULL;92 93 this->firstFace = new ModelFace;94 this->currentFace = this->firstFace;95 }96 97 /**98 * @brief deletes a ModelGroup99 */100 ModelGroup::~ModelGroup()101 {102 PRINTF(5)("Cleaning up group\n");103 if (this->firstFace != NULL)104 delete this->firstFace;105 106 // deleting the glList107 if (this->listNumber != 0)108 glDeleteLists(this->listNumber, 1);109 110 if (this->next !=NULL)111 delete this->next;112 113 }114 115 /**116 * @brief cleans up a ModelGroup117 *118 * actually does the same as the delete Operator, but does not delete the predecessing group119 */120 void ModelGroup::cleanup()121 {122 PRINTF(5)("Cleaning up group\n");123 if (this->firstFace)124 delete this->firstFace;125 this->firstFace = NULL;126 if (this->next)127 this->next->cleanup();128 }129 130 131 28 ///////////// 132 29 /// MODEL /// 133 30 ///////////// 31 ObjectListDefinition(StaticModel); 32 134 33 /** 135 34 * @brief Creates a 3D-Model. … … 138 37 */ 139 38 StaticModel::StaticModel(const std::string& modelName) 39 : data(new StaticModelData(modelName)) 140 40 { 141 this-> setClassID(CL_STATIC_MODEL, "StaticModel");41 this->registerObject(this, StaticModel::_objectList); 142 42 PRINTF(4)("new 3D-Model is being created\n"); 143 43 this->setName(modelName); 44 } 144 45 145 this->finalized = false; 46 StaticModel::StaticModel(const StaticModel& staticModel) 47 : data(staticModel.data) 48 { 49 this->registerObject(this, StaticModel::_objectList); 50 this->setName(staticModel.getName()); 51 this->updateBase(); 52 } 146 53 147 // setting the start group;148 this->currentGroup = this->firstGroup = new ModelGroup;149 this->groupCount = 0;150 this->faceCount = 0;151 152 this->scaleFactor = 1.0f;153 }154 54 155 55 /** … … 161 61 { 162 62 PRINTF(4)("Deleting Model "); 163 if (!this->getName().empty())164 {165 PRINT(4)("%s\n", this->getCName());166 }167 else168 {169 PRINT(4)("\n");170 }171 this->cleanup();172 173 PRINTF(5)("Deleting display Lists.\n");174 delete this->firstGroup;175 176 // deleting the MaterialList177 PRINTF(5)("Deleting Materials.\n");178 179 //! @todo do we really have to delete this material??180 std::list<ModelMaterial*>::iterator modMat;181 for(modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++)182 {183 if (!(*modMat)->external)184 delete (*modMat)->material;185 delete (*modMat);186 }187 63 188 64 // mark this stuff as beeing deleted … … 190 66 this->pModelInfo.pNormals = NULL; 191 67 this->pModelInfo.pTexCoor = NULL; 68 this->pModelInfo.pTriangles = NULL; 192 69 } 70 71 StaticModel& StaticModel::operator=(const StaticModel& model) 72 { 73 this->data = model.data; 74 this->updateBase(); 75 return *this; 76 }; 77 193 78 194 79 /** … … 197 82 void StaticModel::finalize() 198 83 { 199 // this creates the display List. 200 this->importToDisplayList(); 201 this->buildTriangleList(); 202 203 // write out the modelInfo data used for the collision detection! 204 this->pModelInfo.pVertices = &this->vertices[0]; 205 this->pModelInfo.pNormals = &this->normals[0]; 206 this->pModelInfo.pTexCoor = &this->vTexture[0]; 207 208 this->finalized = true; 84 data->finalize(); 85 this->updateBase(); 209 86 } 210 87 211 /** 212 * @brief rebuild the Model from the Information we got. 213 */ 214 void StaticModel::rebuild() 88 void StaticModel::acquireData(const StaticModelData::Pointer& data) 215 89 { 216 PRINTF(3)("Rebuilding Model '%s'\n", this->getCName()); 217 this->finalize(); 218 } 219 220 ////////// 221 // DRAW // 222 ////////// 223 /** 224 * @brief Draws the Models of all Groups. 225 * 226 * It does this by just calling the Lists that must have been created earlier. 227 */ 228 void StaticModel::draw () const 229 { 230 PRINTF(4)("drawing the 3D-Models\n"); 231 ModelGroup* tmpGroup = this->firstGroup; 232 while (tmpGroup != NULL) 233 { 234 PRINTF(5)("Drawing model %s\n", tmpGroup->name.c_str()); 235 glCallList (tmpGroup->listNumber); 236 tmpGroup = tmpGroup->next; 237 } 238 } 239 240 241 /** 242 * @brief Draws the Model number groupNumber 243 * @param groupNumber The number of the group that will be displayed. 244 * 245 * It does this by just calling the List that must have been created earlier. 246 */ 247 void StaticModel::draw (int groupNumber) const 248 { 249 if (unlikely(groupNumber >= this->groupCount)) 250 { 251 PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount); 252 return; 253 } 254 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 255 ModelGroup* tmpGroup = this->firstGroup; 256 int counter = 0; 257 while (tmpGroup != NULL) 258 { 259 if (counter == groupNumber) 260 { 261 PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name.c_str()); 262 glCallList (tmpGroup->listNumber); 263 return; 264 } 265 ++counter; 266 tmpGroup = tmpGroup->next; 267 } 268 PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getCName()); 269 return; 270 } 271 272 273 /** 274 * @brief Draws the Model with a specific groupName 275 * @param groupName The name of the group that will be displayed. 276 * 277 * It does this by just calling the List that must have been created earlier. 278 */ 279 void StaticModel::draw (const std::string& groupName) const 280 { 281 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 282 ModelGroup* tmpGroup = this->firstGroup; 283 while (tmpGroup != NULL) 284 { 285 if (tmpGroup->name == groupName) 286 { 287 PRINTF(4)("Drawing model %s\n", tmpGroup->name.c_str()); 288 glCallList (tmpGroup->listNumber); 289 return; 290 } 291 tmpGroup = tmpGroup->next; 292 } 293 PRINTF(2)("Model Named %s in %s not Found.\n", groupName.c_str(), this->getCName()); 294 return; 295 } 296 297 ////////// 298 // INIT // 299 ////////// 300 301 /** 302 * @brief finalizes an Model. 303 * 304 * This funcion is needed, to delete all the Lists, and arrays that are no more 305 * needed because they are already imported into openGL. 306 * This will be applied at the end of the importing Process. 307 */ 308 bool StaticModel::cleanup() 309 { 310 PRINTF(4)("cleaning up the 3D-Model to save Memory.\n"); 311 this->firstGroup->cleanup(); 312 return true; 313 } 314 315 ////////// 316 // MESH // 317 ////////// 318 /** 319 * @brief adds a new Material to the Material List 320 * @param material the Material to add 321 * @returns the added material 322 * 323 * this also tells this Model, that all the Materials are handled externally 324 * with this option set the Materials will not be deleted with the Model. 325 */ 326 Material* StaticModel::addMaterial(Material* material) 327 { 328 if (material == NULL) 329 return NULL; 330 ModelMaterial* modMat = new ModelMaterial; 331 modMat->external = true; 332 modMat->material = material; 333 this->materialList.push_back(modMat); 334 return modMat->material; 335 } 336 337 /** 338 * @brief adds a new Material to the Material List 339 * @param materialName the name of the Material to add 340 * @returns the added material 341 */ 342 Material* StaticModel::addMaterial(const std::string& materialName) 343 { 344 ModelMaterial* modMat = new ModelMaterial; 345 modMat->external = false; 346 modMat->material = new Material(materialName); 347 348 // adding material to the List of materials 349 this->materialList.push_back(modMat); 350 return modMat->material; 351 } 352 353 /** 354 * @brief finds a Material by its name and returns it 355 * @param materialName the Name of the material to search for. 356 * @returns the Material if found, NULL otherwise 357 */ 358 Material* StaticModel::findMaterialByName(const std::string& materialName) 359 { 360 std::list<ModelMaterial*>::iterator modMat; 361 for (modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++) 362 if (materialName == (*modMat)->material->getName()) 363 return (*modMat)->material; 364 return NULL; 365 } 366 367 /** 368 * @brief parses a group String 369 * @param groupString the new Group to create 370 * 371 * This function initializes a new Group. 372 * With it you should be able to create Models with more than one SubModel inside 373 */ 374 bool StaticModel::addGroup(const std::string& groupString) 375 { 376 PRINTF(5)("Read Group: %s.\n", groupString.c_str()); 377 if (this->groupCount != 0 && this->currentGroup->faceCount > 0) 378 { 379 // finalizeGroup(currentGroup); 380 this->currentGroup = this->currentGroup->next = new ModelGroup; 381 } 382 // setting the group name if not default. 383 if (groupString == "default") 384 { 385 this->currentGroup->name = groupString; 386 } 387 ++this->groupCount; 388 return true; 389 } 390 391 /** 392 * @brief parses a vertex-String 393 * @param vertexString The String that will be parsed. 394 * 395 * If a vertex line is found this function will inject it into the vertex-Array 396 */ 397 bool StaticModel::addVertex (const std::string& vertexString) 398 { 399 float subbuffer1; 400 float subbuffer2; 401 float subbuffer3; 402 sscanf (vertexString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 403 this->vertices.push_back(subbuffer1*scaleFactor); 404 this->vertices.push_back(subbuffer2*scaleFactor); 405 this->vertices.push_back(subbuffer3*scaleFactor); 406 this->pModelInfo.numVertices++; 407 return true; 408 } 409 410 /** 411 * @brief parses a vertex-String 412 * @param x the X-coordinate of the Vertex to add. 413 * @param y the Y-coordinate of the Vertex to add. 414 * @param z the Z-coordinate of the Vertex to add. 415 */ 416 bool StaticModel::addVertex(float x, float y, float z) 417 { 418 PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z); 419 this->vertices.push_back(x*scaleFactor); 420 this->vertices.push_back(y*scaleFactor); 421 this->vertices.push_back(z*scaleFactor); 422 this->pModelInfo.numVertices++; 423 return true; 424 } 425 426 /** 427 * @brief parses a vertexNormal-String 428 * @param normalString The String that will be parsed. 429 * 430 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 431 */ 432 bool StaticModel::addVertexNormal (const std::string& normalString) 433 { 434 float subbuffer1; 435 float subbuffer2; 436 float subbuffer3; 437 sscanf (normalString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 438 this->normals.push_back(subbuffer1); 439 this->normals.push_back(subbuffer2); 440 this->normals.push_back(subbuffer3); 441 this->pModelInfo.numNormals++; 442 return true; 443 } 444 445 /** 446 * @brief adds a VertexNormal. 447 * @param x The x coordinate of the Normal. 448 * @param y The y coordinate of the Normal. 449 * @param z The z coordinate of the Normal. 450 * 451 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 452 */ 453 bool StaticModel::addVertexNormal(float x, float y, float z) 454 { 455 PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z); 456 this->normals.push_back(x); 457 this->normals.push_back(y); 458 this->normals.push_back(z); 459 this->pModelInfo.numNormals++; 460 return true; 461 } 462 463 /** 464 * @brief parses a vertexTextureCoordinate-String 465 * @param vTextureString The String that will be parsed. 466 * 467 * If a vertexTextureCoordinate line is found, 468 * this function will inject it into the vertexTexture-Array 469 * 470 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !! 471 */ 472 bool StaticModel::addVertexTexture (const std::string& vTextureString) 473 { 474 float subbuffer1; 475 float subbuffer2; 476 sscanf (vTextureString.c_str(), "%f %f", &subbuffer1, &subbuffer2); 477 this->vTexture.push_back(subbuffer1); 478 this->vTexture.push_back(1 - subbuffer2); 479 this->pModelInfo.numTexCoor++; 480 return true; 481 } 482 483 /** 484 * @brief adds a Texture Coordinate 485 * @param u The u coordinate of the TextureCoordinate. 486 * @param v The y coordinate of the TextureCoordinate. 487 * 488 * If a TextureCoordinate line is found this function will 489 * inject it into the TextureCoordinate-Array 490 */ 491 bool StaticModel::addVertexTexture(float u, float v) 492 { 493 PRINTF(5)("found vertex-Texture %f, %f\n", u, v); 494 this->vTexture.push_back(u); 495 this->vTexture.push_back(v); 496 this->pModelInfo.numTexCoor++; 497 return true; 498 } 499 500 /** 501 * @brief parses a face-string 502 * @param faceString The String that will be parsed. 503 * 504 * If a face line is found this function will add it to the glList. 505 * 506 * String is different from the argument addFace, 507 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0 508 * 509 * @TODO make it std::string conform 510 */ 511 bool StaticModel::addFace (const std::string& faceStringInput) 512 { 513 const char* faceString = faceStringInput.c_str(); 514 if (this->currentGroup->faceCount >0) 515 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 516 517 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement; 518 tmpElem->next = NULL; 519 while(strcmp (faceString, "\0")) 520 { 521 if (this->currentGroup->currentFace->vertexCount>0) 522 tmpElem = tmpElem->next = new ModelFaceElement; 523 tmpElem->next = NULL; 524 525 char tmpValue [50]; 526 int tmpLen; 527 char* vertex = NULL; 528 char* texture = NULL; 529 char* normal = NULL; 530 531 sscanf (faceString, "%s", tmpValue); 532 tmpLen = strlen(tmpValue); 533 vertex = tmpValue; 534 535 if ((texture = strstr (vertex, "/")) != NULL) 536 { 537 texture[0] = '\0'; 538 texture ++; 539 540 if ((normal = strstr (texture, "/")) !=NULL) 541 { 542 normal[0] = '\0'; 543 normal ++; 544 } 545 } 546 if (vertex) 547 tmpElem->vertexNumber = atoi(vertex)-1; 548 if (texture) 549 tmpElem->texCoordNumber = atoi(texture)-1; 550 if (normal) 551 tmpElem->normalNumber = atoi(normal)-1; 552 553 faceString += tmpLen; 554 if (strcmp (faceString, "\0")) 555 faceString++; 556 this->currentGroup->currentFace->vertexCount++; 557 } 558 559 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2; 560 this->faceCount += this->currentGroup->currentFace->vertexCount -2; 561 return true; 90 this->data = data; 91 this->updateBase(); 562 92 } 563 93 … … 569 99 bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...) 570 100 { 571 if (this->currentGroup->faceCount > 0)572 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;573 574 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;575 576 101 va_list itemlist; 577 102 va_start (itemlist, type); 578 579 for (int i = 0; i < faceElemCount; i++) 580 { 581 if (this->currentGroup->currentFace->vertexCount > 0) 582 tmpElem = tmpElem->next = new ModelFaceElement; 583 584 tmpElem->vertexNumber = va_arg (itemlist, int); 585 if (type & TEXCOORD) 586 tmpElem->texCoordNumber = va_arg (itemlist, int); 587 if (type & NORMAL) 588 tmpElem->normalNumber = va_arg(itemlist, int); 589 this->currentGroup->currentFace->vertexCount++; 590 } 103 bool retVal = this->data->addFace(faceElemCount, type, itemlist); 591 104 va_end(itemlist); 592 593 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount - 2; 594 this->faceCount += this->currentGroup->currentFace->vertexCount -2; 595 return true; 105 return retVal; 596 106 } 597 107 598 /** 599 * Function that selects a material, if changed in the obj file. 600 * @param matString the Material that will be set. 601 */ 602 bool StaticModel::setMaterial(const std::string& matString) 108 void StaticModel::updateBase() 603 109 { 604 if (this->currentGroup->faceCount > 0) 605 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 110 // write out the modelInfo data used for the collision detection! 111 this->pModelInfo.pVertices = &this->data->getVertices()[0]; 112 this->pModelInfo.numVertices = this->data->getVertices().size(); 113 this->pModelInfo.pNormals = &this->data->getNormals()[0]; 114 this->pModelInfo.numNormals = this->data->getNormals().size(); 115 this->pModelInfo.pTexCoor = &this->data->getTexCoords()[0]; 116 this->pModelInfo.numTexCoor = this->data->getTexCoords().size(); 606 117 607 this->currentGroup->currentFace->material = this->findMaterialByName(matString); 608 609 if (this->currentGroup->faceCount == 0) 610 this->currentGroup->faceCount++; 611 return true; 612 } 613 614 /** 615 * Function that selects a material, if changed in the obj file. 616 * @param mtl the Material that will be set. 617 */ 618 bool StaticModel::setMaterial(Material* mtl) 619 { 620 if (this->currentGroup->faceCount > 0) 621 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 622 623 this->currentGroup->currentFace->material = mtl; 624 625 if (this->currentGroup->faceCount == 0) 626 this->currentGroup->faceCount++; 627 return true; 628 } 629 630 /** 631 * @brief A routine that is able to create normals. 632 * 633 * The algorithm does the following: 634 * 1. It calculates creates Vectors for each normale, and sets them to zero. 635 * 2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements 636 * 3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal. 637 * 4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array. 638 */ 639 bool StaticModel::buildVertexNormals () 640 { 641 PRINTF(4)("Normals are being calculated.\n"); 642 643 Vector* normArray = new Vector [vertices.size()/3]; 644 for (unsigned int i=0; i<vertices.size()/3;i++) 645 normArray[i] = Vector(.0,.0,.0); 646 647 Vector prevV; 648 Vector nextV; 649 Vector curV; 650 651 ModelGroup* tmpGroup = firstGroup; 652 while (tmpGroup != NULL) 653 { 654 ModelFace* tmpFace = tmpGroup->firstFace; 655 while (tmpFace != NULL) 656 { 657 if (tmpFace->firstElem != NULL) 658 { 659 ModelFaceElement* firstElem = tmpFace->firstElem; 660 ModelFaceElement* prevElem; 661 ModelFaceElement* curElem = firstElem; 662 ModelFaceElement* nextElem; 663 ModelFaceElement* lastElem; 664 // 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. 665 while (curElem != NULL) 666 { 667 prevElem = curElem; 668 curElem = curElem->next; 669 } 670 lastElem = prevElem; 671 672 curElem = firstElem; 673 for (unsigned int j = 0; j < tmpFace->vertexCount; j++) 674 { 675 if (!(nextElem = curElem->next)) 676 nextElem = firstElem; 677 curElem->normalNumber = curElem->vertexNumber; 678 679 curV = Vector (this->vertices[curElem->vertexNumber*3], 680 this->vertices[curElem->vertexNumber*3+1], 681 this->vertices[curElem->vertexNumber*3+2]); 682 683 prevV = Vector (this->vertices[prevElem->vertexNumber*3], 684 this->vertices[prevElem->vertexNumber*3+1], 685 this->vertices[prevElem->vertexNumber*3+2]) - curV; 686 687 nextV = Vector (this->vertices[nextElem->vertexNumber*3], 688 this->vertices[nextElem->vertexNumber*3+1], 689 this->vertices[nextElem->vertexNumber*3+2]) - curV; 690 normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV); 691 692 prevElem = curElem; 693 curElem = curElem->next; 694 } 695 } 696 tmpFace = tmpFace->next; 697 } 698 tmpGroup = tmpGroup->next; 699 } 700 701 for (unsigned int i=0; i < this->vertices.size()/3;i++) 702 { 703 normArray[i].normalize(); 704 PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z); 705 706 this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z); 707 708 } 709 delete[] normArray; 710 return true; 711 } 712 713 //////////// 714 // openGL // 715 //////////// 716 /** 717 * reads and includes the Faces/Materials into the openGL state Machine 718 */ 719 bool StaticModel::importToDisplayList() 720 { 721 // finalize the Arrays 722 if (normals.size() == 0) // vertices-Array must be built for this 723 this->buildVertexNormals(); 724 725 this->currentGroup = this->firstGroup; 726 727 while (this->currentGroup != NULL) 728 { 729 730 // creating a glList for the Group 731 if ((this->currentGroup->listNumber = glGenLists(1)) == 0) 732 { 733 PRINTF(2)("glList could not be created for this Model\n"); 734 return false; 735 } 736 glNewList (this->currentGroup->listNumber, GL_COMPILE); 737 738 // Putting Faces to GL 739 ModelFace* tmpFace = this->currentGroup->firstFace; 740 while (tmpFace != NULL) 741 { 742 if (tmpFace->vertexCount == 0 && tmpFace->material != NULL) 743 { 744 if (this->currentGroup->faceMode != -1) 745 glEnd(); 746 this->currentGroup->faceMode = 0; 747 if (tmpFace->material != NULL) 748 { 749 tmpFace->material->select(); 750 PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getCName()); 751 } 752 } 753 754 else if (tmpFace->vertexCount == 3) 755 { 756 if (this->currentGroup->faceMode != 3) 757 { 758 if (this->currentGroup->faceMode != -1) 759 glEnd(); 760 glBegin(GL_TRIANGLES); 761 } 762 763 this->currentGroup->faceMode = 3; 764 PRINTF(5)("found triag.\n"); 765 } 766 767 else if (tmpFace->vertexCount == 4) 768 { 769 if (this->currentGroup->faceMode != 4) 770 { 771 if (this->currentGroup->faceMode != -1) 772 glEnd(); 773 glBegin(GL_QUADS); 774 } 775 this->currentGroup->faceMode = 4; 776 PRINTF(5)("found quad.\n"); 777 } 778 779 else if (tmpFace->vertexCount > 4) 780 { 781 if (this->currentGroup->faceMode != -1) 782 glEnd(); 783 glBegin(GL_POLYGON); 784 PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount); 785 this->currentGroup->faceMode = tmpFace->vertexCount; 786 } 787 788 ModelFaceElement* tmpElem = tmpFace->firstElem; 789 while (tmpElem != NULL) 790 { 791 // PRINTF(2)("%s\n", tmpElem->value); 792 this->addGLElement(tmpElem); 793 tmpElem = tmpElem->next; 794 } 795 tmpFace = tmpFace->next; 796 } 797 glEnd(); 798 glEndList(); 799 800 this->currentGroup = this->currentGroup->next; 801 } 802 return true; 118 this->pModelInfo.pTriangles = this->data->getTrianglesExt(); 119 this->pModelInfo.numTriangles = this->data->getTriangles().size(); 803 120 } 804 121 805 122 806 123 /** 807 * builds an array of triangles, that can later on be used for obb separation and octree separation 124 * Includes a default model 125 * 126 * This will inject a Cube, because this is the most basic model. 808 127 */ 809 bool StaticModel::buildTriangleList()810 {811 if( unlikely(this->pModelInfo.pTriangles != NULL))812 return true;813 /* make sure, that all the arrays are finalized */814 if( normals.size() == 0) // vertices-Array must be built for this815 this->buildVertexNormals();816 817 int index = 0; //!< the counter for the triangle array818 ModelFaceElement* tmpElem; //!< the temporary faceelement reference819 ModelFace* tmpFace; //!< the temporary face referece820 821 bool warned = false;822 823 this->pModelInfo.numTriangles = 0;824 825 /* count the number of triangles */826 /* now iterate through all groups and build up the triangle list */827 this->currentGroup = this->firstGroup;828 while( this->currentGroup != NULL)829 {830 tmpFace = this->currentGroup->firstFace;831 while( tmpFace != NULL)832 {833 /* if its a triangle just add it to the list */834 if( tmpFace->vertexCount == 3){835 ++this->pModelInfo.numTriangles;836 } /* if the polygon is a quad */837 else if( tmpFace->vertexCount == 4) {838 this->pModelInfo.numTriangles += 2;839 }840 else if( tmpFace->vertexCount > 4) {841 if (!warned) {842 PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getCName());843 warned = true;844 }845 }846 tmpFace = tmpFace->next;847 }848 this->currentGroup = this->currentGroup->next;849 }850 851 PRINTF(3)("got %i triangles, %i vertices\n", this->pModelInfo.numTriangles, this->pModelInfo.numVertices);852 853 854 /* write MODELINFO structure */855 856 /* allocate memory for the new triangle structures */857 if( (this->pModelInfo.pTriangles = new sTriangleExt[this->pModelInfo.numTriangles]) == NULL)858 {859 PRINTF(1)("Could not allocate memory for triangle list\n");860 return false;861 }862 863 /* now iterate through all groups and build up the triangle list */864 this->currentGroup = this->firstGroup;865 while( this->currentGroup != NULL)866 {867 tmpFace = this->currentGroup->firstFace;868 while( tmpFace != NULL)869 {870 tmpElem = tmpFace->firstElem;871 872 /* if its a triangle just add it to the list */873 if( tmpFace->vertexCount == 3)874 {875 for( int j = 0; j < 3; ++j)876 {877 this->pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3 ;878 this->pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3 ;879 this->pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3 ;880 tmpElem = tmpElem->next;881 882 }883 ++index;884 } /* if the polygon is a quad */885 else if( tmpFace->vertexCount == 4)886 {887 888 this->pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;889 this->pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;890 this->pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;891 892 this->pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;893 this->pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;894 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;895 tmpElem = tmpElem->next;896 897 this->pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;898 this->pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;899 this->pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;900 tmpElem = tmpElem->next;901 902 this->pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;903 this->pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;904 this->pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;905 906 this->pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;907 this->pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;908 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;909 tmpElem = tmpElem->next;910 911 this->pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;912 this->pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;913 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;914 915 index += 2;916 }917 tmpFace = tmpFace->next;918 }919 this->currentGroup = this->currentGroup->next;920 }921 return true;922 }923 924 925 /**926 * Adds a Face-element (one vertex of a face) with all its information.927 * @param elem The FaceElement to add to the OpenGL-environment.928 929 It does this by searching:930 1. The Vertex itself931 2. The VertexNormale932 3. The VertexTextureCoordinate933 merging this information, the face will be drawn.934 */935 bool StaticModel::addGLElement (ModelFaceElement* elem)936 {937 PRINTF(5)("importing grafical Element to openGL.\n");938 939 if (elem->texCoordNumber > -1)940 {941 if (likely((unsigned int)elem->texCoordNumber < this->pModelInfo.numTexCoor))942 glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2);943 else944 PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",945 elem->texCoordNumber, this->pModelInfo.numTexCoor);946 }947 if (elem->normalNumber > -1)948 {949 if (likely((unsigned int)elem->normalNumber < this->pModelInfo.numNormals))950 glNormal3fv(&this->normals[0] + elem->normalNumber * 3);951 else952 PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",953 elem->normalNumber, this->pModelInfo.numNormals);954 }955 if (elem->vertexNumber > -1)956 {957 if (likely((unsigned int)elem->vertexNumber < this->pModelInfo.numVertices))958 glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3);959 else960 PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",961 elem->vertexNumber, this->pModelInfo.numVertices);962 }963 964 return true;965 }966 967 /**968 * Includes a default model969 970 This will inject a Cube, because this is the most basic model.971 */972 128 void StaticModel::cubeModel() 973 129 { -
trunk/src/lib/graphics/importer/static_model.h
r7221 r9869 10 10 11 11 #include "material.h" 12 #include "glincl.h"13 12 #include <vector> 14 #include <list> 15 16 // definition of different modes for setting up Faces 17 #define VERTEX 0 //!< If Faces are created WITH Vertex-Coordinate 18 #define NORMAL 1 //!< If Faces are created WITH Normals (otherwise autocalculate) 19 #define TEXCOORD 2 //!< If Faces are created WITH TextureCoordinate 20 21 //! an enumerator for VERTEX_FORMAT 22 typedef enum VERTEX_FORMAT { 23 VERTEX_ONLY = VERTEX, 24 VERTEX_NORMAL = NORMAL, 25 VERTEX_TEXCOORD = TEXCOORD, 26 VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD 27 }; 28 29 //////////////////// 30 /// SUB-ELEMENTS /// 31 //////////////////// 32 //! This is the placeholder of one Vertex beloning to a Face. 33 class ModelFaceElement 34 { 35 public: 36 ModelFaceElement(); 37 ~ModelFaceElement(); 38 39 int vertexNumber; //!< The number of the Vertex out of the Array* vertices, this vertex points to. 40 int normalNumber; //!< The number of the Normal out of the Array* normals, this vertex points to. 41 int texCoordNumber; //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to. 42 43 ModelFaceElement* next; //!< Point to the next FaceElement in this List. 44 }; 45 46 //! This is the placeholder of a Face belonging to a Group of Faces. 47 class ModelFace 48 { 49 public: 50 ModelFace(); 51 ~ModelFace(); 52 53 unsigned int vertexCount; //!< The Count of vertices this Face has. 54 ModelFaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. 55 Material* material; //!< The Material to use. 56 57 ModelFace* next; //!< Pointer to the next Face. 58 }; 59 60 //! Group to handle multiple Models per obj-file. 61 class ModelGroup 62 { 63 public: 64 ModelGroup(); 65 ~ModelGroup(); 66 67 void cleanup(); 68 69 std::string name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function. 70 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 71 GLuint listNumber; //!< The number of the GL-List this Group gets. 72 ModelFace* firstFace; //!< The first Face in this group. 73 ModelFace* currentFace; //!< The current Face in this Group (the one we are currently working with.) 74 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... 75 int faceCount; //!< The Number of Faces this Group holds. 76 77 ModelGroup* next; //!< Pointer to the next Group. 78 }; 79 80 struct ModelMaterial 81 { 82 Material* material; 83 bool external; 84 }; 13 #include "static_model_data.h" 85 14 86 15 ///////////// … … 94 23 class StaticModel : public Model 95 24 { 96 public: 25 ObjectListDeclaration(StaticModel); 26 public: 97 27 StaticModel(const std::string& modelName = ""); 28 StaticModel(const StaticModel& staticModel); 98 29 virtual ~StaticModel(); 99 30 100 virtual void draw() const; 101 void draw(int groupNumber) const; 102 void draw(const std::string& groupName) const; 31 StaticModel& operator=(const StaticModel& model); 103 32 104 void rebuild(); 33 virtual void draw() const { data->draw(); }; 34 void draw(int groupNumber) const { data->draw(groupNumber); }; 35 void draw(const std::string& groupName) const { data->draw(groupName); }; 105 36 106 Material* addMaterial(Material* material); 107 Material* addMaterial(const std::string& materialName); 37 void rebuild() { data->rebuild(); }; 108 38 109 bool addGroup(const std::string& groupString); 39 Material* addMaterial(Material* material) { return data->addMaterial(material); }; 40 Material* addMaterial(const std::string& materialName) { return data->addMaterial(materialName); }; 110 41 111 bool addVertex(const std::string& vertexString); 112 bool addVertex(float x, float y, float z); 42 bool addGroup(const std::string& groupString) { return data->addGroup(groupString); }; 113 43 114 bool addFace(const std::string& faceString); 44 bool addVertex(const std::string& vertexString) { return data->addVertex(vertexString); }; 45 bool addVertex(float x, float y, float z) { return data->addVertex(x, y, z); }; 46 47 bool addFace(const std::string& faceString) { return data->addFace(faceString); }; 115 48 bool addFace(int faceElemCount, VERTEX_FORMAT type, ...); 116 49 117 bool addVertexNormal(const std::string& normalString) ;118 bool addVertexNormal(float x, float y, float z) ;50 bool addVertexNormal(const std::string& normalString) { return this->data->addVertexNormal(normalString); }; 51 bool addVertexNormal(float x, float y, float z) { return this->data->addVertexNormal(x,y,z); }; 119 52 120 bool addVertexTexture(const std::string& vTextureString) ;121 bool addVertexTexture(float u, float v) ;53 bool addVertexTexture(const std::string& vTextureString) { return this->data->addVertexTexture(vTextureString); }; 54 bool addVertexTexture(float u, float v) { return this->data->addVertexTexture(u, v); }; 122 55 123 bool setMaterial(const std::string& mtlString) ;124 bool setMaterial(Material* mtl) ;56 bool setMaterial(const std::string& mtlString) { return data->setMaterial(mtlString); }; 57 bool setMaterial(Material* mtl) { return data->setMaterial(mtl);}; 125 58 126 59 void finalize(); 127 60 61 void acquireData(const StaticModelData::Pointer& data); 62 const StaticModelData::Pointer& dataPointer() const { return this->data; }; 128 63 129 protected: 64 inline void setScaleFactor(float scaleFactor) { this->data->setScaleFactor(scaleFactor); }; 65 float getScaleFactor() const { return data->getScaleFactor(); } 66 67 protected: 130 68 void cubeModel(); 131 69 132 Material* findMaterialByName(const std::string& materialName); 133 134 protected: 135 float scaleFactor; //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation 136 137 private: 138 bool buildVertexNormals(); 139 140 bool importToDisplayList(); 141 bool buildTriangleList(); 142 143 bool addGLElement(ModelFaceElement* elem); 144 145 bool cleanup(); 146 147 private: 148 bool finalized; //!< Sets the Object to be finalized. 149 150 unsigned int faceCount; //!< A modelwide Counter for the faces 151 152 std::vector<GLfloat> vertices; //!< The Array that handles the Vertices. 153 std::vector<GLfloat> normals; //!< The Array that handles the Normals. 154 std::vector<GLfloat> vTexture; //!< The Array that handles the VertexTextureCoordinates. 155 156 ModelGroup* firstGroup; //!< The first of all groups. 157 ModelGroup* currentGroup; //!< The currentGroup. this is the one we will work with. 158 int groupCount; //!< The Count of Groups. 159 160 std::list<ModelMaterial*> materialList; //!< A list for all the Materials in this Model 70 private: 71 void updateBase(); 72 private: 73 StaticModelData::Pointer data; 161 74 }; 162 75 -
trunk/src/lib/graphics/importer/texture.cc
r9406 r9869 64 64 #endif 65 65 66 66 ObjectListDefinition(Texture); 67 67 68 68 /** … … 86 86 : data(texture.data) 87 87 { 88 this-> setClassID(CL_TEXTURE, "Texture");88 this->registerObject(this, Texture::_objectList); 89 89 this->priority = 0.5; 90 90 } … … 149 149 void Texture::init() 150 150 { 151 this-> setClassID(CL_TEXTURE, "Texture");152 153 this->data = TextureData Pointer(new TextureData());151 this->registerObject(this, Texture::_objectList); 152 153 this->data = TextureData::Pointer(new TextureData()); 154 154 155 155 this->priority = 0.5; … … 176 176 } 177 177 178 Texture& Texture::operator=(const TextureData Pointer& textureDataPointer)178 Texture& Texture::operator=(const TextureData::Pointer& textureDataPointer) 179 179 { 180 180 this->data = textureDataPointer; -
trunk/src/lib/graphics/importer/texture.h
r8761 r9869 1 1 /*! 2 2 * @file texture.h 3 * @brief Contains the texture class, that handles the reading of Images into Tex utre-files.3 * @brief Contains the texture class, that handles the reading of Images into Texture-files. 4 4 */ 5 5 … … 20 20 class Texture : public BaseObject 21 21 { 22 ObjectListDeclaration(Texture); 22 23 public: 23 24 Texture(); … … 28 29 29 30 Texture& operator=(const Texture& texture); 30 Texture& operator=(const TextureDataPointer& textureDataPointer); 31 Texture& operator=(const TextureData::Pointer& textureDataPointer); 32 void acquireData(const TextureData::Pointer& textureDataPointer) { this->data = textureDataPointer; }; 33 const TextureData::Pointer& dataPointer() const { return data; } 31 34 32 35 virtual ~Texture(); … … 62 65 63 66 private: 64 TextureData Pointerdata; //!< The TextureData67 TextureData::Pointer data; //!< The TextureData 65 68 GLclampf priority; //!< the priority of the current texture (used for garphics cards with limited mem) 66 69 -
trunk/src/lib/graphics/importer/texture_data.h
r8761 r9869 18 18 class TextureData 19 19 { 20 public: 21 typedef CountPointer<TextureData> Pointer; 20 22 public: 21 23 TextureData(); … … 43 45 }; 44 46 45 typedef CountPointer<TextureData> TextureDataPointer;46 47 47 #endif /* _TEXTURE_DATA_H */ -
trunk/src/lib/graphics/importer/texture_sequence.cc
r9406 r9869 28 28 #endif 29 29 30 ObjectListDefinition(TextureSequence); 31 30 32 /** 31 33 * @brief Constructor for a Texture … … 33 35 TextureSequence::TextureSequence(unsigned int count, ...) 34 36 { 35 this-> setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");37 this->registerObject(this, TextureSequence::_objectList); 36 38 37 39 va_list textureNameList; … … 54 56 TextureSequence::TextureSequence(const std::vector<std::string>& textureNames, const std::string& prependFolder) 55 57 { 56 this-> setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");58 this->registerObject(this, TextureSequence::_objectList); 57 59 this->loadImageSeries(textureNames, prependFolder); 58 60 } -
trunk/src/lib/graphics/importer/texture_sequence.h
r8324 r9869 15 15 class TextureSequence : public Texture 16 16 { 17 ObjectListDeclaration(TextureSequence); 17 18 public: 18 19 TextureSequence(unsigned int count = 0, ...); -
trunk/src/lib/graphics/importer/vertex_array_model.cc
r9406 r9869 24 24 25 25 26 ObjectListDefinition(VertexArrayModel); 26 27 27 28 ///////////// … … 35 36 VertexArrayModel::VertexArrayModel() 36 37 { 37 this-> setClassID(CL_MODEL, "VertexArrayModel");38 this->registerObject(this, VertexArrayModel::_objectList); 38 39 39 40 this->newStripe(); … … 49 50 VertexArrayModel::VertexArrayModel(const Model& model) 50 51 { 51 this-> setClassID(CL_MODEL, "VertexArrayModel");52 this->registerObject(this, VertexArrayModel::_objectList); 52 53 53 54 // importing the data to the new Model. -
trunk/src/lib/graphics/importer/vertex_array_model.h
r6769 r9869 27 27 class VertexArrayModel : public Model 28 28 { 29 public: 29 ObjectListDeclaration(VertexArrayModel); 30 public: 30 31 VertexArrayModel(); 31 32 VertexArrayModel(const Model& model);
Note: See TracChangeset
for help on using the changeset viewer.