Commit d9b0a3bd authored by Johannes Braun's avatar Johannes Braun
Browse files

Added initial support for non-triangulated mesh conversion

parent add36593
......@@ -204,7 +204,7 @@ void drawSceneWindow()
}
}
selected_node->destroy();
ImGui::ClearSelectableTreeData();
ImGui::ClearSelectableTreeData("tree_scene_graph");
}
if(ImGui::BeginPopup("del_curr_node"))
......@@ -216,7 +216,7 @@ void drawSceneWindow()
if(selected_node)
selected_node->destroy();
selected_node = nullptr;
ImGui::ClearSelectableTreeData();
ImGui::ClearSelectableTreeData("tree_scene_graph");
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
......
......@@ -457,6 +457,7 @@ namespace glare::core
const auto &normals = sources[normals_id];
const auto &texcoords = sources[tcoord_id]; //empty vector if no texcoords are specified.
std::vector<unsigned> vcount = string_parse::as_vector<unsigned>(node.child("vcount").child_value());
std::vector<unsigned> polys = string_parse::as_vector<unsigned>(node.child("p").child_value());
std::vector<math::Vertex> vertices;
std::vector<unsigned> indices;
......@@ -465,34 +466,53 @@ namespace glare::core
if (std::string(node.name()) == "polylist")
{
for (unsigned i = 0; i < polys.size() / stride; i += 1)
unsigned i = 0;
for(auto vc = 0; vc < vcount.size(); ++vc)
{
auto count = vcount[vc];
math::Vertex vertex;
const unsigned index_pos_x = (polys[i*stride]) * 3;
const unsigned index_pos_y = (polys[i*stride]) * 3 + 1;
const unsigned index_pos_z = (polys[i*stride]) * 3 + 2;
//Z-Up
vertex.position = glm::vec4{ positions[index_pos_x], positions[index_pos_y], positions[index_pos_z], 1 };
const unsigned index_norm_x = (polys[i*(stride)+1]) * 3;
const unsigned index_norm_y = (polys[i*(stride)+1]) * 3 + 1;
const unsigned index_norm_z = (polys[i*(stride)+1]) * 3 + 2;
vertex.normal = glm::vec4{ normals[index_norm_x], normals[index_norm_y], normals[index_norm_z], 0 };
if (stride == 3)
int offset = 0;
for(auto p = 0; p<count; ++p)
{
vertex.texcoord = glm::vec2{ texcoords[polys[i*(stride)+2] * 2], texcoords[(polys[i*(stride)+2] * 2) + 1] };
}
else
{
vertex.texcoord = glm::vec2(0);
if((p - offset) > 2)
{
// 0..1..2..3 will then be
// 0..1..2
// 1..2..3
++offset;
p = p - 2;
}
unsigned index = i + ((p - offset == 0) ? 0 : (p));
math::Vertex vertex;
const unsigned index_pos_x = (polys[index*stride]) * 3;
const unsigned index_pos_y = (polys[index*stride]) * 3 + 1;
const unsigned index_pos_z = (polys[index*stride]) * 3 + 2;
//Z-Up
vertex.position = glm::vec4{ positions[index_pos_x], positions[index_pos_y], positions[index_pos_z], 1 };
const unsigned index_norm_x = (polys[index*(stride)+1]) * 3;
const unsigned index_norm_y = (polys[index*(stride)+1]) * 3 + 1;
const unsigned index_norm_z = (polys[index*(stride)+1]) * 3 + 2;
vertex.normal = glm::vec4{ normals[index_norm_x], normals[index_norm_y], normals[index_norm_z], 0 };
if (stride == 3)
{
vertex.texcoord = glm::vec2{ texcoords[polys[index*(stride)+2] * 2], texcoords[(polys[index*(stride)+2] * 2) + 1] };
}
else
{
vertex.texcoord = glm::vec2(0);
}
indices.push_back(static_cast<int>(vertices.size()));
vertices.push_back(vertex);
}
indices.push_back(static_cast<int>(vertices.size()));
vertices.push_back(vertex);
i += count;
}
mesh = std::make_shared<core::Mesh>(vertices, indices);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment