mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:07:45 +00:00
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.
This commit is contained in:
parent
1258d06f74
commit
2eb9dca782
1 changed files with 11 additions and 0 deletions
|
@ -24,6 +24,11 @@ RefPtr<Mesh> WavefrontOBJLoader::load(const String& fname)
|
||||||
for (auto line = obj_file_or_error.value()->line_begin(); !line.at_end(); ++line) {
|
for (auto line = obj_file_or_error.value()->line_begin(); !line.at_end(); ++line) {
|
||||||
auto object_line = *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)
|
// This line describes a vertex (a position in 3D space)
|
||||||
if (object_line.starts_with("v")) {
|
if (object_line.starts_with("v")) {
|
||||||
auto vertex_line = object_line.split_view(' ');
|
auto vertex_line = object_line.split_view(' ');
|
||||||
|
@ -45,6 +50,12 @@ RefPtr<Mesh> WavefrontOBJLoader::load(const String& fname)
|
||||||
return nullptr;
|
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
|
// Create a new triangle
|
||||||
triangles.append(
|
triangles.append(
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue