vkmEngine 1.0.0
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
128 const nlohmann::json& assetsJson,
129 ResourceManager& resources,
131 );
132
145 size_t dropAssetsNotIn(const nlohmann::json& assetsJson, ResourceManager& resources);
146
157 void applyInline(const nlohmann::json& source, MaterialAsset& target, const ResourceManager& resources);
158
169 nlohmann::json materialToInline(const MaterialAsset& material, const ResourceManager& resources);
170
171} // namespace AssetSerializer
172
173} // namespace Vkm::Engine
Open 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.
size_t dropAssetsNotIn(const nlohmann::json &assetsJson, ResourceManager &resources)
Drop every asset in resources that assetsJson does not name.
nlohmann::json saveAssetsForEntities(const Scene &scene, const std::vector< EntityId > &entities, const ResourceManager &resources)
The assets block for a chosen set of entities.
void applyInline(const nlohmann::json &source, MaterialAsset &target, const ResourceManager &resources)
Apply an "inline" material descriptor (kind=="inline") to a freshly constructed MaterialAsset.
nlohmann::json saveAssetsForScene(const Scene &scene, const ResourceManager &resources)
The assets block for every entity in scene.
nlohmann::json materialToInline(const MaterialAsset &material, const ResourceManager &resources)
Build a material's canonical "inline" source descriptor: PBR scalars plus texture refs by name.
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:266
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:67