mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:27:45 +00:00
3DFileViewer: Port MeshLoader
and its child to the new Core::File
As it was using the `lines()` method of `Core::DeprecatedFile`, this patch also introduce the usage of `BufferedFile` to take advantage of its API: `can_read_line()` and `read_line()`.
This commit is contained in:
parent
83da3c5c3e
commit
b4cea1c72e
4 changed files with 14 additions and 6 deletions
|
@ -8,7 +8,9 @@
|
|||
|
||||
#include "WavefrontOBJLoader.h"
|
||||
#include <AK/FixedArray.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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<NonnullRefPtr<Mesh>> WavefrontOBJLoader::load(Core::DeprecatedFile& file)
|
||||
ErrorOr<NonnullRefPtr<Mesh>> WavefrontOBJLoader::load(String const& filename, NonnullOwnPtr<Core::File> file)
|
||||
{
|
||||
auto buffered_file = TRY(Core::BufferedFile::create(move(file)));
|
||||
|
||||
Vector<Vertex> vertices;
|
||||
Vector<Vertex> normals;
|
||||
Vector<TexCoord> tex_coords;
|
||||
Vector<Triangle> 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue