summaryrefslogtreecommitdiff
path: root/assetFactory/modelFactoryMesh.h
blob: ea5f011f8da8ac94c7a7a2c712d8a784f7aa51ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include "modelFactoryMesh_fwd.h"
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
#include <OpenMesh/Core/Mesh/Traits.hh>
#include <glm/geometric.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>

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;
		}
	};
}

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 Color = glm::vec4;
};

struct ModelFactoryMesh : public OpenMesh::PolyMesh_ArrayKernelT<ModelFactoryTraits> {
	ModelFactoryMesh();

	OpenMesh::FPropHandleT<bool> smoothFaceProperty;
	OpenMesh::FPropHandleT<std::string> nameFaceProperty;

	template<typename... Vs>
	std::pair<std::string, OpenMesh::FaceHandle>
	add_namedFace(std::string name, Vs &&... vs)
	{
		const auto handle = add_face(std::forward<Vs>(vs)...);
		property(nameFaceProperty, handle) = name;
		return std::make_pair(name, handle);
	}
};