Index: trunk/src/lib/graphics/importer/md3/md3_data.cc
===================================================================
--- trunk/src/lib/graphics/importer/md3/md3_data.cc	(revision 8490)
+++ trunk/src/lib/graphics/importer/md3/md3_data.cc	(revision 8724)
@@ -37,9 +37,20 @@
 MD3Data::MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale)
 {
-
-
+  this->filename = modelFileName;
+
+  this->parentTagIndex = -1;
+  this->parent = NULL;
+
+  this->animationState.currentFrame = 0;
+  this->animationState.nextFrame = 1;
+  this->animationState.interpolationFraction = 0.0f;
+
+  this->animation = NULL;
+  this->bInterpolate = false;
+  this->upperBound = 0;
 
   this->loadModel(modelFileName);
 //   this->loadSkin(skinFileName);
+  this->init();
 }
 
@@ -54,4 +65,63 @@
   delete this->header;
 }
+
+
+/**
+ * init data
+ */
+void MD3Data::init()
+{
+  // create the temporary data to work with (interpolation data)
+  this->tmpBoneFrame = new MD3BoneFrame();
+
+  this->tmpMesh = new sVec3D*[this->header->meshNum];
+  for( int i = 0; i < this->header->meshNum; i++)
+    this->tmpMesh[i] = new sVec3D[this->meshes[i]->header->vertexNum];
+
+  this->tmpNormal = new MD3Normal*[this->header->meshNum];
+  for( int i = 0; i < this->header->meshNum; i++)
+    this->tmpNormal[i] = new MD3Normal[this->meshes[i]->header->vertexNum];
+
+  // there are at most 4 different models and submodels
+  this->tmpMatrix = new float*[4];
+  for( int i = 0; i < 4; i++)
+    this->tmpMatrix[i] = new float[16];
+
+}
+
+
+/**
+ * link a model at the specified tag position to this model. if the position is already
+ * occupied, the old submodel will be replaced
+ *
+ *  @param tagIndex: tag to link the submodel to
+ *  @param child: the submodel that should be linked to this model
+ */
+void MD3Data::addLinkedModel(int tagIndex, MD3Data* child)
+{
+  this->sortedMap[tagIndex] = child;
+  child->parentTagIndex = tagIndex;
+}
+
+
+
+/**
+ * Return the index of the tag with the given name for this model.
+ *
+ * This will return -1 if their is no such tag.
+ */
+ int MD3Data::getTagIndexByName(std::string tagName)
+{
+   int res = -1;
+
+   if( this->header->boneFrameNum > 0) {
+     MD3Tag** tags = this->boneFrames[0]->tags;
+     for( int i = 0; i < this->header->tagNum; i++)
+       if( tags[i]->name.find(tagName) == std::string::npos)
+         return i;
+   }
+
+   return res;
+ }
 
 
@@ -67,5 +137,4 @@
 //  char* buffer;                           //buffer for frame data
   int fileOffset = 0;                     // file data offset
-
 
 
@@ -219,4 +288,14 @@
       fread(md, 1, sizeof(MD3TagData), pFile);
       this->boneFrames[i]->tags[j]->data = md;
+
+      this->boneFrames[i]->tags[j]->name = std::string(this->boneFrames[i]->tags[j]->data->name);
+      this->boneFrames[i]->tags[j]->position = Vector( this->boneFrames[i]->tags[j]->data->position[0],
+                                                       this->boneFrames[i]->tags[j]->data->position[1],
+                                                       this->boneFrames[i]->tags[j]->data->position[2]);
+      for( int k = 0; k < 3; k++)
+        for( int l = 0; l < 3; l++)
+          this->boneFrames[i]->tags[j]->matrix[k][l] = this->boneFrames[i]->tags[j]->data->matrix[k][l];
+
+      //PRINTF(0)("Tag name: %s\n", this->boneFrames[i]->tags[j]->name.c_str());
     }
   }
@@ -318,4 +397,9 @@
   fread(this->meshes[mesh]->triangles, 1, sizeof(MD3Triangle) * this->meshes[mesh]->header->triangleNum, pFile);
 
+//   for( int i = 0; i < this->meshes[mesh]->header->triangleNum; i++) {
+//     PRINTF(0)("Triangle read: %i, %i, %i\n", this->meshes[mesh]->triangles[i].vertexOffset[0], this->meshes[mesh]->triangles[i].vertexOffset[1]
+//         , this->meshes[mesh]->triangles[i].vertexOffset[2]);
+//   }
+
   return this->meshes[mesh]->header->triangleNum * sizeof(MD3Triangle);
 }
@@ -337,5 +421,9 @@
   for( int i = 0; i < this->meshes[mesh]->header->textureNum; i++) {
     PRINTF(0)(" texture file: %s\n", tex[i].fileName);
-    this->meshes[mesh]->material[i].setDiffuseMap(tex[i].fileName);
+#warning texture stuff hard coded. make this again
+    std::string path("/home/boenzlip/tmp/q3/Downloads/MOH/q3mdl-alien3/");
+    std::string path1(tex[i].fileName);
+    std::string fullPath( path + path1);
+    this->meshes[mesh]->material[i].setDiffuseMap(/*tex[i].fileName*/ /*fullPath.c_str()*/ "maps/creatures/gork/gorkup.tga");
     this->meshes[mesh]->material[i].setAmbient(1, 1, 1);
   }
@@ -355,4 +443,8 @@
   fread(this->meshes[mesh]->texVecs, 1, sizeof(MD3TexVecs) * this->meshes[mesh]->header->vertexNum, pFile);
 
+//   for( int i = 0; i < this->meshes[mesh]->header->vertexNum; i++)  {
+//     PRINTF(0)("TexVec read: %f, %f\n", this->meshes[mesh]->texVecs[i].textureCoord[0], this->meshes[mesh]->texVecs[i].textureCoord[0]);
+//   }
+
   return this->meshes[mesh]->header->vertexNum * sizeof(MD3TexVecs);
 }
@@ -367,35 +459,43 @@
 
   // reserver memory for the vertex informations
-  this->meshes[mesh]->meshFrames = new sVec3D[this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum];
-  this->meshes[mesh]->normals = new MD3Normal[this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum];
-
-  for( int i = 0; i < this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum; i++)
+  this->meshes[mesh]->meshFrames = new sVec3D*[this->meshes[mesh]->header->meshFrameNum]; // * this->meshes[mesh]->header->vertexNum
+  this->meshes[mesh]->normals = new MD3Normal*[this->meshes[mesh]->header->meshFrameNum];
+
+  for( int i = 0; i < this->meshes[mesh]->header->meshFrameNum; i++)
   {
-    // read out the compressed data
-    MD3VertexCompressed* vc = new MD3VertexCompressed;
-    fread(vc, 1, sizeof(MD3VertexCompressed), pFile);
-
-    this->meshes[mesh]->meshFrames[i][0] = (float)vc->vector[0] / 64.0f;
-    this->meshes[mesh]->meshFrames[i][1] = (float)vc->vector[1] / 64.0f;
-    this->meshes[mesh]->meshFrames[i][2] = (float)vc->vector[2] / 64.0f;
-
-    this->meshes[mesh]->normals[i].vertexNormal[0] = vc->vertexNormal[0];
-    this->meshes[mesh]->normals[i].vertexNormal[1] = vc->vertexNormal[1];
-
-    delete vc;
+    this->meshes[mesh]->meshFrames[i] = new sVec3D[this->meshes[mesh]->header->vertexNum];
+    this->meshes[mesh]->normals[i] = new MD3Normal[this->meshes[mesh]->header->vertexNum];
+
+    for( int j = 0; j < this->meshes[mesh]->header->vertexNum; j++)
+    {
+      // read out the compressed data
+      MD3VertexCompressed* vc = new MD3VertexCompressed;
+      fread(vc, 1, sizeof(MD3VertexCompressed), pFile);
+
+      this->meshes[mesh]->meshFrames[i][j][0] = (float)vc->vector[0] / 64.0f;
+      this->meshes[mesh]->meshFrames[i][j][1] = (float)vc->vector[1] / 64.0f;
+      this->meshes[mesh]->meshFrames[i][j][2] = (float)vc->vector[2] / 64.0f;
+
+      this->meshes[mesh]->normals[i][j].vertexNormal[0] = (int)vc->vertexNormal[0];
+      this->meshes[mesh]->normals[i][j].vertexNormal[1] = (int)vc->vertexNormal[1];
+
+//     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],
+//     this->meshes[mesh]->meshFrames[i][2], this->meshes[mesh]->normals[i].vertexNormal[0], this->meshes[mesh]->normals[i].vertexNormal[1]);
+
+      delete vc;
+    }
   }
 
-  // delete the temp memory again
-//   delete vc;
-
   return this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum * sizeof(MD3VertexCompressed);
 }
 
-}
-
-
-
-
-
-
-
+
+
+}
+
+
+
+
+
+
+
