Index: /branches/bsp_model/src/lib/graphics/importer/Makefile.am
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/Makefile.am	(revision 8343)
+++ /branches/bsp_model/src/lib/graphics/importer/Makefile.am	(revision 8344)
@@ -5,4 +5,5 @@
 
 libORXimporter_a_SOURCES = model.cc \
+			   md_model_structure.cc \
                            vertex_array_model.cc \
                            grid.cc \
@@ -26,5 +27,6 @@
                            md3/md3_animation.cc \
                            md3/md3_bone_frame.cc \
-                           md3/md3_mesh.cc
+                           md3/md3_mesh.cc \
+                           md3/md3_data.cc
 
 
@@ -35,4 +37,5 @@
 noinst_HEADERS = \
 		model.h \
+		md_model_structure.cc \
 		tc.h \
 		vertex_array_model.h \
@@ -59,4 +62,5 @@
                 md3/md3_animation.h \
                 md3/md3_bone_frame.h \
-                md3/md3_mesh.h
+                md3/md3_mesh.h \
+                md3/md3_data.h
 
Index: /branches/bsp_model/src/lib/graphics/importer/md2Model.h
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/md2Model.h	(revision 8343)
+++ /branches/bsp_model/src/lib/graphics/importer/md2Model.h	(revision 8344)
@@ -23,4 +23,6 @@
 #include "model.h"
 #include "material.h"
+
+#include "md_model_structure.h"
 
 //! These are the needed defines for the max values when loading .MD2 files
@@ -64,79 +66,4 @@
    int offsetEnd;                       //!< The end of the file offset
 };
-
-
-//! compressed vertex data: char insetead of float, the value will be expanded by the scale value. only for loading
-typedef struct
-{
-  unsigned char    v[3];                 //!< the vector of the vertex
-  unsigned char    lightNormalIndex;     //!< the index of the light normal
-} sVertex;
-
-
-//! compressed texture offset data: coords scaled by the texture size. Only for loading
-typedef struct
-{
-  short            s;                    //!< the s,t coordinates of a texture
-  short            t;                    //!< the s,t coordinates of a texture
-} sTexCoor;
-
-
-//! holds tha informations about a md2 frame
-typedef struct
-{
-  sVec3D           scale;                //!< scales values of the model
-  sVec3D           translate;            //!< translates the model
-  char             name[16];             //!< frame name: something like "run32"
-  sVertex          pVertices[1];         //!< first vertex of thes frame
-} sFrame;
-
-
-//! holds the information about a triangle
-typedef struct
-{
-  unsigned short   indexToVertices[3];   //!< index to the verteces of the triangle
-  unsigned short   indexToTexCoor[3];    //!< index to the texture coordinates
-} sTriangle;
-
-
-
-//! the command list of the md2 model, very md2 specific
-typedef struct
-{
-  float            s;                    //!< texture coordinate 1
-  float            t;                    //!< texture coordinate 2
-  int              vertexIndex;          //!< index of the vertex in the vertex list
-} glCommandVertex;
-
-
-//! a md2 animation definition
-typedef struct
-{
-  int              firstFrame;           //!< first frame of the animation
-  int              lastFrame;            //!< last frame of the animation
-  int              fps;                  //!< speed: number of frames per second
-  int              bStoppable;           //!< 1 if the animation is stoppable 0 else
-} sAnim;
-
-
-//! animation state definition
-typedef struct
-{
-  int              startFrame;           //!< the start frame of an animation
-  int              endFrame;             //!< last frame of the animation
-  int              fps;                  //!< fps of the animaion (speed)
-
-  float            localTime;            //!< the local time
-  float            lastTime;             //!< last time stamp
-  float            interpolationState;   //!< the state of the animation [0..1]
-
-  int              type;                 //!< animation type
-
-  int              currentFrame;         //!< the current frame
-  int              nextFrame;            //!< the next frame in the list
-  int              numPlays;             //!< the number of times, this has been played in series
-
-  int              animPlaybackMode;     //!< the playback mode
-} sAnimState;
 
 
Index: /branches/bsp_model/src/lib/graphics/importer/md3/md3_data.cc
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/md3/md3_data.cc	(revision 8344)
+++ /branches/bsp_model/src/lib/graphics/importer/md3/md3_data.cc	(revision 8344)
@@ -0,0 +1,175 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Patrick Boenzli
+*/
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
+
+#include "md3_data.h"
+
+
+
+/********************************************************************************
+ *   MD3Data                                                                    *
+ ********************************************************************************/
+
+/**
+  \brief simple constructor
+*/
+MD3Data::MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale)
+{
+  scale *= 0.1f;
+
+  this->pVertices = NULL;
+  this->pGLCommands = NULL;
+  this->pLightNormals = NULL;
+  this->pTexCoor = NULL;
+
+  this->numFrames = 0;
+  this->numVertices = 0;
+  this->numGLCommands = 0;
+  this->numTexCoor = 0;
+
+//   this->scaleFactor = 1.0f;
+  this->scaleFactor = scale;
+
+  this->fileName = "";
+  this->skinFileName = "";
+  this->loadModel(modelFileName);
+  this->loadSkin(skinFileName);
+}
+
+
+/**
+  \brief simple destructor
+
+  this will clean out all the necessary data for a specific md2model
+*/
+MD3Data::~MD3Data()
+{
+  delete this->header;
+
+  delete [] this->pVertices;
+  delete [] this->pGLCommands;
+  delete [] this->pLightNormals;
+  delete [] this->pTexCoor;
+}
+
+
+
+/**
+  \brief this will load the whole model data (vertices, opengl command list, ...)
+* @param fileName: the name of the model file
+  \return true if success
+*/
+bool MD3Data::loadModel(const std::string& fileName)
+{
+  FILE *pFile;                            //file stream
+  char* buffer;                           //buffer for frame data
+  sFrame* frame;                          //temp frame
+  sVec3D *pVertex;
+  int* pNormals;
+
+  //! @todo this chek should include deleting a loaded model (eventually)
+  if (fileName.empty())
+    return false;
+
+  pFile = fopen(fileName.c_str(), "rb");
+  if( unlikely(!pFile))
+    {
+      PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n");
+      return false;
+    }
+  this->header = new MD2Header;
+  fread(this->header, 1, sizeof(MD2Header), pFile);
+  /* check for the header version: make sure its a md2 file :) */
+  if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
+    {
+      PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
+      return false;
+    }
+
+  this->fileName =fileName;
+  /* got the data: map it to locals */
+  this->numFrames = this->header->numFrames;
+  this->numVertices = this->header->numVertices;
+  this->numTriangles = this->header->numTriangles;
+  this->numGLCommands = this->header->numGlCommands;
+  this->numTexCoor = this->header->numTexCoords;
+  /* allocate memory for the data storage */
+  this->pVertices = new sVec3D[this->numVertices * this->numFrames];
+  this->pGLCommands = new int[this->numGLCommands];
+  this->pLightNormals = new int[this->numVertices * this->numFrames];
+  this->pTriangles = new sTriangle[this->numTriangles];
+  this->pTexCoor = new sTexCoor[this->numTexCoor];
+  buffer = new char[this->numFrames * this->header->frameSize];
+
+
+  /* read frame data from the file to a temp buffer */
+  fseek(pFile, this->header->offsetFrames, SEEK_SET);
+  fread(buffer, this->header->frameSize, this->numFrames, pFile);
+  /* read opengl commands */
+  fseek(pFile, this->header->offsetGlCommands, SEEK_SET);
+  fread(this->pGLCommands, sizeof(int), this->numGLCommands, pFile);
+  /* triangle list */
+  fseek(pFile, this->header->offsetTriangles, SEEK_SET);
+  fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);
+  /*  read in texture coordinates */
+  fseek(pFile, this->header->offsetTexCoords, SEEK_SET);
+  fread(this->pTexCoor, sizeof(sTexCoor), this->numTexCoor, pFile);
+
+
+  for(int i = 0; i < this->numFrames; ++i)
+    {
+      frame = (sFrame*)(buffer + this->header->frameSize * i);
+      pVertex = this->pVertices + this->numVertices  * i;
+      pNormals = this->pLightNormals + this->numVertices * i;
+
+      for(int j = 0; j < this->numVertices; ++j)
+        {
+          /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)...  */
+           pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor;
+           pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor;
+           pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor;
+
+          //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]);
+
+          pNormals[j] = frame->pVertices[j].lightNormalIndex;
+        }
+    }
+    PRINTF(4)("Finished loading the md2 file\n");
+
+  delete [] buffer;
+  fclose(pFile);
+}
+
+
+/**
+  \brief loads the skin/material stuff
+* @param fileName: name of the skin file
+  \return true if success
+*/
+bool MD3Data::loadSkin(const std::string& fileName)
+{
+  if( fileName.empty())
+    {
+      this->skinFileName = "";
+      return false;
+    }
+
+  this->skinFileName = fileName;
+
+  this->material.setName("md2ModelMaterial");
+  this->material.setDiffuseMap(fileName);
+  this->material.setIllum(3);
+  this->material.setAmbient(1.0, 1.0, 1.0);
+}
Index: /branches/bsp_model/src/lib/graphics/importer/md3/md3_data.h
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/md3/md3_data.h	(revision 8344)
+++ /branches/bsp_model/src/lib/graphics/importer/md3/md3_data.h	(revision 8344)
@@ -0,0 +1,109 @@
+/*!
+ * @file md2Model.h
+  *  Definition of an MD2 Model, a model format invented by ID Software.
+
+    We are deeply thankfull for all the wunderfull things id software made for us gamers!
+
+    The md2 file format is structured in a very simple way: it contains animations which are made out of
+    frames (so called keyframes). Each frame is a complete draweable model in a specific position.
+    A frame is a collection of vertex and its compagnions (normals, texture coordinates).
+
+    A typical model has about 200 frames, the maximum frame count is fixed by MD2_MAX_FRAMES to currently
+    512 frames. The maximal vetices count is set to 2048 verteces, not enough?
+    You just have to change the MD2_MAX_* values if it doesn't fit your purposes...
+
+    Surface Culling is fully implemented in md2 models: quake2 uses front face culling.
+*/
+
+#ifndef _MD2MODEL_H
+#define _MD3_DATA_H
+
+#include "base_object.h"
+
+#include "model.h"
+#include "material.h"
+#include "md_model_structure.h"
+
+//! These are the needed defines for the max values when loading .MD2 files
+#define MD2_IDENT                       (('2'<<24) + ('P'<<16) + ('D'<<8) + 'I') //!< the md2 identifier tag in the bin file
+#define MD2_VERSION                     8                                        //!< the md2 version in the header
+#define MD2_MAX_TRIANGLES               4096                                     //!< maximal triangles count
+#define MD2_MAX_VERTICES                2048                                     //!< maximal vertices count
+#define MD2_MAX_TEXCOORDS               2048                                     //!< maximal tex coordinates
+#define MD2_MAX_FRAMES                  512                                      //!< maximal frames
+#define MD2_MAX_SKINS                   32                                       //!< maximal skins
+#define MD2_MAX_FRAMESIZE               (MD2_MAX_VERTICES * 4 + 128)             //!< maximal framesize
+
+#define NUM_VERTEX_NORMALS              162                                      //!< number of vertex normals
+#define SHADEDOT_QUANT                  16                                       //!< shade dot quantity - no idea what it is
+
+//! This stores the speed of the animation between each key frame - currently conflicting with the animation framework
+#define kAnimationSpeed                 12.0f                                    //!< animation speed
+
+
+//! This holds the header information that is read in at the beginning of the file: id software definition
+struct MD2Header
+{
+   int ident;                           //!< This is used to identify the file
+   int version;                         //!< The version number of the file (Must be 8)
+
+   int skinWidth;                       //!< The skin width in pixels
+   int skinHeight;                      //!< The skin height in pixels
+   int frameSize;                       //!< The size in bytes the frames are
+
+   int numSkins;                        //!< The number of skins associated with the model
+   int numVertices;                     //!< The number of vertices (constant for each frame)
+   int numTexCoords;                    //!< The number of texture coordinates
+   int numTriangles;                    //!< The number of faces (polygons)
+   int numGlCommands;                   //!< The number of gl commands
+   int numFrames;                       //!< The number of animation frames
+
+   int offsetSkins;                     //!< The offset in the file for the skin data
+   int offsetTexCoords;                 //!< The offset in the file for the texture data
+   int offsetTriangles;                 //!< The offset in the file for the face data
+   int offsetFrames;                    //!< The offset in the file for the frames data
+   int offsetGlCommands;                //!< The offset in the file for the gl commands data
+   int offsetEnd;                       //!< The end of the file offset
+};
+
+
+
+//! class to store the md2 data in
+class MD3Data : public BaseObject
+{
+ public:
+   MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
+  virtual ~MD3Data();
+
+
+ private:
+   bool loadModel(const std::string& fileName);
+   bool loadSkin(const std::string& fileName = "");
+
+
+ public:
+  int                numFrames;             //!< number of frames
+  int                numVertices;           //!< number of vertices
+  int                numTriangles;          //!< number of triangles
+  int                numTexCoor;            //!< number of texture coordinates
+  int                numGLCommands;         //!< number of gl commands in the glList (tells how to draw)
+  std::string        fileName;              //!< file name of the model File
+  std::string        skinFileName;          //!< file name of the skin file
+  MD2Header*         header;                //!< the header file
+
+  sVec3D*            pVertices;             //!< pointer to the vertices data block
+  sTriangle*         pTriangles;            //!< pointer to the triangles data
+  sTexCoor*          pTexCoor;              //!< pointer to the texture coordinate data
+  int*               pGLCommands;           //!< pointer to the gllist data block
+  int*               pLightNormals;         //!< pointer to the light normals
+
+  Material           material;              //!< pointer to the material
+  float              scaleFactor;           //!< the scale factor of the model, (global)
+};
+
+
+
+
+
+
+#endif /* _MD3_DATA_H */
