- Timestamp:
- May 13, 2005, 3:40:23 PM (20 years ago)
- Location:
- orxonox/branches/md2_loader
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/md2_loader/ChangeLog
r3995 r4172 1 2005-05-10 Benjamin Grauer <bensch@orxonox.ethz.ch> 2 Merged the gui into the executable 3 Windows compiles again. 4 1 5 2005-04-27 orxonox 2 6 Tagged Version 0.2.3-pre-alpha -
orxonox/branches/md2_loader/src/defs/debug.h
r4139 r4172 59 59 #define DEBUG_MODULE_PNODE 0 60 60 #define DEBUG_MODULE_WORLD_ENTITY 0 61 #define DEBUG_MODULE_COMMAND_NODE 461 #define DEBUG_MODULE_COMMAND_NODE 0 62 62 #define DEBUG_MODULE_GRAPHICS 0 63 #define DEBUG_MODULE_LOAD 263 #define DEBUG_MODULE_LOAD 0 64 64 65 65 #define DEBUG_MODULE_IMPORTER 2 -
orxonox/branches/md2_loader/src/lib/graphics/importer/abstract_model.h
r4159 r4172 30 30 using namespace std; 31 31 32 //template<class T> class tList; 33 ; 32 33 34 //! this is a small and performant 3D vector 35 typedef float sVec3D[3]; 36 37 //! small and performant 2D vector 38 typedef float sVec2D[2]; 39 40 //! compressed vertex data: char insetead of float, the value will be expanded by the scale value. only for loading 41 typedef struct 42 { 43 byte v[3]; 44 unsigned char lightNormalIndex; 45 } sVertex; 46 47 //! compressed texture offset data: coords scaled by the texture size. Only for loading 48 typedef struct 49 { 50 short s,t; 51 } sTexCoor; 52 53 54 //! holds tha informations about a md2 frame 55 typedef struct 56 { 57 sVec3D scale; //!< scales values of the model 58 sVec3D translate; //!< translates the model 59 char name[16]; //!< frame name: something like "run32" 60 sVertex pVertices[1]; //!< first vertex of thes frame 61 } sFrame; 62 63 64 //! holds the information about a triangle 65 typedef struct 66 { 67 short indexToVertices[3]; //!< index to the verteces of the triangle 68 short indexToTexCoor[3]; //!< index to the texture coordinates 69 } sTriangle; 70 71 72 //! a md2 animation definition 73 typedef struct 74 { 75 int firstFrame; //!< first frame of the animation 76 int lastFrame; //!< last frame of the animation 77 int fps; //!< speed: number of frames per second 78 } sAnim; 79 80 //! animation state definition 81 typedef struct 82 { 83 int startFrame; 84 int endFrame; 85 int fps; 86 87 float localTime; 88 float lastTime; 89 float interpolationState; //!< the state of the animation [0..1] 90 91 int type; //!< animation type 92 93 int currentFrame; 94 int nextFrame; 95 } sAnimState; 96 34 97 35 98 //! This is our 3D point class. CONFLICTING with Vector.cc 36 99 class CVector3 37 100 { 38 public:39 101 public: 102 float x, y, z; 40 103 }; 41 104 … … 43 106 class CVector2 44 107 { 45 public:46 108 public: 109 float x, y; 47 110 }; 48 111 … … 50 113 struct tFace 51 114 { 52 53 115 int vertIndex[3]; // indicies for the verts that make up this triangle 116 int coordIndex[3]; // indicies for the tex coords to texture this face 54 117 }; 55 118 … … 57 120 struct tMaterialInfo 58 121 { 59 60 61 62 63 64 65 float uOffset;// u offset of texture66 122 char strName[255]; // The texture name 123 char strFile[255]; // The texture file name (If this is set it's a texture map) 124 byte color[3]; // The color of the object (R, G, B) 125 int texureId; // the texture ID 126 float uTile; // u tiling of texture 127 float vTile; // v tiling of texture 128 float uOffset; // u offset of texture 129 float vOffset; // v offset of texture 67 130 } ; 68 131 … … 70 133 struct t3DObject 71 134 { 72 73 74 75 76 77 78 79 80 81 135 int numOfVerts; // The number of verts in the model 136 int numOfFaces; // The number of faces in the model 137 int numTexVertex; // The number of texture coordinates 138 int materialID; // The texture ID to use, which is the index into our texture array 139 bool bHasTexture; // This is TRUE if there is a texture map for this object 140 char strName[255]; // The name of the object 141 CVector3 *pVerts; // The object's vertices 142 CVector3 *pNormals; // The object's normals 143 CVector2 *pTexVerts; // The texture's UV coordinates 144 tFace *pFaces; // The faces information of the object 82 145 }; 83 146 … … 85 148 struct tAnimationInfo 86 149 { 87 88 89 150 char strName[255]; // This stores the name of the animation (Jump, Pain, etc..) 151 int startFrame; // This stores the first frame number for this animation 152 int endFrame; // This stores the last frame number for this animation 90 153 }; 91 154 … … 93 156 struct t3DModel 94 157 { 95 96 97 98 99 100 101 102 158 int numOfObjects; // The number of objects in the model 159 int numOfMaterials; // The number of materials for the model 160 int numOfAnimations; // The number of animations in this model (NEW) 161 int currentAnim; // The current index into pAnimations list (NEW) 162 int currentFrame; // The current frame of the current animation (NEW) 163 vector<tAnimationInfo> animationList; // The list of animations (NEW) 164 vector<tMaterialInfo> materialList; // The list of material information (Textures and colors) 165 vector<t3DObject> objectList; // The object list for our model 103 166 }; 104 167 -
orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.cc
r4169 r4172 16 16 17 17 #include "md2Model.h" 18 #include "material.h" 18 19 19 20 #include <fstream> … … 107 108 { 108 109 pModel->currentFrame = nextFrame; 109 printf("changing frame\n");110 110 this->localTime = 0.0f; 111 111 } 112 printf("t = %f\n", this->localTime);113 112 return (this->localTime / kAnimationSpeed); 114 113 } … … 455 454 if( this->pFrames) delete this->pFrames; 456 455 } 456 457 458 /******************************************************************************** 459 * MD2LOADER2 * 460 ********************************************************************************/ 461 462 MD2Model2::MD2Model2() 463 { 464 this->pVertices = NULL; 465 this->pGLCommands = NULL; 466 this->pLightNormals = NULL; 467 468 this->numFrames = 0; 469 this->numVertices = 0; 470 this->numGLCommands = 0; 471 472 this->textureID = 0; 473 this->scaleFactor = 1.0f; 474 475 //this->setAnim(0); 476 } 477 478 479 MD2Model2::~MD2Model2() 480 { 481 delete [] this->pVertices; 482 delete [] this->pGLCommands; 483 delete [] this->pLightNormals; 484 } 485 486 487 488 bool MD2Model2::loadModel(const char *fileName) 489 { 490 FILE *pFile; //file stream 491 tMd2Header header; 492 char* buffer; //buffer for frame data 493 sFrame* frame; //temp frame 494 sVec3D *pVertex; 495 int* pNormals; 496 497 pFile = fopen(fileName, "rb"); 498 if( unlikely(!pFile)) 499 { 500 PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n"); 501 return false; 502 } 503 fread(&header, 1, sizeof(tMd2Header), pFile); 504 /* check for the header version: make sure its a md2 file :) */ 505 if( unlikely(header.version != MD2_VERSION) && unlikely(header.ident != MD2_IDENT)) 506 { 507 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName); 508 return false; 509 } 510 511 /* got the data: map it to locals */ 512 this->numFrames = header.numFrames; 513 this->numVertices = header.numVertices; 514 this->numGLCommands = header.numGlCommands; 515 /* allocate memory for the data storage */ 516 this->pVertices = new sVec3D[this->numVertices * this->numFrames]; 517 this->pGLCommands = new int[this->numGLCommands]; 518 this->pLightNormals = new int[this->numVertices * this->numFrames]; 519 buffer = new char[this->numFrames * header.frameSize]; 520 521 /* read frame data from the file to a temp buffer */ 522 fseek(pFile, header.offsetFrames, SEEK_SET); 523 fread(buffer, header.frameSize, this->numFrames, pFile); 524 /* read opengl commands */ 525 fseek(pFile, header.offsetGlCommands, SEEK_SET); 526 fread(this->pGLCommands, sizeof(int), this->numGLCommands, pFile); 527 528 for(int i = 0; i < this->numFrames; ++i) 529 { 530 frame = (sFrame*)(buffer + header.frameSize * i); 531 pVertex = this->pVertices + this->numVertices * i; 532 pNormals = this->pLightNormals + this->numVertices * i; 533 534 for(int j = 0; j < this->numVertices; ++j) 535 { 536 /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)... */ 537 pVertex[i][0] = (frame->pVertices[i].v[0] * frame->scale[0]) + frame->translate[0]; 538 pVertex[i][1] = (frame->pVertices[i].v[1] * frame->scale[1]) + frame->translate[1]; 539 pVertex[i][2] = (frame->pVertices[i].v[2] * frame->scale[2]) + frame->translate[2]; 540 541 pNormals[i] = frame->pVertices[i].lightNormalIndex; 542 } 543 } 544 545 delete [] buffer; 546 fclose(pFile); 547 } 548 549 550 bool MD2Model2::loadSkin(const char* fileName) 551 { 552 this->material = new Material("md2ModelTest"); 553 this->material->setDiffuseMap(fileName); 554 this->material->setIllum(3); 555 this->material->setAmbient(1.0, 1.0, 1.0); 556 } 557 558 559 void MD2Model2::draw() 560 { 561 glPushMatrix(); 562 /* rotate because id software uses another orientation then the openGL default */ 563 /* \todo: rotate the axis already when loading... easy :) */ 564 glRotatef(-90.0, 1.0, 0.0, 0.0); 565 glRotatef(-90.0, 0.0, 0.0, 1.0); 566 567 this->renderFrame(); 568 569 glPopMatrix(); 570 } 571 572 573 /** 574 \brief initializes an array of vert with the current frame scaled vertices 575 576 we won't use the pVertices array directly, since its much easier and we need 577 saving of data anyway 578 */ 579 void MD2Model2::interpolate(sVec3D* verticesList) 580 { 581 for(int i = 0; i < this->numFrames; ++i) 582 { 583 verticesList[i][0] = this->pVertices[i + (this->numFrames * this->animationState.currentFrame)][0] * this->scaleFactor; 584 verticesList[i][1] = this->pVertices[i + (this->numFrames * this->animationState.currentFrame)][1] * this->scaleFactor; 585 verticesList[i][2] = this->pVertices[i + (this->numFrames * this->animationState.currentFrame)][2] * this->scaleFactor; 586 } 587 } 588 589 590 /* hhmmm... id used a very different way to do lightning...*/ 591 void MD2Model2::processLighting() 592 { 593 } 594 595 596 void MD2Model2::renderFrame() 597 { 598 static sVec3D verticesList[MD2_MAX_VERTICES]; /* performance: created only once in a lifetime */ 599 int* pCommands = this->pGLCommands; 600 601 /* some face culling stuff */ 602 glPushAttrib(GL_POLYGON_BIT); 603 glFrontFace(GL_CW); 604 glEnable(GL_CULL_FACE); 605 glCullFace(GL_BACK); 606 607 this->interpolate(verticesList); 608 this->material->select(); 609 610 /* draw the triangles */ 611 /* \todo: take int i out of while loop */ 612 while( int i = *(pCommands++)) /* strange looking while loop for maximum performance */ 613 { 614 if( i < 0) 615 { 616 glBegin(GL_TRIANGLE_FAN); 617 i = -i; 618 } 619 else 620 { 621 glBegin(GL_TRIANGLE_STRIP); 622 } 623 624 for(; i > 0; --i, pCommands += 3) /* down counting for loop, next 3 gl commands */ 625 { 626 /* for quake2 lighting */ 627 //float l = shadedots[this->pLightNormals[pCommands[2]]]; 628 //glColor3f(l * lcolor[0], l * lcolor[1], l * lcolor[2]); 629 630 glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] ); 631 //glNormal3fv(anorms[this->pLightNormals[2]]); 632 glVertex3fv(verticesList[pCommands[2]]); 633 } 634 glEnd(); 635 } 636 glDisable(GL_CULL_FACE); 637 glPopAttrib(); 638 } 639 -
orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.h
r4168 r4172 25 25 26 26 //! These are the needed defines for the max values when loading .MD2 files 27 #define MD2_IDENT (('2'<<24) + ('P'<<16) + ('D'<<8) + 'I') 28 #define MD2_VERSION 8 27 29 #define MD2_MAX_TRIANGLES 4096 28 30 #define MD2_MAX_VERTICES 2048 … … 31 33 #define MD2_MAX_SKINS 32 32 34 #define MD2_MAX_FRAMESIZE (MD2_MAX_VERTICES * 4 + 128) 35 36 #define NUM_VERTEX_NORMALS 162 37 #define SHADEDOT_QUANT 16 33 38 34 39 //! This stores the speed of the animation between each key frame - currently conflicting with the animation framework … … 107 112 typedef char tMd2Skin[64]; 108 113 114 109 115 //! This is a MD2 Model class 110 116 class MD2Model : public AbstractModel { … … 137 143 }; 138 144 145 /* forward definitions */ 146 class Material; 147 148 //! This is a MD2 Model class 149 class MD2Model2 : public AbstractModel { 150 151 public: 152 MD2Model2(); 153 virtual ~MD2Model2(); 154 155 bool loadModel(const char* filename); 156 bool loadSkin(const char* filename); 157 158 void drawFrame(int frame); 159 void draw(); 160 161 void setAnim(int type); 162 void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;} 163 164 void tick(float dtS); 165 166 private: 167 void animate(float time); 168 void processLighting(); 169 void interpolate(sVec3D* verticesList); 170 void renderFrame(); 171 172 public: 173 /* these variables are static, because they are all the same for every model */ 174 static sVec3D anorms[NUM_VERTEX_NORMALS]; 175 static float anormsDots[SHADEDOT_QUANT][256]; 176 static sAnim animationList[21]; 177 178 private: 179 int numFrames; 180 int numVertices; 181 int numGLCommands; 182 183 sVec3D* pVertices; 184 int* pGLCommands; 185 int* pLightNormals; 186 187 unsigned int textureID; 188 Material* material; 189 sAnimState animationState; 190 float scaleFactor; 191 }; 192 193 139 194 //! A class that handles all of the loading code 140 195 class MD2Loader : public BaseObject { -
orxonox/branches/md2_loader/src/world_entities/test_entity.cc
r4168 r4172 28 28 TestEntity::TestEntity () : WorldEntity() 29 29 { 30 this->md2Model = new MD2Model(); 30 //this->md2Model = new MD2Model(); 31 32 MD2Model2* model2 = new MD2Model2(); 33 model2->loadModel("../data/models/tris.md2"); 31 34 32 35 this->material = new Material("Clown"); … … 43 46 void TestEntity::tick (float time) 44 47 { 45 this->md2Model->tick(time);48 //this->md2Model->tick(time); 46 49 } 47 50 … … 68 71 69 72 /* TESTGING TESTING TESTING */ 70 this->material->select();73 //this->material->select(); 71 74 //this->md2Model->draw(this->model); 72 this->md2Model->animate();75 //this->md2Model->animate(); 73 76 74 77 glPopMatrix();
Note: See TracChangeset
for help on using the changeset viewer.