vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
asset_serializer.h
1#pragma once
2
3#include <string>
4#include <utility>
5#include <vector>
6
7#include <nlohmann/json.hpp>
8
9#include "ecs/entity.h"
10#include "io/scene/component_serializer.h"
11#include "resource/asset/material_asset.h"
12#include "resource/asset_type.h"
13
14namespace Vkm::Engine {
15
16class ResourceManager;
17class Scene;
18
28namespace AssetSerializer {
38 std::vector<std::pair<AssetType, std::string>> names;
39 };
40
52 const Scene& scene,
53 EntityId id,
54 const ResourceManager& resources,
55 EntityAssetRefs& refs
56 );
57
68 nlohmann::json saveAssetsForEntities(
69 const Scene& scene,
70 const std::vector<EntityId>& entities,
71 const ResourceManager& resources
72 );
73
84 nlohmann::json saveAssetsForScene(const Scene& scene, const ResourceManager& resources);
85
96 nlohmann::json saveAllAssets(const ResourceManager& resources);
97
101 enum class LoadMode {
117 };
118
130 const nlohmann::json& assetsJson,
131 ResourceManager& resources,
133 );
134
147 size_t dropAssetsNotIn(const nlohmann::json& assetsJson, ResourceManager& resources);
148
159 MaterialAsset materialFromRecipe(const nlohmann::json& source, const ResourceManager& resources);
160
170 nlohmann::json materialToRecipe(const MaterialAsset& material, const ResourceManager& resources);
171
172} // namespace AssetSerializer
173
174} // namespace Vkm::Engine
Type-erased resource registry with typed handles and generational lifetimes.
Definition resource_manager.h:46
Central registry managing entities and an open set of component types.
Definition scene.h:29
Serialize / deserialize the asset graph referenced by a Scene.
Definition asset_serializer.h:28
void collectAssetRefs(const Scene &scene, EntityId id, const ResourceManager &resources, EntityAssetRefs &refs)
Append every asset reference id holds to refs.
nlohmann::json materialToRecipe(const MaterialAsset &material, const ResourceManager &resources)
Build a material's recipe: its PBR scalars plus texture refs by name.
size_t dropAssetsNotIn(const nlohmann::json &assetsJson, ResourceManager &resources)
Drop every asset in resources that assetsJson does not name.
MaterialAsset materialFromRecipe(const nlohmann::json &source, const ResourceManager &resources)
Build a material from its recipe.
nlohmann::json saveAssetsForEntities(const Scene &scene, const std::vector< EntityId > &entities, const ResourceManager &resources)
The assets block for a chosen set of entities.
nlohmann::json saveAssetsForScene(const Scene &scene, const ResourceManager &resources)
The assets block for every entity in scene.
nlohmann::json saveAllAssets(const ResourceManager &resources)
The assets block for everything resources holds, referenced or not.
bool loadAssets(const nlohmann::json &assetsJson, ResourceManager &resources, LoadMode mode=LoadMode::Create)
Recreate the assets a document names into resources.
LoadMode
What loadAssets does about a name resources already holds.
Definition asset_serializer.h:101
@ Reload
Rebuild a material's contents in place, keeping its handle and name; leave every other kind alone,...
Definition asset_serializer.h:116
@ Create
Leave it alone.
Definition asset_serializer.h:107
Every asset reference a set of entities holds, as an assets block would name it.
Definition asset_serializer.h:36
Every asset a set of components references, one list per kind.
Definition component_serializer.h:304
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
A complete PBR material.
Definition material_asset.h:71