diff --git a/Userland/Applications/3DFileViewer/MeshLoader.h b/Userland/Applications/3DFileViewer/MeshLoader.h index 3e1f1f0680..dd0dae08b4 100644 --- a/Userland/Applications/3DFileViewer/MeshLoader.h +++ b/Userland/Applications/3DFileViewer/MeshLoader.h @@ -18,5 +18,5 @@ public: MeshLoader() = default; virtual ~MeshLoader() = default; - virtual ErrorOr> load(Core::DeprecatedFile& file) = 0; + virtual ErrorOr> load(String const& filename, NonnullOwnPtr file) = 0; }; diff --git a/Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp b/Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp index d6231abc92..2739689ff5 100644 --- a/Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp +++ b/Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp @@ -8,7 +8,9 @@ #include "WavefrontOBJLoader.h" #include +#include #include +#include #include static inline GLuint get_index_value(StringView& representation) @@ -16,17 +18,22 @@ static inline GLuint get_index_value(StringView& representation) return representation.to_uint().value_or(1) - 1; } -ErrorOr> WavefrontOBJLoader::load(Core::DeprecatedFile& file) +ErrorOr> WavefrontOBJLoader::load(String const& filename, NonnullOwnPtr file) { + auto buffered_file = TRY(Core::BufferedFile::create(move(file))); + Vector vertices; Vector normals; Vector tex_coords; Vector triangles; - dbgln("Wavefront: Loading {}...", file.name()); + dbgln("Wavefront: Loading {}...", filename); // Start reading file line by line - for (auto object_line : file.lines()) { + auto buffer = TRY(ByteBuffer::create_uninitialized(PAGE_SIZE)); + while (TRY(buffered_file->can_read_line())) { + auto object_line = TRY(buffered_file->read_line(buffer)); + // Ignore file comments if (object_line.starts_with('#')) continue; diff --git a/Userland/Applications/3DFileViewer/WavefrontOBJLoader.h b/Userland/Applications/3DFileViewer/WavefrontOBJLoader.h index 1429547e6c..9ceb524385 100644 --- a/Userland/Applications/3DFileViewer/WavefrontOBJLoader.h +++ b/Userland/Applications/3DFileViewer/WavefrontOBJLoader.h @@ -18,5 +18,5 @@ public: WavefrontOBJLoader() = default; ~WavefrontOBJLoader() override = default; - ErrorOr> load(Core::DeprecatedFile& file) override; + ErrorOr> load(String const& filename, NonnullOwnPtr file) override; }; diff --git a/Userland/Applications/3DFileViewer/main.cpp b/Userland/Applications/3DFileViewer/main.cpp index e74a2ea760..cea5172399 100644 --- a/Userland/Applications/3DFileViewer/main.cpp +++ b/Userland/Applications/3DFileViewer/main.cpp @@ -318,7 +318,8 @@ bool GLContextWidget::load_file(Core::DeprecatedFile& file) return false; } - auto new_mesh = m_mesh_loader->load(file); + auto new_mesh = m_mesh_loader->load(String::from_deprecated_string(file.filename()).release_value_but_fixme_should_propagate_errors(), + Core::File::adopt_fd(file.leak_fd(), Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors()); if (new_mesh.is_error()) { GUI::MessageBox::show(window(), DeprecatedString::formatted("Reading \"{}\" failed: {}", filename, new_mesh.release_error()), "Error"sv, GUI::MessageBox::Type::Error); return false;