summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-03-10 01:41:19 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-03-10 01:41:19 +0000
commitd9a0bcf532a44e94f11f23b910d117ec41c92ec8 (patch)
treeb988ce38d48de9ecf87d57bddabc397edeebfff3
parentInplace operator%= for vec3/mat4 mutation (diff)
downloadilt-d9a0bcf532a44e94f11f23b910d117ec41c92ec8.tar.bz2
ilt-d9a0bcf532a44e94f11f23b910d117ec41c92ec8.tar.xz
ilt-d9a0bcf532a44e94f11f23b910d117ec41c92ec8.zip
Swap messy glmvec wrapper for OpenMesh Point/Normal with real glm::vec and a custom vector_traits implementation
Simplify code previously messy as a result of the original hack.
-rw-r--r--assetFactory/cylinder.cpp6
-rw-r--r--assetFactory/faceController.cpp2
-rw-r--r--assetFactory/modelFactoryMesh.h33
-rw-r--r--assetFactory/shape.cpp2
-rw-r--r--assetFactory/use.cpp4
5 files changed, 28 insertions, 19 deletions
diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp
index 0803369..7d22e36 100644
--- a/assetFactory/cylinder.cpp
+++ b/assetFactory/cylinder.cpp
@@ -19,7 +19,7 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const
// Generate bottom face vertices
std::vector<OpenMesh::VertexHandle> bottom(P);
std::transform(circumference.begin(), circumference.end(), bottom.begin(), [&mesh](const auto & xy) {
- return mesh.add_vertex({xy.x, xy.y, 0.f});
+ return mesh.add_vertex(xy ^ 0.f);
});
surface.insert(mesh.add_namedFace("bottom", bottom));
}
@@ -27,7 +27,7 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const
// Generate top face vertices
std::vector<OpenMesh::VertexHandle> top(P);
std::transform(circumference.rbegin(), circumference.rend(), top.begin(), [&mesh](const auto & xy) {
- return mesh.add_vertex({xy.x, xy.y, 1.f});
+ return mesh.add_vertex(xy ^ 1);
});
surface.insert(mesh.add_namedFace("top", top));
}
@@ -35,7 +35,7 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const
// Generate edge vertices
std::vector<std::pair<OpenMesh::VertexHandle, OpenMesh::VertexHandle>> edge(P + 1);
std::transform(circumference.begin(), circumference.end(), edge.begin(), [&mesh](const auto & xy) {
- return std::make_pair(mesh.add_vertex({xy.x, xy.y, 0.f}), mesh.add_vertex({xy.x, xy.y, 1.f}));
+ return std::make_pair(mesh.add_vertex(xy ^ 0), mesh.add_vertex(xy ^ 1));
});
// Wrap around
edge.back() = edge.front();
diff --git a/assetFactory/faceController.cpp b/assetFactory/faceController.cpp
index b6d3d34..1ec1467 100644
--- a/assetFactory/faceController.cpp
+++ b/assetFactory/faceController.cpp
@@ -44,7 +44,7 @@ FaceController::apply(ModelFactoryMesh & mesh, const StyleStack & parents, const
// create new vertices
std::vector<OpenMesh::VertexHandle> vertices;
std::transform(points.begin(), points.end(), std::back_inserter(vertices), [&mesh](auto && p) {
- return mesh.add_vertex({p.x, p.y, p.z});
+ return mesh.add_vertex(p);
});
// create new faces
const auto ofrange = materializeRange(mesh.ff_range(cf.second));
diff --git a/assetFactory/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h
index ea5f011..149ff1a 100644
--- a/assetFactory/modelFactoryMesh.h
+++ b/assetFactory/modelFactoryMesh.h
@@ -7,16 +7,27 @@
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
+namespace glm {
+ template<length_t L, typename T, qualifier Q>
+ auto
+ norm(const vec<L, T, Q> & v)
+ {
+ return length(v);
+ }
+
+ template<length_t L, typename T, qualifier Q, typename S>
+ auto
+ vectorize(vec<L, T, Q> & v, S scalar)
+ {
+ v = vec<L, T, Q> {static_cast<T>(scalar)};
+ }
+}
+
namespace OpenMesh {
- template<typename Scalar, int DIM> struct glmvec : public VectorT<Scalar, DIM> {
- using VectorT<Scalar, DIM>::VectorT;
- glmvec(const VectorT<Scalar, DIM> & v) : VectorT<Scalar, DIM> {v} { }
- operator glm::vec<DIM, Scalar>() const
- {
- glm::vec<DIM, Scalar> out;
- std::copy(this->begin(), this->end(), &out[0]);
- return out;
- }
+ template<glm::length_t L, typename T, glm::qualifier Q> struct vector_traits<glm::vec<L, T, Q>> {
+ using vector_type = glm::vec<L, T, Q>;
+ using value_type = T;
+ static constexpr glm::length_t size_ = L;
};
}
@@ -24,8 +35,8 @@ 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);
- using Point = OpenMesh::glmvec<float, 3>;
- using Normal = OpenMesh::glmvec<float, 3>;
+ using Point = glm::vec3;
+ using Normal = glm::vec3;
using Color = glm::vec4;
};
diff --git a/assetFactory/shape.cpp b/assetFactory/shape.cpp
index ec6594e..3261354 100644
--- a/assetFactory/shape.cpp
+++ b/assetFactory/shape.cpp
@@ -9,7 +9,7 @@ Shape::addToMesh(ModelFactoryMesh & mesh, const std::span<const glm::vec3> verti
{
std::vector<OpenMesh::VertexHandle> vhs;
std::transform(vertices.begin(), vertices.end(), std::back_inserter(vhs), [&mesh](const auto & p) {
- return mesh.add_vertex({p.x, p.y, p.z});
+ return mesh.add_vertex(p);
});
return vhs;
}
diff --git a/assetFactory/use.cpp b/assetFactory/use.cpp
index 5e45c87..9db3495 100644
--- a/assetFactory/use.cpp
+++ b/assetFactory/use.cpp
@@ -15,9 +15,7 @@ Use::createMesh(ModelFactoryMesh & mesh, float levelOfDetailFactor) const
const auto fvr = mesh.fv_range(f.second);
for (const auto & v : fvr) {
if (!vs.contains(v)) {
- glm::vec3 p = mesh.point(v);
- p = p % m;
- mesh.set_point(v, ModelFactoryMesh::Point(p.x, p.y, p.z));
+ mesh.point(v) %= m;
vs.insert(v);
}
}