Unravel Engine C++ Reference
Loading...
Searching...
No Matches
model_component.cpp
Go to the documentation of this file.
1
#include "
model_component.hpp
"
2
3
#include <
engine/meta/assets/asset_handle.hpp
>
4
#include <
engine/meta/ecs/entity.hpp
>
5
#include <
engine/meta/rendering/material.hpp
>
6
#include <
engine/meta/rendering/mesh.hpp
>
7
#include <
engine/meta/rendering/model.hpp
>
8
9
#include <
serialization/associative_archive.h
>
10
#include <
serialization/binary_archive.h
>
11
#include <
serialization/types/set.hpp
>
12
#include <
serialization/types/vector.hpp
>
13
14
namespace
unravel
15
{
16
17
REFLECT
(
model_component
)
18
{
19
entt::meta_factory<model_component>{}
20
.type(
"model_component"
_hs)
21
.custom<
entt::attributes
>(
entt::attributes
{
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)
31
.data<&
model_component::set_enabled
, &
model_component::is_enabled
>(
"enabled"
_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)
38
.custom<
entt::attributes
>(
entt::attributes
{
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)
44
.custom<
entt::attributes
>(
entt::attributes
{
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)
50
.custom<
entt::attributes
>(
entt::attributes
{
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)
56
.custom<
entt::attributes
>(
entt::attributes
{
57
entt::attribute
{
"name"
,
"model"
},
58
entt::attribute
{
"pretty_name"
,
"Model"
},
59
});
60
}
61
62
SAVE
(
model_component
)
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
}
69
SAVE_INSTANTIATE
(
model_component
,
ser20::oarchive_associative_t
);
70
SAVE_INSTANTIATE
(
model_component
,
ser20::oarchive_binary_t
);
71
72
LOAD
(
model_component
)
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
}
98
LOAD_INSTANTIATE
(
model_component
,
ser20::iarchive_associative_t
);
99
LOAD_INSTANTIATE
(
model_component
,
ser20::iarchive_binary_t
);
100
101
REFLECT
(
bone_component
)
102
{
103
entt::meta_factory<bone_component>{}
104
.type(
"bone_component"
_hs)
105
.custom<
entt::attributes
>(
entt::attributes
{
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
123
SAVE
(
bone_component
)
124
{
125
try_save
(ar, ser20::make_nvp(
"bone_index"
, obj.bone_index));
126
}
127
SAVE_INSTANTIATE
(
bone_component
,
ser20::oarchive_associative_t
);
128
SAVE_INSTANTIATE
(
bone_component
,
ser20::oarchive_binary_t
);
129
130
LOAD
(
bone_component
)
131
{
132
try_load
(ar, ser20::make_nvp(
"bone_index"
, obj.bone_index));
133
}
134
LOAD_INSTANTIATE
(
bone_component
,
ser20::iarchive_associative_t
);
135
LOAD_INSTANTIATE
(
bone_component
,
ser20::iarchive_binary_t
);
136
137
REFLECT
(
submesh_entry
)
138
{
139
entt::meta_factory<submesh_entry>{}
140
.type(
"submesh_entry"
_hs)
141
.custom<
entt::attributes
>(
entt::attributes
{
142
entt::attribute
{
"name"
,
"submesh_entry"
},
143
entt::attribute
{
"pretty_name"
,
"Submesh Entry"
},
144
})
145
.data<nullptr, &submesh_entry::submesh_index>(
"submesh_index"
_hs)
146
.custom<
entt::attributes
>(
entt::attributes
{
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)
152
.custom<
entt::attributes
>(
entt::attributes
{
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)
158
.custom<
entt::attributes
>(
entt::attributes
{
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)
164
.custom<
entt::attributes
>(
entt::attributes
{
165
entt::attribute
{
"name"
,
"enabled"
},
166
entt::attribute
{
"pretty_name"
,
"Enabled"
},
167
entt::attribute
{
"tooltip"
,
"Whether this submesh is rendered."
},
168
});
169
}
170
171
REFLECT
(
submesh_component
)
172
{
173
entt::meta_factory<submesh_component>{}
174
.type(
"submesh_component"
_hs)
175
.custom<
entt::attributes
>(
entt::attributes
{
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
195
SAVE
(
submesh_entry
)
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
}
203
SAVE_INSTANTIATE
(
submesh_entry
,
ser20::oarchive_associative_t
);
204
SAVE_INSTANTIATE
(
submesh_entry
,
ser20::oarchive_binary_t
);
205
206
LOAD
(
submesh_entry
)
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
}
214
LOAD_INSTANTIATE
(
submesh_entry
,
ser20::iarchive_associative_t
);
215
LOAD_INSTANTIATE
(
submesh_entry
,
ser20::iarchive_binary_t
);
216
217
SAVE
(
submesh_component
)
218
{
219
try_save
(ar, ser20::make_nvp(
"entries"
, obj.entries));
220
}
221
SAVE_INSTANTIATE
(
submesh_component
,
ser20::oarchive_associative_t
);
222
SAVE_INSTANTIATE
(
submesh_component
,
ser20::oarchive_binary_t
);
223
224
LOAD
(
submesh_component
)
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
}
233
LOAD_INSTANTIATE
(
submesh_component
,
ser20::iarchive_associative_t
);
234
LOAD_INSTANTIATE
(
submesh_component
,
ser20::iarchive_binary_t
);
235
236
}
// namespace unravel
asset_handle.hpp
associative_archive.h
binary_archive.h
unravel::model_component
Class that contains core data for meshes.
Definition
model_component.h:16
unravel::model_component::set_enabled
void set_enabled(bool enabled)
Sets whether the model is enabled.
Definition
model_component.cpp:777
unravel::model_component::is_enabled
auto is_enabled() const -> bool
Checks if the model is enabled.
Definition
model_component.cpp:813
vector.hpp
entity.hpp
material.hpp
mesh.hpp
model.hpp
model_component.hpp
entt::attribute
attributes::value_type attribute
Definition
reflection.h:19
entt::attributes
std::map< std::string, meta_any > attributes
Definition
reflection.h:18
ser20::iarchive_binary_t
BinaryInputArchive iarchive_binary_t
Definition
binary_archive.h:15
ser20::oarchive_associative_t
simd::JSONOutputArchive oarchive_associative_t
Definition
associative_archive.h:68
ser20::oarchive_binary_t
BinaryOutputArchive oarchive_binary_t
Definition
binary_archive.h:14
ser20::iarchive_associative_t
simd::JSONInputArchive iarchive_associative_t
Definition
associative_archive.h:69
unravel
Definition
crash.cpp:21
REFLECT
#define REFLECT(cls)
Definition
reflection.h:149
SAVE_INSTANTIATE
#define SAVE_INSTANTIATE(cls, Archive)
Definition
serialization.h:148
LOAD
#define LOAD(cls)
Definition
serialization.h:142
try_save
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Definition
serialization.h:275
LOAD_INSTANTIATE
#define LOAD_INSTANTIATE(cls, Archive)
Definition
serialization.h:150
SAVE
#define SAVE(cls)
Definition
serialization.h:138
try_load
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Definition
serialization.h:283
set.hpp
unravel::bone_component
Definition
model_component.h:357
unravel::bone_component::bone_index
uint32_t bone_index
Definition
model_component.h:358
unravel::component_meta
Definition
basic_component.h:101
unravel::submesh_component
Definition
model_component.h:386
unravel::submesh_component::entries
std::vector< submesh_entry > entries
Definition
model_component.h:390
unravel::submesh_entry
Per-submesh render settings authored on the armature node entity that owns the submesh.
Definition
model_component.h:366
engine
engine
meta
ecs
components
model_component.cpp
Generated by
1.12.0