model_comp.hpp 3.13 KB
Newer Older
1
2
3
4
5
6
7
#pragma once

#include "model.hpp"

#include <mirrage/ecs/component.hpp>


8
namespace mirrage::renderer {
9

10
11
12
13
14
	// model components are intially loaded as Model_unloaded_comp, replaced by Model_loading_comp
	//   once the loading of the model data has begun and finally replaced by Model_comp afterwards.
	// Client code should only care about the Model_comp class as it represents an actually usable model.


15
16
17
18
19
	class Material_property_comp : public ecs::Component<Material_property_comp> {
	  public:
		static constexpr const char* name() { return "Material_property"; }

		Material_property_comp() = default;
20
21
22
23
24
25
		Material_property_comp(ecs::Entity_handle   owner,
		                       ecs::Entity_manager& em,
		                       glm::vec4            emissive_color = glm::vec4(1, 1, 1, 1000.f))
		  : Component(owner, em), emissive_color(emissive_color)
		{
		}
26

Florian Oetke's avatar
Florian Oetke committed
27
		glm::vec4 emissive_color = glm::vec4(1, 1, 1, 1000.f);
28
29
30
31
	};
	sf2_structDef(Material_property_comp, emissive_color);


32
	class Model_comp : public ecs::Component<Model_comp> {
33
34
35
	  public:
		static constexpr const char* name() { return "Model_loaded"; }
		static constexpr const char* name_save_as() { return "Model"; }
36
37
		friend void                  load_component(ecs::Deserializer& state, Model_comp&);
		friend void                  save_component(ecs::Serializer& state, const Model_comp&);
38
39

		Model_comp() = default;
Florian Oetke's avatar
Florian Oetke committed
40
41
		Model_comp(ecs::Entity_handle owner, ecs::Entity_manager& em, Model_ptr model = {})
		  : Component(owner, em), _model(std::move(model))
42
43
		{
		}
44

45
		auto model_aid() const -> auto& { return _model.aid(); }
46
47
48
49
		auto model() const -> auto& { return _model; }
		void model(Model_ptr model) { _model = std::move(model); }

	  private:
50
		Model_ptr _model;
51
52
	};

53
	class Model_unloaded_comp : public ecs::Component<Model_unloaded_comp> {
54
55
	  public:
		static constexpr const char* name() { return "Model"; }
56
57
		friend void                  load_component(ecs::Deserializer& state, Model_unloaded_comp&);
		friend void                  save_component(ecs::Serializer& state, const Model_unloaded_comp&);
58

59
		Model_unloaded_comp() = default;
Florian Oetke's avatar
Florian Oetke committed
60
61
		Model_unloaded_comp(ecs::Entity_handle owner, ecs::Entity_manager& em, asset::AID model_aid = {})
		  : Component(owner, em), _model_aid(std::move(model_aid))
62
63
		{
		}
64

65
		auto model_aid() const -> auto& { return _model_aid; }
66

67
68
	  private:
		asset::AID _model_aid;
69
70
71
	};

	class Model_loading_comp : public ecs::Component<Model_loading_comp> {
72
73
74
	  public:
		static constexpr const char* name() { return "Model_loading"; }
		static constexpr const char* name_save_as() { return "Model"; }
75
76
		friend void                  load_component(ecs::Deserializer& state, Model_loading_comp&);
		friend void                  save_component(ecs::Serializer& state, const Model_loading_comp&);
77
78

		Model_loading_comp() = default;
Florian Oetke's avatar
Florian Oetke committed
79
80
		Model_loading_comp(ecs::Entity_handle owner, ecs::Entity_manager& em, Model_ptr model = {})
		  : Component(owner, em), _model(std::move(model))
81
82
		{
		}
83

84
		auto model_aid() const -> auto& { return _model.aid(); }
85
86
87
88
		auto model() const -> auto& { return _model; }
		auto model() -> auto& { return _model; }

	  private:
89
		Model_ptr _model;
90
	};
91
} // namespace mirrage::renderer