Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 22, 2006, 3:14:58 PM (18 years ago)
Author:
bensch
Message:

merged the bsp-model-stuff back here

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/md3/md3_data.cc

    r8490 r8724  
    3737MD3Data::MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale)
    3838{
    39 
    40 
     39  this->filename = modelFileName;
     40
     41  this->parentTagIndex = -1;
     42  this->parent = NULL;
     43
     44  this->animationState.currentFrame = 0;
     45  this->animationState.nextFrame = 1;
     46  this->animationState.interpolationFraction = 0.0f;
     47
     48  this->animation = NULL;
     49  this->bInterpolate = false;
     50  this->upperBound = 0;
    4151
    4252  this->loadModel(modelFileName);
    4353//   this->loadSkin(skinFileName);
     54  this->init();
    4455}
    4556
     
    5465  delete this->header;
    5566}
     67
     68
     69/**
     70 * init data
     71 */
     72void MD3Data::init()
     73{
     74  // create the temporary data to work with (interpolation data)
     75  this->tmpBoneFrame = new MD3BoneFrame();
     76
     77  this->tmpMesh = new sVec3D*[this->header->meshNum];
     78  for( int i = 0; i < this->header->meshNum; i++)
     79    this->tmpMesh[i] = new sVec3D[this->meshes[i]->header->vertexNum];
     80
     81  this->tmpNormal = new MD3Normal*[this->header->meshNum];
     82  for( int i = 0; i < this->header->meshNum; i++)
     83    this->tmpNormal[i] = new MD3Normal[this->meshes[i]->header->vertexNum];
     84
     85  // there are at most 4 different models and submodels
     86  this->tmpMatrix = new float*[4];
     87  for( int i = 0; i < 4; i++)
     88    this->tmpMatrix[i] = new float[16];
     89
     90}
     91
     92
     93/**
     94 * link a model at the specified tag position to this model. if the position is already
     95 * occupied, the old submodel will be replaced
     96 *
     97 *  @param tagIndex: tag to link the submodel to
     98 *  @param child: the submodel that should be linked to this model
     99 */
     100void MD3Data::addLinkedModel(int tagIndex, MD3Data* child)
     101{
     102  this->sortedMap[tagIndex] = child;
     103  child->parentTagIndex = tagIndex;
     104}
     105
     106
     107
     108/**
     109 * Return the index of the tag with the given name for this model.
     110 *
     111 * This will return -1 if their is no such tag.
     112 */
     113 int MD3Data::getTagIndexByName(std::string tagName)
     114{
     115   int res = -1;
     116
     117   if( this->header->boneFrameNum > 0) {
     118     MD3Tag** tags = this->boneFrames[0]->tags;
     119     for( int i = 0; i < this->header->tagNum; i++)
     120       if( tags[i]->name.find(tagName) == std::string::npos)
     121         return i;
     122   }
     123
     124   return res;
     125 }
    56126
    57127
     
    67137//  char* buffer;                           //buffer for frame data
    68138  int fileOffset = 0;                     // file data offset
    69 
    70139
    71140
     
    219288      fread(md, 1, sizeof(MD3TagData), pFile);
    220289      this->boneFrames[i]->tags[j]->data = md;
     290
     291      this->boneFrames[i]->tags[j]->name = std::string(this->boneFrames[i]->tags[j]->data->name);
     292      this->boneFrames[i]->tags[j]->position = Vector( this->boneFrames[i]->tags[j]->data->position[0],
     293                                                       this->boneFrames[i]->tags[j]->data->position[1],
     294                                                       this->boneFrames[i]->tags[j]->data->position[2]);
     295      for( int k = 0; k < 3; k++)
     296        for( int l = 0; l < 3; l++)
     297          this->boneFrames[i]->tags[j]->matrix[k][l] = this->boneFrames[i]->tags[j]->data->matrix[k][l];
     298
     299      //PRINTF(0)("Tag name: %s\n", this->boneFrames[i]->tags[j]->name.c_str());
    221300    }
    222301  }
     
    318397  fread(this->meshes[mesh]->triangles, 1, sizeof(MD3Triangle) * this->meshes[mesh]->header->triangleNum, pFile);
    319398
     399//   for( int i = 0; i < this->meshes[mesh]->header->triangleNum; i++) {
     400//     PRINTF(0)("Triangle read: %i, %i, %i\n", this->meshes[mesh]->triangles[i].vertexOffset[0], this->meshes[mesh]->triangles[i].vertexOffset[1]
     401//         , this->meshes[mesh]->triangles[i].vertexOffset[2]);
     402//   }
     403
    320404  return this->meshes[mesh]->header->triangleNum * sizeof(MD3Triangle);
    321405}
     
    337421  for( int i = 0; i < this->meshes[mesh]->header->textureNum; i++) {
    338422    PRINTF(0)(" texture file: %s\n", tex[i].fileName);
    339     this->meshes[mesh]->material[i].setDiffuseMap(tex[i].fileName);
     423#warning texture stuff hard coded. make this again
     424    std::string path("/home/boenzlip/tmp/q3/Downloads/MOH/q3mdl-alien3/");
     425    std::string path1(tex[i].fileName);
     426    std::string fullPath( path + path1);
     427    this->meshes[mesh]->material[i].setDiffuseMap(/*tex[i].fileName*/ /*fullPath.c_str()*/ "maps/creatures/gork/gorkup.tga");
    340428    this->meshes[mesh]->material[i].setAmbient(1, 1, 1);
    341429  }
     
    355443  fread(this->meshes[mesh]->texVecs, 1, sizeof(MD3TexVecs) * this->meshes[mesh]->header->vertexNum, pFile);
    356444
     445//   for( int i = 0; i < this->meshes[mesh]->header->vertexNum; i++)  {
     446//     PRINTF(0)("TexVec read: %f, %f\n", this->meshes[mesh]->texVecs[i].textureCoord[0], this->meshes[mesh]->texVecs[i].textureCoord[0]);
     447//   }
     448
    357449  return this->meshes[mesh]->header->vertexNum * sizeof(MD3TexVecs);
    358450}
     
    367459
    368460  // reserver memory for the vertex informations
    369   this->meshes[mesh]->meshFrames = new sVec3D[this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum];
    370   this->meshes[mesh]->normals = new MD3Normal[this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum];
    371 
    372   for( int i = 0; i < this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum; i++)
     461  this->meshes[mesh]->meshFrames = new sVec3D*[this->meshes[mesh]->header->meshFrameNum]; // * this->meshes[mesh]->header->vertexNum
     462  this->meshes[mesh]->normals = new MD3Normal*[this->meshes[mesh]->header->meshFrameNum];
     463
     464  for( int i = 0; i < this->meshes[mesh]->header->meshFrameNum; i++)
    373465  {
    374     // read out the compressed data
    375     MD3VertexCompressed* vc = new MD3VertexCompressed;
    376     fread(vc, 1, sizeof(MD3VertexCompressed), pFile);
    377 
    378     this->meshes[mesh]->meshFrames[i][0] = (float)vc->vector[0] / 64.0f;
    379     this->meshes[mesh]->meshFrames[i][1] = (float)vc->vector[1] / 64.0f;
    380     this->meshes[mesh]->meshFrames[i][2] = (float)vc->vector[2] / 64.0f;
    381 
    382     this->meshes[mesh]->normals[i].vertexNormal[0] = vc->vertexNormal[0];
    383     this->meshes[mesh]->normals[i].vertexNormal[1] = vc->vertexNormal[1];
    384 
    385     delete vc;
     466    this->meshes[mesh]->meshFrames[i] = new sVec3D[this->meshes[mesh]->header->vertexNum];
     467    this->meshes[mesh]->normals[i] = new MD3Normal[this->meshes[mesh]->header->vertexNum];
     468
     469    for( int j = 0; j < this->meshes[mesh]->header->vertexNum; j++)
     470    {
     471      // read out the compressed data
     472      MD3VertexCompressed* vc = new MD3VertexCompressed;
     473      fread(vc, 1, sizeof(MD3VertexCompressed), pFile);
     474
     475      this->meshes[mesh]->meshFrames[i][j][0] = (float)vc->vector[0] / 64.0f;
     476      this->meshes[mesh]->meshFrames[i][j][1] = (float)vc->vector[1] / 64.0f;
     477      this->meshes[mesh]->meshFrames[i][j][2] = (float)vc->vector[2] / 64.0f;
     478
     479      this->meshes[mesh]->normals[i][j].vertexNormal[0] = (int)vc->vertexNormal[0];
     480      this->meshes[mesh]->normals[i][j].vertexNormal[1] = (int)vc->vertexNormal[1];
     481
     482//     PRINTF(0)("nr: %i, meshframes: %f, %f, %f, normal: %f, %f\n", i, this->meshes[mesh]->meshFrames[i][0], this->meshes[mesh]->meshFrames[i][1],
     483//     this->meshes[mesh]->meshFrames[i][2], this->meshes[mesh]->normals[i].vertexNormal[0], this->meshes[mesh]->normals[i].vertexNormal[1]);
     484
     485      delete vc;
     486    }
    386487  }
    387488
    388   // delete the temp memory again
    389 //   delete vc;
    390 
    391489  return this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum * sizeof(MD3VertexCompressed);
    392490}
    393491
    394 }
    395 
    396 
    397 
    398 
    399 
    400 
    401 
     492
     493
     494}
     495
     496
     497
     498
     499
     500
     501
Note: See TracChangeset for help on using the changeset viewer.