common.hpp 2.77 KB
Newer Older
Florian Oetke's avatar
Florian Oetke committed
1
2
#pragma once

Florian Oetke's avatar
Florian Oetke committed
3
4
#include <mirrage/renderer/animation.hpp>

Florian Oetke's avatar
Florian Oetke committed
5
6
7
8
9
10
#include <assimp/scene.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <sf2/sf2.hpp>

11
#include <atomic>
Florian Oetke's avatar
Florian Oetke committed
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>


namespace mirrage {

21
22
23
	extern std::atomic<std::size_t> parallel_tasks_started;
	extern std::atomic<std::size_t> parallel_tasks_done;

Florian Oetke's avatar
Florian Oetke committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	sf2_enum(Texture_type, albedo, metalness, roughness, normal, emission);

	using Texture_mapping = std::unordered_map<Texture_type, std::vector<int>>;


	struct Mesh_converted_config {
		Texture_mapping texture_mappings{
		        {Texture_type::albedo, {1}},       // aiTextureType_DIFFUSE
		        {Texture_type::metalness, {3}},    // aiTextureType_AMBIENT
		        {Texture_type::roughness, {7, 2}}, // aiTextureType_SHININESS, aiTextureType_SPECULAR
		        {Texture_type::normal, {6, 5}},    // aiTextureType_NORMALS, aiTextureType_HEIGHT
		        {Texture_type::emission, {4}},     // aiTextureType_EMISSIVE
		};

		std::unordered_map<std::string, std::unordered_map<Texture_type, std::string>>
		        material_texture_override;

		std::vector<std::string> empty_bones_to_keep;

		std::string default_output_directory = "output";

Florian Oetke's avatar
Florian Oetke committed
45
46
		renderer::Skinning_type skinning_type = renderer::Skinning_type::linear_blend_skinning;

Florian Oetke's avatar
Florian Oetke committed
47
48
		bool print_material_info = false;
		bool print_animations    = true;
49
		bool prefix_materials    = true;
Florian Oetke's avatar
Florian Oetke committed
50
51
52
53
54
55
	};
	sf2_structDef(Mesh_converted_config,
	              texture_mappings,
	              material_texture_override,
	              empty_bones_to_keep,
	              default_output_directory,
Florian Oetke's avatar
Florian Oetke committed
56
	              skinning_type,
Florian Oetke's avatar
Florian Oetke committed
57
	              print_material_info,
58
59
	              print_animations,
	              prefix_materials);
Florian Oetke's avatar
Florian Oetke committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91


	template <typename T>
	void write(std::ostream& out, const T& value)
	{
		static_assert(!std::is_pointer<T>::value, "T is a pointer. That is DEFINITLY not what you wanted!");
		out.write(reinterpret_cast<const char*>(&value), sizeof(T));
	}

	template <typename T>
	void write(std::ostream& out, const std::vector<T>& value)
	{
		static_assert(!std::is_pointer<T>::value, "T is a pointer. That is DEFINITLY not what you wanted!");

		out.write(reinterpret_cast<const char*>(value.data()), value.size() * sizeof(T));
	}


	inline auto to_glm(aiMatrix4x4 in) -> glm::mat4
	{
		/*
		return glm::transpose(glm::mat4{{in.a1, in.a2, in.a3, in.a4},
		                                {in.b1, in.b2, in.b3, in.b4},
		                                {in.c1, in.c2, in.c3, in.c4},
		                                {in.d1, in.d2, in.d3, in.d4}});
										*/
		return glm::transpose(glm::make_mat4(&in.a1));
		;
	}
	inline auto to_glm(aiVector3D v) { return glm::vec3(v.x, v.y, v.z); }

} // namespace mirrage