Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/lib/graphics/importer


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

Location:
trunk/src/lib/graphics/importer
Files:
29 edited
8 copied

Legend:

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

    r8724 r9869  
    44noinst_LIBRARIES = libORXimporter.a libtc.a
    55
    6 libORXimporter_a_SOURCES = model.cc \
    7                            interactive_model.cc \
    8                            md_model_structure.cc \
    9                            vertex_array_model.cc \
    10                            grid.cc \
    11                            static_model.cc \
    12                            objModel.cc \
    13                            primitive_model.cc \
    14                            height_map.cc \
    15                            bsp_manager.cc \
    16                            bsp_file.cc \
    17                            bsp_tree_node.cc \
    18                            bsp_tree_leaf.cc \
    19                            \
    20                            material.cc \
    21                            texture.cc \
    22                            texture_data.cc \
    23                            texture_sequence.cc \
    24                            media_container.cc \
    25                            movie_player.cc \
    26                            \
    27                            bsp_manager.cc \
    28                            bsp_file.cc \
    29                            bsp_tree_node.cc \
    30                            bsp_tree_leaf.cc \
    31                            \
    32                            md2/md2Model.cc \
    33                            \
    34                            md3/md3_model.cc \
    35                            md3/md3_animation.cc \
    36                            md3/md3_animation_cfg.cc \
    37                            md3/md3_bone_frame.cc \
    38                            md3/md3_mesh.cc \
    39                            md3/md3_data.cc \
    40                            md3/md3_tag.cc
     6libORXimporter_a_SOURCES = \
     7                model.cc \
     8                interactive_model.cc \
     9                md_model_structure.cc \
     10                vertex_array_model.cc \
     11                grid.cc \
     12                static_model.cc \
     13                static_model_data.cc \
     14                objModel.cc \
     15                resource_obj.cc \
     16                primitive_model.cc \
     17                height_map.cc \
     18                bsp_manager.cc \
     19                bsp_file.cc \
     20                bsp_tree_node.cc \
     21                bsp_tree_leaf.cc \
     22                \
     23                material.cc \
     24                texture.cc \
     25                texture_data.cc \
     26                resource_texture.cc \
     27                texture_sequence.cc \
     28                media_container.cc \
     29                movie_player.cc \
     30                \
     31                bsp_manager.cc \
     32                bsp_file.cc \
     33                bsp_tree_node.cc \
     34                bsp_tree_leaf.cc \
     35                \
     36                md2/md2Model.cc \
     37                md2/resource_md2.cc
     38#               \
     39                md3/md3_model.cc \
     40                md3/md3_animation.cc \
     41                md3/md3_animation_cfg.cc \
     42                md3/md3_bone_frame.cc \
     43                md3/md3_mesh.cc \
     44                md3/md3_data.cc \
     45                md3/md3_tag.cc
    4146
    4247
     
    5459                grid.h \
    5560                static_model.h \
     61                static_model_data.h \
    5662                objModel.h \
     63                resource_obj.h \
    5764                primitive_model.h \
    5865                anorms.h \
     
    6370                texture.h \
    6471                texture_data.h \
     72                resource_texture.h \
    6573                texture_sequence.h \
    6674                \
     
    7482                \
    7583                md2/md2Model.h \
     84                md2/resource_md2.h \
    7685                \
    7786                md3/md3_model.h \
  • trunk/src/lib/graphics/importer/bsp_file.cc

    r9406 r9869  
    466466    PRINTF(4)("BSP FILE: Name %s . \n", fileName);
    467467
    468     absFileName = ResourceManager::getFullName(fileName);
     468    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    469469
    470470    if(File(absFileName).exists()) {
     
    481481    strncat (fileName, ext, strlen(fileName));
    482482
    483     absFileName = ResourceManager::getFullName(fileName);
     483    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    484484
    485485    if(File(absFileName).exists()) {
     
    496496    strncat (fileName, ext, strlen(fileName));
    497497
    498     absFileName = ResourceManager::getFullName(fileName);
     498    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    499499
    500500    if(File(absFileName).exists()) {
     
    511511    strncat (fileName, ext, strlen(fileName));
    512512
    513     absFileName = ResourceManager::getFullName(fileName);
     513    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    514514
    515515    if(File(absFileName).exists()) {
     
    524524    strcpy(ext, ".TGA");
    525525    strncat (fileName, ext, strlen(fileName));
    526     absFileName = ResourceManager::getFullName(fileName);
     526    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    527527
    528528    if(File(absFileName).exists()/*stat( absFileName.c_str() , &results) == 0*/) {
     
    537537    strcpy(ext, ".jpg");
    538538    strncat (fileName, ext, strlen(fileName));
    539     absFileName = ResourceManager::getFullName(fileName);
     539    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    540540    if(File(absFileName).exists()) {
    541541      PRINTF(4)("BSP FILE: gefunden . \n");
     
    551551    strcpy(ext, ".JPG");
    552552    strncat (fileName, ext, strlen(fileName));
    553     absFileName = ResourceManager::getFullName(fileName);
     553    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    554554    if(File(absFileName).exists()) {
    555555      PRINTF(4)("BSP FILE: gefunden . \n");
     
    566566    strcpy(ext, ".bmp");
    567567    strncat (fileName, ext, strlen(fileName));
    568     absFileName = ResourceManager::getFullName(fileName);
     568    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    569569
    570570    if(File(absFileName).exists()) {
     
    580580    strcpy(ext, ".BMP");
    581581    strncat (fileName, ext, strlen(fileName));
    582     absFileName = ResourceManager::getFullName(fileName);
     582    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    583583
    584584    if(File(absFileName).exists()) {
     
    611611  this->testSurf = NULL;
    612612
    613   this->testSurf = IMG_Load(ResourceManager::getFullName(mat).c_str());
     613  this->testSurf = IMG_Load(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(mat).c_str());
    614614  if(this->testSurf != NULL) {
    615615    if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true;
  • trunk/src/lib/graphics/importer/bsp_manager.cc

    r9235 r9869  
    3333#include "world_entities/player.h"
    3434#include "world_entities/playable.h"
    35 #include "util/loading/resource_manager.h"
     35
    3636// STL Containers
    3737#include <vector>
     
    4141#include "world_entity.h"
    4242
     43#include "util/loading/resource_manager.h"
    4344#include "util/loading/load_param.h"
    4445#include "util/loading/factory.h"
     
    9192  this->bspFile = new BspFile();
    9293  this->bspFile->scale =  scale;
    93   if(this->bspFile->read(ResourceManager::getFullName(fileName).c_str()) == -1)
     94  if(this->bspFile->read(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName).c_str()) == -1)
    9495    return -1;
    9596
     
    13761377    if( this->outputFraction == 1.0f) // No collision Detected
    13771378    {
    1378       if( this->outputAllSolid ) 
     1379      if( this->outputAllSolid )
    13791380      {
    13801381        this->collPlane = new plane;
  • trunk/src/lib/graphics/importer/height_map.cc

    r8316 r9869  
    2222#include "p_node.h"
    2323#include "state.h"
    24 #include "util/loading/resource_manager.h"
    2524#include "debug.h"
    2625
     
    327326
    328327
     328ObjectListDefinition(HeightMap);
    329329
    330330
     
    413413void HeightMap::init(const std::string& heightMapName)
    414414{
    415   this->setClassID(CL_HEIGHT_MAP, "HeightMap");
     415  this->registerObject(this, HeightMap::_objectList);
    416416
    417417  this->shiftX = 0;
  • trunk/src/lib/graphics/importer/height_map.h

    r7526 r9869  
    2929
    3030class SDL_Surface;
    31 class Vector;
    3231class Material;
    33 class PNode;
    3432class Texture;
    3533class HeightMap;
     
    7068
    7169
     70
    7271//!< the height map representation itself
    7372class HeightMap : public VertexArrayModel
    7473{
     74  ObjectListDeclaration(HeightMap);
    7575  friend class Tile;
    7676
  • trunk/src/lib/graphics/importer/interactive_model.cc

    r9406 r9869  
    2222
    2323
     24ObjectListDefinition(InteractiveModel);
     25
    2426/**
    2527 * standard constructor
     
    2830InteractiveModel::InteractiveModel()
    2931{
    30   this->setClassID(CL_INTERACTIVE_MODEL, "InteractiveModel");
     32  this->registerObject(this, InteractiveModel::_objectList);
    3133}
    3234
  • trunk/src/lib/graphics/importer/interactive_model.h

    r9003 r9869  
    3030class InteractiveModel : public Model
    3131{
     32  ObjectListDeclaration(InteractiveModel);
    3233  public:
    3334    InteractiveModel();
     
    3839    virtual void setAnimation(int animNum, int playbackMode = 0) = 0;
    3940    virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback) {}
    40     virtual int getAnimation() = 0;
     41    virtual int getAnimation() const = 0;
    4142
    4243    virtual bool isAnimationFinished() { return false; }
  • trunk/src/lib/graphics/importer/material.cc

    r9406 r9869  
    2525#include "loading/load_param.h"
    2626
    27 #include "util/loading/resource_manager.h"
     27#include "resource_texture.h"
     28
     29ObjectListDefinition(Material);
    2830
    2931/**
     
    3335Material::Material (const std::string& mtlName)
    3436{
    35   this->setClassID(CL_MATERIAL, "Material");
     37  this->registerObject(this, Material::_objectList);
    3638
    3739  this->setIllum(3);
     
    9092  PRINTF(5)("delete Material %s.\n", this->getCName());
    9193
    92   if (this->ambientTexture != NULL)
    93     ResourceManager::getInstance()->unload(this->ambientTexture);
    94   if (this->specularTexture != NULL)
    95     ResourceManager::getInstance()->unload(this->specularTexture);
    96 
    9794  if (this == Material::selectedMaterial)
    9895    Material::selectedMaterial = NULL;
     
    10198
    10299const Material* Material::selectedMaterial = NULL;
    103 
    104 
    105 /// TODO FIX THIS
    106 // Material& Material::operator=(const Material& m)
    107 // {
    108 //   this->setIllum(m.illumModel);
    109 //   this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]);
    110 //   this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]);
    111 //   this->setSpecular(m.specular[0],m.specular[1],m.specular[2]);
    112 //   this->setShininess(m.shininess);
    113 //   this->setTransparency(m.transparency);
    114 //
    115 //   if (this->diffuseTexture != NULL)
    116 //     ResourceManager::getInstance()->unload(this->diffuseTexture);
    117 //   if (m.diffuseTexture != NULL)
    118 //     this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);
    119 //   this->ambientTexture = NULL; /// FIXME
    120 //   this->specularTexture = NULL; /// FIXME
    121 //
    122 //   this->setName(m.getName());
    123 // }
    124 
    125 
    126100
    127101/**
     
    288262
    289263
    290 
    291 /**
    292  * @brief Adds a Texture Path to the List of already existing Paths
    293  * @param pathName The Path to add.
    294 */
    295 void Material::addTexturePath(const std::string& pathName)
    296 {
    297   ResourceManager::getInstance()->addImageDir(pathName);
    298 }
    299 
    300 // MAPPING //
    301 
    302 
    303264/**
    304265 * @brief Sets the Diffuse map of this Texture.
     
    322283 * @param textureNumber The Texture-Number from 0 to GL_MAX_TEXTURE_UNITS
    323284 */
    324 void Material::setDiffuseMap(const TextureDataPointer& textureDataPointer, unsigned int textureNumber)
     285void Material::setDiffuseMap(const TextureData::Pointer& textureDataPointer, unsigned int textureNumber)
    325286{
    326287  assert(textureNumber < Material::getMaxTextureUnits());
     
    349310  if (!dMap.empty())
    350311  {
    351     Texture* tex = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target));
    352     if (tex != NULL)
    353       this->textures[textureNumber] = *tex;
     312    this->textures[textureNumber] = ResourceTexture(dMap);
     313        //dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target));
     314/*    if (tex != NULL)
     315      this->textures[textureNumber] = tex;
    354316    else
    355       this->textures[textureNumber] = Texture();
     317      this->textures[textureNumber] = Texture();*/
    356318  }
    357319  else
  • trunk/src/lib/graphics/importer/material.h

    r8761 r9869  
    2424class Material : public BaseObject
    2525{
     26  ObjectListDeclaration(Material);
    2627public:
    2728  Material (const std::string& mtlName = "");
    2829  virtual ~Material ();
    2930
     31  Material& operator=(const Material& material);
     32
    3033  void loadParams(const TiXmlElement* root);
    31 
    32   Material& operator=(const Material& material);
    3334
    3435  bool select () const;
     
    5354  // MAPPING //
    5455  void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0);
    55   void setDiffuseMap(const TextureDataPointer& texturePointer, unsigned int textureNumber = 0);
     56  void setDiffuseMap(const TextureData::Pointer& texturePointer, unsigned int textureNumber = 0);
    5657  void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
    5758  void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
     
    6566
    6667  const Texture& diffuseTexture(unsigned int i = 0) const { return this->textures[i]; };
    67 
    68   static void addTexturePath(const std::string& pathName);
    6968
    7069  static const std::string& blendFuncToString(GLenum blendFunc);
  • trunk/src/lib/graphics/importer/md2/md2Model.cc

    r9406 r9869  
    1919
    2020#include "debug.h"
    21 #include "util/loading/resource_manager.h"
    22 
    23 
    24 
     21#include "resource_md2.h"
     22
     23
     24ObjectListDefinition(MD2Model);
    2525
    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->setClassID(CL_MD2_MODEL, "MD2Model");
    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);
    95 
    96   this->debug();
    97 
    98     //write the modelinfo information
     90
     91  this->data = ResourceMD2(modelFileName, skinFileName, scale).data;
     92  rebuildInfo();
     93
     94  //this->debug();
     95}
     96
     97MD2Model::MD2Model(const MD2Model& model)
     98  : data(model.data)
     99{
     100  this->init();
     101  this->rebuildInfo();
     102}
     103
     104MD2Model& MD2Model::operator=(const MD2Model& md2model)
     105{
     106  this->data = md2model.data;
     107  this->rebuildInfo();
     108  return *this;
     109}
     110
     111void MD2Model::rebuildInfo()
     112{
     113  //write the modelinfo information
    99114  this->pModelInfo.numVertices = this->data->numVertices;
    100115  this->pModelInfo.numTriangles = this->data->numTriangles;
     
    107122
    108123  // triangle conversion
     124  if (this->pModelInfo.pTriangles != NULL)
     125    delete[] this->pModelInfo.pTriangles;
    109126  this->pModelInfo.pTriangles = new sTriangleExt[this->data->numTriangles];
    110127  for( int i = 0; i < this->data->numTriangles; i++)
     
    118135    this->pModelInfo.pTriangles[i].indexToTexCoor[2] = this->data->pTriangles[i].indexToTexCoor[2];
    119136  }
     137}
     138
     139bool MD2Model::load(const std::string& modelFileName, const std::string& skinFileName, float scale)
     140{
     141  this->data = MD2Data::Pointer(new MD2Data(modelFileName, skinFileName, scale));
     142  this->rebuildInfo();
    120143}
    121144
     
    132155  this->pModelInfo.pTexCoor = NULL;
    133156  this->pModelInfo.pTriangles = NULL;
    134 
    135   ResourceManager::getInstance()->unload(this->data);
    136 }
    137 
     157}
     158
     159
     160void MD2Model::init()
     161{
     162  this->registerObject(this, MD2Model::_objectList);
     163  /* this creates the data container via ressource manager */
     164  if( unlikely(this->data.isNull()))
     165    PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n");
     166
     167  this->scaleFactor = 1.0f;
     168  this->animationSpeed = 1.0f;
     169
     170  shadeDots = MD2Model::anormsDots[0];
     171  /* set the animation stat mannualy */
     172  this->animationState.type = STAND;
     173  this->animationState.numPlays = 1;
     174  this->setAnimation(STAND);
     175}
    138176
    139177/**
     
    153191
    154192  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     }
     193  {
     194    this->verticesList[i][0] = currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0]);
     195    this->verticesList[i][1] = currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1]);
     196    this->verticesList[i][2] = currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2]);
     197  }
    160198}
    161199
     
    259297  /* draw the triangles */
    260298  while( int i = *(pCommands++)) /* strange looking while loop for maximum performance */
     299  {
     300    if( i < 0)
    261301    {
    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 
     302      glBegin(GL_TRIANGLE_FAN);
     303      i = -i;
    280304    }
     305    else
     306    {
     307      glBegin(GL_TRIANGLE_STRIP);
     308    }
     309
     310    for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */
     311    {
     312      glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] );
     313      glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]);
     314      glVertex3fv(this->verticesList[pCommands[2]]);
     315    }
     316    glEnd();
     317
     318  }
    281319  glDisable(GL_CULL_FACE);
    282320  glPopAttrib();
     
    289327  int* pCommands = this->data->pGLCommands;
    290328  /* 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*/);
     329  //   glPushAttrib(GL_POLYGON_BIT);
     330  //   glFrontFace(GL_CW);
     331  //   glEnable(GL_CULL_FACE);
     332  //   glCullFace(GL_BACK);
     333  //
     334  //   this->processLighting();
     335  //   this->interpolate(/*this->verticesList*/);
    298336  this->data->material.select();
    299337
     
    337375
    338376  if( this->animationState.localTime - this->animationState.lastTime > (1.0f / this->animationState.fps))
     377  {
     378    this->animationState.currentFrame = this->animationState.nextFrame;
     379    this->animationState.nextFrame++;
     380
     381    if( this->animationState.nextFrame > this->animationState.endFrame )
    339382    {
    340       this->animationState.currentFrame = this->animationState.nextFrame;
    341       this->animationState.nextFrame++;
    342 
    343       if( this->animationState.nextFrame > this->animationState.endFrame )
     383      if( this->animationState.animPlaybackMode == MD2_ANIM_LOOP)
    344384      {
    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         }
     385        this->animationState.nextFrame = this->animationState.startFrame;
     386        this->animationState.numPlays++;
    354387      }
    355       this->animationState.lastTime = this->animationState.localTime;
     388      else
     389      {
     390        this->animationState.nextFrame = this->animationState.endFrame;
     391      }
    356392    }
    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;
     393    this->animationState.lastTime = this->animationState.localTime;
     394  }
     395
     396  //     if( this->animationState.currentFrame > (this->data->numFrames - 1) )
     397  //       this->animationState.currentFrame = 0;
     398
     399  //     if( (this->animationState.nextFrame > (this->data->numFrames - 1)) && this->animationState.animPlaybackMode == MD2_ANIM_LOOP)
     400  //     this->animationState.nextFrame = 0;
    363401
    364402  this->animationState.interpolationState = this->animationState.fps *
    365     (this->animationState.localTime - this->animationState.lastTime);
     403      (this->animationState.localTime - this->animationState.lastTime);
    366404}
    367405
     
    390428  PRINT(0)("=  Number of Frames: \t%i\n", this->data->header->numFrames);
    391429  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);
     430  //PRINT(0)("=  Pointer to the data object: %p\n", this->data);
    393431  PRINT(0)("===================================================\n\n");
    394432}
     
    399437 ********************************************************************************/
    400438
     439MD2Data::MD2Data()
     440{
     441  this->init();
     442}
     443
    401444/**
    402445  \brief simple constructor
     
    404447MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale)
    405448{
    406   scale *= 0.1f;
    407 
     449  this->init();
     450  this->scaleFactor = scale * .1;
     451
     452  this->loadModel(modelFileName);
     453  this->loadSkin(skinFileName);
     454}
     455
     456void MD2Data::init()
     457{
     458  this->scaleFactor = 1.0;
    408459  this->pVertices = NULL;
    409460  this->pGLCommands = NULL;
    410461  this->pLightNormals = NULL;
    411462  this->pTexCoor = NULL;
     463  this->header = NULL;
    412464
    413465  this->numFrames = 0;
     
    415467  this->numGLCommands = 0;
    416468  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 
     469}
    427470
    428471/**
     
    462505  pFile = fopen(fileName.c_str(), "rb");
    463506  if( unlikely(!pFile))
    464     {
    465       PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n");
    466       return false;
    467     }
     507  {
     508    PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n");
     509    return false;
     510  }
    468511  this->header = new MD2Header;
    469512  fread(this->header, 1, sizeof(MD2Header), pFile);
    470513  /* check for the header version: make sure its a md2 file :) */
    471514  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     }
     515  {
     516    PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
     517    return false;
     518  }
    476519
    477520  this->fileName =fileName;
     
    506549
    507550  for(int i = 0; i < this->numFrames; ++i)
     551  {
     552    frame = (sFrame*)(buffer + this->header->frameSize * i);
     553    pVertex = this->pVertices + this->numVertices  * i;
     554    pNormals = this->pLightNormals + this->numVertices * i;
     555
     556    for(int j = 0; j < this->numVertices; ++j)
    508557    {
    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         }
     558      /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)...  */
     559      pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor;
     560      pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor;
     561      pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor;
     562
     563      //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]);
     564
     565      pNormals[j] = frame->pVertices[j].lightNormalIndex;
    524566    }
    525     PRINTF(4)("Finished loading the md2 file\n");
     567  }
     568  PRINTF(4)("Finished loading the md2 file\n");
    526569
    527570  delete [] buffer;
     
    538581{
    539582  if( fileName.empty())
    540     {
    541       this->skinFileName = "";
    542       return false;
    543     }
     583  {
     584    this->skinFileName = "";
     585    return false;
     586  }
    544587
    545588  this->skinFileName = fileName;
  • trunk/src/lib/graphics/importer/md2/md2Model.h

    r9235 r9869  
    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 {
    151 
    152 public:
     155class MD2Model : public InteractiveModel
     156{
     157  ObjectListDeclaration(MD2Model);
     158public:
     159  MD2Model();
    153160  MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f);
     161  MD2Model(const MD2Model& model);
    154162  virtual ~MD2Model();
     163
     164  MD2Model& operator=(const MD2Model& md2model);
     165
     166  bool load(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f);
    155167
    156168  virtual void draw() const;
     
    160172  virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback);
    161173  /**  returns the current animation @returns animation type */
    162   inline int MD2Model::getAnimation() { return this->animationState.type; }
     174  inline int getAnimation() const { return this->animationState.type; }
    163175  virtual void setAnimationSpeed(float speed) { this->animationSpeed = speed; }
    164   virtual bool isAnimationFinished() { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }
     176virtual bool isAnimationFinished() const { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }
    165177  /**  scales the current model @param scaleFactor: the factor [0..1] to use for scaling */
    166178  void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}
    167179
     180
     181  void acquireData(const MD2Data::Pointer& data) { this->data = data; rebuildInfo(); };
     182  const MD2Data::Pointer& dataPointer() const { return this->data; };
    168183  virtual void tick(float dtS);
    169184  void debug();
     
    171186
    172187private:
     188  void init();
     189  void rebuildInfo();
     190
    173191  void animate(float time);
    174192  void processLighting();
     
    177195
    178196
    179  public:
     197public:
    180198  /* 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
     199  static sVec3D         anorms[NUM_VERTEX_NORMALS];       //!< the anormals
     200  static float          anormsDots[SHADEDOT_QUANT][256];  //!< the anormals dot products
     201  static sAnim          animationList[22];                //!< the anomation list
     202  //! again one of these strange id software parts
     203  float*                shadeDots;
     204
     205  CountPointer<MD2Data> data;                           //!< the md2 data pointer
     206
     207private:
     208  float                 scaleFactor;                      //!< the scale factor (individual)
     209  float                 animationSpeed;                   //!< the speed of the animation (factor for the time)
     210  sAnimState            animationState;                   //!< animation state of the model
     211  sVec3D                verticesList[MD2_MAX_VERTICES];   //!< place to temp sav the vert
    194212};
    195213
  • trunk/src/lib/graphics/importer/md3/md3_model.h

    r8724 r9869  
    4545
    4646    virtual void setAnimation(int animNum, int playbackMode = 0) {}
    47     virtual int getAnimation() { return 0;}
     47    virtual int getAnimation() const { return 0;}
    4848
    4949    virtual void tick(float dt);
  • trunk/src/lib/graphics/importer/media_container.cc

    r8316 r9869  
    2626
    2727#include "util/loading/resource_manager.h"
    28 
    2928/* header for debug output */
    3029#include "debug.h"
    3130
     31ObjectListDefinition(MediaContainer);
    3232
    3333/**
     
    3737{
    3838  // set the class id for the base object
    39   this->setClassID(CL_MEDIA_CONTAINER, "MediaContainer");
     39  this->registerObject(this, MediaContainer::_objectList);
    4040
    4141  fps = 0;
     
    9191    return false;
    9292  // check whether file exists
    93   if(!ResourceManager::isInDataDir(filename))
     93  if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename))
    9494  {
    9595    PRINTF(1)("Could not find %s\n", filename.c_str());
     
    101101
    102102  // Open video file
    103   if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )
    104   {
    105     PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str());
     103  if (av_open_input_file(&format_context, Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str(), NULL, 0, NULL) !=0 )
     104  {
     105    PRINTF(1)("Could not open %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    106106    return false;
    107107  }
     
    110110  if (av_find_stream_info(format_context) < 0)
    111111  {
    112     PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str());
     112    PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    113113    return false;
    114114  }
     
    119119  if(video_stream == -1)
    120120  {
    121     PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str());
     121    PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    122122    return false;
    123123  }
  • trunk/src/lib/graphics/importer/media_container.h

    r7221 r9869  
    2424class MediaContainer : public TextureSequence
    2525{
    26 
     26  ObjectListDeclaration(MediaContainer);
    2727private:
    2828
  • trunk/src/lib/graphics/importer/model.cc

    r9406 r9869  
    2020#include "glincl.h"
    2121
    22 
     22ObjectListDefinition(Model);
    2323
    2424/**
     
    2828Model::Model()
    2929{
    30   this->setClassID(CL_MODEL, "Model");
     30  this->registerObject(this, Model::_objectList);
    3131  this->pModelInfo.numVertices = 0;
    3232  this->pModelInfo.numTriangles = 0;
  • trunk/src/lib/graphics/importer/model.h

    r8035 r9869  
    5454//! This class defines the basic components of a model
    5555class Model : virtual public BaseObject {
     56  ObjectListDeclaration(Model);
    5657
    5758  public:
  • trunk/src/lib/graphics/importer/movie_player.cc

    r7221 r9869  
    2424// include your own header
    2525#include "movie_player.h"
    26 
    2726#include "util/loading/resource_manager.h"
    2827
     
    3029#include "debug.h"
    3130
     31ObjectListDefinition(MoviePlayer);
    3232
    3333MoviePlayer::MoviePlayer(const std::string& filename)
    3434{
    3535  // set the class id for the base object
    36   this->setClassID(CL_MOVIE_PLAYER, "MoviePlayer");
    37 
     36  this->registerObject(this, MoviePlayer::_objectList);
    3837  status = STOP;
    3938  timer = 0;
     
    9089    return false;
    9190  // check whether file exists
    92   if(!ResourceManager::isInDataDir(filename))
     91  if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename))
    9392  {
    9493    PRINTF(1)("Could not find %s\n", filename.c_str());
     
    10099
    101100  // Open video file
    102   if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )
    103   {
    104     PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str());
     101  if (av_open_input_file(&format_context, Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str(), NULL, 0, NULL) !=0 )
     102  {
     103    PRINTF(1)("Could not open %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    105104    return false;
    106105  }
     
    109108  if (av_find_stream_info(format_context) < 0)
    110109  {
    111     PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str());
     110    PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    112111    return false;
    113112  }
     
    118117  if(video_stream == -1)
    119118  {
    120     PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str());
     119    PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    121120    return false;
    122121  }
  • trunk/src/lib/graphics/importer/movie_player.h

    r7221 r9869  
    3131class MoviePlayer : public BaseObject
    3232{
     33  ObjectListDeclaration(MoviePlayer);
    3334
    3435private:
  • trunk/src/lib/graphics/importer/objModel.cc

    r8369 r9869  
    1818#include "objModel.h"
    1919
    20 #include <stdio.h>
    2120#include <string.h>
    22 #include <stdlib.h>
     21#include "loading/resource_manager.h"
    2322
    2423#define PARSELINELENGTH 8192
     
    2726#include "compiler.h"
    2827
     28ObjectListDefinition(OBJModel);
    2929/**
    3030 * @brief Crates a 3D-Model, loads in a File and scales it.
     
    3535  : StaticModel(fileName)
    3636{
    37   this->setClassID(CL_OBJ_MODEL, "OBJModel");
     37  this->registerObject(this, OBJModel::_objectList);
    3838
    3939  this->objPath = "./";
    4040
    41   this->scaleFactor = scaling;
     41  this->setScaleFactor(scaling);
    4242
    4343  this->importFile (fileName);
     
    7777  else
    7878    this->objPath = "./";
    79   Material::addTexturePath(this->objPath);
     79  Resources::ResourceManager::getInstance()->addResourcePath("Texture", this->objPath);
    8080
    8181  this->readFromObjFile (fileName);
  • trunk/src/lib/graphics/importer/objModel.h

    r8369 r9869  
    1212class OBJModel : public StaticModel
    1313{
    14  public:
    15    OBJModel(const std::string& fileName, float scaling = 1.0);
     14  ObjectListDeclaration(OBJModel);
     15public:
     16  OBJModel(const std::string& fileName, float scaling = 1.0);
    1617  virtual ~OBJModel();
    1718
    18  private:
     19private:
    1920  ///// readin /////
    20    bool importFile (const std::string& fileName);
    21    bool readFromObjFile (const std::string& fileName);
    22    bool readMtlLib (const std::string& matFile);
     21  bool importFile (const std::string& fileName);
     22  bool readFromObjFile (const std::string& fileName);
     23  bool readMtlLib (const std::string& matFile);
    2324
    24   private:
    25    void setIllum (Material* material, const char* illum);
    26    void setDiffuse (Material* material, const char* rgb);
    27    void setAmbient (Material* material, const char* rgb);
    28    void setSpecular (Material* material, const char* rgb);
    29    void setShininess (Material* material, const char* shini);
    30    void setTransparency (Material* material, const char* trans);
     25private:
     26  void setIllum (Material* material, const char* illum);
     27  void setDiffuse (Material* material, const char* rgb);
     28  void setAmbient (Material* material, const char* rgb);
     29  void setSpecular (Material* material, const char* rgb);
     30  void setShininess (Material* material, const char* shini);
     31  void setTransparency (Material* material, const char* trans);
    3132
    32  private:
    33    std::string       objPath;     //!< The Path where the obj and mtl-file are located.
     33private:
     34  std::string       objPath;     //!< The Path where the obj and mtl-file are located.
    3435};
    3536
  • trunk/src/lib/graphics/importer/static_model.cc

    r9406 r9869  
    2626
    2727
    28 ////////////////////
    29 /// SUB-Elements ///
    30 ////////////////////
    31 /**
    32  * @brief creates a new ModelFaceElement
    33  */
    34 ModelFaceElement::ModelFaceElement()
    35 {
    36   this->vertexNumber = -1;
    37   this->normalNumber = -1;
    38   this->texCoordNumber = -1;
    39 
    40   this->next = NULL;
    41 }
    42 
    43 /**
    44  * @brief destroys a ModelFaceElement
    45  */
    46 ModelFaceElement::~ModelFaceElement()
    47 {
    48   if (this->next)
    49     delete this->next;
    50 }
    51 
    52 /**
    53  * @brief creates a new ModelFace
    54  */
    55 ModelFace::ModelFace()
    56 {
    57   this->vertexCount = 0;
    58 
    59   this->firstElem = NULL;
    60 
    61   this->material = NULL;
    62 
    63   this->next = NULL;
    64 }
    65 
    66 /**
    67  *  deletes a ModelFace
    68 */
    69 ModelFace::~ModelFace()
    70 {
    71   PRINTF(5)("Cleaning up Face\n");
    72 
    73   if (this->firstElem != NULL)
    74     delete this->firstElem;
    75 
    76   if (this->next != NULL)
    77     delete this->next;
    78 }
    79 
    80 /**
    81  * @brief Creates a new ModelGroup
    82  */
    83 ModelGroup::ModelGroup()
    84 {
    85   PRINTF(4)("Adding new Group\n");
    86   this->name = "";
    87   this->faceMode = -1;
    88   this->faceCount = 0;
    89   this->next = NULL;
    90   this->listNumber = 0;
    91   this->indices = NULL;
    92 
    93   this->firstFace = new ModelFace;
    94   this->currentFace = this->firstFace;
    95 }
    96 
    97 /**
    98  * @brief deletes a ModelGroup
    99  */
    100 ModelGroup::~ModelGroup()
    101 {
    102   PRINTF(5)("Cleaning up group\n");
    103   if (this->firstFace != NULL)
    104     delete this->firstFace;
    105 
    106   // deleting the glList
    107   if (this->listNumber != 0)
    108     glDeleteLists(this->listNumber, 1);
    109 
    110   if (this->next !=NULL)
    111     delete this->next;
    112 
    113 }
    114 
    115 /**
    116  * @brief cleans up a ModelGroup
    117  *
    118  * actually does the same as the delete Operator, but does not delete the predecessing group
    119  */
    120 void ModelGroup::cleanup()
    121 {
    122   PRINTF(5)("Cleaning up group\n");
    123   if (this->firstFace)
    124     delete this->firstFace;
    125   this->firstFace = NULL;
    126   if (this->next)
    127     this->next->cleanup();
    128 }
    129 
    130 
    13128/////////////
    13229/// MODEL ///
    13330/////////////
     31ObjectListDefinition(StaticModel);
     32
    13433/**
    13534 * @brief Creates a 3D-Model.
     
    13837 */
    13938StaticModel::StaticModel(const std::string& modelName)
     39    : data(new StaticModelData(modelName))
    14040{
    141   this->setClassID(CL_STATIC_MODEL, "StaticModel");
     41  this->registerObject(this, StaticModel::_objectList);
    14242  PRINTF(4)("new 3D-Model is being created\n");
    14343  this->setName(modelName);
     44}
    14445
    145   this->finalized = false;
     46StaticModel::StaticModel(const StaticModel& staticModel)
     47  : data(staticModel.data)
     48{
     49  this->registerObject(this, StaticModel::_objectList);
     50  this->setName(staticModel.getName());
     51  this->updateBase();
     52}
    14653
    147   // setting the start group;
    148   this->currentGroup = this->firstGroup = new ModelGroup;
    149   this->groupCount = 0;
    150   this->faceCount = 0;
    151 
    152   this->scaleFactor = 1.0f;
    153 }
    15454
    15555/**
     
    16161{
    16262  PRINTF(4)("Deleting Model ");
    163   if (!this->getName().empty())
    164   {
    165     PRINT(4)("%s\n", this->getCName());
    166   }
    167   else
    168   {
    169     PRINT(4)("\n");
    170   }
    171   this->cleanup();
    172 
    173   PRINTF(5)("Deleting display Lists.\n");
    174   delete this->firstGroup;
    175 
    176   // deleting the MaterialList
    177   PRINTF(5)("Deleting Materials.\n");
    178 
    179   //! @todo do we really have to delete this material??
    180   std::list<ModelMaterial*>::iterator modMat;
    181   for(modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++)
    182   {
    183     if (!(*modMat)->external)
    184       delete (*modMat)->material;
    185     delete (*modMat);
    186   }
    18763
    18864  // mark this stuff as beeing deleted
     
    19066  this->pModelInfo.pNormals = NULL;
    19167  this->pModelInfo.pTexCoor = NULL;
     68  this->pModelInfo.pTriangles = NULL;
    19269}
     70
     71StaticModel& StaticModel::operator=(const StaticModel& model)
     72{
     73  this->data = model.data;
     74  this->updateBase();
     75  return *this;
     76};
     77
    19378
    19479/**
     
    19782void StaticModel::finalize()
    19883{
    199   // this creates the display List.
    200   this->importToDisplayList();
    201   this->buildTriangleList();
    202 
    203   // write out the modelInfo data used for the collision detection!
    204   this->pModelInfo.pVertices = &this->vertices[0];
    205   this->pModelInfo.pNormals = &this->normals[0];
    206   this->pModelInfo.pTexCoor = &this->vTexture[0];
    207 
    208   this->finalized = true;
     84  data->finalize();
     85  this->updateBase();
    20986}
    21087
    211 /**
    212  * @brief rebuild the Model from the Information we got.
    213  */
    214 void StaticModel::rebuild()
     88void StaticModel::acquireData(const StaticModelData::Pointer& data)
    21589{
    216   PRINTF(3)("Rebuilding Model '%s'\n", this->getCName());
    217   this->finalize();
    218 }
    219 
    220 //////////
    221 // DRAW //
    222 //////////
    223 /**
    224  * @brief Draws the Models of all Groups.
    225  *
    226  * It does this by just calling the Lists that must have been created earlier.
    227  */
    228 void StaticModel::draw () const
    229 {
    230   PRINTF(4)("drawing the 3D-Models\n");
    231   ModelGroup* tmpGroup = this->firstGroup;
    232   while (tmpGroup != NULL)
    233   {
    234     PRINTF(5)("Drawing model %s\n", tmpGroup->name.c_str());
    235     glCallList (tmpGroup->listNumber);
    236     tmpGroup = tmpGroup->next;
    237   }
    238 }
    239 
    240 
    241 /**
    242  * @brief Draws the Model number groupNumber
    243  * @param groupNumber The number of the group that will be displayed.
    244  *
    245  * It does this by just calling the List that must have been created earlier.
    246  */
    247 void StaticModel::draw (int groupNumber) const
    248 {
    249   if (unlikely(groupNumber >= this->groupCount))
    250   {
    251     PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount);
    252     return;
    253   }
    254   PRINTF(4)("drawing the requested 3D-Models if found.\n");
    255   ModelGroup* tmpGroup = this->firstGroup;
    256   int counter = 0;
    257   while (tmpGroup != NULL)
    258   {
    259     if (counter == groupNumber)
    260     {
    261       PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name.c_str());
    262       glCallList (tmpGroup->listNumber);
    263       return;
    264     }
    265     ++counter;
    266     tmpGroup = tmpGroup->next;
    267   }
    268   PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getCName());
    269   return;
    270 }
    271 
    272 
    273 /**
    274  * @brief Draws the Model with a specific groupName
    275  * @param groupName The name of the group that will be displayed.
    276  *
    277  * It does this by just calling the List that must have been created earlier.
    278  */
    279 void StaticModel::draw (const std::string& groupName) const
    280 {
    281   PRINTF(4)("drawing the requested 3D-Models if found.\n");
    282   ModelGroup* tmpGroup = this->firstGroup;
    283   while (tmpGroup != NULL)
    284   {
    285     if (tmpGroup->name == groupName)
    286     {
    287       PRINTF(4)("Drawing model %s\n", tmpGroup->name.c_str());
    288       glCallList (tmpGroup->listNumber);
    289       return;
    290     }
    291     tmpGroup = tmpGroup->next;
    292   }
    293   PRINTF(2)("Model Named %s in %s not Found.\n", groupName.c_str(), this->getCName());
    294   return;
    295 }
    296 
    297 //////////
    298 // INIT //
    299 //////////
    300 
    301 /**
    302  * @brief finalizes an Model.
    303  *
    304  * This funcion is needed, to delete all the Lists, and arrays that are no more
    305  * needed because they are already imported into openGL.
    306  * This will be applied at the end of the importing Process.
    307 */
    308 bool StaticModel::cleanup()
    309 {
    310   PRINTF(4)("cleaning up the 3D-Model to save Memory.\n");
    311   this->firstGroup->cleanup();
    312   return true;
    313 }
    314 
    315 //////////
    316 // MESH //
    317 //////////
    318 /**
    319  * @brief adds a new Material to the Material List
    320  * @param material the Material to add
    321  * @returns the added material
    322  *
    323  * this also tells this Model, that all the Materials are handled externally
    324  * with this option set the Materials will not be deleted with the Model.
    325  */
    326 Material* StaticModel::addMaterial(Material* material)
    327 {
    328   if (material == NULL)
    329     return NULL;
    330   ModelMaterial* modMat = new ModelMaterial;
    331   modMat->external = true;
    332   modMat->material = material;
    333   this->materialList.push_back(modMat);
    334   return modMat->material;
    335 }
    336 
    337 /**
    338  * @brief adds a new Material to the Material List
    339  * @param materialName the name of the Material to add
    340  * @returns the added material
    341  */
    342 Material* StaticModel::addMaterial(const std::string& materialName)
    343 {
    344   ModelMaterial* modMat = new ModelMaterial;
    345   modMat->external = false;
    346   modMat->material = new Material(materialName);
    347 
    348   // adding material to the List of materials
    349   this->materialList.push_back(modMat);
    350   return modMat->material;
    351 }
    352 
    353 /**
    354  * @brief finds a Material by its name and returns it
    355  * @param materialName the Name of the material to search for.
    356  * @returns the Material if found, NULL otherwise
    357  */
    358 Material* StaticModel::findMaterialByName(const std::string& materialName)
    359 {
    360   std::list<ModelMaterial*>::iterator modMat;
    361   for  (modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++)
    362     if (materialName == (*modMat)->material->getName())
    363       return (*modMat)->material;
    364   return NULL;
    365 }
    366 
    367 /**
    368  * @brief parses a group String
    369  * @param groupString the new Group to create
    370  *
    371  * This function initializes a new Group.
    372  * With it you should be able to create Models with more than one SubModel inside
    373  */
    374 bool StaticModel::addGroup(const std::string& groupString)
    375 {
    376   PRINTF(5)("Read Group: %s.\n", groupString.c_str());
    377   if (this->groupCount != 0 && this->currentGroup->faceCount > 0)
    378   {
    379     // finalizeGroup(currentGroup);
    380     this->currentGroup = this->currentGroup->next = new ModelGroup;
    381   }
    382   // setting the group name if not default.
    383   if (groupString == "default")
    384   {
    385     this->currentGroup->name = groupString;
    386   }
    387   ++this->groupCount;
    388   return true;
    389 }
    390 
    391 /**
    392  * @brief parses a vertex-String
    393  * @param vertexString The String that will be parsed.
    394  *
    395  *  If a vertex line is found this function will inject it into the vertex-Array
    396  */
    397 bool StaticModel::addVertex (const std::string& vertexString)
    398 {
    399   float subbuffer1;
    400   float subbuffer2;
    401   float subbuffer3;
    402   sscanf (vertexString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
    403   this->vertices.push_back(subbuffer1*scaleFactor);
    404   this->vertices.push_back(subbuffer2*scaleFactor);
    405   this->vertices.push_back(subbuffer3*scaleFactor);
    406   this->pModelInfo.numVertices++;
    407   return true;
    408 }
    409 
    410 /**
    411  * @brief parses a vertex-String
    412  * @param x the X-coordinate of the Vertex to add.
    413  * @param y the Y-coordinate of the Vertex to add.
    414  * @param z the Z-coordinate of the Vertex to add.
    415  */
    416 bool StaticModel::addVertex(float x, float y, float z)
    417 {
    418   PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z);
    419   this->vertices.push_back(x*scaleFactor);
    420   this->vertices.push_back(y*scaleFactor);
    421   this->vertices.push_back(z*scaleFactor);
    422   this->pModelInfo.numVertices++;
    423   return true;
    424 }
    425 
    426 /**
    427  * @brief parses a vertexNormal-String
    428  * @param normalString The String that will be parsed.
    429  *
    430  * If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    431  */
    432 bool StaticModel::addVertexNormal (const std::string& normalString)
    433 {
    434   float subbuffer1;
    435   float subbuffer2;
    436   float subbuffer3;
    437   sscanf (normalString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
    438   this->normals.push_back(subbuffer1);
    439   this->normals.push_back(subbuffer2);
    440   this->normals.push_back(subbuffer3);
    441   this->pModelInfo.numNormals++;
    442   return true;
    443 }
    444 
    445 /**
    446  * @brief adds a VertexNormal.
    447  * @param x The x coordinate of the Normal.
    448  * @param y The y coordinate of the Normal.
    449  * @param z The z coordinate of the Normal.
    450  *
    451  * If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    452  */
    453 bool StaticModel::addVertexNormal(float x, float y, float z)
    454 {
    455   PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z);
    456   this->normals.push_back(x);
    457   this->normals.push_back(y);
    458   this->normals.push_back(z);
    459   this->pModelInfo.numNormals++;
    460   return true;
    461 }
    462 
    463 /**
    464  * @brief parses a vertexTextureCoordinate-String
    465  * @param vTextureString The String that will be parsed.
    466  *
    467  * If a vertexTextureCoordinate line is found,
    468  * this function will inject it into the vertexTexture-Array
    469  *
    470  * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !!
    471  */
    472 bool StaticModel::addVertexTexture (const std::string& vTextureString)
    473 {
    474   float subbuffer1;
    475   float subbuffer2;
    476   sscanf (vTextureString.c_str(), "%f %f", &subbuffer1, &subbuffer2);
    477   this->vTexture.push_back(subbuffer1);
    478   this->vTexture.push_back(1 - subbuffer2);
    479   this->pModelInfo.numTexCoor++;
    480   return true;
    481 }
    482 
    483 /**
    484  * @brief adds a Texture Coordinate
    485  * @param u The u coordinate of the TextureCoordinate.
    486  * @param v The y coordinate of the TextureCoordinate.
    487  *
    488  * If a TextureCoordinate line is found this function will
    489  *  inject it into the TextureCoordinate-Array
    490  */
    491 bool StaticModel::addVertexTexture(float u, float v)
    492 {
    493   PRINTF(5)("found vertex-Texture %f, %f\n", u, v);
    494   this->vTexture.push_back(u);
    495   this->vTexture.push_back(v);
    496   this->pModelInfo.numTexCoor++;
    497   return true;
    498 }
    499 
    500 /**
    501  * @brief parses a face-string
    502  * @param faceString The String that will be parsed.
    503  *
    504  * If a face line is found this function will add it to the glList.
    505  *
    506  * String is different from the argument addFace,
    507  * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0
    508  *
    509  * @TODO make it std::string conform
    510  */
    511 bool StaticModel::addFace (const std::string& faceStringInput)
    512 {
    513   const char* faceString = faceStringInput.c_str();
    514   if (this->currentGroup->faceCount >0)
    515     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
    516 
    517   ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;
    518   tmpElem->next = NULL;
    519   while(strcmp (faceString, "\0"))
    520   {
    521     if (this->currentGroup->currentFace->vertexCount>0)
    522       tmpElem = tmpElem->next = new ModelFaceElement;
    523     tmpElem->next = NULL;
    524 
    525     char tmpValue [50];
    526     int tmpLen;
    527     char* vertex = NULL;
    528     char* texture = NULL;
    529     char* normal = NULL;
    530 
    531     sscanf (faceString, "%s", tmpValue);
    532     tmpLen = strlen(tmpValue);
    533     vertex = tmpValue;
    534 
    535     if ((texture = strstr (vertex, "/")) != NULL)
    536     {
    537       texture[0] = '\0';
    538       texture ++;
    539 
    540       if ((normal = strstr (texture, "/")) !=NULL)
    541       {
    542         normal[0] = '\0';
    543         normal ++;
    544       }
    545     }
    546     if (vertex)
    547       tmpElem->vertexNumber = atoi(vertex)-1;
    548     if (texture)
    549       tmpElem->texCoordNumber = atoi(texture)-1;
    550     if (normal)
    551       tmpElem->normalNumber = atoi(normal)-1;
    552 
    553     faceString += tmpLen;
    554     if (strcmp (faceString, "\0"))
    555       faceString++;
    556     this->currentGroup->currentFace->vertexCount++;
    557   }
    558 
    559   this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2;
    560   this->faceCount += this->currentGroup->currentFace->vertexCount -2;
    561   return true;
     90  this->data = data;
     91  this->updateBase();
    56292}
    56393
     
    56999bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
    570100{
    571   if (this->currentGroup->faceCount > 0)
    572     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
    573 
    574   ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;
    575 
    576101  va_list itemlist;
    577102  va_start (itemlist, type);
    578 
    579   for (int i = 0; i < faceElemCount; i++)
    580   {
    581     if (this->currentGroup->currentFace->vertexCount > 0)
    582       tmpElem = tmpElem->next = new ModelFaceElement;
    583 
    584     tmpElem->vertexNumber = va_arg (itemlist, int);
    585     if (type & TEXCOORD)
    586       tmpElem->texCoordNumber = va_arg (itemlist, int);
    587     if (type & NORMAL)
    588       tmpElem->normalNumber = va_arg(itemlist, int);
    589     this->currentGroup->currentFace->vertexCount++;
    590   }
     103  bool retVal = this->data->addFace(faceElemCount, type, itemlist);
    591104  va_end(itemlist);
    592 
    593   this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount - 2;
    594   this->faceCount += this->currentGroup->currentFace->vertexCount -2;
    595   return true;
     105  return retVal;
    596106}
    597107
    598 /**
    599  * Function that selects a material, if changed in the obj file.
    600  * @param matString the Material that will be set.
    601 */
    602 bool StaticModel::setMaterial(const std::string& matString)
     108void StaticModel::updateBase()
    603109{
    604   if (this->currentGroup->faceCount > 0)
    605     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
     110  // write out the modelInfo data used for the collision detection!
     111  this->pModelInfo.pVertices = &this->data->getVertices()[0];
     112  this->pModelInfo.numVertices = this->data->getVertices().size();
     113  this->pModelInfo.pNormals = &this->data->getNormals()[0];
     114  this->pModelInfo.numNormals = this->data->getNormals().size();
     115  this->pModelInfo.pTexCoor = &this->data->getTexCoords()[0];
     116  this->pModelInfo.numTexCoor = this->data->getTexCoords().size();
    606117
    607   this->currentGroup->currentFace->material = this->findMaterialByName(matString);
    608 
    609   if (this->currentGroup->faceCount == 0)
    610     this->currentGroup->faceCount++;
    611   return true;
    612 }
    613 
    614 /**
    615  * Function that selects a material, if changed in the obj file.
    616  * @param mtl the Material that will be set.
    617 */
    618 bool StaticModel::setMaterial(Material* mtl)
    619 {
    620   if (this->currentGroup->faceCount > 0)
    621     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
    622 
    623   this->currentGroup->currentFace->material = mtl;
    624 
    625   if (this->currentGroup->faceCount == 0)
    626     this->currentGroup->faceCount++;
    627   return true;
    628 }
    629 
    630 /**
    631  * @brief A routine that is able to create normals.
    632  *
    633  * The algorithm does the following:
    634  * 1. It calculates creates Vectors for each normale, and sets them to zero.
    635  * 2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements
    636  * 3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal.
    637  * 4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array.
    638  */
    639 bool StaticModel::buildVertexNormals ()
    640 {
    641   PRINTF(4)("Normals are being calculated.\n");
    642 
    643   Vector* normArray = new Vector [vertices.size()/3];
    644   for (unsigned int i=0; i<vertices.size()/3;i++)
    645     normArray[i] = Vector(.0,.0,.0);
    646 
    647   Vector prevV;
    648   Vector nextV;
    649   Vector curV;
    650 
    651   ModelGroup* tmpGroup = firstGroup;
    652   while (tmpGroup != NULL)
    653   {
    654     ModelFace* tmpFace = tmpGroup->firstFace;
    655     while (tmpFace != NULL)
    656     {
    657       if (tmpFace->firstElem != NULL)
    658       {
    659         ModelFaceElement* firstElem = tmpFace->firstElem;
    660         ModelFaceElement* prevElem;
    661         ModelFaceElement* curElem = firstElem;
    662         ModelFaceElement* nextElem;
    663         ModelFaceElement* lastElem;
    664         // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
    665         while (curElem != NULL)
    666         {
    667           prevElem = curElem;
    668           curElem = curElem->next;
    669         }
    670         lastElem = prevElem;
    671 
    672         curElem = firstElem;
    673         for (unsigned int j = 0; j < tmpFace->vertexCount; j++)
    674         {
    675           if (!(nextElem = curElem->next))
    676             nextElem = firstElem;
    677           curElem->normalNumber = curElem->vertexNumber;
    678 
    679           curV = Vector (this->vertices[curElem->vertexNumber*3],
    680                          this->vertices[curElem->vertexNumber*3+1],
    681                          this->vertices[curElem->vertexNumber*3+2]);
    682 
    683           prevV = Vector (this->vertices[prevElem->vertexNumber*3],
    684                           this->vertices[prevElem->vertexNumber*3+1],
    685                           this->vertices[prevElem->vertexNumber*3+2]) - curV;
    686 
    687           nextV = Vector (this->vertices[nextElem->vertexNumber*3],
    688                           this->vertices[nextElem->vertexNumber*3+1],
    689                           this->vertices[nextElem->vertexNumber*3+2]) - curV;
    690           normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
    691 
    692           prevElem = curElem;
    693           curElem = curElem->next;
    694         }
    695       }
    696       tmpFace = tmpFace->next;
    697     }
    698     tmpGroup = tmpGroup->next;
    699   }
    700 
    701   for (unsigned int i=0; i < this->vertices.size()/3;i++)
    702   {
    703     normArray[i].normalize();
    704     PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
    705 
    706     this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z);
    707 
    708   }
    709   delete[] normArray;
    710   return true;
    711 }
    712 
    713 ////////////
    714 // openGL //
    715 ////////////
    716 /**
    717  *  reads and includes the Faces/Materials into the openGL state Machine
    718 */
    719 bool StaticModel::importToDisplayList()
    720 {
    721   // finalize the Arrays
    722   if (normals.size() == 0) // vertices-Array must be built for this
    723     this->buildVertexNormals();
    724 
    725   this->currentGroup = this->firstGroup;
    726 
    727   while (this->currentGroup != NULL)
    728   {
    729 
    730     // creating a glList for the Group
    731     if ((this->currentGroup->listNumber = glGenLists(1)) == 0)
    732     {
    733       PRINTF(2)("glList could not be created for this Model\n");
    734       return false;
    735     }
    736     glNewList (this->currentGroup->listNumber, GL_COMPILE);
    737 
    738     // Putting Faces to GL
    739     ModelFace* tmpFace = this->currentGroup->firstFace;
    740     while (tmpFace != NULL)
    741     {
    742       if (tmpFace->vertexCount == 0 && tmpFace->material != NULL)
    743       {
    744         if (this->currentGroup->faceMode != -1)
    745           glEnd();
    746         this->currentGroup->faceMode = 0;
    747         if (tmpFace->material != NULL)
    748         {
    749           tmpFace->material->select();
    750           PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getCName());
    751         }
    752       }
    753 
    754       else if (tmpFace->vertexCount == 3)
    755       {
    756         if (this->currentGroup->faceMode != 3)
    757         {
    758           if (this->currentGroup->faceMode != -1)
    759             glEnd();
    760           glBegin(GL_TRIANGLES);
    761         }
    762 
    763         this->currentGroup->faceMode = 3;
    764         PRINTF(5)("found triag.\n");
    765       }
    766 
    767       else if (tmpFace->vertexCount == 4)
    768       {
    769         if (this->currentGroup->faceMode != 4)
    770         {
    771           if (this->currentGroup->faceMode != -1)
    772             glEnd();
    773           glBegin(GL_QUADS);
    774         }
    775         this->currentGroup->faceMode = 4;
    776         PRINTF(5)("found quad.\n");
    777       }
    778 
    779       else if (tmpFace->vertexCount > 4)
    780       {
    781         if (this->currentGroup->faceMode != -1)
    782           glEnd();
    783         glBegin(GL_POLYGON);
    784         PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount);
    785         this->currentGroup->faceMode = tmpFace->vertexCount;
    786       }
    787 
    788       ModelFaceElement* tmpElem = tmpFace->firstElem;
    789       while (tmpElem != NULL)
    790       {
    791         //      PRINTF(2)("%s\n", tmpElem->value);
    792         this->addGLElement(tmpElem);
    793         tmpElem = tmpElem->next;
    794       }
    795       tmpFace = tmpFace->next;
    796     }
    797     glEnd();
    798     glEndList();
    799 
    800     this->currentGroup = this->currentGroup->next;
    801   }
    802   return true;
     118  this->pModelInfo.pTriangles = this->data->getTrianglesExt();
     119  this->pModelInfo.numTriangles = this->data->getTriangles().size();
    803120}
    804121
    805122
    806123/**
    807  *  builds an array of triangles, that can later on be used for obb separation and octree separation
     124 *  Includes a default model
     125 *
     126 * This will inject a Cube, because this is the most basic model.
    808127 */
    809 bool StaticModel::buildTriangleList()
    810 {
    811   if( unlikely(this->pModelInfo.pTriangles != NULL))
    812     return true;
    813   /* make sure, that all the arrays are finalized */
    814   if( normals.size() == 0) // vertices-Array must be built for this
    815     this->buildVertexNormals();
    816 
    817   int                index = 0;                   //!< the counter for the triangle array
    818   ModelFaceElement*  tmpElem;       //!< the temporary faceelement reference
    819   ModelFace*         tmpFace;              //!< the temporary face referece
    820 
    821   bool warned = false;
    822 
    823   this->pModelInfo.numTriangles = 0;
    824 
    825   /* count the number of triangles */
    826   /* now iterate through all groups and build up the triangle list */
    827   this->currentGroup = this->firstGroup;
    828   while( this->currentGroup != NULL)
    829   {
    830     tmpFace = this->currentGroup->firstFace;
    831     while( tmpFace != NULL)
    832     {
    833       /* if its a triangle just add it to the list */
    834       if( tmpFace->vertexCount == 3){
    835         ++this->pModelInfo.numTriangles;
    836       } /* if the polygon is a quad */
    837       else if( tmpFace->vertexCount == 4) {
    838         this->pModelInfo.numTriangles += 2;
    839       }
    840       else if( tmpFace->vertexCount > 4) {
    841         if (!warned)        {
    842           PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getCName());
    843           warned = true;
    844         }
    845       }
    846       tmpFace = tmpFace->next;
    847     }
    848     this->currentGroup = this->currentGroup->next;
    849   }
    850 
    851   PRINTF(3)("got %i triangles, %i vertices\n", this->pModelInfo.numTriangles, this->pModelInfo.numVertices);
    852 
    853 
    854   /* write MODELINFO structure */
    855 
    856   /* allocate memory for the new triangle structures */
    857   if( (this->pModelInfo.pTriangles = new sTriangleExt[this->pModelInfo.numTriangles]) == NULL)
    858   {
    859     PRINTF(1)("Could not allocate memory for triangle list\n");
    860     return false;
    861   }
    862 
    863   /* now iterate through all groups and build up the triangle list */
    864   this->currentGroup = this->firstGroup;
    865   while( this->currentGroup != NULL)
    866   {
    867     tmpFace = this->currentGroup->firstFace;
    868     while( tmpFace != NULL)
    869     {
    870       tmpElem = tmpFace->firstElem;
    871 
    872       /* if its a triangle just add it to the list */
    873       if( tmpFace->vertexCount == 3)
    874       {
    875         for( int j = 0; j < 3; ++j)
    876         {
    877           this->pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3 ;
    878           this->pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3 ;
    879           this->pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3 ;
    880           tmpElem = tmpElem->next;
    881 
    882         }
    883         ++index;
    884       } /* if the polygon is a quad */
    885       else if( tmpFace->vertexCount == 4)
    886       {
    887 
    888         this->pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
    889         this->pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
    890         this->pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
    891 
    892         this->pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
    893         this->pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
    894         this->pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
    895         tmpElem = tmpElem->next;
    896 
    897         this->pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
    898         this->pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
    899         this->pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
    900         tmpElem = tmpElem->next;
    901 
    902         this->pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
    903         this->pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
    904         this->pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
    905 
    906         this->pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
    907         this->pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
    908         this->pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
    909         tmpElem = tmpElem->next;
    910 
    911         this->pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
    912         this->pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
    913         this->pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
    914 
    915         index += 2;
    916       }
    917       tmpFace = tmpFace->next;
    918     }
    919     this->currentGroup = this->currentGroup->next;
    920   }
    921   return true;
    922 }
    923 
    924 
    925 /**
    926  *  Adds a Face-element (one vertex of a face) with all its information.
    927  * @param elem The FaceElement to add to the OpenGL-environment.
    928 
    929    It does this by searching:
    930    1. The Vertex itself
    931    2. The VertexNormale
    932    3. The VertexTextureCoordinate
    933    merging this information, the face will be drawn.
    934 */
    935 bool StaticModel::addGLElement (ModelFaceElement* elem)
    936 {
    937   PRINTF(5)("importing grafical Element to openGL.\n");
    938 
    939   if (elem->texCoordNumber > -1)
    940   {
    941     if (likely((unsigned int)elem->texCoordNumber < this->pModelInfo.numTexCoor))
    942       glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2);
    943     else
    944       PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",
    945                 elem->texCoordNumber, this->pModelInfo.numTexCoor);
    946   }
    947   if (elem->normalNumber > -1)
    948   {
    949     if (likely((unsigned int)elem->normalNumber < this->pModelInfo.numNormals))
    950       glNormal3fv(&this->normals[0] + elem->normalNumber * 3);
    951     else
    952       PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",
    953                 elem->normalNumber, this->pModelInfo.numNormals);
    954   }
    955   if (elem->vertexNumber > -1)
    956   {
    957     if (likely((unsigned int)elem->vertexNumber < this->pModelInfo.numVertices))
    958       glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3);
    959     else
    960       PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",
    961                 elem->vertexNumber, this->pModelInfo.numVertices);
    962   }
    963 
    964   return true;
    965 }
    966 
    967 /**
    968  *  Includes a default model
    969 
    970    This will inject a Cube, because this is the most basic model.
    971 */
    972128void StaticModel::cubeModel()
    973129{
  • trunk/src/lib/graphics/importer/static_model.h

    r7221 r9869  
    1010
    1111#include "material.h"
    12 #include "glincl.h"
    1312#include <vector>
    14 #include <list>
    15 
    16 // definition of different modes for setting up Faces
    17 #define VERTEX 0       //!< If Faces are created WITH Vertex-Coordinate
    18 #define NORMAL 1       //!< If Faces are created WITH Normals (otherwise autocalculate)
    19 #define TEXCOORD 2     //!< If Faces are created WITH TextureCoordinate
    20 
    21 //! an enumerator for VERTEX_FORMAT
    22 typedef enum VERTEX_FORMAT {
    23   VERTEX_ONLY = VERTEX,
    24   VERTEX_NORMAL = NORMAL,
    25   VERTEX_TEXCOORD = TEXCOORD,
    26   VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD
    27 };
    28 
    29 ////////////////////
    30 /// SUB-ELEMENTS ///
    31 ////////////////////
    32 //! This is the placeholder of one Vertex beloning to a Face.
    33 class ModelFaceElement
    34 {
    35  public:
    36   ModelFaceElement();
    37   ~ModelFaceElement();
    38 
    39   int                 vertexNumber;         //!< The number of the Vertex out of the Array* vertices, this vertex points to.
    40   int                 normalNumber;         //!< The number of the Normal out of the Array* normals, this vertex points to.
    41   int                 texCoordNumber;       //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
    42 
    43   ModelFaceElement*   next;                 //!< Point to the next FaceElement in this List.
    44 };
    45 
    46 //! This is the placeholder of a Face belonging to a Group of Faces.
    47 class ModelFace
    48 {
    49  public:
    50   ModelFace();
    51   ~ModelFace();
    52 
    53   unsigned int        vertexCount;     //!< The Count of vertices this Face has.
    54   ModelFaceElement*   firstElem;       //!< Points to the first Vertex (FaceElement) of this Face.
    55   Material*           material;        //!< The Material to use.
    56 
    57   ModelFace*          next;            //!< Pointer to the next Face.
    58 };
    59 
    60 //! Group to handle multiple Models per obj-file.
    61 class ModelGroup
    62 {
    63  public:
    64   ModelGroup();
    65   ~ModelGroup();
    66 
    67   void cleanup();
    68 
    69   std::string  name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function.
    70   GLubyte*     indices;        //!< The indices of the Groups. Needed for vertex-arrays
    71   GLuint       listNumber;     //!< The number of the GL-List this Group gets.
    72   ModelFace*   firstFace;      //!< The first Face in this group.
    73   ModelFace*   currentFace;    //!< The current Face in this Group (the one we are currently working with.)
    74   int          faceMode;       //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material,  3 for triangle, 4 for Quad, 5+ for Poly @todo ENUM...
    75   int          faceCount;      //!< The Number of Faces this Group holds.
    76 
    77   ModelGroup*  next;           //!< Pointer to the next Group.
    78 };
    79 
    80 struct ModelMaterial
    81 {
    82   Material* material;
    83   bool external;
    84 };
     13#include "static_model_data.h"
    8514
    8615/////////////
     
    9423class StaticModel : public Model
    9524{
    96  public:
     25  ObjectListDeclaration(StaticModel);
     26public:
    9727  StaticModel(const std::string& modelName = "");
     28  StaticModel(const StaticModel& staticModel);
    9829  virtual ~StaticModel();
    9930
    100   virtual void draw() const;
    101   void draw(int groupNumber) const;
    102   void draw(const std::string& groupName) const;
     31  StaticModel& operator=(const StaticModel& model);
    10332
    104   void rebuild();
     33  virtual void draw() const { data->draw(); };
     34  void draw(int groupNumber) const { data->draw(groupNumber); };
     35  void draw(const std::string& groupName) const { data->draw(groupName); };
    10536
    106   Material* addMaterial(Material* material);
    107   Material* addMaterial(const std::string& materialName);
     37  void rebuild() { data->rebuild(); };
    10838
    109   bool addGroup(const std::string& groupString);
     39  Material* addMaterial(Material* material) { return data->addMaterial(material); };
     40  Material* addMaterial(const std::string& materialName) { return data->addMaterial(materialName); };
    11041
    111   bool addVertex(const std::string& vertexString);
    112   bool addVertex(float x, float y, float z);
     42  bool addGroup(const std::string& groupString) { return data->addGroup(groupString); };
    11343
    114   bool addFace(const std::string& faceString);
     44  bool addVertex(const std::string& vertexString) { return data->addVertex(vertexString); };
     45  bool addVertex(float x, float y, float z) { return data->addVertex(x, y, z); };
     46
     47  bool addFace(const std::string& faceString) { return data->addFace(faceString); };
    11548  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
    11649
    117   bool addVertexNormal(const std::string& normalString);
    118   bool addVertexNormal(float x, float y, float z);
     50  bool addVertexNormal(const std::string& normalString) { return this->data->addVertexNormal(normalString); };
     51  bool addVertexNormal(float x, float y, float z) { return this->data->addVertexNormal(x,y,z); };
    11952
    120   bool addVertexTexture(const std::string& vTextureString);
    121   bool addVertexTexture(float u, float v);
     53  bool addVertexTexture(const std::string& vTextureString) { return this->data->addVertexTexture(vTextureString); };
     54  bool addVertexTexture(float u, float v) { return this->data->addVertexTexture(u, v); };
    12255
    123   bool setMaterial(const std::string& mtlString);
    124   bool setMaterial(Material* mtl);
     56  bool setMaterial(const std::string& mtlString) { return data->setMaterial(mtlString); };
     57  bool setMaterial(Material* mtl) { return data->setMaterial(mtl);};
    12558
    12659  void finalize();
    12760
     61  void acquireData(const StaticModelData::Pointer& data);
     62  const StaticModelData::Pointer& dataPointer() const { return this->data; };
    12863
    129  protected:
     64  inline void setScaleFactor(float scaleFactor) { this->data->setScaleFactor(scaleFactor); };
     65  float getScaleFactor() const { return data->getScaleFactor(); }
     66
     67protected:
    13068  void cubeModel();
    13169
    132   Material* findMaterialByName(const std::string& materialName);
    133 
    134  protected:
    135   float            scaleFactor;     //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation
    136 
    137  private:
    138   bool buildVertexNormals();
    139 
    140   bool importToDisplayList();
    141   bool buildTriangleList();
    142 
    143   bool addGLElement(ModelFaceElement* elem);
    144 
    145   bool cleanup();
    146 
    147  private:
    148   bool                       finalized;       //!< Sets the Object to be finalized.
    149 
    150   unsigned int               faceCount;       //!< A modelwide Counter for the faces
    151 
    152   std::vector<GLfloat>       vertices;        //!< The Array that handles the Vertices.
    153   std::vector<GLfloat>       normals;         //!< The Array that handles the Normals.
    154   std::vector<GLfloat>       vTexture;        //!< The Array that handles the VertexTextureCoordinates.
    155 
    156   ModelGroup*                firstGroup;      //!< The first of all groups.
    157   ModelGroup*                currentGroup;    //!< The currentGroup. this is the one we will work with.
    158   int                        groupCount;      //!< The Count of Groups.
    159 
    160   std::list<ModelMaterial*>  materialList;    //!< A list for all the Materials in this Model
     70private:
     71  void updateBase();
     72private:
     73  StaticModelData::Pointer         data;
    16174};
    16275
  • trunk/src/lib/graphics/importer/texture.cc

    r9406 r9869  
    6464#endif
    6565
    66 
     66ObjectListDefinition(Texture);
    6767
    6868/**
     
    8686    : data(texture.data)
    8787{
    88   this->setClassID(CL_TEXTURE, "Texture");
     88  this->registerObject(this, Texture::_objectList);
    8989  this->priority = 0.5;
    9090}
     
    149149void Texture::init()
    150150{
    151   this->setClassID(CL_TEXTURE, "Texture");
    152 
    153   this->data = TextureDataPointer(new TextureData());
     151  this->registerObject(this, Texture::_objectList);
     152
     153  this->data = TextureData::Pointer(new TextureData());
    154154
    155155  this->priority = 0.5;
     
    176176}
    177177
    178 Texture& Texture::operator=(const TextureDataPointer& textureDataPointer)
     178Texture& Texture::operator=(const TextureData::Pointer& textureDataPointer)
    179179{
    180180  this->data = textureDataPointer;
  • trunk/src/lib/graphics/importer/texture.h

    r8761 r9869  
    11/*!
    22 * @file texture.h
    3  * @brief Contains the texture class, that handles the reading of Images into Texutre-files.
     3 * @brief Contains the texture class, that handles the reading of Images into Texture-files.
    44 */
    55
     
    2020class Texture : public BaseObject
    2121{
     22  ObjectListDeclaration(Texture);
    2223public:
    2324  Texture();
     
    2829
    2930  Texture& operator=(const Texture& texture);
    30   Texture& operator=(const TextureDataPointer& textureDataPointer);
     31  Texture& operator=(const TextureData::Pointer& textureDataPointer);
     32  void acquireData(const TextureData::Pointer& textureDataPointer) { this->data = textureDataPointer; };
     33  const TextureData::Pointer& dataPointer() const { return data; }
    3134
    3235  virtual ~Texture();
     
    6265
    6366private:
    64   TextureDataPointer            data;               //!< The TextureData
     67  TextureData::Pointer          data;               //!< The TextureData
    6568  GLclampf                      priority;           //!< the priority of the current texture (used for garphics cards with limited mem)
    6669
  • trunk/src/lib/graphics/importer/texture_data.h

    r8761 r9869  
    1818class TextureData
    1919{
     20  public:
     21    typedef CountPointer<TextureData> Pointer;
    2022  public:
    2123    TextureData();
     
    4345};
    4446
    45 typedef CountPointer<TextureData> TextureDataPointer;
    46 
    4747#endif /* _TEXTURE_DATA_H */
  • trunk/src/lib/graphics/importer/texture_sequence.cc

    r9406 r9869  
    2828#endif
    2929
     30ObjectListDefinition(TextureSequence);
     31
    3032/**
    3133 * @brief Constructor for a Texture
     
    3335TextureSequence::TextureSequence(unsigned int count, ...)
    3436{
    35   this->setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");
     37  this->registerObject(this, TextureSequence::_objectList);
    3638
    3739  va_list textureNameList;
     
    5456TextureSequence::TextureSequence(const std::vector<std::string>& textureNames, const std::string& prependFolder)
    5557{
    56   this->setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");
     58  this->registerObject(this, TextureSequence::_objectList);
    5759  this->loadImageSeries(textureNames, prependFolder);
    5860}
  • trunk/src/lib/graphics/importer/texture_sequence.h

    r8324 r9869  
    1515class TextureSequence : public Texture
    1616{
     17  ObjectListDeclaration(TextureSequence);
    1718  public:
    1819    TextureSequence(unsigned int count = 0, ...);
  • trunk/src/lib/graphics/importer/vertex_array_model.cc

    r9406 r9869  
    2424
    2525
     26ObjectListDefinition(VertexArrayModel);
    2627
    2728/////////////
     
    3536VertexArrayModel::VertexArrayModel()
    3637{
    37   this->setClassID(CL_MODEL, "VertexArrayModel");
     38  this->registerObject(this, VertexArrayModel::_objectList);
    3839
    3940  this->newStripe();
     
    4950VertexArrayModel::VertexArrayModel(const Model& model)
    5051{
    51   this->setClassID(CL_MODEL, "VertexArrayModel");
     52  this->registerObject(this, VertexArrayModel::_objectList);
    5253
    5354  // importing the data to the new Model.
  • trunk/src/lib/graphics/importer/vertex_array_model.h

    r6769 r9869  
    2727class VertexArrayModel : public Model
    2828{
    29  public:
     29  ObjectListDeclaration(VertexArrayModel);
     30  public:
    3031  VertexArrayModel();
    3132  VertexArrayModel(const Model& model);
Note: See TracChangeset for help on using the changeset viewer.