2022-09-23 15:54:49 +00:00
|
|
|
#include "monochrome_mesh.h"
|
2022-10-18 09:35:04 +00:00
|
|
|
#include <set>
|
2022-09-23 15:54:49 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
MonochromeMesh::MonochromeMesh(const MonochromeMesh& mesh)
|
2022-09-23 15:54:49 +00:00
|
|
|
{
|
|
|
|
m_lineVertices = mesh.m_lineVertices;
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
MonochromeMesh::MonochromeMesh(MonochromeMesh&& mesh)
|
2022-09-23 15:54:49 +00:00
|
|
|
{
|
|
|
|
m_lineVertices = std::move(mesh.m_lineVertices);
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
MonochromeMesh::MonochromeMesh(const dust3d::Object& object)
|
2022-09-23 15:54:49 +00:00
|
|
|
{
|
|
|
|
std::set<std::pair<size_t, size_t>> halfEdges;
|
2022-10-18 09:35:04 +00:00
|
|
|
for (const auto& face : object.triangleAndQuads) {
|
2022-09-23 15:54:49 +00:00
|
|
|
if (3 == face.size()) {
|
2022-10-18 09:35:04 +00:00
|
|
|
halfEdges.insert({ face[0], face[1] });
|
|
|
|
halfEdges.insert({ face[1], face[0] });
|
|
|
|
halfEdges.insert({ face[1], face[2] });
|
|
|
|
halfEdges.insert({ face[2], face[1] });
|
|
|
|
halfEdges.insert({ face[2], face[0] });
|
|
|
|
halfEdges.insert({ face[0], face[2] });
|
2022-09-23 15:54:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-10-18 09:35:04 +00:00
|
|
|
halfEdges.insert({ face[0], face[1] });
|
|
|
|
halfEdges.insert({ face[1], face[0] });
|
|
|
|
halfEdges.insert({ face[1], face[2] });
|
|
|
|
halfEdges.insert({ face[2], face[1] });
|
|
|
|
halfEdges.insert({ face[2], face[3] });
|
|
|
|
halfEdges.insert({ face[3], face[2] });
|
|
|
|
halfEdges.insert({ face[3], face[0] });
|
|
|
|
halfEdges.insert({ face[0], face[3] });
|
2022-09-23 15:54:49 +00:00
|
|
|
}
|
|
|
|
m_lineVertices.reserve(halfEdges.size() * 2);
|
2022-10-18 09:35:04 +00:00
|
|
|
for (const auto& halfEdge : halfEdges) {
|
2022-09-23 15:54:49 +00:00
|
|
|
// For two halfedges shared one edge, only output one line
|
|
|
|
if (halfEdge.first > halfEdge.second)
|
|
|
|
continue;
|
2022-10-18 09:35:04 +00:00
|
|
|
const auto& from = object.vertices[halfEdge.first];
|
|
|
|
const auto& to = object.vertices[halfEdge.second];
|
2022-09-24 13:31:49 +00:00
|
|
|
m_lineVertices.emplace_back(MonochromeOpenGLVertex {
|
2022-10-18 09:35:04 +00:00
|
|
|
(GLfloat)from.x(),
|
|
|
|
(GLfloat)from.y(),
|
|
|
|
(GLfloat)from.z() });
|
2022-09-24 13:31:49 +00:00
|
|
|
m_lineVertices.emplace_back(MonochromeOpenGLVertex {
|
2022-10-18 09:35:04 +00:00
|
|
|
(GLfloat)to.x(),
|
|
|
|
(GLfloat)to.y(),
|
|
|
|
(GLfloat)to.z() });
|
2022-09-23 15:54:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
const MonochromeOpenGLVertex* MonochromeMesh::lineVertices()
|
2022-09-23 15:54:49 +00:00
|
|
|
{
|
|
|
|
if (m_lineVertices.empty())
|
|
|
|
return nullptr;
|
|
|
|
return &m_lineVertices[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
int MonochromeMesh::lineVertexCount()
|
|
|
|
{
|
|
|
|
return (int)m_lineVertices.size();
|
|
|
|
}
|