7#include "hellfire/serializers/MaterialSerializer.h"
8#include "hellfire/serializers/MeshSerializer.h"
15 if (
auto it = mesh_cache_.find(id); it != mesh_cache_.end()) {
22 std::cerr <<
"Invalid mesh asset: " << id << std::endl;
28 std::cerr <<
"Failed to load mesh: " << std::endl;
32 if (mesh && !mesh->is_built()) {
36 mesh_cache_[id] = mesh;
41 if (
auto it = material_cache_.find(id); it != material_cache_.end()) {
57 material->set_diffuse_color(data->diffuse_color);
58 material->set_ambient_color(data->ambient_color);
59 material->set_specular_color(data->specular_color);
60 material->set_emissive_color(data->emissive_color);
61 material->set_opacity(data->opacity);
62 material->set_shininess(data->shininess);
63 material->set_metallic(data->metallic);
64 material->set_roughness(data->roughness);
66 for (
const auto &tex_id: data->texture_assets | std::views::values) {
67 if (
auto tex = get_texture(tex_id)) {
68 material->set_texture(tex, 0);
72 material_cache_[id] = material;
77 if (
auto it = texture_cache_.find(id); it != texture_cache_.end()) {
86 auto texture = std::make_shared<
Texture>(
90 if (!texture->is_valid()) {
94 texture_cache_[id] = texture;
99 mesh_cache_.erase(id);
100 material_cache_.erase(id);
101 texture_cache_.erase(id);
106 material_cache_.clear();
107 texture_cache_.clear();
111 for (
const AssetID id : registry_.get_modified_assets()) {
std::shared_ptr< Texture > get_texture(AssetID id)
AssetManager(AssetRegistry ®istry)
std::shared_ptr< Mesh > get_mesh(AssetID id)
AssetRegistry & registry_
std::shared_ptr< Material > get_material(AssetID id)
Registry for storing assets.
std::filesystem::path get_absolute_path(AssetID uuid)
static std::optional< MaterialData > load(const std::filesystem::path &filepath)
static std::shared_ptr< Mesh > load(const std::filesystem::path &filepath)