Unravel Engine C++ Reference
Loading...
Searching...
No Matches
model_component.cpp
Go to the documentation of this file.
1#include "model_component.hpp"
2
8
13
14namespace unravel
15{
16
18{
19 entt::meta_factory<model_component>{}
20 .type("model_component"_hs)
22 entt::attribute{"name", "model_component"},
23 entt::attribute{"category", "RENDERING"},
24 entt::attribute{"pretty_name", "Model"},
25 })
26 .func<&component_meta<model_component>::exists>("component_exists"_hs)
27 .func<&component_meta<model_component>::add>("component_add"_hs)
28 .func<&component_meta<model_component>::remove>("component_remove"_hs)
29 .func<&component_meta<model_component>::save>("component_save"_hs)
30 .func<&component_meta<model_component>::load>("component_load"_hs)
32 .custom<entt::attributes>(entt::attributes{
33 entt::attribute{"name", "enabled"},
34 entt::attribute{"pretty_name", "Enabled"},
35 entt::attribute{"tooltip", "Is the model visible?"},
36 })
37 .data<&model_component::set_static, &model_component::is_static>("static"_hs)
39 entt::attribute{"name", "static"},
40 entt::attribute{"pretty_name", "Static"},
41 entt::attribute{"tooltip", "Is the model static?"},
42 })
43 .data<&model_component::set_casts_shadow, &model_component::casts_shadow>("casts_shadow"_hs)
45 entt::attribute{"name", "casts_shadow"},
46 entt::attribute{"pretty_name", "Casts Shadow"},
47 entt::attribute{"tooltip", "Is the model casting shadows?"},
48 })
49 .data<nullptr, &model_component::get_world_bounds>("world_bounds"_hs)
51 entt::attribute{"name", "world_bounds"},
52 entt::attribute{"pretty_name", "World Bounds"},
53 entt::attribute{"tooltip", "The world bounds of the model."},
54 })
55 .data<&model_component::set_model, &model_component::get_model>("model"_hs)
57 entt::attribute{"name", "model"},
58 entt::attribute{"pretty_name", "Model"},
59 });
60}
61
63{
64 try_save(ar, ser20::make_nvp("enabled", obj.is_enabled()));
65 try_save(ar, ser20::make_nvp("static", obj.is_static()));
66 try_save(ar, ser20::make_nvp("casts_shadow", obj.casts_shadow()));
67 try_save(ar, ser20::make_nvp("model", obj.get_model()));
68}
71
73{
74 bool is_enabled{true};
75 if(try_load(ar, ser20::make_nvp("enabled", is_enabled)))
76 {
77 obj.set_enabled(is_enabled);
78 }
79
80 bool is_static{};
81 if(try_load(ar, ser20::make_nvp("static", is_static)))
82 {
83 obj.set_static(is_static);
84 }
85
86 bool casts_shadow{};
87 if(try_load(ar, ser20::make_nvp("casts_shadow", casts_shadow)))
88 {
89 obj.set_casts_shadow(casts_shadow);
90 }
91
92 auto mod = obj.get_model();
93 if(try_load(ar, ser20::make_nvp("model", mod)))
94 {
95 obj.set_model(mod);
96 }
97}
100
102{
103 entt::meta_factory<bone_component>{}
104 .type("bone_component"_hs)
106 entt::attribute{"name", "bone_component"},
107 entt::attribute{"category", "RENDERING"},
108 entt::attribute{"pretty_name", "Bone"},
109 })
110 .func<&component_meta<bone_component>::exists>("component_exists"_hs)
111 .func<&component_meta<bone_component>::add>("component_add"_hs)
112 .func<&component_meta<bone_component>::save>("component_save"_hs)
113 .func<&component_meta<bone_component>::load>("component_load"_hs)
114 .func<&component_meta<bone_component>::remove>("component_remove"_hs)
115 .data<nullptr, &bone_component::bone_index>("bone_index"_hs)
116 .custom<entt::attributes>(entt::attributes{
117 entt::attribute{"name", "bone_index"},
118 entt::attribute{"pretty_name", "Bone Index"},
119 entt::attribute{"tooltip", "The bone index this object represents."},
120 });
121}
122
124{
125 try_save(ar, ser20::make_nvp("bone_index", obj.bone_index));
126}
129
131{
132 try_load(ar, ser20::make_nvp("bone_index", obj.bone_index));
133}
136
138{
139 entt::meta_factory<submesh_entry>{}
140 .type("submesh_entry"_hs)
142 entt::attribute{"name", "submesh_entry"},
143 entt::attribute{"pretty_name", "Submesh Entry"},
144 })
145 .data<nullptr, &submesh_entry::submesh_index>("submesh_index"_hs)
147 entt::attribute{"name", "submesh_index"},
148 entt::attribute{"pretty_name", "Submesh Index"},
149 entt::attribute{"tooltip", "Index of the submesh in the mesh asset."},
150 })
151 .data<&submesh_entry::material_override>("material_override"_hs)
153 entt::attribute{"name", "material_override"},
154 entt::attribute{"pretty_name", "Material Override"},
155 entt::attribute{"tooltip", "Overrides the model material for this submesh. Leave empty to use the model material."},
156 })
157 .data<&submesh_entry::casts_shadow>("casts_shadow"_hs)
159 entt::attribute{"name", "casts_shadow"},
160 entt::attribute{"pretty_name", "Casts Shadow"},
161 entt::attribute{"tooltip", "Whether this submesh casts shadows."},
162 })
163 .data<&submesh_entry::enabled>("enabled"_hs)
165 entt::attribute{"name", "enabled"},
166 entt::attribute{"pretty_name", "Enabled"},
167 entt::attribute{"tooltip", "Whether this submesh is rendered."},
168 });
169}
170
172{
173 entt::meta_factory<submesh_component>{}
174 .type("submesh_component"_hs)
176 entt::attribute{"name", "submesh_component"},
177 entt::attribute{"category", "RENDERING"},
178 entt::attribute{"pretty_name", "Submesh"},
179 })
180 .func<&component_meta<submesh_component>::exists>("component_exists"_hs)
181 .func<&component_meta<submesh_component>::add>("component_add"_hs)
182 .func<&component_meta<submesh_component>::remove>("component_remove"_hs)
183 .func<&component_meta<submesh_component>::save>("component_save"_hs)
184 .func<&component_meta<submesh_component>::load>("component_load"_hs)
185 .data<&submesh_component::entries>("entries"_hs)
186 .custom<entt::attributes>(entt::attributes{
187 entt::attribute{"name", "entries"},
188 entt::attribute{"pretty_name", "Entries"},
189 entt::attribute{"tooltip", "Per-submesh render settings (material override, shadows, visibility)."},
190 // The mesh asset dictates which submeshes exist; users edit entry settings only.
191 entt::attribute{"is_fixed_size_array", true},
192 });
193}
194
196{
197 try_save(ar, ser20::make_nvp("submesh_index", obj.submesh_index));
198 try_save(ar, ser20::make_nvp("stable_id", obj.stable_id));
199 try_save(ar, ser20::make_nvp("material_override", obj.material_override));
200 try_save(ar, ser20::make_nvp("casts_shadow", obj.casts_shadow));
201 try_save(ar, ser20::make_nvp("enabled", obj.enabled));
202}
205
207{
208 try_load(ar, ser20::make_nvp("submesh_index", obj.submesh_index));
209 try_load(ar, ser20::make_nvp("stable_id", obj.stable_id));
210 try_load(ar, ser20::make_nvp("material_override", obj.material_override));
211 try_load(ar, ser20::make_nvp("casts_shadow", obj.casts_shadow));
212 try_load(ar, ser20::make_nvp("enabled", obj.enabled));
213}
216
218{
219 try_save(ar, ser20::make_nvp("entries", obj.entries));
220}
223
225{
226 try_load(ar, ser20::make_nvp("entries", obj.entries));
227
228 // Legacy data only serialized the bare index vector - synthesize default entries.
229 std::vector<uint32_t> legacy_indices;
230 try_load(ar, ser20::make_nvp("submeshes", legacy_indices));
231 obj.migrate_legacy_indices(legacy_indices);
232}
235
236} // namespace unravel
Class that contains core data for meshes.
void set_enabled(bool enabled)
Sets whether the model is enabled.
auto is_enabled() const -> bool
Checks if the model is enabled.
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
#define REFLECT(cls)
Definition reflection.h:149
#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
std::vector< submesh_entry > entries
Per-submesh render settings authored on the armature node entity that owns the submesh.