Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9824 in orxonox.OLD for branches/new_class_id


Ignore:
Timestamp:
Sep 26, 2006, 12:43:56 AM (18 years ago)
Author:
bensch
Message:

first try to make the MD2-model a Resource… it looks quite funny… seems like everything gets loaded, but totally wrong :)

Location:
branches/new_class_id/src/lib/graphics/importer
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/graphics/importer/Makefile.am

    r9781 r9824  
    3333                \
    3434                md2/md2Model.cc \
     35                md2/resource_md2.cc \
    3536                \
    3637                md3/md3_model.cc \
     
    7778                \
    7879                md2/md2Model.h \
     80                md2/resource_md2.h \
    7981                \
    8082                md3/md3_model.h \
  • branches/new_class_id/src/lib/graphics/importer/md2/md2Model.cc

    r9715 r9824  
    1919
    2020#include "debug.h"
    21 #include "util/loading/resource_manager.h"
     21#include "resource_md2.h"
    2222
    2323
     
    2626//! the model anorms
    2727sVec3D MD2Model::anorms[NUM_VERTEX_NORMALS] = {
    28  #include "anorms.h"
    29 };
     28#include "anorms.h"
     29    };
    3030
    3131//! anormal dots, no idea of how this shall work, but it does
    3232float MD2Model::anormsDots[SHADEDOT_QUANT][256] = {
    33   #include "anormtab.h"
    34 };
     33#include "anormtab.h"
     34    };
    3535
    3636
     
    4242sAnim MD2Model::animationList[22] =
    4343  {
    44  // begin, end, fps, interruptable
     44    // begin, end, fps, interruptable
    4545    {   0,  39,  9, 1 },   //!< STAND
    4646    {  40,  45, 10, 1 },   //!< RUN
     
    7373 ********************************************************************************/
    7474
     75MD2Model::MD2Model()
     76  : data(new MD2Data())
     77{
     78  this->init();
     79}
     80
     81#include "resource_md2.h"
    7582/**
    7683  \brief simple constructor initializing all variables
    7784*/
    7885MD2Model::MD2Model(const std::string& modelFileName, const std::string& skinFileName, float scale)
    79 {
    80   this->registerObject(this, MD2Model::_objectList);
    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();
    8789  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);
     90
     91  this->data = ResourceMD2(modelFileName, skinFileName, scale).data;
     92  rebuildInfo();
    9593
    9694  this->debug();
    97 
    98     //write the modelinfo information
     95}
     96
     97MD2Model& MD2Model::operator=(const MD2Model& md2model)
     98{
     99  this->data = md2model.data;
     100  rebuildInfo();
     101  return *this;
     102}
     103
     104void MD2Model::rebuildInfo()
     105{
     106  //write the modelinfo information
    99107  this->pModelInfo.numVertices = this->data->numVertices;
    100108  this->pModelInfo.numTriangles = this->data->numTriangles;
     
    107115
    108116  // triangle conversion
     117  if (this->pModelInfo.pTriangles != NULL)
     118    delete[] this->pModelInfo.pTriangles;
    109119  this->pModelInfo.pTriangles = new sTriangleExt[this->data->numTriangles];
    110120  for( int i = 0; i < this->data->numTriangles; i++)
     
    118128    this->pModelInfo.pTriangles[i].indexToTexCoor[2] = this->data->pTriangles[i].indexToTexCoor[2];
    119129  }
     130}
     131
     132bool MD2Model::load(const std::string& modelFileName, const std::string& skinFileName, float scale)
     133{
     134  this->data = MD2Data::Pointer(new MD2Data(modelFileName, skinFileName, scale));
    120135}
    121136
     
    132147  this->pModelInfo.pTexCoor = NULL;
    133148  this->pModelInfo.pTriangles = NULL;
    134 
    135   ResourceManager::getInstance()->unload(this->data);
    136 }
    137 
     149}
     150
     151
     152void MD2Model::init()
     153{
     154  this->registerObject(this, MD2Model::_objectList);
     155  /* this creates the data container via ressource manager */
     156  if( unlikely(this->data.isNull()))
     157    PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n");
     158
     159  this->scaleFactor = 1.0f;
     160  this->animationSpeed = 1.0f;
     161
     162  shadeDots = MD2Model::anormsDots[0];
     163  /* set the animation stat mannualy */
     164  this->animationState.type = STAND;
     165  this->animationState.numPlays = 1;
     166  this->setAnimation(STAND);
     167}
    138168
    139169/**
     
    153183
    154184  for( int i = 0; i < this->data->numVertices; ++i)
    155     {
    156       this->verticesList[i][0] = currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0]);
    157       this->verticesList[i][1] = currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1]);
    158       this->verticesList[i][2] = currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2]);
    159     }
     185  {
     186    this->verticesList[i][0] = currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0]);
     187    this->verticesList[i][1] = currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1]);
     188    this->verticesList[i][2] = currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2]);
     189  }
    160190}
    161191
     
    259289  /* draw the triangles */
    260290  while( int i = *(pCommands++)) /* strange looking while loop for maximum performance */
     291  {
     292    if( i < 0)
    261293    {
    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 
     294      glBegin(GL_TRIANGLE_FAN);
     295      i = -i;
    280296    }
     297    else
     298    {
     299      glBegin(GL_TRIANGLE_STRIP);
     300    }
     301
     302    for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */
     303    {
     304      glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] );
     305      glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]);
     306      glVertex3fv(this->verticesList[pCommands[2]]);
     307    }
     308    glEnd();
     309
     310  }
    281311  glDisable(GL_CULL_FACE);
    282312  glPopAttrib();
     
    289319  int* pCommands = this->data->pGLCommands;
    290320  /* 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*/);
     321  //   glPushAttrib(GL_POLYGON_BIT);
     322  //   glFrontFace(GL_CW);
     323  //   glEnable(GL_CULL_FACE);
     324  //   glCullFace(GL_BACK);
     325  //
     326  //   this->processLighting();
     327  //   this->interpolate(/*this->verticesList*/);
    298328  this->data->material.select();
    299329
     
    337367
    338368  if( this->animationState.localTime - this->animationState.lastTime > (1.0f / this->animationState.fps))
     369  {
     370    this->animationState.currentFrame = this->animationState.nextFrame;
     371    this->animationState.nextFrame++;
     372
     373    if( this->animationState.nextFrame > this->animationState.endFrame )
    339374    {
    340       this->animationState.currentFrame = this->animationState.nextFrame;
    341       this->animationState.nextFrame++;
    342 
    343       if( this->animationState.nextFrame > this->animationState.endFrame )
     375      if( this->animationState.animPlaybackMode == MD2_ANIM_LOOP)
    344376      {
    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         }
     377        this->animationState.nextFrame = this->animationState.startFrame;
     378        this->animationState.numPlays++;
    354379      }
    355       this->animationState.lastTime = this->animationState.localTime;
     380      else
     381      {
     382        this->animationState.nextFrame = this->animationState.endFrame;
     383      }
    356384    }
    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;
     385    this->animationState.lastTime = this->animationState.localTime;
     386  }
     387
     388  //     if( this->animationState.currentFrame > (this->data->numFrames - 1) )
     389  //       this->animationState.currentFrame = 0;
     390
     391  //     if( (this->animationState.nextFrame > (this->data->numFrames - 1)) && this->animationState.animPlaybackMode == MD2_ANIM_LOOP)
     392  //     this->animationState.nextFrame = 0;
    363393
    364394  this->animationState.interpolationState = this->animationState.fps *
    365     (this->animationState.localTime - this->animationState.lastTime);
     395      (this->animationState.localTime - this->animationState.lastTime);
    366396}
    367397
     
    390420  PRINT(0)("=  Number of Frames: \t%i\n", this->data->header->numFrames);
    391421  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);
     422  //PRINT(0)("=  Pointer to the data object: %p\n", this->data);
    393423  PRINT(0)("===================================================\n\n");
    394424}
     
    399429 ********************************************************************************/
    400430
     431MD2Data::MD2Data()
     432{
     433  this->init();
     434}
     435
    401436/**
    402437  \brief simple constructor
     
    404439MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale)
    405440{
    406   scale *= 0.1f;
    407 
     441  this->init();
     442  this->scaleFactor = scale;
     443
     444  this->loadModel(modelFileName);
     445  this->loadSkin(skinFileName);
     446}
     447
     448void MD2Data::init()
     449{
     450  this->scaleFactor = 1.0;
    408451  this->pVertices = NULL;
    409452  this->pGLCommands = NULL;
    410453  this->pLightNormals = NULL;
    411454  this->pTexCoor = NULL;
     455  this->header = NULL;
    412456
    413457  this->numFrames = 0;
     
    415459  this->numGLCommands = 0;
    416460  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 
     461}
    427462
    428463/**
     
    462497  pFile = fopen(fileName.c_str(), "rb");
    463498  if( unlikely(!pFile))
    464     {
    465       PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n");
    466       return false;
    467     }
     499  {
     500    PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n");
     501    return false;
     502  }
    468503  this->header = new MD2Header;
    469504  fread(this->header, 1, sizeof(MD2Header), pFile);
    470505  /* check for the header version: make sure its a md2 file :) */
    471506  if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
    472     {
    473       PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
    474       return false;
    475     }
     507  {
     508    PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
     509    return false;
     510  }
    476511
    477512  this->fileName =fileName;
     
    506541
    507542  for(int i = 0; i < this->numFrames; ++i)
     543  {
     544    frame = (sFrame*)(buffer + this->header->frameSize * i);
     545    pVertex = this->pVertices + this->numVertices  * i;
     546    pNormals = this->pLightNormals + this->numVertices * i;
     547
     548    for(int j = 0; j < this->numVertices; ++j)
    508549    {
    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         }
     550      /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)...  */
     551      pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor;
     552      pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor;
     553      pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor;
     554
     555      //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]);
     556
     557      pNormals[j] = frame->pVertices[j].lightNormalIndex;
    524558    }
    525     PRINTF(4)("Finished loading the md2 file\n");
     559  }
     560  PRINTF(4)("Finished loading the md2 file\n");
    526561
    527562  delete [] buffer;
     
    538573{
    539574  if( fileName.empty())
    540     {
    541       this->skinFileName = "";
    542       return false;
    543     }
     575  {
     576    this->skinFileName = "";
     577    return false;
     578  }
    544579
    545580  this->skinFileName = fileName;
  • branches/new_class_id/src/lib/graphics/importer/md2/md2Model.h

    r9722 r9824  
    2020
    2121#include "base_object.h"
     22#include "count_pointer.h"
    2223
    2324#include "interactive_model.h"
     
    4546struct MD2Header
    4647{
    47    int ident;                           //!< This is used to identify the file
    48    int version;                         //!< The version number of the file (Must be 8)
    49 
    50    int skinWidth;                       //!< The skin width in pixels
    51    int skinHeight;                      //!< The skin height in pixels
    52    int frameSize;                       //!< The size in bytes the frames are
    53 
    54    int numSkins;                        //!< The number of skins associated with the model
    55    int numVertices;                     //!< The number of vertices (constant for each frame)
    56    int numTexCoords;                    //!< The number of texture coordinates
    57    int numTriangles;                    //!< The number of faces (polygons)
    58    int numGlCommands;                   //!< The number of gl commands
    59    int numFrames;                       //!< The number of animation frames
    60 
    61    int offsetSkins;                     //!< The offset in the file for the skin data
    62    int offsetTexCoords;                 //!< The offset in the file for the texture data
    63    int offsetTriangles;                 //!< The offset in the file for the face data
    64    int offsetFrames;                    //!< The offset in the file for the frames data
    65    int offsetGlCommands;                //!< The offset in the file for the gl commands data
    66    int offsetEnd;                       //!< The end of the file offset
     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
    6768};
    6869
     
    7071//! animation names enumeration
    7172typedef enum MD2animType
    72   {
    73     STAND,                       //0
    74     RUN,                         //1
    75     ATTACK,                      //2
    76     PAIN_A,                      //3
    77     PAIN_B,                      //4
    78     PAIN_C,          //5
    79     JUMP,            //6
    80     FLIP,            //7
    81     SALUTE,          //8
    82     FALLBACK,        //9
    83     WAVE,            //10
    84     POINT,           //11
    85     CROUCH_STAND,
    86     CROUCH_WALK,
    87     CROUCH_ATTACK,
    88     CROUCH_PAIN,
    89     CROUCH_DEATH,
    90     DEATH_FALLBACK,
    91     DEATH_FALLFORWARD,
    92     DEATH_FALLBACKSLOW,
    93     BOOM,
    94     WALK,
    95 
    96     MAX_ANIMATIONS
    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};
    9899
    99100
     
    116117class MD2Data : public BaseObject
    117118{
    118  public:
    119    MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
     119public:
     120  typedef CountPointer<MD2Data>    Pointer;
     121public:
     122  MD2Data();
     123  MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
    120124  virtual ~MD2Data();
    121125
    122  private:
    123    bool loadModel(const std::string& fileName);
    124    bool loadSkin(const std::string& fileName = "");
    125 
    126  public:
     126private:
     127  void init();
     128  bool loadModel(const std::string& fileName);
     129  bool loadSkin(const std::string& fileName = "");
     130
     131public:
    127132  int                numFrames;             //!< number of frames
    128133  int                numVertices;           //!< number of vertices
     
    148153
    149154//! This is a MD2 Model class
    150 class MD2Model : public InteractiveModel {
     155class MD2Model : public InteractiveModel
     156{
    151157  ObjectListDeclaration(MD2Model);
    152158public:
     159  MD2Model();
    153160  MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f);
    154161  virtual ~MD2Model();
     162
     163  MD2Model& operator=(const MD2Model& md2model);
     164
     165  bool load(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f);
    155166
    156167  virtual void draw() const;
     
    162173  inline int getAnimation() { return this->animationState.type; }
    163174  virtual void setAnimationSpeed(float speed) { this->animationSpeed = speed; }
    164   virtual bool isAnimationFinished() { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }
     175virtual bool isAnimationFinished() { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }
    165176  /**  scales the current model @param scaleFactor: the factor [0..1] to use for scaling */
    166177  void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}
    167178
     179
     180  void acquireData(const MD2Data::Pointer& data) { this->data = data; rebuildInfo(); };
     181  const MD2Data::Pointer& dataPointer() const { return this->data; };
    168182  virtual void tick(float dtS);
    169183  void debug();
     
    171185
    172186private:
     187  void init();
     188  void rebuildInfo();
     189
    173190  void animate(float time);
    174191  void processLighting();
     
    177194
    178195
    179  public:
     196public:
    180197  /* these variables are static, because they are all the same for every model */
    181   static sVec3D       anorms[NUM_VERTEX_NORMALS];       //!< the anormals
    182   static float        anormsDots[SHADEDOT_QUANT][256];  //!< the anormals dot products
    183   static sAnim        animationList[22];                //!< the anomation list
    184    //! again one of these strange id software parts
    185   float*              shadeDots;
    186 
    187   MD2Data*            data;                             //!< the md2 data pointer
    188 
    189  private:
    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 model
    193   sVec3D              verticesList[MD2_MAX_VERTICES];   //!< place to temp sav the vert
     198  static sVec3D         anorms[NUM_VERTEX_NORMALS];       //!< the anormals
     199  static float          anormsDots[SHADEDOT_QUANT][256];  //!< the anormals dot products
     200  static sAnim          animationList[22];                //!< the anomation list
     201  //! again one of these strange id software parts
     202  float*                shadeDots;
     203
     204  CountPointer<MD2Data> data;                           //!< the md2 data pointer
     205
     206private:
     207  float                 scaleFactor;                      //!< the scale factor (individual)
     208  float                 animationSpeed;                   //!< the speed of the animation (factor for the time)
     209  sAnimState            animationState;                   //!< animation state of the model
     210  sVec3D                verticesList[MD2_MAX_VERTICES];   //!< place to temp sav the vert
    194211};
    195212
  • branches/new_class_id/src/lib/graphics/importer/md2/resource_md2.cc

    r9823 r9824  
    11
    2 #include "resource_texture.h"
     2#include "resource_md2.h"
    33#include "substring.h"
    44#include "multi_type.h"
     
    66
    77
    8 ResourceTexture::ResourceTexture(const std::string& imageName, GLenum target)
    9     : NewResource(&ResourceTexture::type)
     8ResourceMD2::ResourceMD2(const std::string& modelName, const std::string& skinName, float scale)
     9    : NewResource(&ResourceMD2::type)
    1010{
    11   Resources::StorePointer* ptr = this->acquireResource(imageName + ',' + "TEST");
     11  Resources::StorePointer* ptr = this->acquireResource(loadString(modelName, skinName, scale));
    1212
    1313  if (ptr)
    1414  {
    15     PRINTF(5)("FOUNT TEXTURE: %s\n", imageName.c_str());
    16     this->acquireData(static_cast<ResourceTexture::TextureResourcePointer*>(ptr)->ptr());
     15    PRINTF(5)("FOUND MD2: %s\n", modelName.c_str());
     16    this->acquireData(static_cast<ResourceMD2::MD2ResourcePointer*>(ptr)->ptr());
    1717  }
    1818  else
    1919  {
    20     PRINTF(5)("NOT FOUNT TEXTURE: %s\n", imageName.c_str());
    21     std::string fileName = this->NewResource::locateFile(imageName);
    22     this->Texture::loadImage(fileName, target);
    23     this->NewResource::addResource(new ResourceTexture::TextureResourcePointer(imageName + ',' + "TEST", Resources::KeepLevel(0), this->Texture::dataPointer()));
     20    PRINTF(5)("NOT FOUND MD2: %s\n", modelName.c_str());
     21    std::string modelFileName = this->NewResource::locateFile(modelName);
     22    std::string skinFileName = this->NewResource::locateFile(skinName);
     23    this->MD2Model::load(modelFileName, skinFileName, scale);
     24    this->NewResource::addResource(new ResourceMD2::MD2ResourcePointer(loadString(modelName, skinName, scale), Resources::KeepLevel(0), this->MD2Model::dataPointer()));
    2425  }
     26
    2527}
    2628
    27 ResourceTexture ResourceTexture::createFromString(const std::string& loadString)
     29ResourceMD2 ResourceMD2::createFromString(const std::string& loadString)
    2830{
    2931  SubString loadValues(loadString, ',');
    30   std::string imageName;
    31   GLenum target = GL_TEXTURE_2D;
     32  std::string modelName;
     33  std::string skinName;
     34  float scale = 1.0f;
    3235  if (loadValues.size() > 0)
    33     imageName = loadValues[0];
     36    modelName = loadValues[0];
    3437  if (loadValues.size() > 1)
    35     target = (GLenum)MultiType(loadValues[2]).getInt();
     38    skinName = loadValues[1];
     39  if (loadValues.size() > 2)
     40    scale = MultiType(loadValues[2]).getFloat();
    3641
    37   return ResourceTexture(imageName, target);
     42  return ResourceMD2(modelName, skinName, scale);
     43}
     44
     45std::string ResourceMD2::loadString(const std::string& modelName, const std::string& skinName, float scale)
     46{
     47  return modelName + ',' + skinName + ',' + MultiType(scale).getString();
    3848}
    3949
    4050
    41 
    42 Resources::tType<ResourceTexture> ResourceTexture::type("Texture");
     51Resources::tType<ResourceMD2> ResourceMD2::type("MD2");
    4352
    4453
     
    4655
    4756
    48 ResourceTexture::TextureResourcePointer::TextureResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const TextureData::Pointer& data)
     57ResourceMD2::MD2ResourcePointer::MD2ResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const MD2Data::Pointer& data)
    4958    : Resources::StorePointer(loadString, keepLevel) , pointer(data)
    5059{}
  • branches/new_class_id/src/lib/graphics/importer/md2/resource_md2.h

    r9823 r9824  
    11/*!
    2  * @file resource_texture.h
    3  * @brief Contains the ResourceTexture class, that handles the Resource-specific loading part of the Texture.
     2 * @file resource_md2.h
     3 * @brief Contains the ResourceMD2 class, that handles the Resource-specific loading part of the MD2.
    44 *
    55 */
    66
    7 #ifndef _RESOURCE_TEXTURE_H
    8 #define _RESOURCE_TEXTURE_H
     7#ifndef _RESOURCE_MD2_H
     8#define _RESOURCE_MD2_H
    99
    1010#include "util/loading/resource.h"
    11 #include "texture.h"
     11#include "md2Model.h"
    1212
    1313
    14 class ResourceTexture : public Texture, public Resources::NewResource
     14class ResourceMD2 : public MD2Model, public Resources::NewResource
    1515{
    1616public:
    17   ResourceTexture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
    18   static ResourceTexture createFromString(const std::string& loadString);
     17  ResourceMD2(const std::string& modelName, const std::string& skinName = "", float scale = 1.0f);
     18  static ResourceMD2 createFromString(const std::string& loadString);
     19  static std::string loadString(const std::string& modelName, const std::string& skinName = "", float scale = 1.0f);
    1920
    2021private:
    21 class TextureResourcePointer : public Resources::StorePointer
     22class MD2ResourcePointer : public Resources::StorePointer
    2223  {
    2324  public:
    24     TextureResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const TextureData::Pointer& data);
    25     inline const TextureData::Pointer& ptr() const { return pointer; }
     25    MD2ResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const MD2Data::Pointer& data);
     26    inline const MD2Data::Pointer& ptr() const { return pointer; }
    2627private:
    27     TextureData::Pointer pointer;
     28    MD2Data::Pointer pointer;
    2829  };
    2930
    3031private:
    31   static Resources::tType<ResourceTexture> type;
     32  static Resources::tType<ResourceMD2> type;
    3233};
    3334
    3435
    35 #endif /* _RESOURCE_TEXTURE_H */
     36#endif /* _RESOURCE_MD2_H */
Note: See TracChangeset for help on using the changeset viewer.