Index: orxonox/trunk/importer/Makefile.in
===================================================================
--- orxonox/trunk/importer/Makefile.in	(revision 3027)
+++ orxonox/trunk/importer/Makefile.in	(revision 3063)
@@ -429,5 +429,5 @@
 
 
-#  uncomment the following if bencoder requires the math library
+#  uncomment the following if orxonox requires the math library
 #orxonox_LDADD=-lm
 
Index: orxonox/trunk/importer/object.cc
===================================================================
--- orxonox/trunk/importer/object.cc	(revision 3027)
+++ orxonox/trunk/importer/object.cc	(revision 3063)
@@ -70,5 +70,5 @@
       glDeleteLists (walker->listNumber, 1);
       Group* lastWalker = walker;
-      walker = walker->nextGroup;
+      walker = walker->next;
       delete lastWalker;
     } 
@@ -94,8 +94,7 @@
   material = new Material();
 
-  //  glEnableClientState (GL_VERTEX_ARRAY);
-  //  glEnableClientState (GL_NORMAL_ARRAY);
-  //  glEnableClientState (GL_TEXTURE_COORD_ARRAY);
-
+  vertices = new Array();
+  vTexture = new Array();
+  normals = new Array();
 
   return true;
@@ -117,5 +116,5 @@
 /**
   \brief finalizes an Object.
-   This funcion is needed, to close the glList and all the other lists.
+   This funcion is needed, to close the glList and all the other lists. This will be applied at the end of the importing Process.
 */
 bool Object::finalize(void)
@@ -124,4 +123,14 @@
     printf("finalizing the 3D-Object\n"); 
   finalizeGroup (currentGroup);
+
+  importToGL ();
+
+  if (vertices != NULL)
+    delete vertices;
+  if (vTexture != NULL)
+    delete vTexture;
+  if (normals != NULL)
+    delete normals;
+
   if (material != NULL)
     delete material;
@@ -133,5 +142,5 @@
    It does this by just calling the Lists that must have been created earlier.
 */
-void Object::draw (void)
+void Object::draw (void) const
 {
   if (verbose >=2)
@@ -143,5 +152,5 @@
 	printf ("Drawing object %s\n", walker->name);
       glCallList (walker->listNumber);
-      walker = walker->nextGroup;
+      walker = walker->next;
     }
 }
@@ -152,9 +161,9 @@
    \param groupNumber The number of the group that will be displayed.
 */
-void Object::draw (int groupNumber)
+void Object::draw (int groupNumber) const 
 {
   if (groupNumber >= groupCount)
     {
-      if (verbose>=2)
+      if (verbose>=1)
 	printf ("You requested object number %i, but this File only contains of %i Objects.\n", groupNumber-1, groupCount);
       return;
@@ -169,12 +178,12 @@
 	{
 	  if (verbose >= 2)
-	    printf ("Drawing object number %s named %s\n", counter, walker->name);
+	    printf ("Drawing object number %i named %s\n", counter, walker->name);
 	  glCallList (walker->listNumber);
 	  return;
 	}
       ++counter;
-      walker = walker->nextGroup;
-    }
-  if (verbose >= 2)
+      walker = walker->next;
+    }
+  if (verbose >= 1)
     printf("Object number %i in %s not Found.\n", groupNumber, objFileName);
   return;
@@ -183,9 +192,9 @@
 
 /**
-   \brief Draws the Object with a specific groupname
+   \brief Draws the Object with a specific groupName
    It does this by just calling the List that must have been created earlier.
    \param groupName The name of the group that will be displayed.
 */
-void Object::draw (char* groupName)
+void Object::draw (char* groupName) const
 {
   if (verbose >=2)
@@ -201,5 +210,5 @@
 	  return;
 	}
-      walker = walker->nextGroup;
+      walker = walker->next;
     }
   if (verbose >= 2)
@@ -211,5 +220,5 @@
    \returns Count of the Objects in this File
 */
-int Object::getGroupCount (void)
+int Object::getGroupCount (void) const
 {
   return groupCount;
@@ -226,30 +235,8 @@
   group->faceMode = -1;
   group->faceCount = 0;  
-  group->nextGroup = NULL;
-  if ((group->listNumber = glGenLists(1)) == 0 )
-    {
-      printf ("list could not be created for this Object\n");
-      return false;
-    }
-  
-  if (groupCount == 0)
-    {
-      group->firstVertex = 0;
-      group->firstNormal = 0;
-      group->firstVertexTexture = 0;
-    }
-  else
-    {
-      group->firstVertex = currentGroup->firstVertex + currentGroup->vertices->getCount()/3;
-      group->firstNormal = currentGroup->firstNormal + currentGroup->normals->getCount()/3;
-      group->firstVertexTexture = currentGroup->firstVertexTexture + currentGroup->vTexture->getCount()/2;
-    }
-  if (verbose >=2)
-    printf ("Creating new Arrays, with starting points v:%i, vt:%i, vn:%i .\n", group->firstVertex, group->firstVertexTexture, group->firstNormal);
-  group->vertices = new Array();
-  group->normals = new Array();
-  group->vTexture = new Array();
-
-  glNewList (group->listNumber, GL_COMPILE);
+  group->next = NULL;
+
+  group->firstFace = new Face;
+  group->currentFace = group->firstFace;
 }
 
@@ -258,24 +245,9 @@
    \param group the group to finalize.
 */
-bool Object::finalizeGroup(Group* group)
+bool Object::finalizeGroup(Group* group) // think it is not needed anymore
 {
   if (verbose >=2)
     printf ("Finalize group %s.\n", group->name);
-  glEnd();
-  glEndList();
-}
-
-/**
-   \brief deletes the Arrays of the Group to save space.
-   \param group the group to delete the arrays from.
-*/
-bool Object::cleanupGroup(Group* group)
-{
-  if (verbose >=2)
-    printf ("cleaning up group %s.\n", group->name);
-  
-  delete group->vertices;
-  delete group->normals;
-  delete group->vTexture;
+
 }
 
@@ -316,10 +288,10 @@
 	}
       
-      else if (!strncmp(Buffer, "mtllib", 6))
+      else if (!strncmp(Buffer, "mtllib ", 7))
 	{
 	  readMtlLib (Buffer+7);
 	}
 
-      else if (!strncmp(Buffer, "usemtl", 6))
+      else if (!strncmp(Buffer, "usemtl ", 7))
 	{
 	  readUseMtl (Buffer+7);
@@ -327,5 +299,5 @@
 
       // case VertexNormal
-      else if (!strncmp(Buffer, "vn ", 2))
+      else if (!strncmp(Buffer, "vn ", 3))
       {
 	readVertexNormal(Buffer+3);
@@ -333,17 +305,17 @@
 
       // case VertexTextureCoordinate
-      else if (!strncmp(Buffer, "vt ", 2))
+      else if (!strncmp(Buffer, "vt ", 3))
       {
 	readVertexTexture(Buffer+3);
       }
       // case group
-      else if (!strncmp(Buffer, "g", 1))
+      else if (!strncmp(Buffer, "g ", 2))
 	{
 	  readGroup (Buffer+2);
 	}
-      else if (!strncmp(Buffer, "s", 1))
+      else if (!strncmp(Buffer, "s ", 2))
 	{
 	  if (verbose >= 1)
-	    printf("smoothing groups not suportet yet. line: %s\n", Buffer);
+	    printf("smoothing groups not supportet yet. line: %s\n", Buffer);
 	}
     }
@@ -360,5 +332,4 @@
 bool Object::readVertex (char* vertexString)
 {
-  readingVertices = true;
   char subbuffer1[20];
   char subbuffer2[20];
@@ -367,5 +338,5 @@
   if (verbose >= 3)
     printf ("reading in a vertex: %s %s %s\n", subbuffer1, subbuffer2, subbuffer3);
-  currentGroup->vertices->addEntry(atof(subbuffer1)*scaleFactor, atof(subbuffer2)*scaleFactor, atof(subbuffer3)*scaleFactor);
+  vertices->addEntry(atof(subbuffer1)*scaleFactor, atof(subbuffer2)*scaleFactor, atof(subbuffer3)*scaleFactor);
   return true;
 }
@@ -379,88 +350,29 @@
 bool Object::readFace (char* faceString)
 {
-  // finalize the Arrays;
-  if (readingVertices == true)
-    {
-      currentGroup->vertices->finalizeArray();
-      //      glVertexPointer(3, GL_FLOAT, 0, currentGroup->vertices->getArray());
-      currentGroup->normals->finalizeArray();
-      //      glNormalPointer(GL_FLOAT, 0, currentGroup->normals->getArray());
-      currentGroup->vTexture->finalizeArray();
-    }
-
-  readingVertices = false;
-  currentGroup->faceCount++;
-
-  int elemCount = 0;
-  
-  FaceElement* firstElem = new FaceElement;
-  FaceElement* tmpElem = firstElem;
-
-  
+  if (currentGroup->faceCount >0)
+    currentGroup->currentFace = currentGroup->currentFace->next = new Face;
+  initFace (currentGroup->currentFace);
+
+  FaceElement* tmpElem = currentGroup->currentFace->firstElem = new FaceElement;
+
   while(strcmp (faceString, "\0"))
     {
-      if (elemCount>0)
+      if (currentGroup->currentFace->vertexCount>0)
 	  tmpElem = tmpElem->next = new FaceElement;
       tmpElem->next = NULL;
 
-
-      sscanf (faceString, "%s", tmpElem->value);
+      char* tmpValue = new char [50];
+      sscanf (faceString, "%s", tmpValue);
+      tmpElem->value = new char [strlen(tmpValue)];
+      strcpy (tmpElem->value, tmpValue);
+
+      delete tmpValue; ////// DANGEROUS could be wrong to do this (useless) /////
       faceString += strlen(tmpElem->value);
       if (strcmp (faceString, "\0"))
 	faceString++;
-      elemCount++;
-
-
-    }
-  
-  
-  if (elemCount == 3)
-    {
-      if (currentGroup->faceMode != 3)
-	{
-	  if (currentGroup->faceMode != -1)
-	    glEnd();
-	  glBegin(GL_TRIANGLES);
-	}
-      
-      currentGroup->faceMode = 3;
-      if (verbose >=3)
-	printf ("found triag.\n");
-    }
-  
-  else if (elemCount == 4)
-    {
-      if (currentGroup->faceMode != 4)
-	{
-	  if (currentGroup->faceMode != -1)
-	    glEnd();
-	  glBegin(GL_QUADS);
-	}
-      currentGroup->faceMode = 4;
-      if (verbose >=3 )
-	printf ("found quad.\n");
-    }
-  
-  else if (elemCount > 4)
-    {
-      if (currentGroup->faceMode != -1)
-	glEnd();
-      glBegin(GL_POLYGON);
-      if (verbose >=3)
-	printf ("Polygon with %i faces found.", elemCount);
-      currentGroup->faceMode = elemCount;
-    }
-
-  tmpElem = firstElem;
-  FaceElement* delElem;
-  while (tmpElem != NULL)
-    {
-      //      printf ("%s\n", tmpElem->value);
-      addGLElement(tmpElem->value);
-      delElem = tmpElem;
-      tmpElem = tmpElem->next;
-      delete delElem;
-    }
-
+      currentGroup->currentFace->vertexCount++;
+    }
+
+  currentGroup->faceCount++;
 }
 
@@ -485,7 +397,5 @@
       texture[0] = '\0';
       texture ++;
-      if (verbose>=3)
-	printf ("includeing texture #%i, and mapping it to group texture #%i, textureArray has %i entries.\n", atoi(texture), (atoi(texture)-1 - currentGroup->firstVertexTexture)*2, currentGroup->vTexture->getCount());
-      glTexCoord2fv(currentGroup->vTexture->getArray()+(atoi(texture)-1 - currentGroup->firstVertexTexture)*2);
+      glTexCoord2fv(vTexture->getArray()+(atoi(texture)-1)*2);
 
       char* normal;
@@ -495,10 +405,8 @@
 	  normal ++;
 	  //glArrayElement(atoi(vertex)-1);
-	  glNormal3fv(currentGroup->normals->getArray() +(atoi(normal)-1 - currentGroup->firstNormal)*3);
-	}
-    }
-  if (verbose>=3)
-    printf ("includeing vertex #%i, and mapping it to group vertex #%i, vertexArray has %i entries.\n", atoi(vertex), (atoi(vertex)-1 - currentGroup->firstVertex)*3, currentGroup->vertices->getCount());
-  glVertex3fv(currentGroup->vertices->getArray() +(atoi(vertex)-1 - currentGroup->firstVertex)*3);
+	  glNormal3fv(normals->getArray() +(atoi(normal)-1)*3);
+	}
+    }
+  glVertex3fv(vertices->getArray() +(atoi(vertex)-1)*3);
 
 }
@@ -511,5 +419,4 @@
 bool Object::readVertexNormal (char* normalString)
 {
-  readingVertices = true;
   char subbuffer1[20];
   char subbuffer2[20];
@@ -518,5 +425,5 @@
   if (verbose >=3 )
     printf("found vertex-Normal %s, %s, %s\n", subbuffer1,subbuffer2,subbuffer3);
-  currentGroup->normals->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));
+  normals->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));
   return true;
 }
@@ -529,5 +436,4 @@
 bool Object::readVertexTexture (char* vTextureString)
 {
-  readingVertices = true;
   char subbuffer1[20];
   char subbuffer2[20];
@@ -535,6 +441,6 @@
   if (verbose >=3 )
     printf("found vertex-Texture %s, %s\n", subbuffer1,subbuffer2);
-  currentGroup->vTexture->addEntry(atof(subbuffer1));
-  currentGroup->vTexture->addEntry(atof(subbuffer2));
+  vTexture->addEntry(atof(subbuffer1));
+  vTexture->addEntry(atof(subbuffer2));
   return true;
 }
@@ -558,7 +464,6 @@
       Group* newGroup = new Group;
       finalizeGroup(currentGroup);
-      currentGroup->nextGroup = newGroup;
+      currentGroup->next = newGroup;
       initGroup(newGroup);
-      cleanupGroup(currentGroup); // deletes the arrays of the group; must be after initGroup.
       currentGroup = newGroup; // must be after init see initGroup for more info
     }
@@ -566,4 +471,98 @@
   ++groupCount;
 
+}
+
+
+bool Object::initFace (Face* face)
+{
+  face->vertexCount = 0;
+
+  face->firstElem = NULL;
+  
+  face->material = NULL;
+  
+  face->next = NULL;
+
+  return true;
+}
+
+bool Object::importToGL (void)
+{
+
+  // finalize the Arrays
+  vertices->finalizeArray();
+  vTexture->finalizeArray();
+  normals->finalizeArray();
+
+  currentGroup = firstGroup;
+
+  while (currentGroup != NULL)
+    {
+
+      // creating a glList for the Group
+      if ((currentGroup->listNumber = glGenLists(1)) == 0)
+	{
+	  printf ("list could not be created for this Object\n");
+	  return false;
+	}
+      glNewList (currentGroup->listNumber, GL_COMPILE);
+
+      // Putting Faces to GL
+      Face* tmpFace = currentGroup->firstFace;
+      while (tmpFace != NULL)
+	{
+	  if (tmpFace->vertexCount == 3)
+	    {
+	      if (currentGroup->faceMode != 3)
+		{
+		  if (currentGroup->faceMode != -1)
+		    glEnd();
+		  glBegin(GL_TRIANGLES);
+		}
+	      
+	      currentGroup->faceMode = 3;
+	      if (verbose >=3)
+		printf ("found triag.\n");
+	    }
+	  
+	  else if (tmpFace->vertexCount == 4)
+	    {
+	      if (currentGroup->faceMode != 4)
+		{
+		  if (currentGroup->faceMode != -1)
+		    glEnd();
+		  glBegin(GL_QUADS);
+		}
+	      currentGroup->faceMode = 4;
+	      if (verbose >=3 )
+		printf ("found quad.\n");
+	    }
+	  
+	  else if (tmpFace->vertexCount > 4)
+	    {
+	      if (currentGroup->faceMode != -1)
+		glEnd();
+	      glBegin(GL_POLYGON);
+	      if (verbose >=3)
+		printf ("Polygon with %i faces found.", tmpFace->vertexCount);
+	      currentGroup->faceMode = tmpFace->vertexCount;
+	    }
+	  
+	  FaceElement* tmpElem = tmpFace->firstElem;
+	  FaceElement* delElem;
+	  while (tmpElem != NULL)
+	    {
+	      //      printf ("%s\n", tmpElem->value);
+	      addGLElement(tmpElem->value);
+	      delElem = tmpElem;
+	      tmpElem = tmpElem->next;
+	      delete delElem;
+	    }
+	  tmpFace = tmpFace->next;
+	}
+      glEnd();
+      glEndList();
+      currentGroup = currentGroup->next;
+    } 
 }
 
@@ -595,5 +594,5 @@
 
       // create new Material
-      if (!strncmp(Buffer, "newmtl ", 2))
+      if (!strncmp(Buffer, "newmtl ", 7))
 	{
 	  tmpMat = tmpMat->addMaterial(Buffer+7);
@@ -601,5 +600,5 @@
 	}
       // setting a illumMode
-      else if (!strncmp(Buffer, "illum", 5))
+      else if (!strncmp(Buffer, "illum ", 6))
 	{
 	  tmpMat->setIllum(Buffer+6);
@@ -607,29 +606,29 @@
 	}
       // setting Diffuse Color
-      else if (!strncmp(Buffer, "Kd", 2))
+      else if (!strncmp(Buffer, "Kd ", 3))
 	{
 	  tmpMat->setDiffuse(Buffer+3);
 	}
       // setting Ambient Color
-      else if (!strncmp(Buffer, "Ka", 2))
+      else if (!strncmp(Buffer, "Ka ", 3))
 	{
 	  tmpMat->setAmbient(Buffer+3);
 	}
       // setting Specular Color
-      else if (!strncmp(Buffer, "Ks", 2))
+      else if (!strncmp(Buffer, "Ks ", 3))
 	{
 	  tmpMat->setSpecular(Buffer+3);
 	}
       // setting The Specular Shininess
-      else if (!strncmp(Buffer, "Ns", 2))
+      else if (!strncmp(Buffer, "Ns ", 3))
 	{
 	  tmpMat->setShininess(Buffer+3);
 	}
       // setting up transparency
-      else if (!strncmp(Buffer, "d", 1))
+      else if (!strncmp(Buffer, "d ", 2))
 	{
 	  tmpMat->setTransparency(Buffer+2);
 	}
-      else if (!strncpy(Buffer, "Tf", 2))
+      else if (!strncpy(Buffer, "Tf ", 3))
 	{
 	  tmpMat->setTransparency(Buffer+3);
Index: orxonox/trunk/importer/object.h
===================================================================
--- orxonox/trunk/importer/object.h	(revision 3027)
+++ orxonox/trunk/importer/object.h	(revision 3063)
@@ -16,12 +16,7 @@
 using namespace std;
 
-extern int verbose; //!< fill be removed and added again as a verbose-class
+extern int verbose; //!< Will be removed and added again as a verbose-class.
 
 
-struct FaceElement
-{
-  char value[20];
-  FaceElement* next;
-};
 
 //! Class that handles 3D-Objects. it can also read them in and display them.
@@ -37,10 +32,28 @@
   bool initialize (void);
   bool finalize(void);
-  void draw (void);
-  void draw (int groupNumber);
-  void draw (char* groupName);
-  int getGroupCount();
+  void draw (void) const;
+  void draw (int groupNumber) const;
+  void draw (char* groupName) const;
+  int getGroupCount() const;
 
  private:
+  struct FaceElement
+  {
+    char* value;
+    FaceElement* next;
+  };
+
+  //! Face
+  struct Face
+  {
+    int vertexCount;
+
+    FaceElement* firstElem;
+
+    char* material;
+
+    Face* next;
+  };
+
   //! Group to handle multiple Objects per obj-file
   struct Group
@@ -49,24 +62,23 @@
 
     GLuint listNumber;
-    Array* vertices;
-    int verticesCount;
-    Array* colors;
-    Array* normals;
-    Array* vTexture;
+    Face* firstFace;
+    Face* currentFace;
     int faceMode;
     int faceCount;
 
-    int firstVertex;
-    int firstNormal;
-    int firstVertexTexture;
+    Group* next;
+  };
 
-    Group* nextGroup;
-  };
+
+  Array* vertices;
+  int verticesCount;
+  Array* colors;
+  Array* normals;
+  Array* vTexture;
+
   
   Group* firstGroup; //!< the first of all groups.
   Group* currentGroup; //!< the currentGroup. this is the one we will work with.
   int groupCount;
-
-  bool readingVertices;
 
   char* objFileName;
@@ -76,4 +88,5 @@
   float scaleFactor;
 
+  char* objPath;
   ifstream* OBJ_FILE;
   ifstream* MTL_FILE;
@@ -81,5 +94,4 @@
   bool initGroup(Group* group);
   bool finalizeGroup (Group* group);
-  bool cleanupGroup(Group* group);
 
 
@@ -96,4 +108,6 @@
   bool readUseMtl (char* mtlString);
 
+  bool initFace (Face* face);
+  bool importToGL (void);
   bool addGLElement (char* elementString);
 
