Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3127 in orxonox.OLD for orxonox/branches/images/importer


Ignore:
Timestamp:
Dec 7, 2004, 8:02:05 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/images: Implemented a Way to read in the Files from any Directory.

  1. New Class created: PathList, handles lists of Paths (patrick… i really think this list is so small, that it does not make sense to use the list.h instead)
  2. Implemented it so it works. (windows-users should now be able to drag a file onto the importer, and it displays the file with all the maps and textures on it, if they are in the same directory as the obj-file)
Location:
orxonox/branches/images/importer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/images/importer/framework.cc

    r3122 r3127  
    11#include "framework.h"
    22
    3 int verbose = 1;
     3int verbose = 4;
    44
    55void DrawGLScene()
     
    4343  // Create a new OpenGL window with the title "Cone3D Basecode" at
    4444  // 640x480x32, fullscreen and check for errors along the way
    45   if(wHandler.CreateGLWindow("Whandler Basecode", 640, 480, 32, FALSE) == FALSE)
     45  if(wHandler.CreateGLWindow("Whandler Basecode", 800, 600, 32, FALSE) == FALSE)
    4646  {
    4747    // If an error is found, display a message, kill the GL and SDL screens (if they were created) and exit
  • orxonox/branches/images/importer/material.cc

    r3120 r3127  
    2020#include "material.h"
    2121
     22// headers only for PathList
     23#include <unistd.h>
     24#include <sys/types.h>
     25#include <sys/stat.h>
     26#include <stdlib.h>
     27#include <fstream>
     28
     29using namespace std;
     30
     31
     32PathList::PathList()
     33{
     34  pathName = NULL;
     35  next = NULL;
     36}
     37PathList::PathList(char* pName)
     38{
     39  pathName = new char [strlen(pName)+1];
     40  strcpy (pathName, pName);
     41  next = NULL;
     42}
     43
     44PathList::~PathList()
     45{
     46  if (pathName)
     47    delete []pathName;
     48  if (next)
     49    delete next;
     50}
     51
     52void PathList::addPath (char* pName)
     53{
     54  if (pName[0] == '\0')
     55    {
     56      if (verbose >=3)
     57        printf("not Adding empty Path to the List.\n");
     58      return;
     59    }
     60 
     61  if (access (pName, F_OK) == 0)
     62    {
     63      struct stat status;
     64      stat(pName, &status);
     65      if (status.st_mode & S_IFDIR)
     66        {
     67          if (verbose >=2)
     68            printf ("Adding Path %s to the PathList.\n", pName);
     69          PathList* tmpPathList = this;
     70          while (tmpPathList->next)
     71            tmpPathList = tmpPathList->next;
     72          tmpPathList->next = new PathList(pName);
     73        }
     74      else
     75        if (verbose >=1)
     76          printf ("You tried to add non-folder %s to a PathList.\n", pName);
     77    }
     78  else
     79    if (verbose >=1)
     80      printf ("You tried to add non-existing folder %s to a PathList.\n", pName);
     81}
    2282
    2383/**
     
    67127  if (verbose >=2)
    68128    printf ("adding Material %s.\n", mtlName);
    69   Material* newMat = new Material(mtlName);
    70   Material* tmpMat = this;
     129   Material* tmpMat = this;
    71130  while (tmpMat->nextMat != NULL)
    72131    {
    73132      tmpMat = tmpMat->nextMat;
    74133    }
    75   tmpMat->nextMat = newMat;
    76   return newMat;
     134  tmpMat->nextMat = new Material(mtlName);
     135  return tmpMat->nextMat;
    77136 
    78137}
     
    86145    printf ("initializing new Material.\n");
    87146  nextMat = NULL;
    88 
     147  name ="";
    89148  setIllum(1);
    90149  setDiffuse(0,0,0);
     
    94153  setTransparency(0.0);
    95154
     155  if (!pathList)
     156    pathList = new PathList("");
     157
     158
    96159  diffuseTextureSet = false;
    97160  ambientTextureSet = false;
     
    100163 
    101164}
     165
     166PathList *Material::pathList = NULL;
    102167
    103168/**
     
    166231void Material::setName (char* mtlName)
    167232{
    168   if (verbose >= 3)
    169     printf("setting Material Name to %s.\n", mtlName);
    170233  name = new char [strlen(mtlName)+1];
    171234  strcpy(name, mtlName);
     235  if (verbose >= 3)
     236    printf("setting Material Name to %s.\n", name);
     237
    172238  //  printf ("adding new Material: %s, %p\n", this->getName(), this);
    173239
     
    188254{
    189255  if (verbose >= 3)
    190     printf("setting illumModel of Material %s to %i", name, illum);
     256    printf("setting illumModel of Material %s to %i\n", name, illum);
    191257  illumModel = illum;
    192258  //  printf ("setting illumModel to: %i\n", illumModel);
     
    317383}
    318384
     385void Material::addTexturePath(char* pathName)
     386{
     387  pathList->addPath (pathName);
     388}
     389char* Material::searchTextureInPaths(char* texName) const
     390{
     391  char* tmpName = NULL;
     392  PathList* pList = pathList;
     393  while (pList)
     394    {
     395      if (pList->pathName)
     396        {
     397          tmpName = new char [strlen(pList->pathName)+strlen(texName)+1];
     398          strcpy(tmpName, pList->pathName);
     399        }
     400      else
     401        {
     402          tmpName = new char [strlen(texName)+1];
     403          tmpName[0]='\0';
     404        }
     405      strcat(tmpName, texName);
     406      printf("%s\n", tmpName);
     407      if (access (tmpName, F_OK) == 0)
     408        return tmpName;
     409     
     410      if (tmpName)
     411        delete []tmpName;
     412      tmpName = NULL;
     413      pList = pList->next;
     414    }
     415  return NULL;
     416}
     417
     418
    319419// MAPPING //
    320420
     
    364464bool Material::loadTexToGL (Image* pImage, GLuint* texture)
    365465{
     466  if (verbose >=3)
     467    printf ("Loading texture to OpenGL-Environment.\n");
    366468  glGenTextures(1, texture);
    367469  glBindTexture(GL_TEXTURE_2D, *texture);
     
    381483bool Material::loadImage(char* imageName, GLuint* texture)
    382484{
    383   SDL_Surface* map;
    384   Image* pImage = new Image;
    385   map=IMG_Load(imageName);
    386   if(!map)
    387     {
    388       printf("IMG_Load: %s\n", IMG_GetError());
    389       return false;
    390     }
    391   pImage->height = map->h;
    392   pImage->width  = map->w;
    393   pImage->data   = (GLubyte*)map->pixels;
    394   if( !IMG_isPNG(SDL_RWFromFile(imageName, "rb")) && !IMG_isJPG(SDL_RWFromFile(imageName, "rb")))
    395     for (int i=0;i<map->h * map->w *3;i+=3)
    396       {
    397         GLuint temp = pImage->data[i];
    398         pImage->data[i] = pImage->data[i+2];
    399         pImage->data[i+2] = temp;
    400       }
    401   loadTexToGL (pImage, texture);
    402 
     485  char* imgNameWithPath= searchTextureInPaths(imageName);
     486  if (imgNameWithPath)
     487    {
     488      SDL_Surface* map;
     489      Image* pImage = new Image;
     490      map=IMG_Load(imgNameWithPath);
     491      if(!map)
     492        {
     493          printf("IMG_Load: %s\n", IMG_GetError());
     494          return false;
     495        }
     496      pImage->height = map->h;
     497      pImage->width  = map->w;
     498      pImage->data   = (GLubyte*)map->pixels;
     499      if( !IMG_isPNG(SDL_RWFromFile(imgNameWithPath, "rb")) && !IMG_isJPG(SDL_RWFromFile(imgNameWithPath, "rb")))
     500        for (int i=0;i<map->h * map->w *3;i+=3)
     501          {
     502            GLuint temp = pImage->data[i];
     503            pImage->data[i] = pImage->data[i+2];
     504            pImage->data[i+2] = temp;
     505          }
     506      loadTexToGL (pImage, texture);
     507    }
     508  else
     509    {
     510      if (verbose >=2)
     511        printf ("Image not Found: %s\n", imageName);
     512      return false;
     513    }
    403514}
    404515#else
  • orxonox/branches/images/importer/material.h

    r3110 r3127  
    1212#include <GL/glu.h>
    1313#include <SDL/SDL.h>
    14 #include <stdlib.h>
    15 #include <fstream>
    1614
    1715#if HAVE_CONFIG_H
     
    3230#endif /* HAVE_PNG_H */
    3331#endif /* HAVE_SDL_SDL_IMAGE_H */
     32
     33class PathList
     34{
     35 public:
     36  PathList();
     37  PathList(char* pName);
     38
     39  ~PathList();
     40  void addPath (char* pName);
     41  char* pathName;
     42  PathList* next;
     43};
     44
    3445
    3546//! Class to handle Materials.
     
    6273
    6374
    64 
    65 
    66   // MAPPING //
     75 
     76  void addTexturePath(char* pathName);
     77  char* searchTextureInPaths(char* texName) const;
     78 // MAPPING //
    6779  void setDiffuseMap(char* dMap);
    6880  void setAmbientMap(char* aMap);
    6981  void setSpecularMap(char* sMap);
    7082  void setBump(char* bump);
    71 
    7283
    7384 private:
     
    91102  float transparency;
    92103
     104  static PathList* pathList;
     105 
    93106  GLuint diffuseTexture;
    94107  GLuint ambientTexture;
  • orxonox/branches/images/importer/object.cc

    r3122 r3127  
    353353  if (verbose >=2)
    354354    if (strlen(objPath)> 0)
    355       printf("Resolved file %s to folder: %s.\n", name, objPath);
     355      {
     356        printf("Resolved file %s to folder: %s.\n", name, objPath);
     357      }
    356358    else
    357359      printf("Resolved file %s.\n", name);
    358360 
     361  if (material)
     362    material->addTexturePath(objPath);
    359363  objFileName = new char[strlen(name)+1];
    360364  strcpy (objFileName, name);
Note: See TracChangeset for help on using the changeset viewer.