handle quad .objs
parent
25fd136e21
commit
c1f42b2d3b
|
@ -80,6 +80,11 @@ namespace blt::gfx
|
||||||
std::int32_t v[3];
|
std::int32_t v[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct quad_t
|
||||||
|
{
|
||||||
|
std::int32_t v[4];
|
||||||
|
};
|
||||||
|
|
||||||
struct object_data
|
struct object_data
|
||||||
{
|
{
|
||||||
std::string object_name;
|
std::string object_name;
|
||||||
|
@ -128,6 +133,8 @@ namespace blt::gfx
|
||||||
|
|
||||||
void parse_face(char_tokenizer& tokenizer);
|
void parse_face(char_tokenizer& tokenizer);
|
||||||
|
|
||||||
|
void handle_face_vertex(const std::vector<std::string>& face_list, std::int32_t* arr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
obj_objects_t parseFile(std::string_view file);
|
obj_objects_t parseFile(std::string_view file);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 240ab5890b2e8da294937a1710b021ac3f271472
|
Subproject commit a1b06823fe2d964a62fda99385499b218cf5cea5
|
|
@ -1 +1 @@
|
||||||
Subproject commit cfab14287405a0d34f6a0fec1336f46415728fcf
|
Subproject commit 6675317107257c2cc16c947b359d557821d85bf2
|
|
@ -172,38 +172,55 @@ namespace blt::gfx
|
||||||
|
|
||||||
void obj_loader::parse_face(char_tokenizer& tokenizer)
|
void obj_loader::parse_face(char_tokenizer& tokenizer)
|
||||||
{
|
{
|
||||||
auto vertexes = blt::string::split(std::string(tokenizer.read_fully()), ' ');
|
auto faces = blt::string::split(std::string(tokenizer.read_fully()), ' ');
|
||||||
if (vertexes.size() == 3)
|
if (faces.size() == 3)
|
||||||
{
|
{
|
||||||
triangle_t triangle{};
|
triangle_t triangle{};
|
||||||
for (const auto& pair : blt::enumerate(vertexes))
|
handle_face_vertex(faces, triangle.v);
|
||||||
{
|
|
||||||
auto indices = blt::string::split(pair.second, '/');
|
|
||||||
BLT_ASSERT(indices.size() == 3 && "Must have vertex, uv, and normal indices!!");
|
|
||||||
|
|
||||||
auto vi = get<std::int32_t>(indices[0]);
|
|
||||||
auto ui = get<std::int32_t>(indices[1]);
|
|
||||||
auto ni = get<std::int32_t>(indices[2]);
|
|
||||||
|
|
||||||
face_t face{vi, ui, ni};
|
|
||||||
|
|
||||||
auto loc = vertex_map.find(face);
|
|
||||||
if (loc == vertex_map.end())
|
|
||||||
{
|
|
||||||
auto index = static_cast<std::int32_t>(vertex_data.size());
|
|
||||||
vertex_data.push_back({vertices[vi], uvs[ui], normals[ni]});
|
|
||||||
vertex_map.insert({face, index});
|
|
||||||
triangle.v[pair.first] = index;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
triangle.v[pair.first] = loc->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
current_object.indices.push_back(triangle);
|
current_object.indices.push_back(triangle);
|
||||||
} else if (vertexes.size() == 4)
|
} else if (faces.size() == 4)
|
||||||
{
|
{
|
||||||
BLT_WARN("Currently unable to process non-triangulated meshes!");
|
quad_t quad{};
|
||||||
|
handle_face_vertex(faces, quad.v);
|
||||||
|
triangle_t t1{};
|
||||||
|
triangle_t t2{};
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
t1.v[i] = quad.v[i];
|
||||||
|
t2.v[0] = quad.v[0];
|
||||||
|
t2.v[1] = quad.v[2];
|
||||||
|
t2.v[2] = quad.v[3];
|
||||||
|
|
||||||
|
current_object.indices.push_back(t1);
|
||||||
|
current_object.indices.push_back(t2);
|
||||||
} else
|
} else
|
||||||
BLT_WARN("Unsupported vertex count! %d", vertexes.size());
|
BLT_WARN("Unsupported vertex count! %d", faces.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void obj_loader::handle_face_vertex(const std::vector<std::string>& face_list, int32_t* arr)
|
||||||
|
{
|
||||||
|
for (const auto& pair : blt::enumerate(face_list))
|
||||||
|
{
|
||||||
|
auto indices = blt::string::split(pair.second, '/');
|
||||||
|
BLT_ASSERT(indices.size() == 3 && "Must have vertex, uv, and normal indices!!");
|
||||||
|
|
||||||
|
auto vi = get<std::int32_t>(indices[0]);
|
||||||
|
auto ui = get<std::int32_t>(indices[1]);
|
||||||
|
auto ni = get<std::int32_t>(indices[2]);
|
||||||
|
|
||||||
|
face_t face{vi, ui, ni};
|
||||||
|
|
||||||
|
auto loc = vertex_map.find(face);
|
||||||
|
if (loc == vertex_map.end())
|
||||||
|
{
|
||||||
|
auto index = static_cast<std::int32_t>(vertex_data.size());
|
||||||
|
vertex_data.push_back({vertices[vi], uvs[ui], normals[ni]});
|
||||||
|
vertex_map.insert({face, index});
|
||||||
|
arr[pair.first] = index;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
arr[pair.first] = loc->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue