Changeset 4117 in orxonox.OLD for orxonox/trunk/src/lib/graphics
- Timestamp:
- May 7, 2005, 10:50:06 PM (20 years ago)
- Location:
- orxonox/trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/importer/objModel.cc
r4038 r4117 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+1] = '\0'; 77 PRINTF(4)("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(this->objPath) + strlen(this->mtlFileName)+1]; 199 sprintf(fileName, "%s%s", this->objPath, this->mtlFileName); 200 161 char* fileName = new char [strlen(this->objPath) + strlen(mtlFile)+1]; 162 sprintf(fileName, "%s%s", this->objPath, mtlFile); 201 163 202 164 FILE* stream; 203 165 if( (stream = fopen (fileName, "r")) == NULL) 204 166 { 205 printf("IniParser could not open %s\n", fileName); 167 PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName); 168 delete []fileName; 206 169 return false; 207 170 } -
orxonox/trunk/src/lib/graphics/importer/objModel.h
r3916 r4117 15 15 OBJModel(const char* fileName, float scaling = 1.0); 16 16 virtual ~OBJModel(); 17 void initializeOBJ(void);18 17 19 18 private: 20 19 // Variables 21 20 char* objPath; //!< The Path where the obj and mtl-file are located. 22 char* objFileName; //!< The Name of the obj-file.23 char* mtlFileName; //!< The Name of the mtl-file (parsed out of the obj-file)24 21 25 22 ///// readin ///// 26 23 bool importFile (const char* fileName); 27 bool readFromObjFile ( void);24 bool readFromObjFile (const char* fileName); 28 25 bool readMtlLib (const char* matFile); 29 26 };
Note: See TracChangeset
for help on using the changeset viewer.