Changeset 3908 in orxonox.OLD for orxonox/trunk/src/lib/graphics/importer
- Timestamp:
- Apr 20, 2005, 11:55:54 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/importer/objModel.cc
r3658 r3908 17 17 18 18 #include "objModel.h" 19 20 #include <stdio.h> 21 #include <string.h> 22 #include <stdlib.h> 23 24 #define PARSELINELENGTH 8192 19 25 20 26 #include <fstream> … … 120 126 strcat(fileName, this->objFileName); 121 127 122 ifstream* OBJ_FILE = new ifstream(fileName); 123 if (OBJ_FILE->fail()) 124 { 125 PRINTF(1)("unable to open .OBJ file: %s\n Loading cube-Model instead.\n", fileName); 126 cubeModel(); 127 OBJ_FILE->close(); 128 delete []fileName; 129 delete OBJ_FILE; 128 FILE* stream; 129 if( (stream = fopen (fileName, "r")) == NULL) 130 { 131 printf("IniParser could not open %s\n", fileName); 130 132 return false; 131 133 } 132 PRINTF(4)("Reading from opened file %s\n", fileName); 133 char Buffer[10000];134 while(!OBJ_FILE->eof())135 {136 OBJ_FILE->getline(Buffer, 10000);137 PRINTF(5)("Read input line: %s\n", Buffer);138 139 134 135 char readLine[PARSELINELENGTH]; 136 char buffer[PARSELINELENGTH]; 137 int i = 0; 138 while(fgets(readLine, PARSELINELENGTH, stream)) 139 { 140 strcpy(buffer, readLine); 141 i++; 140 142 // case vertice 141 if (!strncmp( Buffer, "v ", 2))142 { 143 this->addVertex( Buffer+2);143 if (!strncmp(buffer, "v ", 2)) 144 { 145 this->addVertex(buffer+2); 144 146 } 145 147 146 148 // case face 147 else if (!strncmp( Buffer, "f ", 2))148 { 149 this->addFace ( Buffer+2);150 } 151 152 else if (!strncmp( Buffer, "mtllib ", 7))153 { 154 this->readMtlLib ( Buffer+7);155 } 156 157 else if (!strncmp( Buffer, "usemtl ", 7))158 { 159 this->addUseMtl ( Buffer+7);149 else if (!strncmp(buffer, "f ", 2)) 150 { 151 this->addFace (buffer+2); 152 } 153 154 else if (!strncmp(buffer, "mtllib ", 7)) 155 { 156 this->readMtlLib (buffer+7); 157 } 158 159 else if (!strncmp(buffer, "usemtl ", 7)) 160 { 161 this->addUseMtl (buffer+7); 160 162 } 161 163 162 164 // case VertexNormal 163 else if (!strncmp( Buffer, "vn ", 3))164 { 165 this->addVertexNormal( Buffer+3);165 else if (!strncmp(buffer, "vn ", 3)) 166 { 167 this->addVertexNormal(buffer+3); 166 168 } 167 169 168 170 // case VertexTextureCoordinate 169 else if (!strncmp( Buffer, "vt ", 3))170 { 171 this->addVertexTexture( Buffer+3);171 else if (!strncmp(buffer, "vt ", 3)) 172 { 173 this->addVertexTexture(buffer+3); 172 174 } 173 175 // case group 174 else if (!strncmp(Buffer, "g ", 2)) 175 { 176 this->addGroup (Buffer+2); 177 } 178 else if (!strncmp(Buffer, "s ", 2)) //! \todo smoothing groups have to be implemented 179 { 180 PRINTF(2)("smoothing groups not supportet yet. line: %s\n", Buffer); 181 } 182 } 183 OBJ_FILE->close(); 184 delete OBJ_FILE; 176 else if (!strncmp(buffer, "g ", 2)) 177 { 178 this->addGroup (buffer+2); 179 } 180 else if (!strncmp(buffer, "s ", 2)) //! \todo smoothing groups have to be implemented 181 { 182 PRINTF(2)("smoothing groups not supportet yet. line: %s\n", buffer); 183 } 184 } 185 fclose (stream); 185 186 delete []fileName; 186 187 return true; … … 216 217 return false; 217 218 } 218 char Buffer[500];219 char buffer[500]; 219 220 Material* tmpMat = material; 220 221 while(!MTL_FILE->eof()) 221 222 { 222 MTL_FILE->getline( Buffer, 500);223 PRINTF(5)("found line in mtlFile: %s\n", Buffer);223 MTL_FILE->getline(buffer, 500); 224 PRINTF(5)("found line in mtlFile: %s\n", buffer); 224 225 225 226 226 227 // create new Material 227 if (!strncmp( Buffer, "newmtl ", 7))228 { 229 tmpMat = tmpMat->addMaterial( Buffer+7);228 if (!strncmp(buffer, "newmtl ", 7)) 229 { 230 tmpMat = tmpMat->addMaterial(buffer+7); 230 231 // PRINTF(2)("%s, %p\n", tmpMat->getName(), tmpMat); 231 232 } 232 233 // setting a illumMode 233 else if (!strncmp( Buffer, "illum ", 6))234 { 235 tmpMat->setIllum( Buffer+6);234 else if (!strncmp(buffer, "illum ", 6)) 235 { 236 tmpMat->setIllum(buffer+6); 236 237 237 238 } 238 239 // setting Diffuse Color 239 else if (!strncmp( Buffer, "Kd ", 3))240 { 241 tmpMat->setDiffuse( Buffer+3);240 else if (!strncmp(buffer, "Kd ", 3)) 241 { 242 tmpMat->setDiffuse(buffer+3); 242 243 } 243 244 // setting Ambient Color 244 else if (!strncmp( Buffer, "Ka ", 3))245 { 246 tmpMat->setAmbient( Buffer+3);245 else if (!strncmp(buffer, "Ka ", 3)) 246 { 247 tmpMat->setAmbient(buffer+3); 247 248 } 248 249 // setting Specular Color 249 else if (!strncmp( Buffer, "Ks ", 3))250 { 251 tmpMat->setSpecular( Buffer+3);250 else if (!strncmp(buffer, "Ks ", 3)) 251 { 252 tmpMat->setSpecular(buffer+3); 252 253 } 253 254 // setting The Specular Shininess 254 else if (!strncmp( Buffer, "Ns ", 3))255 { 256 tmpMat->setShininess( Buffer+3);255 else if (!strncmp(buffer, "Ns ", 3)) 256 { 257 tmpMat->setShininess(buffer+3); 257 258 } 258 259 // setting up transparency 259 else if (!strncmp( Buffer, "d ", 2))260 { 261 tmpMat->setTransparency( Buffer+2);262 } 263 else if (!strncmp( Buffer, "Tf ", 3))264 { 265 tmpMat->setTransparency( Buffer+3);266 } 267 268 else if (!strncmp( Buffer, "map_Kd ", 7))269 { 270 tmpMat->setDiffuseMap( Buffer+7);271 } 272 else if (!strncmp( Buffer, "map_Ka ", 7))273 { 274 tmpMat->setAmbientMap( Buffer+7);275 } 276 else if (!strncmp( Buffer, "map_Ks ", 7))277 { 278 tmpMat->setSpecularMap( Buffer+7);279 } 280 else if (!strncmp( Buffer, "bump ", 5))281 { 282 tmpMat->setBump( Buffer+7);260 else if (!strncmp(buffer, "d ", 2)) 261 { 262 tmpMat->setTransparency(buffer+2); 263 } 264 else if (!strncmp(buffer, "Tf ", 3)) 265 { 266 tmpMat->setTransparency(buffer+3); 267 } 268 269 else if (!strncmp(buffer, "map_Kd ", 7)) 270 { 271 tmpMat->setDiffuseMap(buffer+7); 272 } 273 else if (!strncmp(buffer, "map_Ka ", 7)) 274 { 275 tmpMat->setAmbientMap(buffer+7); 276 } 277 else if (!strncmp(buffer, "map_Ks ", 7)) 278 { 279 tmpMat->setSpecularMap(buffer+7); 280 } 281 else if (!strncmp(buffer, "bump ", 5)) 282 { 283 tmpMat->setBump(buffer+7); 283 284 } 284 285
Note: See TracChangeset
for help on using the changeset viewer.