Index: orxonox/trunk/importer/object.cc
===================================================================
--- orxonox/trunk/importer/object.cc	(revision 3065)
+++ orxonox/trunk/importer/object.cc	(revision 3066)
@@ -29,5 +29,5 @@
   importToGL ();
 
-  finalize();
+  cleanup();
 }
 
@@ -44,5 +44,5 @@
   importToGL ();
 
-  finalize();
+  cleanup();
 }
 
@@ -61,5 +61,5 @@
   importToGL ();
 
-  finalize();
+  cleanup();
 }
 
@@ -70,16 +70,104 @@
 {
   if (verbose >= 2)
-    printf ("Deleting display List.\n");
+    printf ("Deleting display Lists.\n");
   Group* walker = firstGroup;
   while (walker != NULL)
     {
       glDeleteLists (walker->listNumber, 1);
-      Group* lastWalker = walker;
+      Group* delWalker = walker;
       walker = walker->next;
-      delete lastWalker;
+      delete delWalker;
     } 
 }
 
-/** 
+
+/**
+   \brief Draws the Objects of all Groups.
+   It does this by just calling the Lists that must have been created earlier.
+*/
+void Object::draw (void) const
+{
+  if (verbose >=2)
+    printf("drawing the 3D-Objects\n"); 
+  Group* walker = firstGroup;
+  while (walker != NULL)
+    {
+      if (verbose >= 3)
+	printf ("Drawing object %s\n", walker->name);
+      glCallList (walker->listNumber);
+      walker = walker->next;
+    }
+}
+
+/**
+   \brief Draws the Object number groupNumber
+   It does this by just calling the List that must have been created earlier.
+   \param groupNumber The number of the group that will be displayed.
+*/
+void Object::draw (int groupNumber) const 
+{
+  if (groupNumber >= groupCount)
+    {
+      if (verbose>=1)
+	printf ("You requested object number %i, but this File only contains of %i Objects.\n", groupNumber-1, groupCount);
+      return;
+    }
+  if (verbose >=2)
+    printf("drawing the requested 3D-Objects if found.\n"); 
+  Group* walker = firstGroup;
+  int counter = 0;
+  while (walker != NULL)
+    {
+      if (counter == groupNumber)
+	{
+	  if (verbose >= 2)
+	    printf ("Drawing object number %i named %s\n", counter, walker->name);
+	  glCallList (walker->listNumber);
+	  return;
+	}
+      ++counter;
+      walker = walker->next;
+    }
+  if (verbose >= 1)
+    printf("Object number %i in %s not Found.\n", groupNumber, objFileName);
+  return;
+
+}
+
+/**
+   \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) const
+{
+  if (verbose >=2)
+    printf("drawing the requested 3D-Objects if found.\n"); 
+  Group* walker = firstGroup;
+  while (walker != NULL)
+    {
+      if (!strcmp(walker->name, groupName))
+	{
+	  if (verbose >= 2)
+	    printf ("Drawing object %s\n", walker->name);
+	  glCallList (walker->listNumber);
+	  return;
+	}
+      walker = walker->next;
+    }
+  if (verbose >= 2)
+    printf("Object Named %s in %s not Found.\n", groupName, objFileName);
+  return;
+}
+
+/**
+   \returns Count of the Objects in this File
+*/
+int Object::getGroupCount (void) const
+{
+  return groupCount;
+}
+
+/**
     \brief initializes the Object
     This Function initializes all the needed arrays, Lists and clientStates
@@ -108,25 +196,43 @@
 
 /**
-   \brief Imports a obj file and handles the the relative location
-   \param fileName The file to import
-*/
-bool Object::importFile (char* fileName)
-{
-  if (verbose >=3)
-    printf("preparing to read in file: %s\n", fileName);   
-  objFileName = fileName;
-  this->readFromObjFile (objFileName);
+   \brief initializes a new Group object
+*/
+bool Object::initGroup(Group* group)
+{
+  if (verbose >= 2)
+    printf("Adding new Group\n");
+  group->name = "";
+  group->faceMode = -1;
+  group->faceCount = 0;  
+  group->next = NULL;
+
+  group->firstFace = new Face;
+  group->currentFace = group->firstFace;
+}
+
+/**
+   \brief initializes a new Face. (sets default Values)
+*/
+bool Object::initFace (Face* face)
+{
+  face->vertexCount = 0;
+
+  face->firstElem = NULL;
+  
+  face->materialString = NULL;
+  
+  face->next = NULL;
+
   return true;
 }
 
 /**
-  \brief finalizes an Object.
-   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)
+   \brief finalizes an Object.
+   This funcion is needed, to delete all the Lists, and arrays that are no more needed because they are already imported into openGL. This will be applied at the end of the importing Process.
+*/
+bool Object::cleanup(void)
 {
   //  if (verbose >=3)
     printf("finalizing the 3D-Object\n"); 
-  finalizeGroup (currentGroup);
 
   if (vertices != NULL)
@@ -143,115 +249,14 @@
 
 /**
-   \brief Draws the Objects of all Groups.
-   It does this by just calling the Lists that must have been created earlier.
-*/
-void Object::draw (void) const
-{
-  if (verbose >=2)
-    printf("drawing the 3D-Objects\n"); 
-  Group* walker = firstGroup;
-  while (walker != NULL)
-    {
-      if (verbose >= 3)
-	printf ("Drawing object %s\n", walker->name);
-      glCallList (walker->listNumber);
-      walker = walker->next;
-    }
-}
-
-/**
-   \brief Draws the Object number groupNumber
-   It does this by just calling the List that must have been created earlier.
-   \param groupNumber The number of the group that will be displayed.
-*/
-void Object::draw (int groupNumber) const 
-{
-  if (groupNumber >= groupCount)
-    {
-      if (verbose>=1)
-	printf ("You requested object number %i, but this File only contains of %i Objects.\n", groupNumber-1, groupCount);
-      return;
-    }
-  if (verbose >=2)
-    printf("drawing the requested 3D-Objects if found.\n"); 
-  Group* walker = firstGroup;
-  int counter = 0;
-  while (walker != NULL)
-    {
-      if (counter == groupNumber)
-	{
-	  if (verbose >= 2)
-	    printf ("Drawing object number %i named %s\n", counter, walker->name);
-	  glCallList (walker->listNumber);
-	  return;
-	}
-      ++counter;
-      walker = walker->next;
-    }
-  if (verbose >= 1)
-    printf("Object number %i in %s not Found.\n", groupNumber, objFileName);
-  return;
-
-}
-
-/**
-   \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) const
-{
-  if (verbose >=2)
-    printf("drawing the requested 3D-Objects if found.\n"); 
-  Group* walker = firstGroup;
-  while (walker != NULL)
-    {
-      if (!strcmp(walker->name, groupName))
-	{
-	  if (verbose >= 2)
-	    printf ("Drawing object %s\n", walker->name);
-	  glCallList (walker->listNumber);
-	  return;
-	}
-      walker = walker->next;
-    }
-  if (verbose >= 2)
-    printf("Object Named %s in %s not Found.\n", groupName, objFileName);
-  return;
-}
-
-/**
-   \returns Count of the Objects in this File
-*/
-int Object::getGroupCount (void) const
-{
-  return groupCount;
-}
-
-/**
-   \brief initializes a new Group object
-*/
-bool Object::initGroup(Group* group)
-{
-  if (verbose >= 2)
-    printf("Adding new Group\n");
-  group->name = "";
-  group->faceMode = -1;
-  group->faceCount = 0;  
-  group->next = NULL;
-
-  group->firstFace = new Face;
-  group->currentFace = group->firstFace;
-}
-
-/**
-   \brief finalizes a Group.
-   \param group the group to finalize.
-*/
-bool Object::finalizeGroup(Group* group) // think it is not needed anymore
-{
-  //  if (verbose >=2)
-  //    printf ("Finalize group %s.\n", group->name);
-
+   \brief Imports a obj file and handles the the relative location
+   \param fileName The file to import
+*/
+bool Object::importFile (char* fileName)
+{
+  if (verbose >=3)
+    printf("preparing to read in file: %s\n", fileName);   
+  objFileName = fileName;
+  this->readFromObjFile (objFileName);
+  return true;
 }
 
@@ -326,4 +331,31 @@
   OBJ_FILE->close();
   return true;
+
+}
+
+/**
+   \brief parses a group String
+   This function initializes a new Group. 
+   With it you should be able to import .obj-files with more than one Objects inside. 
+   \param groupString the new Group to create
+*/
+bool Object::readGroup (char* groupString)
+{
+  // setting the group name if not default.
+  if (strcmp(currentGroup->name, "default"))
+    {
+      currentGroup->name = new char [strlen(groupString)];
+      strcpy(currentGroup->name, groupString);
+    }
+  if (groupCount != 0 && currentGroup->faceCount>0)
+    {
+      Group* newGroup = new Group;
+      //      finalizeGroup(currentGroup);
+      currentGroup->next = newGroup;
+      initGroup(newGroup);
+      currentGroup = newGroup; // must be after init see initGroup for more info
+    }
+
+  ++groupCount;
 
 }
@@ -381,39 +413,4 @@
 
 /**
-   \brief Adds a Face-element (one vertex of a face) with all its information. 
-   It does this by searching:
-   1. The Vertex itself
-   2. The VertexNormale
-   3. The VertexTextureCoordinate
-   merging this information, the face will be drawn.
-
-*/
-bool Object::addGLElement (char* elementString)
-{
-  if (verbose >=3)
-    printf ("importing grafical Element to openGL: %s\n", elementString);
-  char* vertex = elementString;
-
-  char* texture;
-  if ((texture = strstr (vertex, "/")) != NULL)
-    {
-      texture[0] = '\0';
-      texture ++;
-      glTexCoord2fv(vTexture->getArray()+(atoi(texture)-1)*2);
-
-      char* normal;
-      if ((normal = strstr (texture, "/")) !=NULL)
-	{
-	  normal[0] = '\0';
-	  normal ++;
-	  //glArrayElement(atoi(vertex)-1);
-	  glNormal3fv(normals->getArray() +(atoi(normal)-1)*3);
-	}
-    }
-  glVertex3fv(vertices->getArray() +(atoi(vertex)-1)*3);
-
-}
-
-/**
    \brief parses a vertexNormal-String
    If a vertexNormal line is found this function will inject it into the vertexNormal-Array
@@ -449,45 +446,104 @@
 }
 
-/**
-   \brief parses a group String
-   This function initializes a new Group. 
-   With it you should be able to import .obj-files with more than one Objects inside. 
-   \param groupString the new Group to create
-*/
-bool Object::readGroup (char* groupString)
-{
-  // setting the group name if not default.
-  if (strcmp(currentGroup->name, "default"))
-    {
-      currentGroup->name = new char [strlen(groupString)];
-      strcpy(currentGroup->name, groupString);
-    }
-  if (groupCount != 0 && currentGroup->faceCount>0)
-    {
-      Group* newGroup = new Group;
-      //      finalizeGroup(currentGroup);
-      currentGroup->next = newGroup;
-      initGroup(newGroup);
-      currentGroup = newGroup; // must be after init see initGroup for more info
-    }
-
-  ++groupCount;
-
-}
-
-
-bool Object::initFace (Face* face)
-{
-  face->vertexCount = 0;
-
-  face->firstElem = NULL;
+/** 
+    \brief Function to read in a mtl File.
+    this Function parses all Lines of an mtl File
+    \param mtlFile The .mtl file to read
+*/
+bool Object::readMtlLib (char* mtlFile)
+{
+  MTL_FILE = new ifstream (mtlFile);
+  if (!MTL_FILE->is_open())
+    {
+      if (verbose >= 1)
+	printf ("unable to open file: %s\n", mtlFile);
+      return false;
+    }
+  mtlFileName = mtlFile;
+  if (verbose >=2)
+    printf ("Opening mtlFile: %s\n", mtlFileName);
+  char Buffer[500];
+  Material* tmpMat = material;
+  while(!MTL_FILE->eof())
+    {
+      MTL_FILE->getline(Buffer, 500);
+      if (verbose >= 4)
+	printf("found line in mtlFile: %s\n", Buffer);
+      
+
+      // create new Material
+      if (!strncmp(Buffer, "newmtl ", 7))
+	{
+	  tmpMat = tmpMat->addMaterial(Buffer+7);
+	  //	  printf ("%s, %p\n", tmpMat->getName(), tmpMat);
+	}
+      // setting a illumMode
+      else if (!strncmp(Buffer, "illum ", 6))
+	{
+	  tmpMat->setIllum(Buffer+6);
+
+	}
+      // setting Diffuse Color
+      else if (!strncmp(Buffer, "Kd ", 3))
+	{
+	  tmpMat->setDiffuse(Buffer+3);
+	}
+      // setting Ambient Color
+      else if (!strncmp(Buffer, "Ka ", 3))
+	{
+	  tmpMat->setAmbient(Buffer+3);
+	}
+      // setting Specular Color
+      else if (!strncmp(Buffer, "Ks ", 3))
+	{
+	  tmpMat->setSpecular(Buffer+3);
+	}
+      // setting The Specular Shininess
+      else if (!strncmp(Buffer, "Ns ", 3))
+	{
+	  tmpMat->setShininess(Buffer+3);
+	}
+      // setting up transparency
+      else if (!strncmp(Buffer, "d ", 2))
+	{
+	  tmpMat->setTransparency(Buffer+2);
+	}
+      else if (!strncpy(Buffer, "Tf ", 3))
+	{
+	  tmpMat->setTransparency(Buffer+3);
+	}
+
+    }
+  return true;
+}
+
+/**
+   \brief Function that selects a material, if changed in the obj file.
+   \param matString the Material that will be set.
+*/
+bool Object::readUseMtl (char* matString)
+{
+  if (!strcmp (mtlFileName, ""))
+    {
+      if (verbose >= 1)
+	printf ("Not using new defined material, because no mtlFile found yet\n");
+      return false;
+    }
+      
+  if (currentGroup->faceCount >0)
+    currentGroup->currentFace = currentGroup->currentFace->next = new Face;
+  initFace (currentGroup->currentFace);
   
-  face->materialString = NULL;
+  currentGroup->currentFace->materialString = new char[strlen(matString)];
+  strcpy (currentGroup->currentFace->materialString, matString);
   
-  face->next = NULL;
-
-  return true;
-}
-
+  if (currentGroup->faceCount == 0)
+    currentGroup->faceCount ++;
+
+}
+
+/**
+   \brief reads and includes the Faces/Materials into the openGL state Machine
+*/
 bool Object::importToGL (void)
 {
@@ -564,12 +620,9 @@
 	  
 	  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;
@@ -581,100 +634,39 @@
 }
 
-/** 
-    \brief Function to read in a mtl File.
-    this Function parses all Lines of an mtl File
-    \param mtlFile The .mtl file to read
-*/
-bool Object::readMtlLib (char* mtlFile)
-{
-  MTL_FILE = new ifstream (mtlFile);
-  if (!MTL_FILE->is_open())
-    {
-      if (verbose >= 1)
-	printf ("unable to open file: %s\n", mtlFile);
-      return false;
-    }
-  mtlFileName = mtlFile;
-  if (verbose >=2)
-    printf ("Opening mtlFile: %s\n", mtlFileName);
-  char Buffer[500];
-  Material* tmpMat = material;
-  while(!MTL_FILE->eof())
-    {
-      MTL_FILE->getline(Buffer, 500);
-      if (verbose >= 4)
-	printf("found line in mtlFile: %s\n", Buffer);
-      
-
-      // create new Material
-      if (!strncmp(Buffer, "newmtl ", 7))
-	{
-	  tmpMat = tmpMat->addMaterial(Buffer+7);
-	  //	  printf ("%s, %p\n", tmpMat->getName(), tmpMat);
-	}
-      // setting a illumMode
-      else if (!strncmp(Buffer, "illum ", 6))
-	{
-	  tmpMat->setIllum(Buffer+6);
-
-	}
-      // setting Diffuse Color
-      else if (!strncmp(Buffer, "Kd ", 3))
-	{
-	  tmpMat->setDiffuse(Buffer+3);
-	}
-      // setting Ambient Color
-      else if (!strncmp(Buffer, "Ka ", 3))
-	{
-	  tmpMat->setAmbient(Buffer+3);
-	}
-      // setting Specular Color
-      else if (!strncmp(Buffer, "Ks ", 3))
-	{
-	  tmpMat->setSpecular(Buffer+3);
-	}
-      // setting The Specular Shininess
-      else if (!strncmp(Buffer, "Ns ", 3))
-	{
-	  tmpMat->setShininess(Buffer+3);
-	}
-      // setting up transparency
-      else if (!strncmp(Buffer, "d ", 2))
-	{
-	  tmpMat->setTransparency(Buffer+2);
-	}
-      else if (!strncpy(Buffer, "Tf ", 3))
-	{
-	  tmpMat->setTransparency(Buffer+3);
-	}
-
-    }
-  return true;
-}
-
-/**
-   \brief Function that selects a material, if changed in the obj file.
-   \param matString the Material that will be set.
-*/
-bool Object::readUseMtl (char* matString)
-{
-  if (!strcmp (mtlFileName, ""))
-    {
-      if (verbose >= 1)
-	printf ("Not using new defined material, because no mtlFile found yet\n");
-      return false;
-    }
-      
-  if (currentGroup->faceCount >0)
-    currentGroup->currentFace = currentGroup->currentFace->next = new Face;
-  initFace (currentGroup->currentFace);
-  
-  currentGroup->currentFace->materialString = new char[strlen(matString)];
-  strcpy (currentGroup->currentFace->materialString, matString);
-  
-  if (currentGroup->faceCount == 0)
-    currentGroup->faceCount ++;
-
-}
+/**
+   \brief Adds a Face-element (one vertex of a face) with all its information. 
+   It does this by searching:
+   1. The Vertex itself
+   2. The VertexNormale
+   3. The VertexTextureCoordinate
+   merging this information, the face will be drawn.
+
+*/
+bool Object::addGLElement (char* elementString)
+{
+  if (verbose >=3)
+    printf ("importing grafical Element to openGL: %s\n", elementString);
+  char* vertex = elementString;
+
+  char* texture;
+  if ((texture = strstr (vertex, "/")) != NULL)
+    {
+      texture[0] = '\0';
+      texture ++;
+      glTexCoord2fv(vTexture->getArray()+(atoi(texture)-1)*2);
+
+      char* normal;
+      if ((normal = strstr (texture, "/")) !=NULL)
+	{
+	  normal[0] = '\0';
+	  normal ++;
+	  //glArrayElement(atoi(vertex)-1);
+	  glNormal3fv(normals->getArray() +(atoi(normal)-1)*3);
+	}
+    }
+  glVertex3fv(vertices->getArray() +(atoi(vertex)-1)*3);
+
+}
+
 
 /**
Index: orxonox/trunk/importer/object.h
===================================================================
--- orxonox/trunk/importer/object.h	(revision 3065)
+++ orxonox/trunk/importer/object.h	(revision 3066)
@@ -29,7 +29,4 @@
   ~Object ();
   
-  bool importFile (char* fileName);
-  bool initialize (void);
-  bool finalize(void);
   void draw (void) const;
   void draw (int groupNumber) const;
@@ -48,5 +45,4 @@
   {
     int vertexCount;
-
     FaceElement* firstElem;
 
@@ -82,31 +78,32 @@
   int groupCount;
 
-  char* objFileName;
-  char* mtlFileName;
-
   Material* material;
   float scaleFactor;
 
   char* objPath;
+  char* objFileName;
+  char* mtlFileName;
   ifstream* OBJ_FILE;
   ifstream* MTL_FILE;
 
+  bool initialize (void);
   bool initGroup(Group* group);
-  bool finalizeGroup (Group* group);
-
+  bool initFace (Face* face);
+  bool cleanup(void);
+  bool cleanupGroup(Group* group);
+  bool cleanupFace(Face* face);
 
   ///// readin ///
+  bool importFile (char* fileName);
   bool readFromObjFile (char* fileName);
   
+  bool readGroup (char* groupString);
   bool readVertex (char* vertexString);
   bool readFace (char* faceString);
-  bool readVT (char* vtString);
   bool readVertexNormal (char* normalString);
   bool readVertexTexture (char* vTextureString);
-  bool readGroup (char* groupString);
   bool readMtlLib (char* matFile);
   bool readUseMtl (char* mtlString);
 
-  bool initFace (Face* face);
   bool importToGL (void);
   bool addGLElement (char* elementString);
