Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3396 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Feb 6, 2005, 3:58:40 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: splitted obj-loader out of the model-class: this will enable different kinds of Filetypes to be included with the importer.
Althought there is a name-field error, the Model gets loaded and unloaded as good as previously

Location:
orxonox/trunk/src
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.am

    r3377 r3396  
    2525                 environment.cc \
    2626                 importer/model.cc \
     27                 importer/objModel.cc \
    2728                 importer/array.cc \
    2829                 importer/material.cc \
  • orxonox/trunk/src/Makefile.in

    r3377 r3396  
    5959        track.$(OBJEXT) base_entity.$(OBJEXT) game_loader.$(OBJEXT) \
    6060        campaign.$(OBJEXT) story_entity.$(OBJEXT) \
    61         environment.$(OBJEXT) model.$(OBJEXT) array.$(OBJEXT) \
    62         material.$(OBJEXT) texture.$(OBJEXT) list.$(OBJEXT) \
    63         p_node.$(OBJEXT) null_parent.$(OBJEXT) base_object.$(OBJEXT) \
    64         helper_parent.$(OBJEXT) track_manager.$(OBJEXT) \
    65         matrix.$(OBJEXT) curve.$(OBJEXT) glmenu_imagescreen.$(OBJEXT)
     61        environment.$(OBJEXT) model.$(OBJEXT) objModel.$(OBJEXT) \
     62        array.$(OBJEXT) material.$(OBJEXT) texture.$(OBJEXT) \
     63        list.$(OBJEXT) p_node.$(OBJEXT) null_parent.$(OBJEXT) \
     64        base_object.$(OBJEXT) helper_parent.$(OBJEXT) \
     65        track_manager.$(OBJEXT) matrix.$(OBJEXT) curve.$(OBJEXT) \
     66        glmenu_imagescreen.$(OBJEXT)
    6667orxonox_OBJECTS = $(am_orxonox_OBJECTS)
    6768orxonox_LDADD = $(LDADD)
     
    8283@AMDEP_TRUE@    ./$(DEPDIR)/list.Po ./$(DEPDIR)/material.Po \
    8384@AMDEP_TRUE@    ./$(DEPDIR)/matrix.Po ./$(DEPDIR)/model.Po \
    84 @AMDEP_TRUE@    ./$(DEPDIR)/null_parent.Po ./$(DEPDIR)/orxonox.Po \
    85 @AMDEP_TRUE@    ./$(DEPDIR)/p_node.Po ./$(DEPDIR)/player.Po \
    86 @AMDEP_TRUE@    ./$(DEPDIR)/story_entity.Po ./$(DEPDIR)/texture.Po \
    87 @AMDEP_TRUE@    ./$(DEPDIR)/track.Po ./$(DEPDIR)/track_manager.Po \
    88 @AMDEP_TRUE@    ./$(DEPDIR)/vector.Po ./$(DEPDIR)/world.Po \
    89 @AMDEP_TRUE@    ./$(DEPDIR)/world_entity.Po
     85@AMDEP_TRUE@    ./$(DEPDIR)/null_parent.Po ./$(DEPDIR)/objModel.Po \
     86@AMDEP_TRUE@    ./$(DEPDIR)/orxonox.Po ./$(DEPDIR)/p_node.Po \
     87@AMDEP_TRUE@    ./$(DEPDIR)/player.Po ./$(DEPDIR)/story_entity.Po \
     88@AMDEP_TRUE@    ./$(DEPDIR)/texture.Po ./$(DEPDIR)/track.Po \
     89@AMDEP_TRUE@    ./$(DEPDIR)/track_manager.Po ./$(DEPDIR)/vector.Po \
     90@AMDEP_TRUE@    ./$(DEPDIR)/world.Po ./$(DEPDIR)/world_entity.Po
    9091CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
    9192        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
     
    225226                 environment.cc \
    226227                 importer/model.cc \
     228                 importer/objModel.cc \
    227229                 importer/array.cc \
    228230                 importer/material.cc \
     
    378380@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Po@am__quote@
    379381@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/null_parent.Po@am__quote@
     382@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/objModel.Po@am__quote@
    380383@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox.Po@am__quote@
    381384@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/p_node.Po@am__quote@
     
    420423@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    421424@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o model.obj `if test -f 'importer/model.cc'; then $(CYGPATH_W) 'importer/model.cc'; else $(CYGPATH_W) '$(srcdir)/importer/model.cc'; fi`
     425
     426objModel.o: importer/objModel.cc
     427@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT objModel.o -MD -MP -MF "$(DEPDIR)/objModel.Tpo" -c -o objModel.o `test -f 'importer/objModel.cc' || echo '$(srcdir)/'`importer/objModel.cc; \
     428@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/objModel.Tpo" "$(DEPDIR)/objModel.Po"; else rm -f "$(DEPDIR)/objModel.Tpo"; exit 1; fi
     429@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='importer/objModel.cc' object='objModel.o' libtool=no @AMDEPBACKSLASH@
     430@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/objModel.Po' tmpdepfile='$(DEPDIR)/objModel.TPo' @AMDEPBACKSLASH@
     431@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     432@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o objModel.o `test -f 'importer/objModel.cc' || echo '$(srcdir)/'`importer/objModel.cc
     433
     434objModel.obj: importer/objModel.cc
     435@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT objModel.obj -MD -MP -MF "$(DEPDIR)/objModel.Tpo" -c -o objModel.obj `if test -f 'importer/objModel.cc'; then $(CYGPATH_W) 'importer/objModel.cc'; else $(CYGPATH_W) '$(srcdir)/importer/objModel.cc'; fi`; \
     436@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/objModel.Tpo" "$(DEPDIR)/objModel.Po"; else rm -f "$(DEPDIR)/objModel.Tpo"; exit 1; fi
     437@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='importer/objModel.cc' object='objModel.obj' libtool=no @AMDEPBACKSLASH@
     438@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/objModel.Po' tmpdepfile='$(DEPDIR)/objModel.TPo' @AMDEPBACKSLASH@
     439@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     440@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o objModel.obj `if test -f 'importer/objModel.cc'; then $(CYGPATH_W) 'importer/objModel.cc'; else $(CYGPATH_W) '$(srcdir)/importer/objModel.cc'; fi`
    422441
    423442array.o: importer/array.cc
  • orxonox/trunk/src/environment.cc

    r3380 r3396  
    2121#include "world_entity.h"
    2222#include "vector.h"
    23 #include "importer/model.h"
     23#include "importer/objModel.h"
    2424
    2525using namespace std;
     
    2929Environment::Environment () : WorldEntity()
    3030{
    31   this->model = new Model("../data/models/fighter.obj");
     31  this->model = new OBJModel("../data/models/fighter.obj");
    3232}
    3333
  • orxonox/trunk/src/importer/Makefile.am

    r3365 r3396  
    99                  windowHandler.cc \
    1010                  model.cc \
     11                  objModel.cc \
    1112                  array.cc \
    1213                  material.cc \
     
    1718                windowHandler.h \
    1819                model.h \
     20                objModel.h \
    1921                array.h \
    2022                material.h \
  • orxonox/trunk/src/importer/Makefile.in

    r3377 r3396  
    5454PROGRAMS = $(bin_PROGRAMS)
    5555am_importer_OBJECTS = framework.$(OBJEXT) windowHandler.$(OBJEXT) \
    56         model.$(OBJEXT) array.$(OBJEXT) material.$(OBJEXT) \
    57         texture.$(OBJEXT) vector.$(OBJEXT)
     56        model.$(OBJEXT) objModel.$(OBJEXT) array.$(OBJEXT) \
     57        material.$(OBJEXT) texture.$(OBJEXT) vector.$(OBJEXT)
    5858importer_OBJECTS = $(am_importer_OBJECTS)
    5959importer_LDADD = $(LDADD)
     
    6363@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/array.Po ./$(DEPDIR)/framework.Po \
    6464@AMDEP_TRUE@    ./$(DEPDIR)/material.Po ./$(DEPDIR)/model.Po \
    65 @AMDEP_TRUE@    ./$(DEPDIR)/texture.Po ./$(DEPDIR)/vector.Po \
    66 @AMDEP_TRUE@    ./$(DEPDIR)/windowHandler.Po
     65@AMDEP_TRUE@    ./$(DEPDIR)/objModel.Po ./$(DEPDIR)/texture.Po \
     66@AMDEP_TRUE@    ./$(DEPDIR)/vector.Po ./$(DEPDIR)/windowHandler.Po
    6767CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
    6868        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
     
    180180                  windowHandler.cc \
    181181                  model.cc \
     182                  objModel.cc \
    182183                  array.cc \
    183184                  material.cc \
     
    188189                windowHandler.h \
    189190                model.h \
     191                objModel.h \
    190192                array.h \
    191193                material.h \
     
    262264@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/material.Po@am__quote@
    263265@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Po@am__quote@
     266@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/objModel.Po@am__quote@
    264267@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@
    265268@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@
  • orxonox/trunk/src/importer/framework.cc

    r3365 r3396  
    7171  PRINTF(2)("screensize: %i, %i\n", wHandler.screen->w, wHandler.screen->h);
    7272  if (argc>=3)
    73     obj = new Model (argv[1], atof(argv[2]));
     73    obj = new OBJModel (argv[1], atof(argv[2]));
    7474  else if (argc>=2)
    75     obj = new Model(argv[1]);
     75    obj = new OBJModel(argv[1]);
    7676  else
    77     obj = new Model();
     77    obj = (OBJModel*) new Model();
    7878 
    7979  M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0);
     
    215215          case SDLK_c:
    216216            if (!obj)
    217               obj = new Model(argv[1]);
     217              obj = new OBJModel(argv[1]);
    218218            break;
    219219          }
  • orxonox/trunk/src/importer/framework.h

    r3365 r3396  
    33 
    44#include "windowHandler.h" // Include the Whandler Basecode
    5 #include "model.h"
     5#include "objModel.h"
    66#include "vector.h"
    77
     
    3333
    3434WindowHandler wHandler;  // Create an instance of the whandler basecode class
    35 Model* obj;
     35OBJModel* obj;
    3636
    3737
  • orxonox/trunk/src/importer/material.cc

    r3365 r3396  
    112112  while (searcher != NULL)
    113113    {
    114       PRINTF(2)(".");
     114      PRINT(2)(".");
    115115      if (!strcmp (searcher->getName(), mtlName))
    116116        {
    117           PRINTF(2)("found.\n");
     117          PRINT(2)("found.\n");
    118118          return searcher;
    119119        }
    120120      searcher = searcher->nextMat;
    121121    }
    122   PRINTF(2)("not found\n");
     122  PRINT(2)("not found\n");
    123123  return NULL;
    124124}
  • orxonox/trunk/src/importer/model.cc

    r3365 r3396  
    3636
    3737/**
    38    \brief Crates a 3D-Model and loads in a File.
    39    \param fileName file to parse and load (must be a .obj file)
    40 */
    41 Model::Model(char* fileName)
    42 {
    43   this->initialize();
    44 
    45   this->importFile (fileName);
    46 
    47   this->importToGL ();
    48 
    49   this->cleanup();
    50 }
    51 
    52 /**
    53    \brief Crates a 3D-Model, loads in a File and scales it.
    54    \param fileName file to parse and load (must be a .obj file)
    55    \param scaling The factor that the model will be scaled with.
    56 */
    57 Model::Model(char* fileName, float scaling)
    58 {
    59   this->initialize();
    60   this->scaleFactor = scaling;
    61 
    62   this->importFile (fileName);
    63 
    64   this->importToGL ();
    65 
    66   this->cleanup();
    67 }
    68 
    69 /**
    7038   \brief deletes an Model.
    7139
     
    7442Model::~Model()
    7543{
     44  PRINTF(0)("Deleting Model ");
     45  if (this->name)
     46    {
     47      PRINT(0)("%s\n");
     48      delete []this->name;
     49    }
     50  else
     51      PRINT(0)("\n");
     52
    7653  PRINTF(2)("Deleting display Lists.\n");
    7754  Group* walker = this->firstGroup;
     
    8461    }
    8562
    86   if (this->objPath)
    87     delete []this->objPath;
    88   if (this->objFileName)
    89     delete []this->objFileName;
    90   if (this->mtlFileName)
    91     delete []this->mtlFileName;
    9263  PRINTF(2)("Deleting Materials.\n");
    9364  if (this->material)
    9465    delete this->material;
    9566}
    96 
    9767
    9868/**
     
    139109      walker = walker->next;
    140110    }
    141   PRINTF(1)("Model number %i in %s not Found.\n", groupNumber, this->objFileName);
     111  PRINTF(1)("Model number %i in %s not Found.\n", groupNumber, this->name);
    142112  return;
    143113
     
    164134      walker = walker->next;
    165135    }
    166   PRINTF(1)("Model Named %s in %s not Found.\n", groupName, this->objFileName);
     136  PRINTF(1)("Model Named %s in %s not Found.\n", groupName, this->name);
    167137  return;
    168138}
     
    186156  PRINTF(2)("new 3D-Model is being created\n");
    187157
     158  this->name = NULL;
    188159  // setting the start group;
    189160  this->firstGroup = new Group;
     
    192163 
    193164  this->initGroup (this->currentGroup);
    194   this->objPath = NULL;
    195   this->objFileName = NULL;
    196   this->mtlFileName = NULL;
    197165  this->scaleFactor = 1;
    198166  this->material = new Material();
     
    317285
    318286/**
    319    \brief Imports a obj file and handles the the relative location
    320    \param fileName The file to import
    321 */
    322 bool Model::importFile (char* fileName)
    323 {
    324   PRINTF(3)("preparing to read in file: %s\n", fileName);
    325 
    326 
    327 #ifdef __WIN32__
    328   // win32 path reading
    329   char pathSplitter= '\\';
    330 #else /* __WIN32__ */
    331   // unix path reading
    332   char pathSplitter='/';
    333 #endif /* __WIN32__ */
    334   char* tmpName = fileName;
    335   if (tmpName[0] == pathSplitter)
    336     tmpName++;
    337   char* name = tmpName;
    338   while (( tmpName = strchr (tmpName+1, pathSplitter)))
    339     {
    340       name = tmpName+1;
    341     }
    342   this->objPath = new char[name-fileName];
    343   strncpy(this->objPath, fileName, name-fileName);
    344   this->objPath[name-fileName] = '\0';
    345   if (verbose >=2)
    346     if (strlen(objPath)> 0)
    347       PRINTF(0)("Resolved file %s to folder: %s.\n", name, objPath);
    348     else
    349       PRINTF(0)("Resolved file %s.\n", name);
    350  
    351   if (this->material)
    352     this->material->addTexturePath(this->objPath);
    353   this->objFileName = new char[strlen(name)+1];
    354   strcpy (this->objFileName, name);
    355   this->readFromObjFile ();
    356   return true;
    357 }
    358 
    359 /**
    360    \brief Reads in the .obj File and sets all the Values.
    361    This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks
    362 */
    363 bool Model::readFromObjFile (void)
    364 {
    365   char* fileName = new char [strlen(objPath)+strlen(objFileName)+1];
    366   if (this->objFileName != NULL && !strcmp(this->objFileName, ""))
    367     return false;
    368   strcpy(fileName, this->objPath);
    369   strcat(fileName, this->objFileName);
    370 
    371   ifstream* OBJ_FILE = new ifstream(fileName);
    372   if (OBJ_FILE->fail())
    373     {
    374       PRINTF(1)("unable to open .OBJ file: %s\n Loading Box Model instead.\n", fileName);
    375       BoxModel();
    376       OBJ_FILE->close();
    377       delete []fileName;
    378       delete OBJ_FILE;
    379       return false;
    380     }
    381   PRINTF(2)("Reading from opened file %s\n", fileName);
    382   char Buffer[10000];
    383   while(!OBJ_FILE->eof())
    384     {
    385       OBJ_FILE->getline(Buffer, 10000);
    386       PRINTF(3)("Read input line: %s\n", Buffer);
    387      
    388 
    389       // case vertice
    390       if (!strncmp(Buffer, "v ", 2))
    391         {
    392           this->readVertex(Buffer+2);
    393         }
    394 
    395       // case face
    396       else if (!strncmp(Buffer, "f ", 2))
    397         {
    398           this->readFace (Buffer+2);
    399         }
    400      
    401       else if (!strncmp(Buffer, "mtllib ", 7))
    402         {
    403           this->readMtlLib (Buffer+7);
    404         }
    405 
    406       else if (!strncmp(Buffer, "usemtl ", 7))
    407         {
    408           this->readUseMtl (Buffer+7);
    409         }
    410 
    411       // case VertexNormal
    412       else if (!strncmp(Buffer, "vn ", 3))
    413         {
    414           this->readVertexNormal(Buffer+3);
    415         }
    416      
    417       // case VertexTextureCoordinate
    418       else if (!strncmp(Buffer, "vt ", 3))
    419         {
    420           this->readVertexTexture(Buffer+3);
    421         }
    422       // case group
    423       else if (!strncmp(Buffer, "g ", 2))
    424         {
    425           this->readGroup (Buffer+2);
    426         }
    427       else if (!strncmp(Buffer, "s ", 2)) //! \todo smoothing groups have to be implemented
    428         {
    429           if (verbose >= 2)
    430             PRINTF(2)("smoothing groups not supportet yet. line: %s\n", Buffer);
    431         }
    432     }
    433   OBJ_FILE->close();
    434   delete OBJ_FILE;
    435   delete []fileName;
    436   return true;
    437 
    438 }
    439 
    440 /**
    441287   \brief parses a group String
    442288   \param groupString the new Group to create
     
    445291   With it you should be able to import .obj-files with more than one Models inside.
    446292*/
    447 bool Model::readGroup (char* groupString)
     293bool Model::addGroup (char* groupString)
    448294{
    449295  PRINTF(3)("Read Group: %s.\n", groupString);
     
    470316   If a vertex line is found this function will inject it into the vertex-Array
    471317*/
    472 bool Model::readVertex (char* vertexString)
     318bool Model::addVertex (char* vertexString)
    473319{
    474320  float subbuffer1;
     
    488334   The function makes a difference between QUADS and TRIANGLES, and will if changed re-open, set and re-close the gl-processe.
    489335*/
    490 bool Model::readFace (char* faceString)
     336bool Model::addFace (char* faceString)
    491337{
    492338  if (this->currentGroup->faceCount >0)
     
    551397   If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    552398*/
    553 bool Model::readVertexNormal (char* normalString)
     399bool Model::addVertexNormal (char* normalString)
    554400{
    555401  float subbuffer1;
     
    569415   this function will inject it into the vertexTexture-Array
    570416*/
    571 bool Model::readVertexTexture (char* vTextureString)
     417bool Model::addVertexTexture (char* vTextureString)
    572418{
    573419  float subbuffer1;
     
    580426}
    581427
    582 /**
    583     \brief Function to read in a mtl File.
    584     \param mtlFile The .mtl file to read
    585 
    586     This Function parses all Lines of an mtl File.
    587     The reason for it not to be in the materials-class is,
    588     that a material does not have to be able to read itself in from a File.
    589 
    590 */
    591 bool Model::readMtlLib (char* mtlFile)
    592 {
    593   this->mtlFileName = new char [strlen(mtlFile)+1];
    594   strcpy(this->mtlFileName, mtlFile);
    595   char* fileName = new char [strlen(objPath) + strlen(this->mtlFileName)+1];
    596   strcpy(fileName, this->objPath);
    597   strcat(fileName, this->mtlFileName);
    598  
    599 
    600   PRINTF(3)("Opening mtlFile: %s\n", fileName);
    601 
    602   ifstream* MTL_FILE = new ifstream (fileName);
    603   if (MTL_FILE->fail())
    604     {
    605       PRINTF(1)("unable to open file: %s\n", fileName);
    606       MTL_FILE->close();
    607       delete []fileName;
    608       delete MTL_FILE;
    609       return false;
    610     }
    611   char Buffer[500];
    612   Material* tmpMat = material;
    613   while(!MTL_FILE->eof())
    614     {
    615       MTL_FILE->getline(Buffer, 500);
    616       PRINTF(4)("found line in mtlFile: %s\n", Buffer);
    617      
    618 
    619       // create new Material
    620       if (!strncmp(Buffer, "newmtl ", 7))
    621         {
    622           tmpMat = tmpMat->addMaterial(Buffer+7);
    623           //      PRINTF(2)("%s, %p\n", tmpMat->getName(), tmpMat);
    624         }
    625       // setting a illumMode
    626       else if (!strncmp(Buffer, "illum ", 6))
    627         {
    628           tmpMat->setIllum(Buffer+6);
    629 
    630         }
    631       // setting Diffuse Color
    632       else if (!strncmp(Buffer, "Kd ", 3))
    633         {
    634           tmpMat->setDiffuse(Buffer+3);
    635         }
    636       // setting Ambient Color
    637       else if (!strncmp(Buffer, "Ka ", 3))
    638         {
    639           tmpMat->setAmbient(Buffer+3);
    640         }
    641       // setting Specular Color
    642       else if (!strncmp(Buffer, "Ks ", 3))
    643         {
    644           tmpMat->setSpecular(Buffer+3);
    645         }
    646       // setting The Specular Shininess
    647       else if (!strncmp(Buffer, "Ns ", 3))
    648         {
    649           tmpMat->setShininess(Buffer+3);
    650         }
    651       // setting up transparency
    652       else if (!strncmp(Buffer, "d ", 2))
    653         {
    654           tmpMat->setTransparency(Buffer+2);
    655         }
    656       else if (!strncmp(Buffer, "Tf ", 3))
    657         {
    658           tmpMat->setTransparency(Buffer+3);
    659         }
    660      
    661       else if (!strncmp(Buffer, "map_Kd ", 7))
    662         {
    663           tmpMat->setDiffuseMap(Buffer+7);
    664         }
    665       else if (!strncmp(Buffer, "map_Ka ", 7))
    666         {
    667           tmpMat->setAmbientMap(Buffer+7);
    668         }
    669       else if (!strncmp(Buffer, "map_Ks ", 7))
    670         {
    671           tmpMat->setSpecularMap(Buffer+7);
    672         }
    673       else if (!strncmp(Buffer, "bump ", 5))
    674         {
    675           tmpMat->setBump(Buffer+7);
    676         }
    677      
    678 
    679     }
    680   MTL_FILE->close();
    681   delete []fileName;
    682   delete MTL_FILE;
    683   return true;
    684 }
    685 
    686428/**
    687429   \brief Function that selects a material, if changed in the obj file.
    688430   \param matString the Material that will be set.
    689431*/
    690 bool Model::readUseMtl (char* matString)
    691 {
     432bool Model::addUseMtl (char* matString)
     433{
     434  /*
    692435  if (!this->mtlFileName)
    693436    {
     
    695438      return false;
    696439    }
    697      
     440  */     
    698441  if (this->currentGroup->faceCount >0)
    699442    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
     
    743486                glEnd();
    744487              this->currentGroup->faceMode = 0;
    745               PRINTF(2)("using material %s for coming Faces.\n", tmpFace->materialString);
    746488              Material* tmpMat;
    747489              if ((tmpMat = material->search(tmpFace->materialString)) != NULL)
    748                 tmpMat->select();
     490                {
     491                  tmpMat->select();
     492                  PRINTF(2)("using material %s for coming Faces.\n", tmpFace->materialString);
     493                }
     494              else
     495                PRINTF(1)("material %s not found.\n", tmpFace->materialString);
     496
    749497
    750498            }
     
    909657void Model::BoxModel(void)
    910658{
    911   this->readVertex ("-0.5 -0.5 0.5");
    912   this->readVertex ("0.5 -0.5 0.5");
    913   this->readVertex ("-0.5 0.5 0.5");
    914   this->readVertex ("0.5 0.5 0.5");
    915   this->readVertex ("-0.5 0.5 -0.5");
    916   this->readVertex ("0.5 0.5 -0.5");
    917   this->readVertex ("-0.5 -0.5 -0.5");
    918   this->readVertex ("0.5 -0.5 -0.5");
    919 
    920   this->readVertexTexture ("0.0 0.0");
    921   this->readVertexTexture ("1.0 0.0");
    922   this->readVertexTexture ("0.0 1.0");
    923   this->readVertexTexture ("1.0 1.0");
    924   this->readVertexTexture ("0.0 2.0");
    925   this->readVertexTexture ("1.0 2.0");
    926   this->readVertexTexture ("0.0 3.0");
    927   this->readVertexTexture ("1.0 3.0");
    928   this->readVertexTexture ("0.0 4.0");
    929   this->readVertexTexture ("1.0 4.0");
    930   this->readVertexTexture ("2.0 0.0");
    931   this->readVertexTexture ("2.0 1.0");
    932   this->readVertexTexture ("-1.0 0.0");
    933   this->readVertexTexture ("-1.0 1.0");
    934 
    935   this->readVertexNormal ("0.0 0.0 1.0");
    936   this->readVertexNormal ("0.0 0.0 1.0");
    937   this->readVertexNormal ("0.0 0.0 1.0");
    938   this->readVertexNormal ("0.0 0.0 1.0");
    939   this->readVertexNormal ("0.0 1.0 0.0");
    940   this->readVertexNormal ("0.0 1.0 0.0");
    941   this->readVertexNormal ("0.0 1.0 0.0");
    942   this->readVertexNormal ("0.0 1.0 0.0");
    943   this->readVertexNormal ("0.0 0.0 -1.0");
    944   this->readVertexNormal ("0.0 0.0 -1.0");
    945   this->readVertexNormal ("0.0 0.0 -1.0");
    946   this->readVertexNormal ("0.0 0.0 -1.0");
    947   this->readVertexNormal ("0.0 -1.0 0.0");
    948   this->readVertexNormal ("0.0 -1.0 0.0");
    949   this->readVertexNormal ("0.0 -1.0 0.0");
    950   this->readVertexNormal ("0.0 -1.0 0.0");
    951   this->readVertexNormal ("1.0 0.0 0.0");
    952   this->readVertexNormal ("1.0 0.0 0.0");
    953   this->readVertexNormal ("1.0 0.0 0.0");
    954   this->readVertexNormal ("1.0 0.0 0.0");
    955   this->readVertexNormal ("-1.0 0.0 0.0");
    956   this->readVertexNormal ("-1.0 0.0 0.0");
    957   this->readVertexNormal ("-1.0 0.0 0.0");
    958   this->readVertexNormal ("-1.0 0.0 0.0");
     659  this->addVertex ("-0.5 -0.5 0.5");
     660  this->addVertex ("0.5 -0.5 0.5");
     661  this->addVertex ("-0.5 0.5 0.5");
     662  this->addVertex ("0.5 0.5 0.5");
     663  this->addVertex ("-0.5 0.5 -0.5");
     664  this->addVertex ("0.5 0.5 -0.5");
     665  this->addVertex ("-0.5 -0.5 -0.5");
     666  this->addVertex ("0.5 -0.5 -0.5");
     667
     668  this->addVertexTexture ("0.0 0.0");
     669  this->addVertexTexture ("1.0 0.0");
     670  this->addVertexTexture ("0.0 1.0");
     671  this->addVertexTexture ("1.0 1.0");
     672  this->addVertexTexture ("0.0 2.0");
     673  this->addVertexTexture ("1.0 2.0");
     674  this->addVertexTexture ("0.0 3.0");
     675  this->addVertexTexture ("1.0 3.0");
     676  this->addVertexTexture ("0.0 4.0");
     677  this->addVertexTexture ("1.0 4.0");
     678  this->addVertexTexture ("2.0 0.0");
     679  this->addVertexTexture ("2.0 1.0");
     680  this->addVertexTexture ("-1.0 0.0");
     681  this->addVertexTexture ("-1.0 1.0");
     682
     683  this->addVertexNormal ("0.0 0.0 1.0");
     684  this->addVertexNormal ("0.0 0.0 1.0");
     685  this->addVertexNormal ("0.0 0.0 1.0");
     686  this->addVertexNormal ("0.0 0.0 1.0");
     687  this->addVertexNormal ("0.0 1.0 0.0");
     688  this->addVertexNormal ("0.0 1.0 0.0");
     689  this->addVertexNormal ("0.0 1.0 0.0");
     690  this->addVertexNormal ("0.0 1.0 0.0");
     691  this->addVertexNormal ("0.0 0.0 -1.0");
     692  this->addVertexNormal ("0.0 0.0 -1.0");
     693  this->addVertexNormal ("0.0 0.0 -1.0");
     694  this->addVertexNormal ("0.0 0.0 -1.0");
     695  this->addVertexNormal ("0.0 -1.0 0.0");
     696  this->addVertexNormal ("0.0 -1.0 0.0");
     697  this->addVertexNormal ("0.0 -1.0 0.0");
     698  this->addVertexNormal ("0.0 -1.0 0.0");
     699  this->addVertexNormal ("1.0 0.0 0.0");
     700  this->addVertexNormal ("1.0 0.0 0.0");
     701  this->addVertexNormal ("1.0 0.0 0.0");
     702  this->addVertexNormal ("1.0 0.0 0.0");
     703  this->addVertexNormal ("-1.0 0.0 0.0");
     704  this->addVertexNormal ("-1.0 0.0 0.0");
     705  this->addVertexNormal ("-1.0 0.0 0.0");
     706  this->addVertexNormal ("-1.0 0.0 0.0");
    959707
    960708  /* normaleLess-testingMode
    961   this->readFace ("1 2 4 3");
    962   this->readFace ("3 4 6 5");
    963   this->readFace ("5 6 8 7");
    964   this->readFace ("7 8 2 1");
    965   this->readFace ("2 8 6 4");
    966   this->readFace ("7 1 3 5");
     709  this->addFace ("1 2 4 3");
     710  this->addFace ("3 4 6 5");
     711  this->addFace ("5 6 8 7");
     712  this->addFace ("7 8 2 1");
     713  this->addFace ("2 8 6 4");
     714  this->addFace ("7 1 3 5");
    967715  */
    968716
    969   this->readFace ("1/1/1 2/2/2 4/4/3 3/3/4");
    970   this->readFace ("3/3/5 4/4/6 6/6/7 5/5/8");
    971   this->readFace ("5/5/9 6/6/10 8/8/11 7/7/12");
    972   this->readFace ("7/7/13 8/8/14 2/10/15 1/9/16");
    973   this->readFace ("2/2/17 8/11/18 6/12/19 4/4/20");
    974   this->readFace ("7/13/21 1/1/22 3/3/23 5/14/24");
    975 
    976 }
     717  this->addFace ("1/1/1 2/2/2 4/4/3 3/3/4");
     718  this->addFace ("3/3/5 4/4/6 6/6/7 5/5/8");
     719  this->addFace ("5/5/9 6/6/10 8/8/11 7/7/12");
     720  this->addFace ("7/7/13 8/8/14 2/10/15 1/9/16");
     721  this->addFace ("2/2/17 8/11/18 6/12/19 4/4/20");
     722  this->addFace ("7/13/21 1/1/22 3/3/23 5/14/24");
     723
     724}
  • orxonox/trunk/src/importer/model.h

    r3395 r3396  
    2121{
    2222 public:
    23   Model ();
    24   Model (char* fileName);
    25   Model(char* fileName, float scaling);
    26   ~Model ();
     23  Model(void);
     24  virtual ~Model(void);
    2725 
    28   void draw (void) const;
    29   void draw (int groupNumber) const;
    30   void draw (char* groupName) const;
     26  void draw(void) const;
     27  void draw(int groupNumber) const;
     28  void draw(char* groupName) const;
    3129  int getGroupCount() const;
    3230
    33  private:
     31 protected:
     32  char* name;            //!< This is the name of the Model;
    3433  //! This is the placeholder of one Vertex beloning to a Face.
    35   struct FaceElement 
     34  struct FaceElement
    3635  {
    3736    int vertexNumber;    //!< The number of the Vertex out of the Array* vertices, this vertex points to.
     
    8786  float scaleFactor;    //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation
    8887
    89   char* objPath;        //!< The Path where the obj and mtl-file are located.
    90   char* objFileName;    //!< The Name of the obj-file.
    91   char* mtlFileName;    //!< The Name of the mtl-file (parsed out of the obj-file)
    92 
    9388  bool initialize (void);
    9489  bool initGroup(Group* group);
     
    9994  bool cleanupFaceElement(FaceElement* faceElem);
    10095
    101   ///// readin ///
    102   bool importFile (char* fileName);
    103   bool readFromObjFile (void);
    104  
    105   bool readGroup (char* groupString);
    106   bool readVertex (char* vertexString);
    107   bool readFace (char* faceString);
    108   bool readVertexNormal (char* normalString);
    109   bool readVertexTexture (char* vTextureString);
    110   bool readMtlLib (char* matFile);
    111   bool readUseMtl (char* mtlString);
     96  bool addGroup (char* groupString);
     97  bool addVertex (char* vertexString);
     98  bool addFace (char* faceString);
     99  bool addVertexNormal (char* normalString);
     100  bool addVertexTexture (char* vTextureString);
     101  bool addUseMtl (char* mtlString);
    112102
    113103  bool importToGL (void);
  • orxonox/trunk/src/player.cc

    r3380 r3396  
    1919#include "stdincl.h"
    2020#include "collision.h"
    21 #include "importer/model.h"
     21#include "importer/objModel.h"
    2222
    2323using namespace std;
     
    2727{
    2828
    29   this->model = new Model("../data/models/reaplow.obj");
     29  this->model = new OBJModel("../data/models/reaplow.obj");
    3030  /*
    3131  objectList = glGenLists(1);
  • orxonox/trunk/src/player.h

    r3365 r3396  
    99#include "world_entity.h"
    1010
    11 class Model;
     11class OBJModel;
    1212
    1313//! Basic controllable WorldEntity
  • orxonox/trunk/src/world_entity.h

    r3365 r3396  
    1111
    1212class CollisionCluster;
    13 class Model;
     13class OBJModel;
    1414
    1515//! Basic class from which all interactive stuff in the world is derived from
     
    2222  virtual ~WorldEntity ();
    2323
    24   Model* model;
     24  OBJModel* model;
    2525 
    2626  void setCollision (CollisionCluster* newhull);
Note: See TracChangeset for help on using the changeset viewer.