summaryrefslogtreecommitdiff
path: root/assetFactory/modelFactoryMesh.h
blob: 6a1815573c271b089e2cde337cc1876747d315c1 (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
#pragma once

#include "config/types.h"
#include "modelFactoryMesh_fwd.h"
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
#include <glad/gl.h>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <thirdparty/openmesh/glmcompat.h>
#include <thirdparty/openmesh/helpers.h>

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);
	HalfedgeAttributes(OpenMesh::Attributes::TexCoord2D);
	using Point = RelativePosition3D;
	using Normal = Normal3D;
	using Color = RGBA;
	using TexCoord2D = TextureRelCoord;
};

struct ModelFactoryMesh : public OpenMesh::PolyMesh_ArrayKernelT<ModelFactoryTraits> {
	bool normalsProvidedProperty {};
	const OpenMesh::Helpers::Property<bool, OpenMesh::FPropHandleT> smoothFaceProperty {this};
	const OpenMesh::Helpers::Property<GLuint, OpenMesh::FPropHandleT> materialFaceProperty {this};
	const OpenMesh::Helpers::Property<std::string, OpenMesh::FPropHandleT> nameFaceProperty {this};
	const OpenMesh::Helpers::Property<std::string, OpenMesh::HPropHandleT> nameAdjFaceProperty {this};

	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)...);
		configNamedFace(name, handle);
		return {std::move(name), handle};
	}

private:
	void configNamedFace(const std::string & name, OpenMesh::FaceHandle);
};