From 51f0f60bd24a3d7ed77cf713f846bc49c2f1aed5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 18 Mar 2023 02:44:00 +0000 Subject: Use halfedge for texture coordinates More unique than vertex as it is also per face, allowing for a different texture on adjacent faces --- assetFactory/factoryMesh.cpp | 9 +++++---- assetFactory/modelFactoryMesh.h | 3 ++- assetFactory/style.cpp | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/factoryMesh.cpp b/assetFactory/factoryMesh.cpp index 59b390f..6cca388 100644 --- a/assetFactory/factoryMesh.cpp +++ b/assetFactory/factoryMesh.cpp @@ -18,16 +18,17 @@ FactoryMesh::createMesh() const for (const auto & face : mesh.faces()) { const auto smooth = mesh.property(mesh.smoothFaceProperty, face); const auto colour = mesh.color(face); - auto vrange = mesh.fv_range(face); + auto hrange = mesh.fh_range(face); const unsigned int start = static_cast(vertices.size()); - for (const auto & vertex : vrange) { - const auto textureUV = mesh.texcoord2D(vertex); + for (const auto & heh : hrange) { + const auto & vertex = mesh.to_vertex_handle(heh); + const auto textureUV = mesh.texcoord2D(heh); vertices.emplace_back(mesh.point(vertex), textureUV, smooth ? mesh.property(mesh.vertex_normals_pph(), vertex) : mesh.property(mesh.face_normals_pph(), face), colour); } - const auto vcount = std::distance(vrange.begin(), vrange.end()); + const auto vcount = std::distance(hrange.begin(), hrange.end()); for (unsigned int i = 2; i < vcount; i++) { indices.push_back(start); indices.push_back(start + i - 1); diff --git a/assetFactory/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h index 493ce1b..a862dc1 100644 --- a/assetFactory/modelFactoryMesh.h +++ b/assetFactory/modelFactoryMesh.h @@ -35,7 +35,8 @@ namespace OpenMesh { struct ModelFactoryTraits : public OpenMesh::DefaultTraits { FaceAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status | OpenMesh::Attributes::Color); EdgeAttributes(OpenMesh::Attributes::Status); - VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status | OpenMesh::Attributes::TexCoord2D); + VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status); + HalfedgeAttributes(OpenMesh::Attributes::TexCoord2D); using Point = glm::vec3; using Normal = glm::vec3; using Color = glm::vec4; diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index 8aecc71..d1d4adc 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -30,8 +30,8 @@ Style::applyStyle( auto coords = mf->getTextureCoords(texture); auto coord = coords.begin(); // Wild assumption that face is a quad and the texture should apply linearly - for (const auto & vh : mesh.fv_range(face)) { - mesh.set_texcoord2D(vh, *coord++); + for (const auto & heh : mesh.fh_range(face)) { + mesh.set_texcoord2D(heh, *coord++); } } } -- cgit v1.2.3