From 2eb9dca7827cd91b696a95a309a49086b52bba07 Mon Sep 17 00:00:00 2001 From: Erik Biederstadt Date: Sun, 16 May 2021 15:48:23 -0600 Subject: [PATCH] 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. --- Userland/Demos/GLTeapot/WavefrontOBJLoader.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Userland/Demos/GLTeapot/WavefrontOBJLoader.cpp b/Userland/Demos/GLTeapot/WavefrontOBJLoader.cpp index 81412c82f2..08fa574447 100644 --- a/Userland/Demos/GLTeapot/WavefrontOBJLoader.cpp +++ b/Userland/Demos/GLTeapot/WavefrontOBJLoader.cpp @@ -24,6 +24,11 @@ RefPtr WavefrontOBJLoader::load(const String& fname) for (auto line = obj_file_or_error.value()->line_begin(); !line.at_end(); ++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) if (object_line.starts_with("v")) { auto vertex_line = object_line.split_view(' '); @@ -45,6 +50,12 @@ RefPtr WavefrontOBJLoader::load(const String& fname) 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 triangles.append( {