1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:17:44 +00:00

GLTeapot: Add support for loading OBJ files containing extra information

If the OBJ loader encounters a file with vertex normals or texture
coordinates then it will no longer crash.
This commit is contained in:
Erik Biederstadt 2021-05-16 15:48:23 -06:00 committed by GitHub
parent 1258d06f74
commit 2eb9dca782
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,11 @@ RefPtr<Mesh> WavefrontOBJLoader::load(const String& fname)
for (auto line = obj_file_or_error.value()->line_begin(); !line.at_end(); ++line) { for (auto line = obj_file_or_error.value()->line_begin(); !line.at_end(); ++line) {
auto object_line = *line; auto object_line = *line;
// FIXME: Parse texture coordinates and vertex normals
if (object_line.starts_with("vt") || object_line.starts_with("vn")) {
continue;
}
// This line describes a vertex (a position in 3D space) // This line describes a vertex (a position in 3D space)
if (object_line.starts_with("v")) { if (object_line.starts_with("v")) {
auto vertex_line = object_line.split_view(' '); auto vertex_line = object_line.split_view(' ');
@ -45,6 +50,12 @@ RefPtr<Mesh> WavefrontOBJLoader::load(const String& fname)
return nullptr; return nullptr;
} }
if (object_line.contains("/")) {
for (int i = 1; i <= 3; ++i) {
face_line.at(i) = face_line.at(i).split_view("/").at(0);
}
}
// Create a new triangle // Create a new triangle
triangles.append( triangles.append(
{ {