Unravel Engine C++ Reference
Loading...
Searching...
No Matches
material.cpp
Go to the documentation of this file.
1#include "material.hpp"
2
3#include <fstream>
6
7namespace unravel
8{
9
11{
12 entt::meta_factory<cull_type>{}
13 .type("cull_type"_hs)
15 entt::attribute{"name", "cull_type"},
16 entt::attribute{"pretty_name", "Cull Type"},
17 })
18 .data<cull_type::none>("none"_hs)
20 entt::attribute{"name", "none"},
21 entt::attribute{"pretty_name", "None"},
22 })
23 .data<cull_type::clockwise>("clockwise"_hs)
25 entt::attribute{"name", "clockwise"},
26 entt::attribute{"pretty_name", "Clockwise"},
27 })
28 .data<cull_type::counter_clockwise>("counter_clockwise"_hs)
30 entt::attribute{"name", "counter_clockwise"},
31 entt::attribute{"pretty_name", "Counter Clockwise"},
32 });
33
34 // Register material with entt
35 entt::meta_factory<material>{}
36 .type("material"_hs)
38 entt::attribute{"name", "material"},
39 entt::attribute{"pretty_name", "Material"},
40 })
41 .data<&material::set_cull_type, &material::get_cull_type>("cull_type"_hs)
43 entt::attribute{"name", "cull_type"},
44 entt::attribute{"pretty_name", "Cull Type"},
45 })
46 .func<&material::get_meta_type>("get_meta_type"_hs)
47 .func<&material::get_static_meta_type>("get_static_meta_type"_hs)
48 .func<&material::as_derived>("as_derived"_hs)
49 ;
50}
51
53{
54 try_save(ar, ser20::make_nvp("cull_type", obj.cull_type_));
55}
58
60{
61 try_load(ar, ser20::make_nvp("cull_type", obj.cull_type_));
62}
65
66void save_to_file(const std::string& absolute_path, const std::shared_ptr<material>& obj)
67{
68 std::ofstream stream(absolute_path);
69 if(stream.good())
70 {
71 auto ar = ser20::create_oarchive_associative(stream);
72 try_save(ar, ser20::make_nvp("material", obj));
73 }
74}
75
76void save_to_file_bin(const std::string& absolute_path, const std::shared_ptr<material>& obj)
77{
78 std::ofstream stream(absolute_path, std::ios::binary);
79 if(stream.good())
80 {
81 ser20::oarchive_binary_t ar(stream);
82 try_save(ar, ser20::make_nvp("material", obj));
83 }
84}
85
86void load_from_file(const std::string& absolute_path, std::shared_ptr<material>& obj)
87{
88 std::ifstream stream(absolute_path);
89 if(stream.good())
90 {
91 auto ar = ser20::create_iarchive_associative(stream);
92 try_load(ar, ser20::make_nvp("material", obj));
93 }
94}
95
96void load_from_file_bin(const std::string& absolute_path, std::shared_ptr<material>& obj)
97{
98 std::ifstream stream(absolute_path, std::ios::binary);
99 if(stream.good())
100 {
101 ser20::iarchive_binary_t ar(stream);
102 try_load(ar, ser20::make_nvp("material", obj));
103 }
104}
105
106} // namespace unravel
Base class for materials used in rendering.
Definition material.h:32
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
auto create_oarchive_associative(std::ostream &stream)
BinaryInputArchive iarchive_binary_t
auto create_iarchive_associative(std::istream &stream)
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
void save_to_file_bin(const std::string &absolute_path, const animation_clip &obj)
void load_from_file(const std::string &absolute_path, animation_clip &obj)
void save_to_file(const std::string &absolute_path, const animation_clip &obj)
void load_from_file_bin(const std::string &absolute_path, animation_clip &obj)
#define REFLECT(cls)
Definition reflection.h:133
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
static auto get_static_meta_type() -> entt::meta_type