common.hpp 2.99 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
	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{
31
32
33
		        {Texture_type::albedo, {1, 12}}, // aiTextureType_DIFFUSE, aiTextureType_BASE_COLOR
		        {Texture_type::metalness,
		         {3, 11, 15}}, // aiTextureType_AMBIENT, aiTextureType_REFLECTION aiTextureType_METALNESS
34
35
36
37
38
39
40
		        {Texture_type::roughness,
		         {7,
		          2,
		          16}}, // aiTextureType_SHININESS, aiTextureType_SPECULAR, aiTextureType_DIFFUSE_ROUGHNESS
		        {Texture_type::normal,
		         {6, 13, 5}}, // aiTextureType_NORMALS, aiTextureType_NORMAL_CAMERA, aiTextureType_HEIGHT
		        {Texture_type::emission, {4, 14}}, // aiTextureType_EMISSIVE, aiTextureType_EMISSION_COLOR
Florian Oetke's avatar
Florian Oetke committed
41
42
43
44
45
46
47
48
49
		};

		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
50
51
		renderer::Skinning_type skinning_type = renderer::Skinning_type::linear_blend_skinning;

Florian Oetke's avatar
Florian Oetke committed
52
53
		bool print_material_info = false;
		bool print_animations    = true;
54
		bool prefix_materials    = true;
Florian Oetke's avatar
Florian Oetke committed
55
56
57
58
59
60
	};
	sf2_structDef(Mesh_converted_config,
	              texture_mappings,
	              material_texture_override,
	              empty_bones_to_keep,
	              default_output_directory,
Florian Oetke's avatar
Florian Oetke committed
61
	              skinning_type,
Florian Oetke's avatar
Florian Oetke committed
62
	              print_material_info,
63
64
	              print_animations,
	              prefix_materials);
Florian Oetke's avatar
Florian Oetke committed
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
92
93
94
95
96


	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