Changeset 4194 in orxonox.OLD for orxonox/branches/openAL/src/lib/graphics/importer/objModel.cc
- Timestamp:
- May 16, 2005, 1:33:19 PM (20 years ago)
- Location:
- orxonox/branches/openAL
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/openAL
- Property svn:externals
-
old new 1 data http://svn.orxonox.ethz.ch/data 1
-
- Property svn:externals
-
orxonox/branches/openAL/src/lib/graphics/importer/objModel.cc
r3916 r4194 34 34 OBJModel::OBJModel(const char* fileName, float scaling) : Model(fileName) 35 35 { 36 this->initializeOBJ(); 36 this->objPath = "./"; 37 37 38 this->scaleFactor = scaling; 38 39 … … 52 53 if (this->objPath) 53 54 delete []this->objPath; 54 if (this->objFileName)55 delete []this->objFileName;56 if (this->mtlFileName)57 delete []this->mtlFileName;58 }59 60 /**61 \brief Initializes an obj-model62 */63 void OBJModel::initializeOBJ(void)64 {65 this->objPath = NULL;66 this->objFileName = NULL;67 this->mtlFileName = NULL;68 55 } 69 56 … … 71 58 \brief Imports a obj file and handles the the relative location 72 59 \param fileName The file to import 60 61 Splits the FileName from the DirectoryName 73 62 */ 74 63 bool OBJModel::importFile (const char* fileName) 75 64 { 76 65 PRINTF(4)("preparing to read in file: %s\n", fileName); 77 78 79 #ifdef __WIN32__ 80 // win32 path reading 81 char pathSplitter= '\\'; 82 #else /* __WIN32__ */ 83 // unix path reading 84 char pathSplitter='/'; 85 #endif /* __WIN32__ */ 86 char* tmpName; 87 strcpy(tmpName, fileName); 88 if (tmpName[0] == pathSplitter) 89 tmpName++; 90 char* name = tmpName; 91 while (( tmpName = strchr (tmpName+1, pathSplitter))) 92 { 93 name = tmpName+1; 94 } 95 this->objPath = new char[name-fileName+1]; 96 strncpy(this->objPath, fileName, name-fileName); 97 this->objPath[name-fileName] = '\0'; 98 if (strlen(objPath)> 0) 99 PRINTF(5)("Resolved file %s to folder: %s.\n", name, objPath); 100 else 101 PRINTF(5)("Resolved file %s.\n", name); 102 103 this->setName(name); 104 105 this->objFileName = new char[strlen(name)+1]; 106 strcpy (this->objFileName, name); 107 this->readFromObjFile (); 66 // splitting the 67 char* split = NULL; 68 69 if (!(split = strrchr(fileName, '/'))) 70 split = strrchr(fileName, '\\'); // windows Case 71 if (split) 72 { 73 int len = split - fileName+1; 74 this->objPath = new char[len +2]; 75 strncpy(this->objPath, fileName, len); 76 this->objPath[len] = '\0'; 77 PRINTF(1)("Resolved file %s to Path %s.\n", fileName, this->objPath); 78 } 79 this->readFromObjFile (fileName); 108 80 return true; 109 81 } … … 113 85 This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks 114 86 */ 115 bool OBJModel::readFromObjFile (void) 116 { 117 char* fileName = new char [strlen(objPath)+strlen(objFileName)+1]; 118 if (this->objFileName != NULL && !strcmp(this->objFileName, "")) 119 return false; 120 strcpy(fileName, this->objPath); 121 strcat(fileName, this->objFileName); 122 87 bool OBJModel::readFromObjFile(const char* fileName) 88 { 123 89 FILE* stream; 124 90 if( (stream = fopen (fileName, "r")) == NULL) 125 91 { 126 printf(" IniParser could not open%s\n", fileName);92 printf("Object File Could not be Opened %s\n", fileName); 127 93 return false; 128 94 } … … 179 145 } 180 146 fclose (stream); 181 delete []fileName;182 147 return true; 183 148 } … … 194 159 bool OBJModel::readMtlLib (const char* mtlFile) 195 160 { 196 this->mtlFileName = new char [strlen(mtlFile)+1]; 197 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); 201 161 char* fileName = new char [strlen(this->objPath) + strlen(mtlFile)+1]; 162 sprintf(fileName, "%s%s", this->objPath, mtlFile); 202 163 203 164 FILE* stream; 204 165 if( (stream = fopen (fileName, "r")) == NULL) 205 166 { 206 printf("IniParser could not open %s\n", fileName); 167 PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName); 168 delete []fileName; 207 169 return false; 208 170 }
Note: See TracChangeset
for help on using the changeset viewer.