From 92c1aed7a471f34e18eb8d0077aad90fd8b7344b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Mar 2023 18:18:43 +0000 Subject: Make add_namedFace a thin template wrapper --- assetFactory/cuboid.cpp | 12 ++++++------ assetFactory/cylinder.cpp | 10 +++------- assetFactory/modelFactoryMesh.cpp | 8 -------- assetFactory/modelFactoryMesh.h | 9 ++++++++- 4 files changed, 17 insertions(+), 22 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/cuboid.cpp b/assetFactory/cuboid.cpp index 03b1304..f200258 100644 --- a/assetFactory/cuboid.cpp +++ b/assetFactory/cuboid.cpp @@ -19,11 +19,11 @@ Cuboid::createMesh(ModelFactoryMesh & mesh, float) const const auto vhs = addToMesh(mesh, VERTICES); return { - mesh.add_namedFace("top", {vhs[4], vhs[5], vhs[6], vhs[7]}), - mesh.add_namedFace("bottom", {vhs[0], vhs[1], vhs[2], vhs[3]}), - mesh.add_namedFace("left", {vhs[0], vhs[7], vhs[6], vhs[1]}), - mesh.add_namedFace("right", {vhs[2], vhs[5], vhs[4], vhs[3]}), - mesh.add_namedFace("front", {vhs[0], vhs[3], vhs[4], vhs[7]}), - mesh.add_namedFace("back", {vhs[2], vhs[1], vhs[6], vhs[5]}), + mesh.add_namedFace("top", vhs[4], vhs[5], vhs[6], vhs[7]), + mesh.add_namedFace("bottom", vhs[0], vhs[1], vhs[2], vhs[3]), + mesh.add_namedFace("left", vhs[0], vhs[7], vhs[6], vhs[1]), + mesh.add_namedFace("right", vhs[2], vhs[5], vhs[4], vhs[3]), + mesh.add_namedFace("front", vhs[0], vhs[3], vhs[4], vhs[7]), + mesh.add_namedFace("back", vhs[2], vhs[1], vhs[6], vhs[5]), }; } diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp index e32ebcb..ca08bf8 100644 --- a/assetFactory/cylinder.cpp +++ b/assetFactory/cylinder.cpp @@ -25,13 +25,9 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const const auto xyz2b = (xy2 ^ 0); const auto xyz1t = (xy1 ^ 1); const auto xyz2t = (xy2 ^ 1); - return mesh.add_namedFace("edge", - { - mesh.add_vertex({xyz1b.x, xyz1b.y, xyz1b.z}), - mesh.add_vertex({xyz2b.x, xyz2b.y, xyz2b.z}), - mesh.add_vertex({xyz2t.x, xyz2t.y, xyz2t.z}), - mesh.add_vertex({xyz1t.x, xyz1t.y, xyz1t.z}), - }); + return mesh.add_namedFace("edge", mesh.add_vertex({xyz1b.x, xyz1b.y, xyz1b.z}), + mesh.add_vertex({xyz2b.x, xyz2b.y, xyz2b.z}), mesh.add_vertex({xyz2t.x, xyz2t.y, xyz2t.z}), + mesh.add_vertex({xyz1t.x, xyz1t.y, xyz1t.z})); }); for (const auto & [name, face] : surface) { mesh.property(mesh.smoothFaceProperty, face) = true; diff --git a/assetFactory/modelFactoryMesh.cpp b/assetFactory/modelFactoryMesh.cpp index f9ee6a0..806ac3b 100644 --- a/assetFactory/modelFactoryMesh.cpp +++ b/assetFactory/modelFactoryMesh.cpp @@ -5,11 +5,3 @@ ModelFactoryMesh::ModelFactoryMesh() add_property(smoothFaceProperty); add_property(nameFaceProperty); } - -std::pair -ModelFactoryMesh::add_namedFace(std::string name, std::vector p) -{ - const auto handle = add_face(std::move(p)); - property(nameFaceProperty, handle) = name; - return std::make_pair(name, handle); -} diff --git a/assetFactory/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h index 258913b..ea5f011 100644 --- a/assetFactory/modelFactoryMesh.h +++ b/assetFactory/modelFactoryMesh.h @@ -35,5 +35,12 @@ struct ModelFactoryMesh : public OpenMesh::PolyMesh_ArrayKernelT smoothFaceProperty; OpenMesh::FPropHandleT nameFaceProperty; - std::pair add_namedFace(std::string name, std::vector p); + template + std::pair + add_namedFace(std::string name, Vs &&... vs) + { + const auto handle = add_face(std::forward(vs)...); + property(nameFaceProperty, handle) = name; + return std::make_pair(name, handle); + } }; -- cgit v1.2.3