Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4111 in orxonox.OLD


Ignore:
Timestamp:
May 7, 2005, 5:22:44 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the Trunk/importer back here.
merged with command:
svn merge -r 3918:HEAD ../../trunk/src/lib/graphics/importer/ src/lib/graphics/importer/

this fixed the issue with the segfault. It really was an error in the Model-class
@nico:

  1. sorry
  2. thanks for pointing this out to me
Location:
orxonox/branches/heightMap/src/lib/graphics/importer
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/heightMap/src/lib/graphics/importer/Makefile.in

    r4090 r4111  
    115115EXEEXT = @EXEEXT@
    116116GPROF = @GPROF@
    117 GTHREAD_CFLAGS = @GTHREAD_CFLAGS@
    118 GTHREAD_LIBS = @GTHREAD_LIBS@
    119117GTK2_CFLAGS = @GTK2_CFLAGS@
    120118GTK2_LIBS = @GTK2_LIBS@
    121119HAVE_CURL_FALSE = @HAVE_CURL_FALSE@
    122120HAVE_CURL_TRUE = @HAVE_CURL_TRUE@
    123 HAVE_GTHREAD_FALSE = @HAVE_GTHREAD_FALSE@
    124 HAVE_GTHREAD_TRUE = @HAVE_GTHREAD_TRUE@
    125121HAVE_GTK2_FALSE = @HAVE_GTK2_FALSE@
    126122HAVE_GTK2_TRUE = @HAVE_GTK2_TRUE@
     
    143139PACKAGE_VERSION = @PACKAGE_VERSION@
    144140PATH_SEPARATOR = @PATH_SEPARATOR@
     141RANLIB = @RANLIB@
    145142SET_MAKE = @SET_MAKE@
    146143SHELL = @SHELL@
     
    151148ac_ct_CC = @ac_ct_CC@
    152149ac_ct_CXX = @ac_ct_CXX@
     150ac_ct_RANLIB = @ac_ct_RANLIB@
    153151ac_ct_STRIP = @ac_ct_STRIP@
    154152am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
  • orxonox/branches/heightMap/src/lib/graphics/importer/array.cc

    r3590 r4111  
    112112 
    113113/**
    114    \brief Gives back the array !! MUST be executed AFTER finalize.
    115    \returns The created array.
    116 */
    117 GLfloat* Array::getArray ()
    118 {
    119   return this->array;
    120 }
    121 
    122 /**
    123    \returns The Count of entries in the Array
    124 */
    125 int Array::getCount()
    126 {
    127   return this->entryCount;
    128 }
    129 
    130 /**
    131114   \brief Simple debug info about the Array
    132115*/
    133 void Array::debug ()
     116void Array::debug (void) const
    134117{
    135118  PRINT(0)("entryCount=%i, address=%p\n", this->entryCount, this->array);
  • orxonox/branches/heightMap/src/lib/graphics/importer/array.h

    r3590 r4111  
    2323  void addEntry(GLfloat entry0, GLfloat entry1, GLfloat entry2);
    2424 
    25   GLfloat* getArray ();
    26   int getCount();
    27   void debug(void);
     25  /** \returns The array */
     26  inline const GLfloat* getArray () const {return this->array;}
     27  /**   \returns The Count of entries in the Array*/
     28  inline int getCount(void)const {return this->entryCount;}
     29  void debug(void) const ;
    2830 private:
    2931  //! One entry of the Array
  • orxonox/branches/heightMap/src/lib/graphics/importer/material.cc

    r3914 r4111  
    8888 
    8989  // setting the transparency
    90   if (this->transparency == 1.0)
    91     {
    92       glDisable(GL_BLEND);
    93     }
    94   else
     90  if (this->transparency < 1.0)
    9591    {
    9692      glEnable(GL_BLEND);
     
    9894      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    9995    }
     96  else
     97    {
     98      glDisable(GL_BLEND);
     99      glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
     100    }
     101
    100102
    101103  // setting illumination Model
     
    109111      glEnable(GL_TEXTURE_2D);
    110112      glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
     113
     114      /* This allows alpha blending of 2D textures with the scene */
     115      if (this->diffuseTexture->hasAlpha())
     116        {
     117          glEnable(GL_BLEND);
     118          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     119        }
    111120    }
    112121  else
  • orxonox/branches/heightMap/src/lib/graphics/importer/model.cc

    r3917 r4111  
    2727using namespace std;
    2828
    29 //////////////////
    30 // DE-CONSTRUCT //
    31 //////////////////
    32 /**
    33    \brief Creates a 3D-Model. and assigns it a Name.
     29
     30////////////////////
     31/// SUB-Elements ///
     32////////////////////
     33/**
     34   \brief creates a new ModelFaceElement
     35*/
     36ModelFaceElement::ModelFaceElement()
     37{
     38  this->vertexNumber = -1;
     39  this->normalNumber = -1;
     40  this->texCoordNumber = -1;   
     41
     42  this->next = NULL;
     43}
     44
     45/**
     46   \brief destroys a ModelFaceElement
     47*/
     48ModelFaceElement::~ModelFaceElement()
     49{
     50  if (this->next)
     51    delete this->next;
     52}
     53
     54/**
     55   \brief creates a new ModelFace
     56*/
     57ModelFace::ModelFace()
     58{
     59  this->vertexCount = 0;
     60
     61  this->firstElem = NULL;
     62 
     63  this->material = NULL;
     64 
     65  this->next = NULL;
     66
     67}
     68
     69/**
     70   \brief deletes a ModelFace
     71*/
     72ModelFace::~ModelFace()
     73{
     74  PRINTF(5)("Cleaning up Face\n");
     75
     76  if (this->firstElem != NULL)
     77    delete this->firstElem;
     78 
     79  if (this->next != NULL)
     80    delete this->next;
     81}
     82
     83/**
     84   \brief Creates a new ModelGroup
     85*/
     86ModelGroup::ModelGroup()
     87{
     88  PRINTF(4)("Adding new Group\n");
     89  this->name = "";
     90  this->faceMode = -1;
     91  this->faceCount = 0; 
     92  this->next = NULL;
     93 
     94  this->firstFace = new ModelFace;
     95  this->currentFace = this->firstFace;
     96}
     97
     98/**
     99   \brief deletes a ModelGroup
     100*/
     101ModelGroup::~ModelGroup()
     102{
     103  PRINTF(5)("Cleaning up group\n");
     104  if (this->firstFace != NULL)
     105    delete this->firstFace;
     106
     107  if (this->next !=NULL)
     108    delete this->next;
     109}
     110
     111/**
     112   \brief cleans up a ModelGroup
     113
     114   actually does the same as the delete Operator, but does not delete the predecessing group
     115*/
     116void ModelGroup::cleanup(void)
     117{
     118  PRINTF(5)("Cleaning up group\n");
     119  if (this->firstFace)
     120    delete this->firstFace;
     121  this->firstFace = NULL;
     122  if (this->next)
     123    this->next->cleanup();
     124}
     125
     126
     127/////////////
     128/// MODEL ///
     129/////////////
     130/**
     131   \brief Creates a 3D-Model.
     132
     133   assigns it a Name and a Type
    34134*/
    35135Model::Model(const char* modelName, MODEL_TYPE type)
     
    42142  this->finalized = false;
    43143  // setting the start group;
    44   this->firstGroup = new Group;
    45   this->currentGroup = this->firstGroup;
     144  this->currentGroup = this->firstGroup = new ModelGroup;
    46145  this->groupCount = 0;
    47  
    48   this->initGroup (this->currentGroup);
     146  this->vertexCount = 0;
     147  this->normalCount = 0;
     148  this->texCoordCount = 0;
     149 
    49150  this->scaleFactor = 1;
    50151
     
    76177
    77178  PRINTF(5)("Deleting display Lists.\n");
    78   Group* walker = this->firstGroup;
    79   while (walker != NULL)
    80     {
    81       glDeleteLists (walker->listNumber, 1);
    82       Group* delWalker = walker;
    83       walker = walker->next;
    84       delete delWalker;
    85     }
     179  delete this->firstGroup;
    86180
    87181  // deleting Arrays
     
    92186  tIterator<Material>* tmpIt = this->materialList->getIterator();
    93187  Material* material = tmpIt->nextElement();
     188
     189  //! \todo do we really have to delete this material??
    94190  while(material)
    95191    {
     
    128224{
    129225  PRINTF(4)("drawing the 3D-Models\n");
    130   Group* walker = this->firstGroup;
    131   while (walker != NULL)
    132     {
    133       PRINTF(5)("Drawing model %s\n", walker->name);
    134       glCallList (walker->listNumber);
    135       walker = walker->next;
     226  ModelGroup* tmpGroup = this->firstGroup;
     227  while (tmpGroup != NULL)
     228    {
     229      PRINTF(5)("Drawing model %s\n", tmpGroup->name);
     230      glCallList (tmpGroup->listNumber);
     231      tmpGroup = tmpGroup->next;
    136232    }
    137233}
     
    151247    }
    152248  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    153   Group* walker = this->firstGroup;
     249  ModelGroup* tmpGroup = this->firstGroup;
    154250  int counter = 0;
    155   while (walker != NULL)
     251  while (tmpGroup != NULL)
    156252    {
    157253      if (counter == groupNumber)
    158254        {
    159           PRINTF(4)("Drawing model number %i named %s\n", counter, walker->name);
    160           glCallList (walker->listNumber);
     255          PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name);
     256          glCallList (tmpGroup->listNumber);
    161257          return;
    162258        }
    163259      ++counter;
    164       walker = walker->next;
     260      tmpGroup = tmpGroup->next;
    165261    }
    166262  PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->name);
     
    178274{
    179275  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    180   Group* walker = this->firstGroup;
    181   while (walker != NULL)
    182     {
    183       if (!strcmp(walker->name, groupName))
     276  ModelGroup* tmpGroup = this->firstGroup;
     277  while (tmpGroup != NULL)
     278    {
     279      if (!strcmp(tmpGroup->name, groupName))
    184280        {
    185           PRINTF(4)("Drawing model %s\n", walker->name);
    186           glCallList (walker->listNumber);
     281          PRINTF(4)("Drawing model %s\n", tmpGroup->name);
     282          glCallList (tmpGroup->listNumber);
    187283          return;
    188284        }
    189       walker = walker->next;
     285      tmpGroup = tmpGroup->next;
    190286    }
    191287  PRINTF(2)("Model Named %s in %s not Found.\n", groupName, this->name);
    192288  return;
    193 }
    194 
    195 /**
    196    \returns Count of the Models in this File
    197 */
    198 int Model::getGroupCount (void) const
    199 {
    200   return this->groupCount;
    201289}
    202290
     
    210298void Model::setName(const char* name)
    211299{
    212   if (this->name) 
    213     delete this->name;
     300  if (this->name)
     301    delete []this->name;
    214302  if (name)
    215303    {
     
    219307  else
    220308    this->name = NULL;
    221 }
    222 
    223 /**
    224    \brief initializes a new Group model
    225    \param group the group that should be initialized.
    226    \todo Maybe Group should be a Class, because it does a lot of stuff
    227    
    228 */
    229 bool Model::initGroup(Group* group)
    230 {
    231   PRINTF(4)("Adding new Group\n");
    232   group->name = "";
    233   group->faceMode = -1;
    234   group->faceCount = 0; 
    235   group->next = NULL;
    236 
    237   group->firstFace = new Face;
    238   this->initFace (group->firstFace);
    239   group->currentFace = group->firstFace;
    240 }
    241 
    242 /**
    243    \brief initializes a new Face. (sets default Values)
    244    \param face The face to initialize
    245 */
    246 bool Model::initFace (Face* face)
    247 {
    248   face->vertexCount = 0;
    249 
    250   face->firstElem = NULL;
    251  
    252   face->material = NULL;
    253  
    254   face->next = NULL;
    255 
    256   return true;
    257309}
    258310
     
    268320  if (this->normals)
    269321    delete this->normals;
     322
    270323  this->vertices = NULL;
    271324  this->vTexture = NULL;
     
    280333{
    281334  PRINTF(4)("cleaning up the 3D-Model to save Memory.\n");
    282   this->cleanupGroup(this->firstGroup);
     335  this->firstGroup->cleanup();
    283336  return true;
    284337}
    285338
    286 /**
    287    \brief Cleans up all groups starting from group.
    288    \param group the first Group to clean
    289 */
    290 bool Model::cleanupGroup (Group* group)
    291 {
    292   PRINTF(5)("Cleaning up group\n");
    293   if (group->firstFace != NULL)
    294     {
    295       cleanupFace (group->firstFace);
    296       delete group->firstFace;
    297     }
    298 
    299   if (group->next !=NULL)
    300     cleanupGroup (group->next);
    301   return true;
    302 }
    303 
    304 /**
    305    \brief Cleans up all Faces starting from face until NULL is reached.
    306    \param face the first face to clean.
    307 */
    308 bool Model::cleanupFace (Face* face)
    309 {
    310   PRINTF(5)("Cleaning up Face\n");
    311 
    312   if (face->firstElem != NULL)
    313     {
    314       this->cleanupFaceElement(face->firstElem);
    315       delete face->firstElem;
    316     }
    317      
    318   if (face->next != NULL)
    319     {
    320       this->cleanupFace (face->next);
    321       delete face->next;
    322     }
    323 }
    324 
    325 /**
    326    \brief Cleans up all FaceElements starting from faceElem.
    327    \param faceElem the first FaceElement to clean.
    328 */
    329 bool Model::cleanupFaceElement(FaceElement* faceElem)
    330 {
    331   if (faceElem->next != NULL)
    332     {
    333       this->cleanupFaceElement (faceElem->next);
    334       delete faceElem->next;
    335     }
    336 }
     339
    337340
    338341//////////
     
    354357/**
    355358   \brief adds a new Material to the Material List
    356    \param material the name of the Material to add
     359   \param materialName the name of the Material to add
    357360   \returns the added material
    358361*/
    359362Material* Model::addMaterial(const char* materialName)
    360363{
    361  
    362364  Material* newMat = new Material();
    363365  newMat->setName(materialName);
     
    395397
    396398   This function initializes a new Group.
    397    With it you should be able to import .obj-files with more than one Models inside.
    398 */
    399 bool Model::addGroup (const char* groupString)
     399   With it you should be able to create Models with more than one SubModel inside
     400*/
     401bool Model::addGroup(const char* groupString)
    400402{
    401403  PRINTF(5)("Read Group: %s.\n", groupString);
    402   if (this->groupCount != 0 && this->currentGroup->faceCount>0)
     404  if (this->groupCount != 0 && this->currentGroup->faceCount > 0)
    403405    {
    404406      //      finalizeGroup(currentGroup);
    405       this->currentGroup = this->currentGroup->next = new Group;
    406       this->initGroup(this->currentGroup);
     407      this->currentGroup = this->currentGroup->next = new ModelGroup;
    407408    }
    408409  // setting the group name if not default.
     
    429430  PRINTF(5)("reading in a vertex: %f %f %f\n", &subbuffer1, &subbuffer2, &subbuffer3);
    430431  this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor);
     432  this->vertexCount++;
    431433  return true;
    432434}
     
    443445  PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z);
    444446  this->vertices->addEntry(x*scaleFactor, y*scaleFactor, z*scaleFactor);
     447  this->vertexCount++;
    445448  return true;
    446449}
     
    460463  PRINTF(5)("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3);
    461464  this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3);
     465  this->normalCount++;
    462466  return true;
    463467}
     
    475479  PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z);
    476480  this->normals->addEntry(x, y, z);
     481  this->normalCount++;
     482  return true;
    477483}
    478484
     
    492498  this->vTexture->addEntry(subbuffer1);
    493499  this->vTexture->addEntry(subbuffer2);
     500  this->texCoordCount++;
    494501  return true;
    495502}
     
    507514  this->vTexture->addEntry(u);
    508515  this->vTexture->addEntry(v);
     516  this->texCoordCount++;
     517  return true;
    509518}
    510519
     
    518527{
    519528  if (this->currentGroup->faceCount >0)
    520     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
    521   this->initFace (this->currentGroup->currentFace);
    522 
    523   FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement;
     529    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
     530
     531  ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;
    524532  tmpElem->next = NULL;
    525533  while(strcmp (faceString, "\0"))
    526534    {
    527535      if (this->currentGroup->currentFace->vertexCount>0)
    528           tmpElem = tmpElem->next = new FaceElement;
     536          tmpElem = tmpElem->next = new ModelFaceElement;
    529537      tmpElem->next = NULL;
    530538
     
    552560      if (vertex)
    553561        tmpElem->vertexNumber = atoi(vertex)-1;
    554       else
    555         tmpElem->vertexNumber = -1;
    556562      if (texture)
    557563        tmpElem->texCoordNumber = atoi(texture)-1;
    558       else
    559         tmpElem->texCoordNumber = -1;
    560564      if (normal)
    561565        tmpElem->normalNumber = atoi(normal)-1;
    562       else
    563         tmpElem->normalNumber = -1;
    564566
    565567      faceString += tmpLen;
     
    579581bool Model::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
    580582{
    581    if (this->currentGroup->faceCount > 0)
    582     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
    583   this->initFace (this->currentGroup->currentFace);
    584 
    585   FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement;
    586   tmpElem->next = NULL;
     583  if (this->currentGroup->faceCount > 0)
     584    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
     585 
     586  ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;
    587587 
    588588  va_list itemlist;
     
    591591  for (int i = 0; i < faceElemCount; i++)
    592592    {
    593       if (this->currentGroup->currentFace->vertexCount>0)
    594           tmpElem = tmpElem->next = new FaceElement;
    595       tmpElem->next = NULL;
     593      if (this->currentGroup->currentFace->vertexCount > 0)
     594        tmpElem = tmpElem->next = new ModelFaceElement;
    596595
    597596      tmpElem->vertexNumber = va_arg (itemlist, int) -1;
     
    614613{
    615614  if (this->currentGroup->faceCount > 0)
    616     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
    617   this->initFace (this->currentGroup->currentFace);
     615    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
    618616 
    619617  this->currentGroup->currentFace->material = this->findMaterialByName(matString);
     
    630628{
    631629  if (this->currentGroup->faceCount > 0)
    632     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
    633   this->initFace (this->currentGroup->currentFace);
     630    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
    634631 
    635632  this->currentGroup->currentFace->material = mtl;
     
    662659  Vector curV;
    663660
    664   Group* tmpGroup = firstGroup;
     661  ModelGroup* tmpGroup = firstGroup;
    665662  while (tmpGroup)
    666663    {
    667       Face* tmpFace = tmpGroup->firstFace;
     664      ModelFace* tmpFace = tmpGroup->firstFace;
    668665      while (tmpFace)
    669666        {
    670667          if (tmpFace->firstElem)
    671668            {
    672               FaceElement* firstElem = tmpFace->firstElem;
    673               FaceElement* prevElem;
    674               FaceElement* curElem = firstElem;
    675               FaceElement* nextElem;
    676               FaceElement* lastElem;
     669              ModelFaceElement* firstElem = tmpFace->firstElem;
     670              ModelFaceElement* prevElem;
     671              ModelFaceElement* curElem = firstElem;
     672              ModelFaceElement* nextElem;
     673              ModelFaceElement* lastElem;
    677674              // 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.
    678675              while (curElem)
     
    704701    }
    705702
    706   for (int i=0; i<vertices->getCount()/3;i++)
     703  for (int i=0; i < vertices->getCount()/3;i++)
    707704    {
    708705      normArray[i].normalize();
    709706      PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
    710707     
    711       this->normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z);
     708      this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z);
    712709
    713710    }
     
    744741
    745742      // Putting Faces to GL
    746       Face* tmpFace = this->currentGroup->firstFace;
     743      ModelFace* tmpFace = this->currentGroup->firstFace;
    747744      while (tmpFace != NULL)
    748745        {
     
    794791            }
    795792         
    796           FaceElement* tmpElem = tmpFace->firstElem;
     793          ModelFaceElement* tmpElem = tmpFace->firstElem;
    797794          while (tmpElem != NULL)
    798795            {
     
    826823  glNormalPointer(3, 0, this->normals->getArray());
    827824  glTexCoordPointer(2, GL_FLOAT, 0, this->vTexture->getArray());
    828 
    829825}
    830826
     
    841837   merging this information, the face will be drawn.
    842838*/
    843 bool Model::addGLElement (FaceElement* elem)
     839bool Model::addGLElement (ModelFaceElement* elem)
    844840{
    845841  PRINTF(5)("importing grafical Element to openGL.\n");
    846842
    847843  if (elem->texCoordNumber != -1)
    848     glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2);
     844    {
     845      if (likely(elem->texCoordNumber < this->texCoordCount))
     846        glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2);
     847      else
     848        PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",
     849                  elem->texCoordNumber, this->texCoordCount);
     850    }
    849851  if (elem->normalNumber != -1)
    850     glNormal3fv(this->normals->getArray() + elem->normalNumber * 3);
     852    {
     853    if (likely(elem->normalNumber < this->normalCount))
     854      glNormal3fv(this->normals->getArray() + elem->normalNumber * 3);
     855    else
     856        PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",
     857                  elem->normalNumber, this->normalCount);     
     858    }
    851859  if (elem->vertexNumber != -1)
    852     glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
     860    {
     861      if (likely(elem->vertexNumber < this->vertexCount))
     862          glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
     863      else
     864        PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",
     865                  elem->vertexNumber, this->vertexCount);     
     866    }   
    853867
    854868}
  • orxonox/branches/heightMap/src/lib/graphics/importer/model.h

    r3917 r4111  
    3434                    VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD};
    3535
     36////////////////////
     37/// SUB-ELEMENTS ///
     38////////////////////
     39//! This is the placeholder of one Vertex beloning to a Face.
     40class ModelFaceElement
     41{
     42 public:
     43  ModelFaceElement();
     44  ~ModelFaceElement();
     45
     46  int vertexNumber;         //!< The number of the Vertex out of the Array* vertices, this vertex points to.
     47  int normalNumber;         //!< The number of the Normal out of the Array* normals, this vertex points to.
     48  int texCoordNumber;       //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
     49  ModelFaceElement* next;   //!< Point to the next FaceElement in this List.
     50};
     51
     52//! This is the placeholder of a Face belonging to a Group of Faces.
     53class ModelFace
     54{
     55 public:
     56  ModelFace();
     57  ~ModelFace();
     58
     59  int vertexCount;                //!< The Count of vertices this Face has.
     60  ModelFaceElement* firstElem;    //!< Points to the first Vertex (FaceElement) of this Face.
     61 
     62  Material* material;             //!< The Material to use.
     63 
     64  ModelFace* next;                //!< Pointer to the next Face.
     65};
     66
     67//! Group to handle multiple Models per obj-file.
     68class ModelGroup
     69{
     70 public:
     71  ModelGroup();
     72  ~ModelGroup();
     73
     74  void cleanup();
     75
     76  char* name;                 //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
     77 
     78  GLubyte* indices;           //!< The indices of the Groups. Needed for vertex-arrays
     79  GLuint listNumber;          //!< The number of the GL-List this Group gets.
     80  ModelFace* firstFace;       //!< The first Face in this group.
     81  ModelFace* currentFace;     //!< The current Face in this Group (the one we are currently working with.)
     82  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...
     83  int faceCount;              //!< The Number of Faces this Group holds.
     84 
     85  ModelGroup* next;           //!< Pointer to the next Group.
     86};
     87
     88/////////////
     89/// MODEL ///
     90/////////////
     91
    3692//! Class that handles 3D-Models. it can also read them in and display them.
    3793class Model
    3894{
    3995 private:
    40   /////////////
    41   // structs //
    42   /////////////
    43   //! This is the placeholder of one Vertex beloning to a Face.
    44   struct FaceElement
    45   {
    46     int vertexNumber;    //!< The number of the Vertex out of the Array* vertices, this vertex points to.
    47     int normalNumber;    //!< The number of the Normal out of the Array* normals, this vertex points to.
    48     int texCoordNumber;  //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
    49     FaceElement* next;   //!< Point to the next FaceElement in this List.
    50   };
    5196
    52   //! This is the placeholder of a Face belonging to a Group of Faces.
    53   struct Face
    54   {
    55     int vertexCount;        //!< The Count of vertices this Face has.
    56     FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face.
     97  char* name;                 //!< This is the name of the Model.
     98  MODEL_TYPE type;            //!< A type for the Model
     99  bool finalized;             //!< Sets the Object to be finalized.
    57100
    58     Material* material;     //!< The Material to use.
     101  int vertexCount;            //!< A modelwide Counter for vertices.
     102  int normalCount;            //!< A modelwide Counter for the normals.
     103  int texCoordCount;          //!< A modelwide Counter for the texCoord.
     104  Array* vertices;            //!< The Array that handles the Vertices.
     105  Array* normals;             //!< The Array that handles the Normals.
     106  Array* vTexture;            //!< The Array that handles the VertexTextureCoordinates.
    59107
    60     Face* next;             //!< Pointer to the next Face.
    61   };
     108  ModelGroup* firstGroup;     //!< The first of all groups.
     109  ModelGroup* currentGroup;   //!< The currentGroup. this is the one we will work with.
     110  int groupCount;             //!< The Count of Groups.
    62111
    63   //! Group to handle multiple Models per obj-file.
    64   struct Group
    65   {
    66     char* name;         //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
    67 
    68     GLubyte* indices;   //!< The indices of the Groups. Needed for vertex-arrays
    69     GLuint listNumber;  //!< The number of the GL-List this Group gets.
    70     Face* firstFace;    //!< The first Face in this group.
    71     Face* currentFace;  //!< The current Face in this Group (the one we are currently working with.)
    72     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...
    73     int faceCount;      //!< The Number of Faces this Group holds.
    74 
    75     Group* next;        //!< Pointer to the next Group.
    76   };
    77 
    78   char* name;            //!< This is the name of the Model.
    79   MODEL_TYPE type;
    80   bool finalized;        //!< Sets the Object to be finalized.
    81 
    82   Array* vertices;      //!< The Array that handles the Vertices.
    83   int verticesCount;    //!< A global Counter for vertices.
    84   Array* normals;       //!< The Array that handles the Normals.
    85   Array* vTexture;      //!< The Array that handles the VertexTextureCoordinates.
    86 
    87   Group* firstGroup;    //!< The first of all groups.
    88   Group* currentGroup;  //!< The currentGroup. this is the one we will work with.
    89   int groupCount;       //!< The Count of Groups.
    90 
    91   tList<Material>* materialList;
     112  tList<Material>* materialList;//!< A list for all the Materials in this Model
    92113 
    93 
    94   bool initGroup(Group* group);
    95   bool initFace (Face* face);
    96 
    97114  bool buildVertexNormals(void);
    98115
    99116  bool importToDisplayList(void);
    100   bool addGLElement(FaceElement* elem);
     117  bool addGLElement(ModelFaceElement* elem);
    101118
    102119  bool importToVertexArray(void);
     
    104121  bool deleteArrays(void);
    105122  bool cleanup(void);
    106   bool cleanupGroup(Group* group);
    107   bool cleanupFace(Face* face);
    108   bool cleanupFaceElement(FaceElement* faceElem);
    109123
    110124
     
    121135
    122136  void setName(const char* name);
     137  /** \returns the Name of the Model */
    123138  inline const char* getName() {return this->name;}
    124139 
     
    126141  void draw(int groupNumber) const;
    127142  void draw(char* groupName) const;
    128   int getGroupCount() const;
     143
     144  /** \returns Count of the Models (Groups) in this File */
     145  inline int getGroupCount(void) const {return this->groupCount;}
    129146
    130147  Material* addMaterial(Material* material);
     
    143160  bool setMaterial(Material* mtl);
    144161  void finalize(void);
     162
     163  /** \returns The number of Vertices of the Model */
     164  inline int getVertexCount(void) const {return this->vertexCount;}
     165  /** \returns The number of Normals of the Model */
     166  inline int getNormalCount(void) const {return this->normalCount;}
     167  /** \returns The number of Texture Coordinates of the Model*/
     168  inline int getTexCoordCount(void) const {return this->texCoordCount;}
    145169};
    146170
  • orxonox/branches/heightMap/src/lib/graphics/importer/objModel.cc

    r3916 r4111  
    196196  this->mtlFileName = new char [strlen(mtlFile)+1];
    197197  strcpy(this->mtlFileName, mtlFile);
    198   char* fileName = new char [strlen(objPath) + strlen(this->mtlFileName)+1];
    199   strcpy(fileName, this->objPath);
    200   strcat(fileName, this->mtlFileName);
     198  char* fileName = new char [strlen(this->objPath) + strlen(this->mtlFileName)+1];
     199  sprintf(fileName, "%s%s", this->objPath, this->mtlFileName);
    201200 
    202201
  • orxonox/branches/heightMap/src/lib/graphics/importer/texture.cc

    r3905 r4111  
    2525Texture::Texture(const char* imageName)
    2626{
     27  bAlpha = false;
    2728  this->texture = 0;
    2829  if (imageName)
     
    112113      if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
    113114        SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);
     115        this->bAlpha = true;
    114116      }
    115117     
     
    119121      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    120122      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    121       /*      glTexImage2D(GL_TEXTURE_2D,
     123      // build the Texture
     124      glTexImage2D(GL_TEXTURE_2D,
    122125                   0,
    123126                   GL_RGBA,
     
    127130                   GL_UNSIGNED_BYTE,
    128131                   image->pixels);
    129       */
     132      // build the MipMaps
    130133      gluBuild2DMipmaps(GL_TEXTURE_2D,
    131                         3,
     134                        GL_RGBA,
    132135                        w,
    133136                        h,
     
    135138                        GL_UNSIGNED_BYTE,
    136139                        image->pixels);
    137 
     140     
    138141      SDL_FreeSurface(image); /* No longer needed */
    139142     
  • orxonox/branches/heightMap/src/lib/graphics/importer/texture.h

    r3905 r4111  
    2323  char* searchTextureInPaths(const char* texName) const;
    2424  void swap(unsigned char &a, unsigned char &b);
     25
     26  bool bAlpha;           //!< if the texture has an alpha channel.
    2527 public:
    2628  Texture(const char* imageName = NULL);
     
    3032  inline GLuint getTexture(void) {return this->texture;}
    3133  GLuint loadTexToGL (SDL_Surface* surface);
     34  inline bool hasAlpha(void) {return bAlpha;}
    3235
    3336  bool loadImage(const char* imageName);
Note: See TracChangeset for help on using the changeset viewer.