summaryrefslogtreecommitdiff
path: root/assetFactory/modelFactoryMesh.h
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 /assetFactory/modelFactoryMesh.h
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.
Diffstat (limited to 'assetFactory/modelFactoryMesh.h')
-rw-r--r--assetFactory/modelFactoryMesh.h33
1 files changed, 22 insertions, 11 deletions
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;
};