Unravel Engine C++ Reference
Loading...
Searching...
No Matches
asset_extensions.h
Go to the documentation of this file.
1#pragma once
3#include <engine/engine_export.h>
4#include <string>
5#include <vector>
6
7namespace gfx
8{
9struct texture;
10struct shader;
11} // namespace gfx
12
13namespace unravel
14{
15class mesh;
16class material;
17struct prefab;
18struct scene_prefab;
19struct animation_clip;
20struct physics_material;
21struct audio_clip;
22struct script;
23struct font;
24struct ui_tree;
25struct style_sheet;
26
27} // namespace unravel
28
29namespace ex
30{
31
32template<typename T>
33auto get_suported_formats() -> const std::vector<std::string>&
34{
35 static_assert(!std::is_same_v<T, T>, "get_suported_formats must be specialized for this type");
36 static const std::vector<std::string> result = {};
37 return result;
38}
39
40template<typename T>
41auto get_suported_dependencies_formats() -> const std::vector<std::string>&;
42
43
44template<>
45inline auto get_suported_formats<unravel::font>() -> const std::vector<std::string>&
46{
47 static std::vector<std::string> formats = {".ttf", ".otf"};
48 return formats;
49}
50
51template<>
52inline auto get_suported_formats<gfx::texture>() -> const std::vector<std::string>&
53{
54 static std::vector<std::string> formats = {".etex", ".png", ".jpg", ".jpeg", ".tga", ".dds", ".ktx", ".ktx2", ".pvr", ".exr", ".hdr", ".bmp", ".gif", ".psd"};
55 return formats;
56}
57
58template<>
59inline auto get_suported_formats<unravel::mesh>() -> const std::vector<std::string>&
60{
61 static std::vector<std::string> formats = {".emesh", ".gltf", ".glb", ".obj", ".fbx", ".FBX", ".dae", ".blend", ".3ds"};
62 return formats;
63}
64
65template<>
66inline auto get_suported_formats<unravel::audio_clip>() -> const std::vector<std::string>&
67{
68 static std::vector<std::string> formats = {".eaudioclip", ".ogg", ".wav", ".flac", ".mp3"};
69 return formats;
70}
71
72template<>
73inline auto get_suported_dependencies_formats<gfx::shader>() -> const std::vector<std::string>&
74{
75 static std::vector<std::string> formats = {".sh"};
76 return formats;
77}
78
79template<>
80inline auto get_suported_dependencies_formats<unravel::ui_tree>() -> const std::vector<std::string>&
81{
82 static std::vector<std::string> formats = {".rcss"};
83 return formats;
84}
85
86template<>
87inline auto get_suported_formats<gfx::shader>() -> const std::vector<std::string>&
88{
89 static std::vector<std::string> formats = {".sc"};
90 return formats;
91}
92
93template<>
94inline auto get_suported_formats<unravel::material>() -> const std::vector<std::string>&
95{
96 static std::vector<std::string> formats = {".mat", ".ematerial"};
97 return formats;
98}
99
100template<>
101inline auto get_suported_formats<unravel::animation_clip>() -> const std::vector<std::string>&
102{
103 static std::vector<std::string> formats = {".anim"};
104 return formats;
105}
106
107template<>
108inline auto get_suported_formats<unravel::prefab>() -> const std::vector<std::string>&
109{
110 static std::vector<std::string> formats = {".pfb"};
111 return formats;
112}
113
114template<>
115inline auto get_suported_formats<unravel::scene_prefab>() -> const std::vector<std::string>&
116{
117 static std::vector<std::string> formats = {".spfb"};
118 return formats;
119}
120
121template<>
122inline auto get_suported_formats<unravel::physics_material>() -> const std::vector<std::string>&
123{
124 static std::vector<std::string> formats = {".phm", ".ephmaterial"};
125 return formats;
126}
127
128template<>
129inline auto get_suported_formats<unravel::script>() -> const std::vector<std::string>&
130{
131 static std::vector<std::string> formats = {".cs"};
132 return formats;
133}
134
135template<>
136inline auto get_suported_formats<unravel::ui_tree>() -> const std::vector<std::string>&
137{
138 static std::vector<std::string> formats = {".rhtml"};
139 return formats;
140}
141
142template<>
143inline auto get_suported_formats<unravel::style_sheet>() -> const std::vector<std::string>&
144{
145 static std::vector<std::string> formats = {".rcss"};
146 return formats;
147}
148
167
168template<typename T>
169inline auto is_format(const std::string& ex) -> bool
170{
171 if(ex.empty())
172 {
173 return false;
174 }
175
176 const auto& supported = ex::get_suported_formats<T>();
177 return std::find_if(std::begin(supported),
178 std::end(supported),
179 [&](const std::string& el)
180 {
181 return el.find(ex) != std::string::npos;
182 }) != std::end(supported);
183}
184
185template<typename T>
186inline auto get_format_version() -> uint64_t
187{
188 return 0;
189}
190
191// Template specializations for format versions
192// Increment these versions when the binary serialization format changes for each asset type
193template<>
194inline auto get_format_version<unravel::mesh>() -> uint64_t
195{
196 // 8: per-submesh stable_id, per-bone bind-space bounds, per-LOD submesh bbox recompute.
197 // 9: mesh bounds are bind-pose only (import-time animation sampling removed; runtime
198 // pose bounds handle animation-driven expansion).
199 return 9;
200}
201
202template<>
204{
205 return 4;
206}
207
208template<>
210{
211 return 1;
212}
213
214template<>
216{
217 return 1;
218}
219
220template<>
222{
223 return 1;
224}
225
226template<>
227inline auto get_format_version<gfx::texture>() -> uint64_t
228{
229 return 1;
230}
231
232inline auto get_format_version(const std::string& extension) -> uint64_t
233{
234 if(is_format<gfx::texture>(extension))
235 {
237 }
238
239 if(is_format<unravel::mesh>(extension))
240 {
242 }
243
244 if(is_format<unravel::material>(extension))
245 {
247 }
248
250 {
252 }
253
255 {
257 }
258
259 if(is_format<unravel::audio_clip>(extension))
260 {
262 }
263
264 return 0;
265}
266
267template<typename T>
268inline auto get_format(bool include_dot = true) -> std::string
269{
270 auto format = get_suported_formats<T>().front();
271 if(include_dot)
272 {
273 return format;
274 }
275 return format.substr(1);
276}
277
278template<typename T>
279inline auto get_suported_formats_with_wildcard() -> std::vector<std::string>
280{
281 auto formats = get_suported_formats<T>();
282 for(auto& fmt : formats)
283 {
284 fmt.insert(fmt.begin(), '*');
285 }
286
287 return formats;
288}
289
290inline auto get_meta_format() -> const std::string&
291{
292 static const std::string result = ".meta";
293 return result;
294}
295
296
297inline auto get_meta_directory_no_slash(const std::string& prefix = {}) -> std::string
298{
299 return prefix + "data";
300}
301
302inline auto get_data_directory_no_slash(const std::string& prefix = {}) -> std::string
303{
304 return prefix + "data";
305}
306
307inline auto get_compiled_directory_no_slash(const std::string& prefix = {}) -> std::string
308{
309 return prefix + "compiled";
310}
311
312inline auto get_meta_directory(const std::string& prefix = {}) -> std::string
313{
314 return get_meta_directory_no_slash(prefix + ":/");
315}
316
317inline auto get_data_directory(const std::string& prefix = {}) -> std::string
318{
319 return get_data_directory_no_slash(prefix + ":/");
320}
321
322inline auto get_compiled_directory(const std::string& prefix = {}) -> std::string
323{
324 return get_compiled_directory_no_slash(prefix + ":/");
325}
326
327
328inline auto get_type(const std::string& ex, bool is_directory = false) -> const std::string&
329{
331 {
332 static const std::string result = "Texture";
333 return result;
334 }
336 {
337 static const std::string result = "Shader";
338 return result;
339 }
341 {
342 static const std::string result = "Material";
343 return result;
344 }
346 {
347 static const std::string result = "Mesh";
348 return result;
349 }
351 {
352 static const std::string result = "Animation Clip";
353 return result;
354 }
356 {
357 static const std::string result = "Audio Clip";
358 return result;
359 }
361 {
362 static const std::string result = "Prefab";
363 return result;
364 }
366 {
367 static const std::string result = "Scene";
368 return result;
369 }
371 {
372 static const std::string result = "Physics Material";
373 return result;
374 }
376 {
377 static const std::string result = "Script";
378 return result;
379 }
381 {
382 static const std::string result = "Font";
383 return result;
384 }
386 {
387 static const std::string result = "UI Tree";
388 return result;
389 }
391 {
392 static const std::string result = "Style Sheet";
393 return result;
394 }
395 if(is_directory)
396 {
397 static const std::string result = "Folder";
398 return result;
399 }
400
401 static const std::string result;
402 return result;
403}
404
405inline auto is_binary(const std::string& ex) -> bool
406{
407 // Binary formats (compiled/processed assets)
409 {
410 // Most texture formats are binary, except some like .hdr which can be text-based
411 // But for simplicity, we'll consider all texture formats as binary
412 return true;
413 }
415 {
416 // .emesh is binary, but source formats like .obj, .gltf can be text
417 // Check for binary formats specifically
418 return ex == ".emesh" || ex == ".glb" || ex == ".fbx" || ex == ".FBX" ||
419 ex == ".blend" || ex == ".3ds" || ex == ".dae";
420 }
422 {
423 // Audio formats are typically binary
424 return true;
425 }
427 {
428 // .sc shader files are text-based
429 return false;
430 }
432 {
433 // .mat and .ematerial are typically text-based (JSON/XML)
434 return false;
435 }
437 {
438 // .anim files are typically text-based
439 return false;
440 }
442 {
443 // .pfb files are typically text-based
444 return false;
445 }
447 {
448 // .spfb files are typically text-based
449 return false;
450 }
452 {
453 // Physics material files are typically text-based
454 return false;
455 }
457 {
458 // .cs script files are text-based
459 return false;
460 }
462 {
463 // Font files (.ttf, .otf) are binary
464 return true;
465 }
467 {
468 // .rhtml files are text-based
469 return false;
470 }
472 {
473 // .rcss files are text-based
474 return false;
475 }
476
477 // Unknown format, assume text-based for safety
478 return false;
479}
480
481template<typename T>
482inline auto get_type() -> const std::string&
483{
484 if constexpr(std::is_same_v<T, gfx::texture>)
485 {
486 static const std::string result = "Texture";
487 return result;
488 }
489 if constexpr(std::is_same_v<T, gfx::shader>)
490 {
491 static const std::string result = "Shader";
492 return result;
493 }
494 if constexpr(std::is_same_v<T, unravel::material>)
495 {
496 static const std::string result = "Material";
497 return result;
498 }
499 if constexpr(std::is_same_v<T, unravel::mesh>)
500 {
501 static const std::string result = "Mesh";
502 return result;
503 }
504 if constexpr(std::is_same_v<T, unravel::animation_clip>)
505 {
506 static const std::string result = "Animation Clip";
507 return result;
508 }
509 if constexpr(std::is_same_v<T, unravel::audio_clip>)
510 {
511 static const std::string result = "Audio Clip";
512 return result;
513 }
514 if constexpr(std::is_same_v<T, unravel::prefab>)
515 {
516 static const std::string result = "Prefab";
517 return result;
518 }
519 if constexpr(std::is_same_v<T, unravel::scene_prefab>)
520 {
521 static const std::string result = "Scene";
522 return result;
523 }
524 if constexpr(std::is_same_v<T, unravel::physics_material>)
525 {
526 static const std::string result = "Physics Material";
527 return result;
528 }
529 if constexpr(std::is_same_v<T, unravel::script>)
530 {
531 static const std::string result = "Script";
532 return result;
533 }
534 if constexpr(std::is_same_v<T, unravel::script_library>)
535 {
536 static const std::string result = "Scripts";
537 return result;
538 }
539 if constexpr(std::is_same_v<T, unravel::font>)
540 {
541 static const std::string result = "Font";
542 return result;
543 }
544 if constexpr(std::is_same_v<T, unravel::ui_tree>)
545 {
546 static const std::string result = "UI Tree";
547 return result;
548 }
549 if constexpr(std::is_same_v<T, unravel::style_sheet>)
550 {
551 static const std::string result = "Style Sheet";
552 return result;
553 }
554
555 static const std::string result;
556 return result;
557}
558
559} // namespace ex
gfx::texture_format format
ImGui::Font::Enum font
Definition hub.cpp:30
auto get_suported_formats< gfx::shader >() -> const std::vector< std::string > &
auto get_all_formats() -> const std::vector< std::vector< std::string > > &
auto get_format(bool include_dot=true) -> std::string
auto get_compiled_directory_no_slash(const std::string &prefix={}) -> std::string
auto get_suported_formats< unravel::ui_tree >() -> const std::vector< std::string > &
auto get_data_directory(const std::string &prefix={}) -> std::string
auto get_format_version< unravel::material >() -> uint64_t
auto get_suported_formats< unravel::audio_clip >() -> const std::vector< std::string > &
auto get_type() -> const std::string &
auto is_format(const std::string &ex) -> bool
auto get_format_version< unravel::animation_clip >() -> uint64_t
auto get_meta_directory_no_slash(const std::string &prefix={}) -> std::string
auto get_suported_formats< unravel::scene_prefab >() -> const std::vector< std::string > &
auto get_suported_formats< unravel::style_sheet >() -> const std::vector< std::string > &
auto get_suported_formats< unravel::animation_clip >() -> const std::vector< std::string > &
auto get_suported_formats< unravel::font >() -> const std::vector< std::string > &
auto get_meta_format() -> const std::string &
auto get_compiled_directory(const std::string &prefix={}) -> std::string
auto get_suported_formats< unravel::physics_material >() -> const std::vector< std::string > &
auto get_suported_formats< gfx::texture >() -> const std::vector< std::string > &
auto get_suported_dependencies_formats< gfx::shader >() -> const std::vector< std::string > &
auto get_meta_directory(const std::string &prefix={}) -> std::string
auto get_suported_formats< unravel::prefab >() -> const std::vector< std::string > &
auto is_binary(const std::string &ex) -> bool
auto get_format_version< unravel::audio_clip >() -> uint64_t
auto get_format_version< gfx::texture >() -> uint64_t
auto get_suported_formats< unravel::material >() -> const std::vector< std::string > &
auto get_suported_formats< unravel::mesh >() -> const std::vector< std::string > &
auto get_format_version() -> uint64_t
auto get_suported_formats() -> const std::vector< std::string > &
auto get_suported_dependencies_formats< unravel::ui_tree >() -> const std::vector< std::string > &
auto get_format_version< unravel::physics_material >() -> uint64_t
auto get_data_directory_no_slash(const std::string &prefix={}) -> std::string
auto get_suported_dependencies_formats() -> const std::vector< std::string > &
auto get_suported_formats_with_wildcard() -> std::vector< std::string >
auto get_suported_formats< unravel::script >() -> const std::vector< std::string > &
auto get_format_version< unravel::mesh >() -> uint64_t