mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:47:34 +00:00
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.
This commit is contained in:
parent
728e6dad73
commit
2a16c8bdb8
4 changed files with 49 additions and 46 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue