![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
Serialize / deserialize the asset graph referenced by a Scene. More...
Classes | |
| struct | EntityAssetRefs |
| Every asset reference a set of entities holds, as an assets block would name it. More... | |
Enumerations | |
| enum class | LoadMode { Create , Reload } |
What loadAssets does about a name resources already holds. More... | |
Functions | |
| void | collectAssetRefs (const Scene &scene, EntityId id, const ResourceManager &resources, EntityAssetRefs &refs) |
Append every asset reference id holds to refs. | |
| 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. | |
| size_t | dropAssetsNotIn (const nlohmann::json &assetsJson, ResourceManager &resources) |
Drop every asset in resources that assetsJson does not name. | |
| 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 | materialToInline (const MaterialAsset &material, const ResourceManager &resources) |
| Build a material's canonical "inline" source descriptor: PBR scalars plus texture refs by name. | |
Serialize / deserialize the asset graph referenced by a Scene.
Saves name every asset the scene references, one section per kind keyed like the library's directories; an unnamed asset has no serializable identity and is skipped. Loads resolve names through the asset library - the cooked file, else the recipe through the AssetFactory seam - skipping names ResourceManager already holds; a name neither serves stays unresolved. Sections load in ASSET_DEPENDENCY_ORDER, so textures land before the materials that resolve them.
|
strong |
What loadAssets does about a name resources already holds.
| Enumerator | |
|---|---|
| Create | Leave it alone. What a load wants: a name not held is built; a held one already is what the document describes. |
| Reload | Rebuild a material's contents in place, keeping its handle and name; leave every other kind alone, as Create does. For restoring a snapshot (see PlaySnapshot). In place, so handles already held still name the material (see ResourceManager::swapValue). Materials alone: their rebuild reads a small recipe, where other kinds would re-read cooked data, so those keep edits made during the session. |
| void Vkm::Engine::AssetSerializer::collectAssetRefs | ( | const Scene & | scene, |
| EntityId | id, | ||
| const ResourceManager & | resources, | ||
| EntityAssetRefs & | refs ) |
Append every asset reference id holds to refs.
The one walk over an entity's references: a field that names an asset is seen here or nowhere.
| scene | Scene holding the entity. |
| id | Entity to walk; alive. |
| resources | The asset graph the entity's handles index into. |
| refs | Where the references are appended; duplicates are kept. |
| nlohmann::json Vkm::Engine::AssetSerializer::saveAssetsForEntities | ( | const Scene & | scene, |
| const std::vector< EntityId > & | entities, | ||
| const ResourceManager & | resources ) |
The assets block for a chosen set of entities.
What a prefab needs: its file lists the assets its subtree names, not the whole scene's.
| scene | Scene holding the entities. |
| entities | The entities to walk; must be alive. |
| resources | Resolves each handle to the asset it names. |
| nlohmann::json Vkm::Engine::AssetSerializer::saveAssetsForScene | ( | const Scene & | scene, |
| const ResourceManager & | resources ) |
The assets block for every entity in scene.
Includes entities inside prefab instances, though the prefab file has its own block: an instance may override a Mesh or a Decal with an asset the prefab never names.
| scene | Scene to walk. |
| resources | Resolves each handle to the asset it names. |
| nlohmann::json Vkm::Engine::AssetSerializer::saveAllAssets | ( | const ResourceManager & | resources | ) |
The assets block for everything resources holds, referenced or not.
Unlike saveAssetsForScene, also lists assets not yet assigned to anything, which restoring a whole graph needs (see PlaySnapshot). Hidden and unnamed assets are skipped: a private preview asset is not the author's, and loadAssets finds by name.
| resources | The asset graph to enumerate. |
| bool Vkm::Engine::AssetSerializer::loadAssets | ( | const nlohmann::json & | assetsJson, |
| ResourceManager & | resources, | ||
| LoadMode | mode = LoadMode::Create ) |
Recreate the assets a document names into resources.
| assetsJson | An assets block, from any of the save functions above. |
| resources | The asset graph to build into. |
| mode | What to do about a name the graph already holds; see LoadMode. |
| size_t Vkm::Engine::AssetSerializer::dropAssetsNotIn | ( | const nlohmann::json & | assetsJson, |
| ResourceManager & | resources ) |
Drop every asset in resources that assetsJson does not name.
The other half of a restore: loadAssets leaves alone what the document does not name, and a session that generates its world creates assets the document has never heard of. Only the kinds saveAllAssets writes are considered, so never a font. Hidden assets are kept: save filters them, so their absence says nothing.
| assetsJson | A document from saveAllAssets(). |
| resources | Graph to prune. |
| void Vkm::Engine::AssetSerializer::applyInline | ( | const nlohmann::json & | source, |
| MaterialAsset & | target, | ||
| const ResourceManager & | resources ) |
Apply an "inline" material descriptor (kind=="inline") to a freshly constructed MaterialAsset.
A missing key keeps the field's value; a wrong-typed value throws, reported against the material.
| source | The descriptor, as materialToInline writes it. |
| target | The material to fill. |
| resources | Resolves texture names; one it does not hold leaves its slot as it was. |
| nlohmann::json Vkm::Engine::AssetSerializer::materialToInline | ( | const MaterialAsset & | material, |
| const ResourceManager & | resources ) |
Build a material's canonical "inline" source descriptor: PBR scalars plus texture refs by name.
The material's editable source of truth, its runtime form, and what its recipe file holds.
| material | The material to describe. |
| resources | Resolves its texture handles to the names written. |