Changeset 3430 in orxonox.OLD for orxonox/branches/trackManager/src/importer
- Timestamp:
- Mar 1, 2005, 9:50:30 AM (20 years ago)
- Location:
- orxonox/branches/trackManager
- Files:
-
- 2 deleted
- 10 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/trackManager
- Property svn:externals set to
-
orxonox/branches/trackManager/src/importer/Makefile.am
r3369 r3430 9 9 windowHandler.cc \ 10 10 model.cc \ 11 objModel.cc \ 11 12 array.cc \ 12 13 material.cc \ 13 14 texture.cc \ 14 vector.cc15 ../vector.cc 15 16 16 17 noinst_HEADERS= framework.h \ 17 18 windowHandler.h \ 18 19 model.h \ 20 objModel.h \ 19 21 array.h \ 20 22 material.h \ -
orxonox/branches/trackManager/src/importer/Makefile.in
r3369 r3430 54 54 PROGRAMS = $(bin_PROGRAMS) 55 55 am_importer_OBJECTS = framework.$(OBJEXT) windowHandler.$(OBJEXT) \ 56 model.$(OBJEXT) array.$(OBJEXT) material.$(OBJEXT) \57 texture.$(OBJEXT) vector.$(OBJEXT)56 model.$(OBJEXT) objModel.$(OBJEXT) array.$(OBJEXT) \ 57 material.$(OBJEXT) texture.$(OBJEXT) vector.$(OBJEXT) 58 58 importer_OBJECTS = $(am_importer_OBJECTS) 59 59 importer_LDADD = $(LDADD) … … 63 63 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/array.Po ./$(DEPDIR)/framework.Po \ 64 64 @AMDEP_TRUE@ ./$(DEPDIR)/material.Po ./$(DEPDIR)/model.Po \ 65 @AMDEP_TRUE@ ./$(DEPDIR)/ texture.Po ./$(DEPDIR)/vector.Po \66 @AMDEP_TRUE@ ./$(DEPDIR)/ windowHandler.Po65 @AMDEP_TRUE@ ./$(DEPDIR)/objModel.Po ./$(DEPDIR)/texture.Po \ 66 @AMDEP_TRUE@ ./$(DEPDIR)/vector.Po ./$(DEPDIR)/windowHandler.Po 67 67 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 68 68 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) … … 89 89 CPP = @CPP@ 90 90 CPPFLAGS = @CPPFLAGS@ 91 CURL_CFLAGS = @CURL_CFLAGS@ 92 CURL_LIBS = @CURL_LIBS@ 91 93 CXX = @CXX@ 92 94 CXXDEPMODE = @CXXDEPMODE@ … … 104 106 EGREP = @EGREP@ 105 107 EXEEXT = @EXEEXT@ 108 GTHREAD_CFLAGS = @GTHREAD_CFLAGS@ 109 GTHREAD_LIBS = @GTHREAD_LIBS@ 106 110 GTK2_CFLAGS = @GTK2_CFLAGS@ 107 111 GTK2_LIBS = @GTK2_LIBS@ 112 HAVE_CURL_FALSE = @HAVE_CURL_FALSE@ 113 HAVE_CURL_TRUE = @HAVE_CURL_TRUE@ 114 HAVE_GTHREAD_FALSE = @HAVE_GTHREAD_FALSE@ 115 HAVE_GTHREAD_TRUE = @HAVE_GTHREAD_TRUE@ 108 116 HAVE_GTK2_FALSE = @HAVE_GTK2_FALSE@ 109 117 HAVE_GTK2_TRUE = @HAVE_GTK2_TRUE@ … … 129 137 SHELL = @SHELL@ 130 138 STRIP = @STRIP@ 139 SUB_PROJECTS_FALSE = @SUB_PROJECTS_FALSE@ 140 SUB_PROJECTS_TRUE = @SUB_PROJECTS_TRUE@ 131 141 VERSION = @VERSION@ 132 142 ac_ct_CC = @ac_ct_CC@ … … 178 188 windowHandler.cc \ 179 189 model.cc \ 190 objModel.cc \ 180 191 array.cc \ 181 192 material.cc \ 182 193 texture.cc \ 183 vector.cc194 ../vector.cc 184 195 185 196 noinst_HEADERS = framework.h \ 186 197 windowHandler.h \ 187 198 model.h \ 199 objModel.h \ 188 200 array.h \ 189 201 material.h \ … … 260 272 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/material.Po@am__quote@ 261 273 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Po@am__quote@ 274 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/objModel.Po@am__quote@ 262 275 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@ 263 276 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@ … … 279 292 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 280 293 @am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` 294 295 vector.o: ../vector.cc 296 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vector.o -MD -MP -MF "$(DEPDIR)/vector.Tpo" -c -o vector.o `test -f '../vector.cc' || echo '$(srcdir)/'`../vector.cc; \ 297 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/vector.Tpo" "$(DEPDIR)/vector.Po"; else rm -f "$(DEPDIR)/vector.Tpo"; exit 1; fi 298 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../vector.cc' object='vector.o' libtool=no @AMDEPBACKSLASH@ 299 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/vector.Po' tmpdepfile='$(DEPDIR)/vector.TPo' @AMDEPBACKSLASH@ 300 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 301 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vector.o `test -f '../vector.cc' || echo '$(srcdir)/'`../vector.cc 302 303 vector.obj: ../vector.cc 304 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vector.obj -MD -MP -MF "$(DEPDIR)/vector.Tpo" -c -o vector.obj `if test -f '../vector.cc'; then $(CYGPATH_W) '../vector.cc'; else $(CYGPATH_W) '$(srcdir)/../vector.cc'; fi`; \ 305 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/vector.Tpo" "$(DEPDIR)/vector.Po"; else rm -f "$(DEPDIR)/vector.Tpo"; exit 1; fi 306 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../vector.cc' object='vector.obj' libtool=no @AMDEPBACKSLASH@ 307 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/vector.Po' tmpdepfile='$(DEPDIR)/vector.TPo' @AMDEPBACKSLASH@ 308 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 309 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vector.obj `if test -f '../vector.cc'; then $(CYGPATH_W) '../vector.cc'; else $(CYGPATH_W) '$(srcdir)/../vector.cc'; fi` 281 310 uninstall-info-am: 282 311 -
orxonox/branches/trackManager/src/importer/array.h
r3196 r3430 12 12 13 13 #include "../stdincl.h" 14 #include <fstream>15 16 14 17 15 //! Array Class that handles dynamic-float arrays. -
orxonox/branches/trackManager/src/importer/framework.cc
r3369 r3430 16 16 #include "framework.h" 17 17 18 #include "../vector.h" 19 20 int verbose; 18 21 void DrawGLScene() 19 22 { … … 52 55 int main(int argc, char *argv[]) 53 56 { 54 verbose = 2; 55 56 PRINTF(2)("This is The big verbose-Test %i, %s\n", 1, "cool"); 57 verbose = 3; 57 58 58 59 Uint8* keys; // This variable will be used in the keyboard routine … … 71 72 PRINTF(2)("screensize: %i, %i\n", wHandler.screen->w, wHandler.screen->h); 72 73 if (argc>=3) 73 obj = new Model (argv[1], atof(argv[2]));74 obj = new OBJModel (argv[1], atof(argv[2])); 74 75 else if (argc>=2) 75 obj = new Model(argv[1]);76 obj = new OBJModel(argv[1]); 76 77 else 77 obj = new Model(); 78 78 { 79 // This is an example, of how it is possible, to create a new Model, and adding some vertex-information. 80 // This also packs everything into a DisplayList, and can be handled exactly as any other model. 81 // This is an example of a cube with Texture-Coordinates, but without explicite Vertex-Normals. (they are soft-created). 82 /* 83 obj = (OBJModel*) new Model(); 84 obj->setName("CUBE"); 85 obj->addVertex (-0.5, -0.5, 0.5); 86 obj->addVertex (0.5, -0.5, 0.5); 87 obj->addVertex (-0.5, 0.5, 0.5); 88 obj->addVertex (0.5, 0.5, 0.5); 89 obj->addVertex (-0.5, 0.5, -0.5); 90 obj->addVertex (0.5, 0.5, -0.5); 91 obj->addVertex (-0.5, -0.5, -0.5); 92 obj->addVertex (0.5, -0.5, -0.5); 93 94 obj->addVertexTexture (0.0, 0.0); 95 obj->addVertexTexture (1.0, 0.0); 96 obj->addVertexTexture (0.0, 1.0); 97 obj->addVertexTexture (1.0, 1.0); 98 obj->addVertexTexture (0.0, 2.0); 99 obj->addVertexTexture (1.0, 2.0); 100 obj->addVertexTexture (0.0, 3.0); 101 obj->addVertexTexture (1.0, 3.0); 102 obj->addVertexTexture (0.0, 4.0); 103 obj->addVertexTexture (1.0, 4.0); 104 obj->addVertexTexture (2.0, 0.0); 105 obj->addVertexTexture (2.0, 1.0); 106 obj->addVertexTexture (-1.0, 0.0); 107 obj->addVertexTexture (-1.0, 1.0); 108 109 obj->addFace ("1 2 4 3"); 110 obj->addFace ("3 4 6 5"); 111 obj->addFace ("5 6 8 7"); 112 obj->addFace ("7 8 2 1"); 113 obj->addFace ("2 8 6 4"); 114 obj->addFace ("7 1 3 5"); 115 obj->finalize(); 116 */ 117 obj = (OBJModel*) new Model(CYLINDER); 118 } 79 119 M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0); 80 120 rotAxis = Vector (0.0,1.0,0.0); … … 215 255 case SDLK_c: 216 256 if (!obj) 217 obj = new Model(argv[1]);257 obj = new OBJModel(argv[1]); 218 258 break; 259 case SDLK_a: 260 zoomTo /=2; 261 break; 262 case SDLK_z: 263 zoomTo *=2; 264 219 265 } 220 266 break; -
orxonox/branches/trackManager/src/importer/framework.h
r3369 r3430 3 3 4 4 #include "windowHandler.h" // Include the Whandler Basecode 5 #include "model.h" 6 #include "vector.h" 5 #include "objModel.h" 6 7 class Vector; 7 8 8 9 float rotatorP; … … 33 34 34 35 WindowHandler wHandler; // Create an instance of the whandler basecode class 35 Model* obj;36 OBJModel* obj; 36 37 37 38 -
orxonox/branches/trackManager/src/importer/material.cc
r3369 r3430 16 16 17 17 #include "material.h" 18 19 #include "texture.h" 20 #include <stdlib.h> 21 #include <string.h> 18 22 19 23 using namespace std; … … 112 116 while (searcher != NULL) 113 117 { 114 PRINT F(2)(".");118 PRINT(2)("."); 115 119 if (!strcmp (searcher->getName(), mtlName)) 116 120 { 117 PRINT F(2)("found.\n");121 PRINT(2)("found.\n"); 118 122 return searcher; 119 123 } 120 124 searcher = searcher->nextMat; 121 125 } 122 PRINT F(2)("not found\n");126 PRINT(2)("not found\n"); 123 127 return NULL; 124 128 } -
orxonox/branches/trackManager/src/importer/material.h
r3369 r3430 13 13 extern int verbose; //!< will be obsolete soon. 14 14 15 #include "../stdincl.h"16 #include "texture.h"17 18 15 #if HAVE_CONFIG_H 19 16 #include <config.h> 20 17 #endif /* HAVE_CONFIG_H */ 21 18 22 19 // FORWARD DEFINITIONS // 20 class Texture; 23 21 24 22 -
orxonox/branches/trackManager/src/importer/model.cc
r3369 r3430 15 15 16 16 #include "model.h" 17 int verbose = 1; //! \todo should be GLOBAL 17 18 #include <math.h> 19 #include <stdarg.h> 20 21 #include "array.h" 22 #include "../vector.h" 23 18 24 using namespace std; 19 25 20 26 /** 21 \brief Creates a 3D-Model, but does not load any 3D-models. 22 23 This Constructor is pretty useless, because why load no model in an model-loader?? 24 */ 25 Model::Model () 26 { 27 27 \brief Creates a 3D-Model. 28 29 This only initializes a 3D-Model, but does not cleanup the Faces. 30 */ 31 Model::Model(void) 32 { 28 33 this->initialize(); 29 30 this->BoxModel(); 31 34 } 35 36 /** 37 \brief Creates a 3D-Model of Primitive-Type type 38 39 if you want to just display a Cube/Sphere/Cylinder/... without any material. 40 41 \todo implement Cube/Sphere/Cylinder/... 42 */ 43 Model::Model(PRIMITIVE type) 44 { 45 this->initialize(); 46 47 switch (type) 48 { 49 default: 50 case CUBE: 51 this->cubeModel(); 52 break; 53 case SPHERE: 54 this->sphereModel(); 55 break; 56 case CYLINDER: 57 this->cylinderModel(); 58 break; 59 60 } 32 61 this->importToGL (); 33 62 … … 36 65 37 66 /** 38 \brief Crates a 3D-Model and loads in a File. 39 \param fileName file to parse and load (must be a .obj file) 40 */ 41 Model::Model(char* fileName) 67 \brief Creates a 3D-Model. and assigns it a Name. 68 */ 69 Model::Model(char* modelName) 42 70 { 43 71 this->initialize(); 44 45 this->importFile (fileName); 46 47 this->importToGL (); 48 49 this->cleanup(); 50 } 51 52 /** 53 \brief Crates a 3D-Model, loads in a File and scales it. 54 \param fileName file to parse and load (must be a .obj file) 55 \param scaling The factor that the model will be scaled with. 56 */ 57 Model::Model(char* fileName, float scaling) 58 { 59 this->initialize(); 60 this->scaleFactor = scaling; 61 62 this->importFile (fileName); 63 64 this->importToGL (); 65 66 this->cleanup(); 72 this->setName(modelName); 67 73 } 68 74 … … 72 78 Looks if any from model allocated space is still in use, and if so deleted it. 73 79 */ 74 Model::~Model() 75 { 76 PRINTF(2)("Deleting display Lists.\n"); 80 Model::~Model(void) 81 { 82 PRINTF(3)("Deleting Model "); 83 if (this->name) 84 { 85 PRINT(3)("%s\n", this->name); 86 delete []this->name; 87 } 88 else 89 PRINT(3)("\n"); 90 91 PRINTF(3)("Deleting display Lists.\n"); 77 92 Group* walker = this->firstGroup; 78 93 while (walker != NULL) … … 84 99 } 85 100 86 if (this->objPath) 87 delete []this->objPath; 88 if (this->objFileName) 89 delete []this->objFileName; 90 if (this->mtlFileName) 91 delete []this->mtlFileName; 92 PRINTF(2)("Deleting Materials.\n"); 101 PRINTF(3)("Deleting Materials.\n"); 93 102 if (this->material) 94 103 delete this->material; 95 104 } 96 105 106 /** 107 \brief Finalizes an Object. This can be done outside of the Class. 108 */ 109 void Model::finalize(void) 110 { 111 this->importToGL (); 112 113 this->cleanup(); 114 115 this->finalized = true; 116 } 97 117 98 118 /** … … 139 159 walker = walker->next; 140 160 } 141 PRINTF(1)("Model number %i in %s not Found.\n", groupNumber, this-> objFileName);161 PRINTF(1)("Model number %i in %s not Found.\n", groupNumber, this->name); 142 162 return; 143 163 … … 164 184 walker = walker->next; 165 185 } 166 PRINTF(1)("Model Named %s in %s not Found.\n", groupName, this-> objFileName);186 PRINTF(1)("Model Named %s in %s not Found.\n", groupName, this->name); 167 187 return; 168 188 } … … 186 206 PRINTF(2)("new 3D-Model is being created\n"); 187 207 208 this->name = NULL; 209 this->finalized = false; 188 210 // setting the start group; 189 211 this->firstGroup = new Group; … … 192 214 193 215 this->initGroup (this->currentGroup); 194 this->objPath = NULL;195 this->objFileName = NULL;196 this->mtlFileName = NULL;197 216 this->scaleFactor = 1; 198 217 this->material = new Material(); … … 205 224 } 206 225 226 void Model::setName(const char* name) 227 { 228 if (this->name) 229 delete this->name; 230 this->name = new char[strlen(name)+1]; 231 strcpy(this->name, name); 232 } 207 233 /** 208 234 \brief initializes a new Group model … … 317 343 318 344 /** 319 \brief Imports a obj file and handles the the relative location320 \param fileName The file to import321 */322 bool Model::importFile (char* fileName)323 {324 PRINTF(3)("preparing to read in file: %s\n", fileName);325 326 327 #ifdef __WIN32__328 // win32 path reading329 char pathSplitter= '\\';330 #else /* __WIN32__ */331 // unix path reading332 char pathSplitter='/';333 #endif /* __WIN32__ */334 char* tmpName = fileName;335 if (tmpName[0] == pathSplitter)336 tmpName++;337 char* name = tmpName;338 while (( tmpName = strchr (tmpName+1, pathSplitter)))339 {340 name = tmpName+1;341 }342 this->objPath = new char[name-fileName];343 strncpy(this->objPath, fileName, name-fileName);344 this->objPath[name-fileName] = '\0';345 if (verbose >=2)346 if (strlen(objPath)> 0)347 PRINTF(0)("Resolved file %s to folder: %s.\n", name, objPath);348 else349 PRINTF(0)("Resolved file %s.\n", name);350 351 if (this->material)352 this->material->addTexturePath(this->objPath);353 this->objFileName = new char[strlen(name)+1];354 strcpy (this->objFileName, name);355 this->readFromObjFile ();356 return true;357 }358 359 /**360 \brief Reads in the .obj File and sets all the Values.361 This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks362 */363 bool Model::readFromObjFile (void)364 {365 char* fileName = new char [strlen(objPath)+strlen(objFileName)+1];366 if (this->objFileName != NULL && !strcmp(this->objFileName, ""))367 return false;368 strcpy(fileName, this->objPath);369 strcat(fileName, this->objFileName);370 371 ifstream* OBJ_FILE = new ifstream(fileName);372 if (OBJ_FILE->fail())373 {374 PRINTF(1)("unable to open .OBJ file: %s\n Loading Box Model instead.\n", fileName);375 BoxModel();376 OBJ_FILE->close();377 delete []fileName;378 delete OBJ_FILE;379 return false;380 }381 PRINTF(2)("Reading from opened file %s\n", fileName);382 char Buffer[10000];383 while(!OBJ_FILE->eof())384 {385 OBJ_FILE->getline(Buffer, 10000);386 PRINTF(3)("Read input line: %s\n", Buffer);387 388 389 // case vertice390 if (!strncmp(Buffer, "v ", 2))391 {392 this->readVertex(Buffer+2);393 }394 395 // case face396 else if (!strncmp(Buffer, "f ", 2))397 {398 this->readFace (Buffer+2);399 }400 401 else if (!strncmp(Buffer, "mtllib ", 7))402 {403 this->readMtlLib (Buffer+7);404 }405 406 else if (!strncmp(Buffer, "usemtl ", 7))407 {408 this->readUseMtl (Buffer+7);409 }410 411 // case VertexNormal412 else if (!strncmp(Buffer, "vn ", 3))413 {414 this->readVertexNormal(Buffer+3);415 }416 417 // case VertexTextureCoordinate418 else if (!strncmp(Buffer, "vt ", 3))419 {420 this->readVertexTexture(Buffer+3);421 }422 // case group423 else if (!strncmp(Buffer, "g ", 2))424 {425 this->readGroup (Buffer+2);426 }427 else if (!strncmp(Buffer, "s ", 2)) //! \todo smoothing groups have to be implemented428 {429 if (verbose >= 2)430 PRINTF(2)("smoothing groups not supportet yet. line: %s\n", Buffer);431 }432 }433 OBJ_FILE->close();434 delete OBJ_FILE;435 delete []fileName;436 return true;437 438 }439 440 /**441 345 \brief parses a group String 442 346 \param groupString the new Group to create … … 445 349 With it you should be able to import .obj-files with more than one Models inside. 446 350 */ 447 bool Model:: readGroup (char* groupString)351 bool Model::addGroup (char* groupString) 448 352 { 449 353 PRINTF(3)("Read Group: %s.\n", groupString); … … 470 374 If a vertex line is found this function will inject it into the vertex-Array 471 375 */ 472 bool Model:: readVertex (char* vertexString)376 bool Model::addVertex (char* vertexString) 473 377 { 474 378 float subbuffer1; … … 482 386 483 387 /** 388 \brief parses a vertex-String 389 \param x the X-coordinate of the Vertex to add. 390 \param y the Y-coordinate of the Vertex to add. 391 \param z the Z-coordinate of the Vertex to add. 392 393 */ 394 bool Model::addVertex(const float x, const float y, const float z) 395 { 396 PRINTF(4)("reading in a vertex: %f %f %f\n", x, y, z); 397 this->vertices->addEntry(x*scaleFactor, y*scaleFactor, z*scaleFactor); 398 return true; 399 } 400 401 /** 484 402 \brief parses a face-string 485 403 \param faceString The String that will be parsed. 486 404 487 405 If a face line is found this function will add it to the glList. 488 The function makes a difference between QUADS and TRIANGLES, and will if changed re-open, set and re-close the gl-processe. 489 */ 490 bool Model::readFace (char* faceString) 406 */ 407 bool Model::addFace (char* faceString) 491 408 { 492 409 if (this->currentGroup->faceCount >0) … … 546 463 547 464 /** 465 \brief adds a new Face 466 \param faceElemCount the number of Vertices to add to the Face. 467 \param type 0: vertex only, 1: vertex and normal, 2: vertex and Texture, 3 vertex, normal and texture 468 */ 469 bool Model::addFace(const float faceElemCount, int type, ...) 470 { 471 if (this->currentGroup->faceCount > 0) 472 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 473 this->initFace (this->currentGroup->currentFace); 474 475 FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement; 476 tmpElem->next = NULL; 477 478 va_list itemlist; 479 va_start (itemlist, type); 480 481 for (int i = 0; i < faceElemCount; i++) 482 { 483 if (this->currentGroup->currentFace->vertexCount>0) 484 tmpElem = tmpElem->next = new FaceElement; 485 tmpElem->next = NULL; 486 487 tmpElem->vertexNumber = va_arg (itemlist, int) -1; 488 if (type >= 2) 489 tmpElem->texCoordNumber = va_arg (itemlist, int) -1; 490 if (type == 1 || type ==3) 491 tmpElem->normalNumber = va_arg(itemlist, int) -1; 492 this->currentGroup->currentFace->vertexCount++; 493 } 494 va_end(itemlist); 495 496 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount - 2; 497 } 498 499 /** 548 500 \brief parses a vertexNormal-String 549 501 \param normalString The String that will be parsed. … … 551 503 If a vertexNormal line is found this function will inject it into the vertexNormal-Array 552 504 */ 553 bool Model:: readVertexNormal (char* normalString)505 bool Model::addVertexNormal (char* normalString) 554 506 { 555 507 float subbuffer1; … … 563 515 564 516 /** 517 \brief adds a VertexNormal. 518 \param x The x coordinate of the Normal. 519 \param y The y coordinate of the Normal. 520 \param z The z coordinate of the Normal. 521 522 If a vertexNormal line is found this function will inject it into the vertexNormal-Array 523 */ 524 bool Model::addVertexNormal(const float x, const float y, const float z) 525 { 526 PRINTF(3)("found vertex-Normal %f, %f, %f\n", x, y, z); 527 this->normals->addEntry(x, y, z); 528 } 529 530 /** 565 531 \brief parses a vertexTextureCoordinate-String 566 532 \param vTextureString The String that will be parsed. … … 569 535 this function will inject it into the vertexTexture-Array 570 536 */ 571 bool Model:: readVertexTexture (char* vTextureString)537 bool Model::addVertexTexture (char* vTextureString) 572 538 { 573 539 float subbuffer1; … … 580 546 } 581 547 582 /** 583 \brief Function to read in a mtl File. 584 \param mtlFile The .mtl file to read 585 586 This Function parses all Lines of an mtl File. 587 The reason for it not to be in the materials-class is, 588 that a material does not have to be able to read itself in from a File. 589 590 */ 591 bool Model::readMtlLib (char* mtlFile) 592 { 593 this->mtlFileName = new char [strlen(mtlFile)+1]; 594 strcpy(this->mtlFileName, mtlFile); 595 char* fileName = new char [strlen(objPath) + strlen(this->mtlFileName)+1]; 596 strcpy(fileName, this->objPath); 597 strcat(fileName, this->mtlFileName); 598 599 600 PRINTF(3)("Opening mtlFile: %s\n", fileName); 601 602 ifstream* MTL_FILE = new ifstream (fileName); 603 if (MTL_FILE->fail()) 604 { 605 PRINTF(1)("unable to open file: %s\n", fileName); 606 MTL_FILE->close(); 607 delete []fileName; 608 delete MTL_FILE; 609 return false; 610 } 611 char Buffer[500]; 612 Material* tmpMat = material; 613 while(!MTL_FILE->eof()) 614 { 615 MTL_FILE->getline(Buffer, 500); 616 PRINTF(4)("found line in mtlFile: %s\n", Buffer); 617 618 619 // create new Material 620 if (!strncmp(Buffer, "newmtl ", 7)) 621 { 622 tmpMat = tmpMat->addMaterial(Buffer+7); 623 // PRINTF(2)("%s, %p\n", tmpMat->getName(), tmpMat); 624 } 625 // setting a illumMode 626 else if (!strncmp(Buffer, "illum ", 6)) 627 { 628 tmpMat->setIllum(Buffer+6); 629 630 } 631 // setting Diffuse Color 632 else if (!strncmp(Buffer, "Kd ", 3)) 633 { 634 tmpMat->setDiffuse(Buffer+3); 635 } 636 // setting Ambient Color 637 else if (!strncmp(Buffer, "Ka ", 3)) 638 { 639 tmpMat->setAmbient(Buffer+3); 640 } 641 // setting Specular Color 642 else if (!strncmp(Buffer, "Ks ", 3)) 643 { 644 tmpMat->setSpecular(Buffer+3); 645 } 646 // setting The Specular Shininess 647 else if (!strncmp(Buffer, "Ns ", 3)) 648 { 649 tmpMat->setShininess(Buffer+3); 650 } 651 // setting up transparency 652 else if (!strncmp(Buffer, "d ", 2)) 653 { 654 tmpMat->setTransparency(Buffer+2); 655 } 656 else if (!strncmp(Buffer, "Tf ", 3)) 657 { 658 tmpMat->setTransparency(Buffer+3); 659 } 660 661 else if (!strncmp(Buffer, "map_Kd ", 7)) 662 { 663 tmpMat->setDiffuseMap(Buffer+7); 664 } 665 else if (!strncmp(Buffer, "map_Ka ", 7)) 666 { 667 tmpMat->setAmbientMap(Buffer+7); 668 } 669 else if (!strncmp(Buffer, "map_Ks ", 7)) 670 { 671 tmpMat->setSpecularMap(Buffer+7); 672 } 673 else if (!strncmp(Buffer, "bump ", 5)) 674 { 675 tmpMat->setBump(Buffer+7); 676 } 677 678 679 } 680 MTL_FILE->close(); 681 delete []fileName; 682 delete MTL_FILE; 683 return true; 548 /** 549 \brief adds a Texture Coordinate 550 \param u The u coordinate of the TextureCoordinate. 551 \param v The y coordinate of the TextureCoordinate. 552 553 If a TextureCoordinate line is found this function will inject it into the TextureCoordinate-Array 554 */ 555 bool Model::addVertexTexture(const float u, const float v) 556 { 557 PRINTF(3)("found vertex-Texture %f, %f\n", u, v); 558 this->vTexture->addEntry(u); 559 this->vTexture->addEntry(v); 684 560 } 685 561 … … 688 564 \param matString the Material that will be set. 689 565 */ 690 bool Model::readUseMtl (char* matString) 691 { 566 bool Model::addUseMtl (char* matString) 567 { 568 /* 692 569 if (!this->mtlFileName) 693 570 { … … 695 572 return false; 696 573 } 697 574 */ 698 575 if (this->currentGroup->faceCount >0) 699 576 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; … … 717 594 this->vertices->finalizeArray(); 718 595 this->vTexture->finalizeArray(); 719 if (normals->getCount() == 0) // vertices-Array must be uilt for this596 if (normals->getCount() == 0) // vertices-Array must be built for this 720 597 this->buildVertexNormals(); 721 598 this->normals->finalizeArray(); … … 743 620 glEnd(); 744 621 this->currentGroup->faceMode = 0; 745 PRINTF(2)("using material %s for coming Faces.\n", tmpFace->materialString);746 622 Material* tmpMat; 747 623 if ((tmpMat = material->search(tmpFace->materialString)) != NULL) 748 tmpMat->select(); 624 { 625 tmpMat->select(); 626 PRINTF(2)("using material %s for coming Faces.\n", tmpFace->materialString); 627 } 628 else 629 PRINTF(1)("material %s not found.\n", tmpFace->materialString); 630 749 631 750 632 } … … 893 775 normArray[i].normalize(); 894 776 PRINTF(3)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z); 895 777 896 778 this->normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z); 897 779 … … 907 789 This will inject a Cube, because this is the most basic model. 908 790 */ 909 void Model:: BoxModel(void)910 { 911 this-> readVertex ("-0.5 -0.5 0.5");912 this-> readVertex ("0.5 -0.5 0.5");913 this-> readVertex ("-0.5 0.5 0.5");914 this-> readVertex ("0.5 0.5 0.5");915 this-> readVertex ("-0.5 0.5 -0.5");916 this-> readVertex ("0.5 0.5 -0.5");917 this-> readVertex ("-0.5 -0.5 -0.5");918 this-> readVertex ("0.5 -0.5 -0.5");919 920 this-> readVertexTexture ("0.0 0.0");921 this-> readVertexTexture ("1.0 0.0");922 this-> readVertexTexture ("0.0 1.0");923 this-> readVertexTexture ("1.0 1.0");924 this-> readVertexTexture ("0.0 2.0");925 this-> readVertexTexture ("1.0 2.0");926 this-> readVertexTexture ("0.0 3.0");927 this-> readVertexTexture ("1.0 3.0");928 this-> readVertexTexture ("0.0 4.0");929 this-> readVertexTexture ("1.0 4.0");930 this-> readVertexTexture ("2.0 0.0");931 this-> readVertexTexture ("2.0 1.0");932 this-> readVertexTexture ("-1.0 0.0");933 this-> readVertexTexture ("-1.0 1.0");934 935 this-> readVertexNormal ("0.0 0.0 1.0");936 this-> readVertexNormal ("0.0 0.0 1.0");937 this-> readVertexNormal ("0.0 0.0 1.0");938 this-> readVertexNormal ("0.0 0.0 1.0");939 this-> readVertexNormal ("0.0 1.0 0.0");940 this-> readVertexNormal ("0.0 1.0 0.0");941 this-> readVertexNormal ("0.0 1.0 0.0");942 this-> readVertexNormal ("0.0 1.0 0.0");943 this-> readVertexNormal ("0.0 0.0 -1.0");944 this-> readVertexNormal ("0.0 0.0 -1.0");945 this-> readVertexNormal ("0.0 0.0 -1.0");946 this-> readVertexNormal ("0.0 0.0 -1.0");947 this-> readVertexNormal ("0.0 -1.0 0.0");948 this-> readVertexNormal ("0.0 -1.0 0.0");949 this-> readVertexNormal ("0.0 -1.0 0.0");950 this-> readVertexNormal ("0.0 -1.0 0.0");951 this-> readVertexNormal ("1.0 0.0 0.0");952 this-> readVertexNormal ("1.0 0.0 0.0");953 this-> readVertexNormal ("1.0 0.0 0.0");954 this-> readVertexNormal ("1.0 0.0 0.0");955 this-> readVertexNormal ("-1.0 0.0 0.0");956 this-> readVertexNormal ("-1.0 0.0 0.0");957 this-> readVertexNormal ("-1.0 0.0 0.0");958 this-> readVertexNormal ("-1.0 0.0 0.0");791 void Model::cubeModel(void) 792 { 793 this->addVertex ("-0.5 -0.5 0.5"); 794 this->addVertex ("0.5 -0.5 0.5"); 795 this->addVertex ("-0.5 0.5 0.5"); 796 this->addVertex ("0.5 0.5 0.5"); 797 this->addVertex ("-0.5 0.5 -0.5"); 798 this->addVertex ("0.5 0.5 -0.5"); 799 this->addVertex ("-0.5 -0.5 -0.5"); 800 this->addVertex ("0.5 -0.5 -0.5"); 801 802 this->addVertexTexture ("0.0 0.0"); 803 this->addVertexTexture ("1.0 0.0"); 804 this->addVertexTexture ("0.0 1.0"); 805 this->addVertexTexture ("1.0 1.0"); 806 this->addVertexTexture ("0.0 2.0"); 807 this->addVertexTexture ("1.0 2.0"); 808 this->addVertexTexture ("0.0 3.0"); 809 this->addVertexTexture ("1.0 3.0"); 810 this->addVertexTexture ("0.0 4.0"); 811 this->addVertexTexture ("1.0 4.0"); 812 this->addVertexTexture ("2.0 0.0"); 813 this->addVertexTexture ("2.0 1.0"); 814 this->addVertexTexture ("-1.0 0.0"); 815 this->addVertexTexture ("-1.0 1.0"); 816 817 this->addVertexNormal ("0.0 0.0 1.0"); 818 this->addVertexNormal ("0.0 0.0 1.0"); 819 this->addVertexNormal ("0.0 0.0 1.0"); 820 this->addVertexNormal ("0.0 0.0 1.0"); 821 this->addVertexNormal ("0.0 1.0 0.0"); 822 this->addVertexNormal ("0.0 1.0 0.0"); 823 this->addVertexNormal ("0.0 1.0 0.0"); 824 this->addVertexNormal ("0.0 1.0 0.0"); 825 this->addVertexNormal ("0.0 0.0 -1.0"); 826 this->addVertexNormal ("0.0 0.0 -1.0"); 827 this->addVertexNormal ("0.0 0.0 -1.0"); 828 this->addVertexNormal ("0.0 0.0 -1.0"); 829 this->addVertexNormal ("0.0 -1.0 0.0"); 830 this->addVertexNormal ("0.0 -1.0 0.0"); 831 this->addVertexNormal ("0.0 -1.0 0.0"); 832 this->addVertexNormal ("0.0 -1.0 0.0"); 833 this->addVertexNormal ("1.0 0.0 0.0"); 834 this->addVertexNormal ("1.0 0.0 0.0"); 835 this->addVertexNormal ("1.0 0.0 0.0"); 836 this->addVertexNormal ("1.0 0.0 0.0"); 837 this->addVertexNormal ("-1.0 0.0 0.0"); 838 this->addVertexNormal ("-1.0 0.0 0.0"); 839 this->addVertexNormal ("-1.0 0.0 0.0"); 840 this->addVertexNormal ("-1.0 0.0 0.0"); 959 841 960 842 /* normaleLess-testingMode 961 this-> readFace ("1 2 4 3");962 this-> readFace ("3 4 6 5");963 this-> readFace ("5 6 8 7");964 this-> readFace ("7 8 2 1");965 this-> readFace ("2 8 6 4");966 this-> readFace ("7 1 3 5");843 this->addFace ("1 2 4 3"); 844 this->addFace ("3 4 6 5"); 845 this->addFace ("5 6 8 7"); 846 this->addFace ("7 8 2 1"); 847 this->addFace ("2 8 6 4"); 848 this->addFace ("7 1 3 5"); 967 849 */ 968 850 969 this->readFace ("1/1/1 2/2/2 4/4/3 3/3/4"); 970 this->readFace ("3/3/5 4/4/6 6/6/7 5/5/8"); 971 this->readFace ("5/5/9 6/6/10 8/8/11 7/7/12"); 972 this->readFace ("7/7/13 8/8/14 2/10/15 1/9/16"); 973 this->readFace ("2/2/17 8/11/18 6/12/19 4/4/20"); 974 this->readFace ("7/13/21 1/1/22 3/3/23 5/14/24"); 975 976 } 851 this->addFace ("1/1/1 2/2/2 4/4/3 3/3/4"); 852 this->addFace ("3/3/5 4/4/6 6/6/7 5/5/8"); 853 this->addFace ("5/5/9 6/6/10 8/8/11 7/7/12"); 854 this->addFace ("7/7/13 8/8/14 2/10/15 1/9/16"); 855 this->addFace ("2/2/17 8/11/18 6/12/19 4/4/20"); 856 this->addFace ("7/13/21 1/1/22 3/3/23 5/14/24"); 857 858 } 859 860 861 void Model::sphereModel() 862 { 863 int detail = 30; 864 if (detail <= 0) detail = 1; 865 float df = (float)detail; 866 for (float i = 0.0; i < df/2; i+=1.0) 867 { 868 for (float j = 0.0; j < df; j+=1.0) 869 { 870 float vz = i/df *2.0*PI - PI/2.0; 871 this->addVertex(cos(j/df*2.0*PI) * cos(vz) , 872 sin(j/df*2.0*PI) * cos(vz), 873 sin(vz)); 874 //if (j==0.0) 875 //printf ("%f %f\n", vz, sin (vz)); 876 if (i==0.0) 877 printf("%f, %f\n", j/df*2.0*PI, cos(j/df*PI)); 878 } 879 } 880 vertices->debug(); 881 for (int i = 0; i < detail/2; i++) 882 for (int j = 1; j < detail; j++) 883 { 884 unsigned int v1,v2,v3,v4; 885 v1 = i*detail +j; 886 887 /* if (j+1 == detail) 888 { 889 v2 = i*detail +1; 890 v3 = i*detail+detail + 1; 891 } 892 else*/ 893 { 894 v2 = i*detail +j+1; 895 v3 = i*detail+detail + j+1; 896 } 897 v4 = i*detail+detail + j; 898 //printf("%i %i %i %i\n", v1, v2, v3, v4); 899 this->addFace(4, 0, v1, v2, v3, v4); 900 } 901 } 902 903 /** 904 \brief Creates a Cylinder. 905 */ 906 void Model::cylinderModel(void) 907 { 908 unsigned int detail = 20; 909 float size = 1.0; 910 911 // check if devision by zero 912 if (detail <= 3) 913 detail = 3; 914 int count = 0; 915 // defining Points of the Cylinder. 916 for (float phi = 0.0; phi < 2.0*PI; phi += 2.0*PI/(float)detail) 917 { 918 this->addVertex(size*cos(phi), size*sin(phi), -size); 919 this->addVertex(size*cos(phi), size*sin(phi), size); 920 count ++; 921 } 922 this->addVertex(0, 0, -size); 923 this->addVertex(0, 0, size); 924 925 926 if (count != detail) 927 cout << "calculation error, count should be " << detail << " but is " << count << endl; 928 vertices->debug(); 929 930 // adding Faces 931 for (int i = 0; i < detail-1; i++) 932 { 933 int p1, p2, p3, p4; 934 p1 = 2*i+1; 935 p2 = 2*i+2; 936 if (i <= detail); 937 p3 = 2*i+4; 938 p4 = 2*i+3; 939 cout <<i+1 <<": "<< p1 <<" "<< p2 <<" "<< p3 <<" "<< p4 <<endl; 940 this->addFace(4, 0, p1, p2, p3, p4); 941 this->addFace(3, 0, p4, p1, 2*detail+1); 942 this->addFace(3, 0, p2, p3, 2*detail+2); 943 } 944 addFace(4,0, 2*detail-1, 2*detail, 2, 1); 945 this->addFace(3, 0, 1, 2*detail-1, 2*detail+1); 946 this->addFace(3, 0, 2*detail, 2, 2*detail+2); 947 948 } -
orxonox/branches/trackManager/src/importer/model.h
r3369 r3430 7 7 #define _MODEL_H 8 8 9 #include "../stdincl.h"9 //#include "../stdincl.h" 10 10 11 #include "array.h"12 11 #include "material.h" 13 #include "vector.h" 14 #include <fstream> 12 13 // FORWARD DEFINITION // 14 class Array; 15 class Vector; 15 16 16 17 using namespace std; 17 18 18 19 enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER}; 19 20 20 21 //! Class that handles 3D-Models. it can also read them in and display them. … … 22 23 { 23 24 public: 24 Model (); 25 Model (char* fileName); 26 Model(char* fileName, float scaling); 27 ~Model (); 25 Model(void); 26 Model(PRIMITIVE type); 27 Model(char* modelName); 28 virtual ~Model(void); 29 30 void setName(const char* name); 28 31 29 void draw 30 void draw 31 void draw 32 void draw(void) const; 33 void draw(int groupNumber) const; 34 void draw(char* groupName) const; 32 35 int getGroupCount() const; 33 36 34 private: 37 protected: 38 char* name; //!< This is the name of the Model. 39 bool finalized; //!< Sets the Object to be finalized. 40 35 41 //! This is the placeholder of one Vertex beloning to a Face. 36 struct FaceElement 42 struct FaceElement 37 43 { 38 44 int vertexNumber; //!< The number of the Vertex out of the Array* vertices, this vertex points to. … … 43 49 44 50 //! This is the placeholder of a Face belonging to a Group of Faces. 45 /** 46 \todo take Material to a call for itself. 47 48 This can also be a Material-Change switch. 49 That means if you want to change a Material inside of a group, 50 you can create an empty face and apply a material to it, and the Importer will cahnge Colors 51 */ 52 struct Face 51 struct Face 53 52 { 54 53 int vertexCount; //!< The Count of vertices this Face has. … … 65 64 char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function. 66 65 67 GLuint listNumber;//!< The number of the GL-List this Group gets.66 unsigned int listNumber;//!< The number of the GL-List this Group gets. 68 67 Face* firstFace; //!< The first Face in this group. 69 68 Face* currentFace; //!< The current Face in this Group (the one we are currently working with.) … … 88 87 float scaleFactor; //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation 89 88 90 char* objPath; //!< The Path wher the obj and mtl-file are located. 91 char* objFileName; //!< The Name of the obj-file. 92 char* mtlFileName; //!< The Name of the mtl-file (parsed out of the obj-file) 93 94 bool initialize (void); 89 bool initialize(void); 95 90 bool initGroup(Group* group); 96 91 bool initFace (Face* face); … … 100 95 bool cleanupFaceElement(FaceElement* faceElem); 101 96 102 ///// readin /// 103 bool importFile (char* fileName); 104 bool readFromObjFile (void); 105 106 bool readGroup (char* groupString); 107 bool readVertex (char* vertexString); 108 bool readFace (char* faceString); 109 bool readVertexNormal (char* normalString); 110 bool readVertexTexture (char* vTextureString); 111 bool readMtlLib (char* matFile); 112 bool readUseMtl (char* mtlString); 97 public: 98 bool addGroup(char* groupString); 99 bool addVertex(char* vertexString); 100 bool addVertex(const float x, const float y, const float z); 101 bool addFace(char* faceString); 102 bool addFace(const float faceElemCount, int type, ...); 103 bool addVertexNormal(char* normalString); 104 bool addVertexNormal(const float x, const float y, const float z); 105 bool addVertexTexture(char* vTextureString); 106 bool addVertexTexture(const float u, const float v); 107 bool addUseMtl(char* mtlString); 108 void finalize(void); 113 109 114 bool importToGL (void); 115 bool addGLElement (FaceElement* elem); 110 protected: 111 bool importToGL(void); 112 bool addGLElement(FaceElement* elem); 116 113 117 bool buildVertexNormals ();114 bool buildVertexNormals(void); 118 115 119 void BoxModel (void); 116 void cubeModel(void); 117 void sphereModel(void); 118 void cylinderModel(void); 120 119 }; 121 120
Note: See TracChangeset
for help on using the changeset viewer.