[2823] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Benjamin Grauer |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[3360] | 16 | #include "model.h" |
---|
[3196] | 17 | int verbose = 1; //! \todo should be GLOBAL |
---|
[3140] | 18 | using namespace std; |
---|
[2776] | 19 | |
---|
[2842] | 20 | /** |
---|
[3360] | 21 | \brief Creates a 3D-Model, but does not load any 3D-models. |
---|
[3186] | 22 | |
---|
[3360] | 23 | This Constructor is pretty useless, because why load no model in an model-loader?? |
---|
[2842] | 24 | */ |
---|
[3360] | 25 | Model::Model () |
---|
[2748] | 26 | { |
---|
[2765] | 27 | |
---|
[3195] | 28 | this->initialize(); |
---|
[2847] | 29 | |
---|
[3360] | 30 | this->BoxModel(); |
---|
[2765] | 31 | |
---|
[3195] | 32 | this->importToGL (); |
---|
[3064] | 33 | |
---|
[3195] | 34 | this->cleanup(); |
---|
[2767] | 35 | } |
---|
| 36 | |
---|
[2842] | 37 | /** |
---|
[3360] | 38 | \brief Crates a 3D-Model and loads in a File. |
---|
[2842] | 39 | \param fileName file to parse and load (must be a .obj file) |
---|
| 40 | */ |
---|
[3360] | 41 | Model::Model(char* fileName) |
---|
[2773] | 42 | { |
---|
[3195] | 43 | this->initialize(); |
---|
[2773] | 44 | |
---|
[3195] | 45 | this->importFile (fileName); |
---|
[2773] | 46 | |
---|
[3195] | 47 | this->importToGL (); |
---|
[3064] | 48 | |
---|
[3195] | 49 | this->cleanup(); |
---|
[2773] | 50 | } |
---|
| 51 | |
---|
[2842] | 52 | /** |
---|
[3360] | 53 | \brief Crates a 3D-Model, loads in a File and scales it. |
---|
[2842] | 54 | \param fileName file to parse and load (must be a .obj file) |
---|
[3360] | 55 | \param scaling The factor that the model will be scaled with. |
---|
[2842] | 56 | */ |
---|
[3360] | 57 | Model::Model(char* fileName, float scaling) |
---|
[2767] | 58 | { |
---|
[3195] | 59 | this->initialize(); |
---|
| 60 | this->scaleFactor = scaling; |
---|
[2833] | 61 | |
---|
[3195] | 62 | this->importFile (fileName); |
---|
[2833] | 63 | |
---|
[3195] | 64 | this->importToGL (); |
---|
[3064] | 65 | |
---|
[3195] | 66 | this->cleanup(); |
---|
[2767] | 67 | } |
---|
| 68 | |
---|
[2847] | 69 | /** |
---|
[3360] | 70 | \brief deletes an Model. |
---|
[3186] | 71 | |
---|
[3360] | 72 | Looks if any from model allocated space is still in use, and if so deleted it. |
---|
[2847] | 73 | */ |
---|
[3360] | 74 | Model::~Model() |
---|
[2847] | 75 | { |
---|
[3206] | 76 | PRINTF(2)("Deleting display Lists.\n"); |
---|
[3195] | 77 | Group* walker = this->firstGroup; |
---|
[2850] | 78 | while (walker != NULL) |
---|
| 79 | { |
---|
| 80 | glDeleteLists (walker->listNumber, 1); |
---|
[3066] | 81 | Group* delWalker = walker; |
---|
[3063] | 82 | walker = walker->next; |
---|
[3066] | 83 | delete delWalker; |
---|
[3140] | 84 | } |
---|
| 85 | |
---|
[3195] | 86 | if (this->objPath) |
---|
| 87 | delete []this->objPath; |
---|
| 88 | if (this->objFileName) |
---|
| 89 | delete []this->objFileName; |
---|
| 90 | if (this->mtlFileName) |
---|
| 91 | delete []this->mtlFileName; |
---|
[3206] | 92 | PRINTF(2)("Deleting Materials.\n"); |
---|
[3195] | 93 | if (this->material) |
---|
| 94 | delete this->material; |
---|
[2847] | 95 | } |
---|
| 96 | |
---|
[2833] | 97 | |
---|
[2842] | 98 | /** |
---|
[3360] | 99 | \brief Draws the Models of all Groups. |
---|
[2851] | 100 | It does this by just calling the Lists that must have been created earlier. |
---|
[2842] | 101 | */ |
---|
[3360] | 102 | void Model::draw (void) const |
---|
[2748] | 103 | { |
---|
[3360] | 104 | PRINTF(2)("drawing the 3D-Models\n"); |
---|
[3195] | 105 | Group* walker = this->firstGroup; |
---|
[2850] | 106 | while (walker != NULL) |
---|
| 107 | { |
---|
[3360] | 108 | PRINTF(3)("Drawing model %s\n", walker->name); |
---|
[2850] | 109 | glCallList (walker->listNumber); |
---|
[3063] | 110 | walker = walker->next; |
---|
[2850] | 111 | } |
---|
[2748] | 112 | } |
---|
[2754] | 113 | |
---|
[2842] | 114 | /** |
---|
[3360] | 115 | \brief Draws the Model number groupNumber |
---|
[3186] | 116 | \param groupNumber The number of the group that will be displayed. |
---|
| 117 | |
---|
[2851] | 118 | It does this by just calling the List that must have been created earlier. |
---|
| 119 | */ |
---|
[3360] | 120 | void Model::draw (int groupNumber) const |
---|
[2851] | 121 | { |
---|
[3195] | 122 | if (groupNumber >= this->groupCount) |
---|
[2852] | 123 | { |
---|
[3360] | 124 | PRINTF(1)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount); |
---|
[2852] | 125 | return; |
---|
| 126 | } |
---|
[3360] | 127 | PRINTF(2)("drawing the requested 3D-Models if found.\n"); |
---|
[3195] | 128 | Group* walker = this->firstGroup; |
---|
[2851] | 129 | int counter = 0; |
---|
| 130 | while (walker != NULL) |
---|
| 131 | { |
---|
| 132 | if (counter == groupNumber) |
---|
| 133 | { |
---|
[3360] | 134 | PRINTF(2)("Drawing model number %i named %s\n", counter, walker->name); |
---|
[2851] | 135 | glCallList (walker->listNumber); |
---|
| 136 | return; |
---|
| 137 | } |
---|
| 138 | ++counter; |
---|
[3063] | 139 | walker = walker->next; |
---|
[2851] | 140 | } |
---|
[3360] | 141 | PRINTF(1)("Model number %i in %s not Found.\n", groupNumber, this->objFileName); |
---|
[2851] | 142 | return; |
---|
| 143 | |
---|
| 144 | } |
---|
[2852] | 145 | |
---|
| 146 | /** |
---|
[3360] | 147 | \brief Draws the Model with a specific groupName |
---|
[3186] | 148 | \param groupName The name of the group that will be displayed. |
---|
| 149 | |
---|
[2852] | 150 | It does this by just calling the List that must have been created earlier. |
---|
| 151 | */ |
---|
[3360] | 152 | void Model::draw (char* groupName) const |
---|
[2851] | 153 | { |
---|
[3360] | 154 | PRINTF(2)("drawing the requested 3D-Models if found.\n"); |
---|
[3195] | 155 | Group* walker = this->firstGroup; |
---|
[2851] | 156 | while (walker != NULL) |
---|
| 157 | { |
---|
| 158 | if (!strcmp(walker->name, groupName)) |
---|
| 159 | { |
---|
[3360] | 160 | PRINTF(2)("Drawing model %s\n", walker->name); |
---|
[2851] | 161 | glCallList (walker->listNumber); |
---|
| 162 | return; |
---|
| 163 | } |
---|
[3063] | 164 | walker = walker->next; |
---|
[2851] | 165 | } |
---|
[3360] | 166 | PRINTF(1)("Model Named %s in %s not Found.\n", groupName, this->objFileName); |
---|
[2851] | 167 | return; |
---|
| 168 | } |
---|
| 169 | |
---|
[2852] | 170 | /** |
---|
[3360] | 171 | \returns Count of the Models in this File |
---|
[2852] | 172 | */ |
---|
[3360] | 173 | int Model::getGroupCount (void) const |
---|
[2852] | 174 | { |
---|
[3195] | 175 | return this->groupCount; |
---|
[2852] | 176 | } |
---|
[2851] | 177 | |
---|
| 178 | /** |
---|
[3360] | 179 | \brief initializes the Model. |
---|
[3186] | 180 | |
---|
| 181 | This Function initializes all the needed arrays, Lists and clientStates. |
---|
| 182 | It also defines default values. |
---|
[3066] | 183 | */ |
---|
[3360] | 184 | bool Model::initialize (void) |
---|
[3066] | 185 | { |
---|
[3360] | 186 | PRINTF(2)("new 3D-Model is being created\n"); |
---|
[3066] | 187 | |
---|
| 188 | // setting the start group; |
---|
[3195] | 189 | this->firstGroup = new Group; |
---|
| 190 | this->currentGroup = this->firstGroup; |
---|
| 191 | this->groupCount = 0; |
---|
[3066] | 192 | |
---|
[3195] | 193 | this->initGroup (this->currentGroup); |
---|
| 194 | this->objPath = NULL; |
---|
| 195 | this->objFileName = NULL; |
---|
| 196 | this->mtlFileName = NULL; |
---|
| 197 | this->scaleFactor = 1; |
---|
| 198 | this->material = new Material(); |
---|
[3066] | 199 | |
---|
[3195] | 200 | this->vertices = new Array(); |
---|
| 201 | this->vTexture = new Array(); |
---|
| 202 | this->normals = new Array(); |
---|
[3066] | 203 | |
---|
| 204 | return true; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | /** |
---|
[3360] | 208 | \brief initializes a new Group model |
---|
[3186] | 209 | \param group the group that should be initialized. |
---|
| 210 | \todo Maybe Group should be a Class, because it does a lot of stuff |
---|
| 211 | |
---|
[2850] | 212 | */ |
---|
[3360] | 213 | bool Model::initGroup(Group* group) |
---|
[2850] | 214 | { |
---|
[3207] | 215 | PRINTF(3)("Adding new Group\n"); |
---|
[2863] | 216 | group->name = ""; |
---|
[2850] | 217 | group->faceMode = -1; |
---|
[2967] | 218 | group->faceCount = 0; |
---|
[3063] | 219 | group->next = NULL; |
---|
[2850] | 220 | |
---|
[3063] | 221 | group->firstFace = new Face; |
---|
[3195] | 222 | this->initFace (group->firstFace); |
---|
[3063] | 223 | group->currentFace = group->firstFace; |
---|
[2850] | 224 | } |
---|
| 225 | |
---|
| 226 | /** |
---|
[3066] | 227 | \brief initializes a new Face. (sets default Values) |
---|
[3186] | 228 | \param face The face to initialize |
---|
[2850] | 229 | */ |
---|
[3360] | 230 | bool Model::initFace (Face* face) |
---|
[2850] | 231 | { |
---|
[3066] | 232 | face->vertexCount = 0; |
---|
[2967] | 233 | |
---|
[3066] | 234 | face->firstElem = NULL; |
---|
| 235 | |
---|
| 236 | face->materialString = NULL; |
---|
| 237 | |
---|
| 238 | face->next = NULL; |
---|
| 239 | |
---|
| 240 | return true; |
---|
[2850] | 241 | } |
---|
[2863] | 242 | |
---|
[2850] | 243 | /** |
---|
[3360] | 244 | \brief finalizes an Model. |
---|
[3066] | 245 | This funcion is needed, to delete all the Lists, and arrays that are no more needed because they are already imported into openGL. This will be applied at the end of the importing Process. |
---|
| 246 | */ |
---|
[3360] | 247 | bool Model::cleanup(void) |
---|
[3066] | 248 | { |
---|
[3360] | 249 | PRINTF(3)("cleaning up the 3D-Model to save Memory.\n"); |
---|
[3066] | 250 | |
---|
[3195] | 251 | if (this->vertices) |
---|
| 252 | delete this->vertices; |
---|
| 253 | if (this->vTexture) |
---|
| 254 | delete this->vTexture; |
---|
| 255 | if (this->normals) |
---|
| 256 | delete this->normals; |
---|
[3066] | 257 | |
---|
[3195] | 258 | this->cleanupGroup(this->firstGroup); |
---|
[3066] | 259 | return true; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | /** |
---|
[3068] | 263 | \brief Cleans up all groups starting from group. |
---|
| 264 | \param group the first Group to clean |
---|
| 265 | */ |
---|
[3360] | 266 | bool Model::cleanupGroup (Group* group) |
---|
[3068] | 267 | { |
---|
[3207] | 268 | PRINTF(3)("Cleaning up group\n"); |
---|
[3068] | 269 | if (group->firstFace != NULL) |
---|
| 270 | { |
---|
| 271 | cleanupFace (group->firstFace); |
---|
| 272 | delete group->firstFace; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | if (group->next !=NULL) |
---|
| 276 | cleanupGroup (group->next); |
---|
| 277 | return true; |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | /** |
---|
[3186] | 281 | \brief Cleans up all Faces starting from face until NULL is reached. |
---|
| 282 | \param face the first face to clean. |
---|
[3068] | 283 | */ |
---|
[3360] | 284 | bool Model::cleanupFace (Face* face) |
---|
[3068] | 285 | { |
---|
[3207] | 286 | PRINTF(3)("Cleaning up Face\n"); |
---|
[3068] | 287 | |
---|
| 288 | if (face->materialString != NULL) |
---|
[3080] | 289 | delete []face->materialString; |
---|
[3068] | 290 | if (face->firstElem != NULL) |
---|
| 291 | { |
---|
[3195] | 292 | this->cleanupFaceElement(face->firstElem); |
---|
[3068] | 293 | delete face->firstElem; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | if (face->next != NULL) |
---|
| 297 | { |
---|
[3195] | 298 | this->cleanupFace (face->next); |
---|
[3068] | 299 | delete face->next; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | |
---|
| 305 | /** |
---|
| 306 | \brief Cleans up all FaceElements starting from faceElem. |
---|
| 307 | \param faceElem the first FaceElement to clean. |
---|
| 308 | */ |
---|
[3360] | 309 | bool Model::cleanupFaceElement(FaceElement* faceElem) |
---|
[3068] | 310 | { |
---|
| 311 | if (faceElem->next != NULL) |
---|
| 312 | { |
---|
[3195] | 313 | this->cleanupFaceElement (faceElem->next); |
---|
[3072] | 314 | delete faceElem->next; |
---|
[3068] | 315 | } |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | /** |
---|
[3066] | 319 | \brief Imports a obj file and handles the the relative location |
---|
| 320 | \param fileName The file to import |
---|
| 321 | */ |
---|
[3360] | 322 | bool Model::importFile (char* fileName) |
---|
[3066] | 323 | { |
---|
[3207] | 324 | PRINTF(3)("preparing to read in file: %s\n", fileName); |
---|
[3140] | 325 | |
---|
| 326 | |
---|
| 327 | #ifdef __WIN32__ |
---|
| 328 | // win32 path reading |
---|
| 329 | char pathSplitter= '\\'; |
---|
| 330 | #else /* __WIN32__ */ |
---|
| 331 | // unix path reading |
---|
| 332 | 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 | } |
---|
[3195] | 342 | this->objPath = new char[name-fileName]; |
---|
| 343 | strncpy(this->objPath, fileName, name-fileName); |
---|
| 344 | this->objPath[name-fileName] = '\0'; |
---|
[3140] | 345 | if (verbose >=2) |
---|
| 346 | if (strlen(objPath)> 0) |
---|
[3207] | 347 | PRINTF(0)("Resolved file %s to folder: %s.\n", name, objPath); |
---|
[3140] | 348 | else |
---|
[3207] | 349 | PRINTF(0)("Resolved file %s.\n", name); |
---|
[3140] | 350 | |
---|
[3195] | 351 | if (this->material) |
---|
| 352 | this->material->addTexturePath(this->objPath); |
---|
| 353 | this->objFileName = new char[strlen(name)+1]; |
---|
| 354 | strcpy (this->objFileName, name); |
---|
[3140] | 355 | this->readFromObjFile (); |
---|
[3066] | 356 | return true; |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | /** |
---|
[2842] | 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 tasks |
---|
| 362 | */ |
---|
[3360] | 363 | bool Model::readFromObjFile (void) |
---|
[2754] | 364 | { |
---|
[3140] | 365 | char* fileName = new char [strlen(objPath)+strlen(objFileName)+1]; |
---|
[3195] | 366 | if (this->objFileName != NULL && !strcmp(this->objFileName, "")) |
---|
[3140] | 367 | return false; |
---|
[3195] | 368 | strcpy(fileName, this->objPath); |
---|
| 369 | strcat(fileName, this->objFileName); |
---|
[3140] | 370 | |
---|
| 371 | ifstream* OBJ_FILE = new ifstream(fileName); |
---|
| 372 | if (OBJ_FILE->fail()) |
---|
[2775] | 373 | { |
---|
[3360] | 374 | PRINTF(1)("unable to open .OBJ file: %s\n Loading Box Model instead.\n", fileName); |
---|
| 375 | BoxModel(); |
---|
[3195] | 376 | OBJ_FILE->close(); |
---|
[3140] | 377 | delete []fileName; |
---|
[3195] | 378 | delete OBJ_FILE; |
---|
[2775] | 379 | return false; |
---|
| 380 | } |
---|
[3207] | 381 | PRINTF(2)("Reading from opened file %s\n", fileName); |
---|
[2931] | 382 | char Buffer[10000]; |
---|
[2765] | 383 | while(!OBJ_FILE->eof()) |
---|
| 384 | { |
---|
[2931] | 385 | OBJ_FILE->getline(Buffer, 10000); |
---|
[3207] | 386 | PRINTF(3)("Read input line: %s\n", Buffer); |
---|
[2765] | 387 | |
---|
| 388 | |
---|
| 389 | // case vertice |
---|
| 390 | if (!strncmp(Buffer, "v ", 2)) |
---|
| 391 | { |
---|
[3195] | 392 | this->readVertex(Buffer+2); |
---|
[2765] | 393 | } |
---|
| 394 | |
---|
| 395 | // case face |
---|
| 396 | else if (!strncmp(Buffer, "f ", 2)) |
---|
| 397 | { |
---|
[3195] | 398 | this->readFace (Buffer+2); |
---|
[2765] | 399 | } |
---|
[2776] | 400 | |
---|
[3063] | 401 | else if (!strncmp(Buffer, "mtllib ", 7)) |
---|
[2776] | 402 | { |
---|
[3195] | 403 | this->readMtlLib (Buffer+7); |
---|
[2776] | 404 | } |
---|
[2765] | 405 | |
---|
[3063] | 406 | else if (!strncmp(Buffer, "usemtl ", 7)) |
---|
[2769] | 407 | { |
---|
[3195] | 408 | this->readUseMtl (Buffer+7); |
---|
[2769] | 409 | } |
---|
[2794] | 410 | |
---|
| 411 | // case VertexNormal |
---|
[3063] | 412 | else if (!strncmp(Buffer, "vn ", 3)) |
---|
[3195] | 413 | { |
---|
| 414 | this->readVertexNormal(Buffer+3); |
---|
| 415 | } |
---|
| 416 | |
---|
[2848] | 417 | // case VertexTextureCoordinate |
---|
[3063] | 418 | else if (!strncmp(Buffer, "vt ", 3)) |
---|
[3195] | 419 | { |
---|
| 420 | this->readVertexTexture(Buffer+3); |
---|
| 421 | } |
---|
[2848] | 422 | // case group |
---|
[3063] | 423 | else if (!strncmp(Buffer, "g ", 2)) |
---|
[2848] | 424 | { |
---|
[3195] | 425 | this->readGroup (Buffer+2); |
---|
[2848] | 426 | } |
---|
[3195] | 427 | else if (!strncmp(Buffer, "s ", 2)) //! \todo smoothing groups have to be implemented |
---|
[2995] | 428 | { |
---|
[3069] | 429 | if (verbose >= 2) |
---|
[3207] | 430 | PRINTF(2)("smoothing groups not supportet yet. line: %s\n", Buffer); |
---|
[2995] | 431 | } |
---|
[2765] | 432 | } |
---|
[2846] | 433 | OBJ_FILE->close(); |
---|
[3195] | 434 | delete OBJ_FILE; |
---|
[3140] | 435 | delete []fileName; |
---|
[2863] | 436 | return true; |
---|
[2765] | 437 | |
---|
[2767] | 438 | } |
---|
[2765] | 439 | |
---|
[2842] | 440 | /** |
---|
[3066] | 441 | \brief parses a group String |
---|
[3186] | 442 | \param groupString the new Group to create |
---|
| 443 | |
---|
[3066] | 444 | This function initializes a new Group. |
---|
[3360] | 445 | With it you should be able to import .obj-files with more than one Models inside. |
---|
[3066] | 446 | */ |
---|
[3360] | 447 | bool Model::readGroup (char* groupString) |
---|
[3066] | 448 | { |
---|
[3207] | 449 | PRINTF(3)("Read Group: %s.\n", groupString); |
---|
[3195] | 450 | if (this->groupCount != 0 && this->currentGroup->faceCount>0) |
---|
[3066] | 451 | { |
---|
| 452 | // finalizeGroup(currentGroup); |
---|
[3195] | 453 | this->currentGroup = this->currentGroup->next = new Group; |
---|
| 454 | this->initGroup(this->currentGroup); |
---|
[3066] | 455 | } |
---|
[3140] | 456 | // setting the group name if not default. |
---|
| 457 | if (strcmp(groupString, "default")) |
---|
| 458 | { |
---|
[3195] | 459 | this->currentGroup->name = new char [strlen(groupString)+1]; |
---|
| 460 | strcpy(this->currentGroup->name, groupString); |
---|
[3140] | 461 | } |
---|
[3195] | 462 | ++this->groupCount; |
---|
[3066] | 463 | |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | /** |
---|
[2842] | 467 | \brief parses a vertex-String |
---|
[3186] | 468 | \param vertexString The String that will be parsed. |
---|
| 469 | |
---|
[2842] | 470 | If a vertex line is found this function will inject it into the vertex-Array |
---|
| 471 | */ |
---|
[3360] | 472 | bool Model::readVertex (char* vertexString) |
---|
[2767] | 473 | { |
---|
[3071] | 474 | float subbuffer1; |
---|
| 475 | float subbuffer2; |
---|
| 476 | float subbuffer3; |
---|
| 477 | sscanf (vertexString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); |
---|
[3207] | 478 | PRINTF(3)("reading in a vertex: %f %f %f\n", &subbuffer1, &subbuffer2, &subbuffer3); |
---|
[3195] | 479 | this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor); |
---|
[2767] | 480 | return true; |
---|
| 481 | } |
---|
| 482 | |
---|
[2842] | 483 | /** |
---|
| 484 | \brief parses a face-string |
---|
[3186] | 485 | \param faceString The String that will be parsed. |
---|
| 486 | |
---|
[2842] | 487 | 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 | */ |
---|
[3360] | 490 | bool Model::readFace (char* faceString) |
---|
[2767] | 491 | { |
---|
[3195] | 492 | if (this->currentGroup->faceCount >0) |
---|
| 493 | this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; |
---|
| 494 | this->initFace (this->currentGroup->currentFace); |
---|
[2767] | 495 | |
---|
[3195] | 496 | FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement; |
---|
[3068] | 497 | tmpElem->next = NULL; |
---|
[2934] | 498 | while(strcmp (faceString, "\0")) |
---|
[2767] | 499 | { |
---|
[3195] | 500 | if (this->currentGroup->currentFace->vertexCount>0) |
---|
[2934] | 501 | tmpElem = tmpElem->next = new FaceElement; |
---|
| 502 | tmpElem->next = NULL; |
---|
| 503 | |
---|
[3064] | 504 | char tmpValue [50]; |
---|
[3072] | 505 | int tmpLen; |
---|
| 506 | char* vertex = NULL; |
---|
| 507 | char* texture = NULL; |
---|
| 508 | char* normal = NULL; |
---|
| 509 | |
---|
[3063] | 510 | sscanf (faceString, "%s", tmpValue); |
---|
[3072] | 511 | tmpLen = strlen(tmpValue); |
---|
| 512 | vertex = tmpValue; |
---|
[2934] | 513 | |
---|
[3072] | 514 | if ((texture = strstr (vertex, "/")) != NULL) |
---|
| 515 | { |
---|
| 516 | texture[0] = '\0'; |
---|
| 517 | texture ++; |
---|
| 518 | |
---|
| 519 | if ((normal = strstr (texture, "/")) !=NULL) |
---|
| 520 | { |
---|
| 521 | normal[0] = '\0'; |
---|
| 522 | normal ++; |
---|
| 523 | } |
---|
| 524 | } |
---|
| 525 | if (vertex) |
---|
[3073] | 526 | tmpElem->vertexNumber = atoi(vertex)-1; |
---|
[3072] | 527 | else |
---|
[3073] | 528 | tmpElem->vertexNumber = -1; |
---|
[3072] | 529 | if (texture) |
---|
[3073] | 530 | tmpElem->texCoordNumber = atoi(texture)-1; |
---|
[3072] | 531 | else |
---|
[3073] | 532 | tmpElem->texCoordNumber = -1; |
---|
[3072] | 533 | if (normal) |
---|
[3073] | 534 | tmpElem->normalNumber = atoi(normal)-1; |
---|
[3072] | 535 | else |
---|
[3073] | 536 | tmpElem->normalNumber = -1; |
---|
[3072] | 537 | |
---|
| 538 | faceString += tmpLen; |
---|
[2934] | 539 | if (strcmp (faceString, "\0")) |
---|
| 540 | faceString++; |
---|
[3195] | 541 | this->currentGroup->currentFace->vertexCount++; |
---|
[2934] | 542 | } |
---|
| 543 | |
---|
[3195] | 544 | this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2; |
---|
[2754] | 545 | } |
---|
[2768] | 546 | |
---|
[2842] | 547 | /** |
---|
| 548 | \brief parses a vertexNormal-String |
---|
[3186] | 549 | \param normalString The String that will be parsed. |
---|
| 550 | |
---|
[2842] | 551 | If a vertexNormal line is found this function will inject it into the vertexNormal-Array |
---|
| 552 | */ |
---|
[3360] | 553 | bool Model::readVertexNormal (char* normalString) |
---|
[2794] | 554 | { |
---|
[3071] | 555 | float subbuffer1; |
---|
| 556 | float subbuffer2; |
---|
| 557 | float subbuffer3; |
---|
| 558 | sscanf (normalString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); |
---|
[3207] | 559 | PRINTF(3)("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3); |
---|
[3195] | 560 | this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3); |
---|
[2794] | 561 | return true; |
---|
| 562 | } |
---|
| 563 | |
---|
[2842] | 564 | /** |
---|
| 565 | \brief parses a vertexTextureCoordinate-String |
---|
| 566 | \param vTextureString The String that will be parsed. |
---|
[3186] | 567 | |
---|
| 568 | If a vertexTextureCoordinate line is found, |
---|
| 569 | this function will inject it into the vertexTexture-Array |
---|
[2842] | 570 | */ |
---|
[3360] | 571 | bool Model::readVertexTexture (char* vTextureString) |
---|
[2820] | 572 | { |
---|
[3071] | 573 | float subbuffer1; |
---|
| 574 | float subbuffer2; |
---|
| 575 | sscanf (vTextureString, "%f %f", &subbuffer1, &subbuffer2); |
---|
[3207] | 576 | PRINTF(3)("found vertex-Texture %f, %f\n", &subbuffer1, &subbuffer2); |
---|
[3195] | 577 | this->vTexture->addEntry(subbuffer1); |
---|
| 578 | this->vTexture->addEntry(subbuffer2); |
---|
[2820] | 579 | return true; |
---|
| 580 | } |
---|
| 581 | |
---|
[3066] | 582 | /** |
---|
| 583 | \brief Function to read in a mtl File. |
---|
| 584 | \param mtlFile The .mtl file to read |
---|
[3186] | 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 | |
---|
[2850] | 590 | */ |
---|
[3360] | 591 | bool Model::readMtlLib (char* mtlFile) |
---|
[2850] | 592 | { |
---|
[3195] | 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); |
---|
[3140] | 598 | |
---|
| 599 | |
---|
[3340] | 600 | PRINTF(3)("Opening mtlFile: %s\n", fileName); |
---|
[3140] | 601 | |
---|
| 602 | ifstream* MTL_FILE = new ifstream (fileName); |
---|
| 603 | if (MTL_FILE->fail()) |
---|
[2850] | 604 | { |
---|
[3340] | 605 | PRINTF(1)("unable to open file: %s\n", fileName); |
---|
[3195] | 606 | MTL_FILE->close(); |
---|
[3140] | 607 | delete []fileName; |
---|
[3195] | 608 | delete MTL_FILE; |
---|
[3066] | 609 | return false; |
---|
[2850] | 610 | } |
---|
[3066] | 611 | char Buffer[500]; |
---|
| 612 | Material* tmpMat = material; |
---|
| 613 | while(!MTL_FILE->eof()) |
---|
[2850] | 614 | { |
---|
[3066] | 615 | MTL_FILE->getline(Buffer, 500); |
---|
[3207] | 616 | PRINTF(4)("found line in mtlFile: %s\n", Buffer); |
---|
[3066] | 617 | |
---|
[2863] | 618 | |
---|
[3066] | 619 | // create new Material |
---|
| 620 | if (!strncmp(Buffer, "newmtl ", 7)) |
---|
| 621 | { |
---|
| 622 | tmpMat = tmpMat->addMaterial(Buffer+7); |
---|
[3207] | 623 | // PRINTF(2)("%s, %p\n", tmpMat->getName(), tmpMat); |
---|
[3066] | 624 | } |
---|
| 625 | // setting a illumMode |
---|
| 626 | else if (!strncmp(Buffer, "illum ", 6)) |
---|
| 627 | { |
---|
| 628 | tmpMat->setIllum(Buffer+6); |
---|
[2863] | 629 | |
---|
[3066] | 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 | } |
---|
[3070] | 656 | else if (!strncmp(Buffer, "Tf ", 3)) |
---|
[3066] | 657 | { |
---|
| 658 | tmpMat->setTransparency(Buffer+3); |
---|
| 659 | } |
---|
[3070] | 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 | |
---|
[3066] | 678 | |
---|
| 679 | } |
---|
[3195] | 680 | MTL_FILE->close(); |
---|
[3140] | 681 | delete []fileName; |
---|
[3195] | 682 | delete MTL_FILE; |
---|
[3066] | 683 | return true; |
---|
[2850] | 684 | } |
---|
| 685 | |
---|
[3066] | 686 | /** |
---|
| 687 | \brief Function that selects a material, if changed in the obj file. |
---|
| 688 | \param matString the Material that will be set. |
---|
| 689 | */ |
---|
[3360] | 690 | bool Model::readUseMtl (char* matString) |
---|
[3063] | 691 | { |
---|
[3195] | 692 | if (!this->mtlFileName) |
---|
[3066] | 693 | { |
---|
[3207] | 694 | PRINTF(4)("Not using new defined material, because no mtlFile found yet\n"); |
---|
[3066] | 695 | return false; |
---|
| 696 | } |
---|
| 697 | |
---|
[3195] | 698 | if (this->currentGroup->faceCount >0) |
---|
| 699 | this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; |
---|
| 700 | this->initFace (this->currentGroup->currentFace); |
---|
[3063] | 701 | |
---|
[3195] | 702 | this->currentGroup->currentFace->materialString = new char[strlen(matString)+1]; |
---|
| 703 | strcpy (this->currentGroup->currentFace->materialString, matString); |
---|
[3063] | 704 | |
---|
[3195] | 705 | if (this->currentGroup->faceCount == 0) |
---|
| 706 | this->currentGroup->faceCount ++; |
---|
[3063] | 707 | |
---|
| 708 | } |
---|
| 709 | |
---|
[3066] | 710 | /** |
---|
| 711 | \brief reads and includes the Faces/Materials into the openGL state Machine |
---|
| 712 | */ |
---|
[3360] | 713 | bool Model::importToGL (void) |
---|
[3063] | 714 | { |
---|
| 715 | |
---|
| 716 | // finalize the Arrays |
---|
[3195] | 717 | this->vertices->finalizeArray(); |
---|
| 718 | this->vTexture->finalizeArray(); |
---|
[3075] | 719 | if (normals->getCount() == 0) // vertices-Array must be uilt for this |
---|
[3195] | 720 | this->buildVertexNormals(); |
---|
| 721 | this->normals->finalizeArray(); |
---|
[3063] | 722 | |
---|
[3195] | 723 | this->currentGroup = this->firstGroup; |
---|
[3063] | 724 | |
---|
[3195] | 725 | while (this->currentGroup != NULL) |
---|
[3063] | 726 | { |
---|
| 727 | |
---|
| 728 | // creating a glList for the Group |
---|
[3195] | 729 | if ((this->currentGroup->listNumber = glGenLists(1)) == 0) |
---|
[3063] | 730 | { |
---|
[3360] | 731 | PRINTF(1)("list could not be created for this Model\n"); |
---|
[3063] | 732 | return false; |
---|
| 733 | } |
---|
[3195] | 734 | glNewList (this->currentGroup->listNumber, GL_COMPILE); |
---|
[3063] | 735 | |
---|
| 736 | // Putting Faces to GL |
---|
[3195] | 737 | Face* tmpFace = this->currentGroup->firstFace; |
---|
[3063] | 738 | while (tmpFace != NULL) |
---|
| 739 | { |
---|
[3065] | 740 | if (tmpFace->vertexCount == 0 && tmpFace->materialString != NULL) |
---|
[3063] | 741 | { |
---|
[3195] | 742 | if (this->currentGroup->faceMode != -1) |
---|
[3065] | 743 | glEnd(); |
---|
[3195] | 744 | this->currentGroup->faceMode = 0; |
---|
[3207] | 745 | PRINTF(2)("using material %s for coming Faces.\n", tmpFace->materialString); |
---|
[3069] | 746 | Material* tmpMat; |
---|
| 747 | if ((tmpMat = material->search(tmpFace->materialString)) != NULL) |
---|
| 748 | tmpMat->select(); |
---|
[3065] | 749 | |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | else if (tmpFace->vertexCount == 3) |
---|
| 753 | { |
---|
[3195] | 754 | if (this->currentGroup->faceMode != 3) |
---|
[3063] | 755 | { |
---|
[3195] | 756 | if (this->currentGroup->faceMode != -1) |
---|
[3063] | 757 | glEnd(); |
---|
| 758 | glBegin(GL_TRIANGLES); |
---|
| 759 | } |
---|
| 760 | |
---|
[3195] | 761 | this->currentGroup->faceMode = 3; |
---|
[3207] | 762 | PRINTF(3)("found triag.\n"); |
---|
[3063] | 763 | } |
---|
| 764 | |
---|
| 765 | else if (tmpFace->vertexCount == 4) |
---|
| 766 | { |
---|
[3195] | 767 | if (this->currentGroup->faceMode != 4) |
---|
[3063] | 768 | { |
---|
[3195] | 769 | if (this->currentGroup->faceMode != -1) |
---|
[3063] | 770 | glEnd(); |
---|
| 771 | glBegin(GL_QUADS); |
---|
| 772 | } |
---|
[3195] | 773 | this->currentGroup->faceMode = 4; |
---|
[3207] | 774 | PRINTF(3)("found quad.\n"); |
---|
[3063] | 775 | } |
---|
| 776 | |
---|
| 777 | else if (tmpFace->vertexCount > 4) |
---|
| 778 | { |
---|
[3195] | 779 | if (this->currentGroup->faceMode != -1) |
---|
[3063] | 780 | glEnd(); |
---|
| 781 | glBegin(GL_POLYGON); |
---|
[3207] | 782 | PRINTF(3)("Polygon with %i faces found.", tmpFace->vertexCount); |
---|
[3195] | 783 | this->currentGroup->faceMode = tmpFace->vertexCount; |
---|
[3063] | 784 | } |
---|
| 785 | |
---|
| 786 | FaceElement* tmpElem = tmpFace->firstElem; |
---|
| 787 | while (tmpElem != NULL) |
---|
| 788 | { |
---|
[3207] | 789 | // PRINTF(2)("%s\n", tmpElem->value); |
---|
[3195] | 790 | this->addGLElement(tmpElem); |
---|
[3063] | 791 | tmpElem = tmpElem->next; |
---|
| 792 | } |
---|
| 793 | tmpFace = tmpFace->next; |
---|
| 794 | } |
---|
| 795 | glEnd(); |
---|
| 796 | glEndList(); |
---|
[3195] | 797 | |
---|
| 798 | this->currentGroup = this->currentGroup->next; |
---|
[3063] | 799 | } |
---|
| 800 | } |
---|
| 801 | |
---|
[3066] | 802 | /** |
---|
| 803 | \brief Adds a Face-element (one vertex of a face) with all its information. |
---|
[3186] | 804 | \param elem The FaceElement to add to the OpenGL-environment. |
---|
| 805 | |
---|
[3066] | 806 | It does this by searching: |
---|
| 807 | 1. The Vertex itself |
---|
| 808 | 2. The VertexNormale |
---|
| 809 | 3. The VertexTextureCoordinate |
---|
| 810 | merging this information, the face will be drawn. |
---|
[2842] | 811 | */ |
---|
[3360] | 812 | bool Model::addGLElement (FaceElement* elem) |
---|
[2776] | 813 | { |
---|
[3207] | 814 | PRINTF(3)("importing grafical Element to openGL.\n"); |
---|
[3066] | 815 | |
---|
[3073] | 816 | if (elem->texCoordNumber != -1) |
---|
[3195] | 817 | glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2); |
---|
[3073] | 818 | if (elem->normalNumber != -1) |
---|
[3195] | 819 | glNormal3fv(this->normals->getArray() + elem->normalNumber * 3); |
---|
[3073] | 820 | if (elem->vertexNumber != -1) |
---|
[3195] | 821 | glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3); |
---|
[2769] | 822 | |
---|
[2776] | 823 | } |
---|
| 824 | |
---|
[3079] | 825 | /** |
---|
| 826 | \brief A routine that is able to create normals. |
---|
[3186] | 827 | |
---|
[3079] | 828 | The algorithm does the following: |
---|
| 829 | 1. It calculates creates Vectors for each normale, and sets them to zero. |
---|
| 830 | 2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements |
---|
| 831 | 3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal. |
---|
| 832 | 4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array. |
---|
| 833 | */ |
---|
[3360] | 834 | bool Model::buildVertexNormals () |
---|
[3075] | 835 | { |
---|
[3081] | 836 | |
---|
[3207] | 837 | PRINTF(2)("Normals are being calculated.\n"); |
---|
[3075] | 838 | |
---|
| 839 | Vector* normArray = new Vector [vertices->getCount()/3]; |
---|
[3079] | 840 | for (int i=0; i<vertices->getCount()/3;i++) |
---|
[3075] | 841 | normArray[i] = Vector(.0,.0,.0); |
---|
[3081] | 842 | |
---|
[3075] | 843 | int firstTouch; |
---|
| 844 | int secondTouch; |
---|
| 845 | Vector prevV; |
---|
| 846 | Vector nextV; |
---|
| 847 | Vector curV; |
---|
| 848 | |
---|
| 849 | Group* tmpGroup = firstGroup; |
---|
| 850 | while (tmpGroup) |
---|
| 851 | { |
---|
| 852 | Face* tmpFace = tmpGroup->firstFace; |
---|
| 853 | while (tmpFace) |
---|
| 854 | { |
---|
| 855 | if (tmpFace->firstElem) |
---|
| 856 | { |
---|
| 857 | FaceElement* firstElem = tmpFace->firstElem; |
---|
[3082] | 858 | FaceElement* prevElem; |
---|
| 859 | FaceElement* curElem = firstElem; |
---|
| 860 | FaceElement* nextElem; |
---|
[3081] | 861 | FaceElement* lastElem; |
---|
[3082] | 862 | // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop. |
---|
[3081] | 863 | while (curElem) |
---|
| 864 | { |
---|
| 865 | prevElem = curElem; |
---|
| 866 | curElem = curElem->next; |
---|
| 867 | } |
---|
| 868 | lastElem = prevElem; |
---|
[3075] | 869 | |
---|
[3081] | 870 | curElem = firstElem; |
---|
| 871 | for (int j=0; j<tmpFace->vertexCount; j++) |
---|
[3075] | 872 | { |
---|
[3082] | 873 | if (!(nextElem = curElem->next)) |
---|
| 874 | nextElem = firstElem; |
---|
[3075] | 875 | curElem->normalNumber = curElem->vertexNumber; |
---|
| 876 | |
---|
| 877 | curV = Vector (vertices->getArray()[curElem->vertexNumber*3], vertices->getArray()[curElem->vertexNumber*3+1], vertices->getArray()[curElem->vertexNumber*3+2]); |
---|
| 878 | prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV; |
---|
[3082] | 879 | nextV = Vector (vertices->getArray()[nextElem->vertexNumber*3], vertices->getArray()[nextElem->vertexNumber*3+1], vertices->getArray()[nextElem->vertexNumber*3+2]) - curV; |
---|
[3081] | 880 | normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV); |
---|
[3075] | 881 | |
---|
| 882 | prevElem = curElem; |
---|
| 883 | curElem = curElem->next; |
---|
| 884 | } |
---|
| 885 | } |
---|
| 886 | tmpFace = tmpFace->next; |
---|
| 887 | } |
---|
| 888 | tmpGroup = tmpGroup->next; |
---|
| 889 | } |
---|
| 890 | |
---|
| 891 | for (int i=0; i<vertices->getCount()/3;i++) |
---|
| 892 | { |
---|
| 893 | normArray[i].normalize(); |
---|
[3207] | 894 | PRINTF(3)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z); |
---|
[3079] | 895 | |
---|
[3195] | 896 | this->normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z); |
---|
[3075] | 897 | |
---|
| 898 | } |
---|
[3080] | 899 | delete []normArray; |
---|
[3081] | 900 | |
---|
[3075] | 901 | } |
---|
| 902 | |
---|
| 903 | |
---|
[2842] | 904 | /** |
---|
[3360] | 905 | \brief Includes a default model |
---|
[3186] | 906 | |
---|
[3360] | 907 | This will inject a Cube, because this is the most basic model. |
---|
[2842] | 908 | */ |
---|
[3360] | 909 | void Model::BoxModel(void) |
---|
[2821] | 910 | { |
---|
[3195] | 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"); |
---|
[2967] | 919 | |
---|
[3195] | 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"); |
---|
[3081] | 934 | |
---|
[3195] | 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"); |
---|
[2821] | 959 | |
---|
[3083] | 960 | /* normaleLess-testingMode |
---|
[3195] | 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"); |
---|
[3083] | 967 | */ |
---|
[3081] | 968 | |
---|
[3195] | 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"); |
---|
[3083] | 975 | |
---|
[2821] | 976 | } |
---|