Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
bool ModelClass::LoadModel(char* filename) { //Temp Variablen std :: vector <unsigned int > vertexIndices, uvIndices, normalIndices; std :: vector <vec3> temp_vertices; std :: vector <vec2> temp_uvs; std :: vector <vec3> temp_normals; FILE * file = fopen(filename, "r"); if( file == NULL ) { printf("Impossible to open the file !\n"); return false; } while( 1 ) { char lineHeader[128]; // read the first word of the line int res = fscanf(file, "%s", lineHeader); if (res == EOF) { break; // EOF = End Of File. Quit the loop. } if ( strcmp( lineHeader, "v" ) == 0 ) { vec3 vertex; fscanf(file, "%f %f %f\n", &vertex.x, &vertex.y, &vertex.z ); temp_vertices.push_back(vertex); } else if ( strcmp( lineHeader, "vt" ) == 0 ) { vec2 uv; fscanf(file, "%f %f\n", &uv.x, &uv.y ); temp_uvs.push_back(uv); } else if ( strcmp( lineHeader, "vn" ) == 0 ) { vec3 normal; fscanf(file, "%f %f %f\n", &normal.x, &normal.y, &normal.z ); temp_normals.push_back(normal); } else if ( strcmp( lineHeader, "f" ) == 0 ) { std::string vertex1, vertex2, vertex3; unsigned int vertexIndex[3], uvIndex[3], normalIndex[3]; int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[1], &uvIndex[1], &normalIndex[1], &vertexIndex[2], &uvIndex[2], &normalIndex[2] ); if (matches != 9) { printf("File can't be read by our simple parser : ( Try exporting with other options\n"); return false; } vertexIndices.push_back(vertexIndex[0]); vertexIndices.push_back(vertexIndex[1]); vertexIndices.push_back(vertexIndex[2]); uvIndices .push_back(uvIndex[0]); uvIndices .push_back(uvIndex[1]); uvIndices .push_back(uvIndex[2]); normalIndices.push_back(normalIndex[0]); normalIndices.push_back(normalIndex[1]); normalIndices.push_back(normalIndex[2]); } } // For each vertex of each triangle for( unsigned int i=0; i<vertexIndices.size(); i++ ) { unsigned int vertexIndex = vertexIndices[i]; vec3 vertex = temp_vertices[ vertexIndex-1 ]; this->vertices.push_back(vertex); } for( unsigned int i=0; i<uvIndices.size(); i++ ) { unsigned int uvIndex = uvIndices[i]; vec2 uv = temp_uvs[ uvIndex-1 ]; this->uv.push_back(uv); } for( unsigned int i=0; normalIndices.size(); i++ ) { unsigned int normalIndex = normalIndices[i]; vec3 normal = temp_normals[ normalIndex-1 ]; this->normals.push_back(normal); } m_model = new ModelType[vertices.size()]; for(unsigned int i = 0; i < vertices.size(); i++) { m_model[i].x = vertices[i].x; m_model[i].y = vertices[i].y; m_model[i].z = vertices[i].z; m_model[i].tu = uv[i].x; m_model[i].tv = uv[i].y; m_model[i].nx = normals[i].x; m_model[i].ny = normals[i].y; m_model[i].nz = normals[i].z; } return true; } |
Ich muss leider passen , sie soll abbrechen wenn der komplette Vector Kopiert ist, was bei den Schleifen davor auch funktioniert
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Das ist mir jetzt peinlich, da habe ich drei Stunden dran geknobeltManchmal sieht man aber wirklich den Wald vor lauter Bäumen nicht.
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Weil sie eben ganz anders als die Schleifen davor ist. Kann doch nicht so schwer sein die Zeilen mal zu vergleichen, oder?
Edit:
Architekt, du oller Spoiler, lass die Leute doch mal selber ihren Code richtig lesen und selber denken.
Werbeanzeige