diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-20 21:50:53 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-20 22:22:56 +0200 |
commit | 2a16c8bdb8b285209950a4e26b3eee1d95ec1a7a (patch) | |
tree | 65c2f48a960f161401d248e4982692c066205308 /Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp | |
parent | 728e6dad7306b2aceff46b19491346e49b0bba15 (diff) | |
download | serenity-2a16c8bdb8b285209950a4e26b3eee1d95ec1a7a.zip |
3DFileViewer: Clean up file handling
This unifies how 3DFileViewer handles the initial file when starting
the application and when opening files later on via the menu.
Errors are shown both for the initial load as well as when loading
files later on. An error during file load no longer clears the
existing model.
It also adds support for specifying the filename as a command-line
argument.
The opened file's name is shown in the titlebar.
Diffstat (limited to 'Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp')
-rw-r--r-- | Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp b/Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp index 891f13dc8f..3022d5218f 100644 --- a/Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp +++ b/Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp @@ -9,19 +9,15 @@ #include <LibCore/File.h> #include <stdlib.h> -RefPtr<Mesh> WavefrontOBJLoader::load(const String& fname) +RefPtr<Mesh> WavefrontOBJLoader::load(Core::File& file) { - auto obj_file_or_error = Core::File::open(fname, Core::OpenMode::ReadOnly); Vector<Vertex> vertices; Vector<Triangle> triangles; - dbgln("Wavefront: Loading {}...", fname); - - if (obj_file_or_error.is_error()) - return nullptr; + dbgln("Wavefront: Loading {}...", file.name()); // Start reading file line by line - for (auto line = obj_file_or_error.value()->line_begin(); !line.at_end(); ++line) { + for (auto line = file.line_begin(); !line.at_end(); ++line) { auto object_line = *line; // FIXME: Parse texture coordinates and vertex normals @@ -67,7 +63,7 @@ RefPtr<Mesh> WavefrontOBJLoader::load(const String& fname) } if (vertices.is_empty()) { - dbgln("Wavefront: Failed to read any data from 3D file: {}", fname); + dbgln("Wavefront: Failed to read any data from 3D file: {}", file.name()); return nullptr; } |