|
Kemena3D
|
A serialized object subtree saved as a .prefab JSON asset. More...
#include <kprefab.h>
Public Member Functions | |
| kPrefab () | |
| Constructs an empty prefab with no UUID, name, or root subtree. | |
| ~kPrefab () | |
| Destroys the prefab and releases its stored JSON. | |
| bool | loadFromFile (const kString &path) |
| Loads a .prefab JSON file from disk into this prefab. | |
| bool | saveToFile (const kString &path) |
| Writes this prefab to a .prefab JSON file. | |
| kString | getUuid () const |
| Returns the prefab asset UUID. | |
| void | setUuid (const kString &v) |
| Sets the prefab asset UUID. | |
| kString | getName () const |
| Returns the display name of the prefab. | |
| void | setName (const kString &v) |
| Sets the display name of the prefab. | |
| const json & | getRootJson () const |
| Returns the object subtree JSON (the "root" field). | |
| json & | getRootJson () |
| Returns a mutable reference to the object subtree JSON (the "root" field). | |
| void | setRootJson (const json &j) |
| Replaces the object subtree JSON. | |
Static Public Member Functions | |
| static json | instantiateJson (const json &source, std::unordered_map< kString, kString > *templateMap=nullptr) |
| Generates a fresh-uuid copy of an object subtree. | |
A serialized object subtree saved as a .prefab JSON asset.
A prefab stores a tree of objects (transforms, scripts, components) rooted at a single object. Multiple prefab instances can be placed in scenes; each instance gets fresh per-node UUIDs while remembering the template UUID it was derived from, so the editor can match nodes across instances and the template.
On-disk format:
| kemena::kPrefab::kPrefab | ( | ) |
Constructs an empty prefab with no UUID, name, or root subtree.
| kemena::kPrefab::~kPrefab | ( | ) |
Destroys the prefab and releases its stored JSON.
|
inline |
Returns the display name of the prefab.
|
inline |
Returns a mutable reference to the object subtree JSON (the "root" field).
|
inline |
Returns the object subtree JSON (the "root" field).
|
inline |
Returns the prefab asset UUID.
|
static |
Generates a fresh-uuid copy of an object subtree.
Walks the JSON, replaces every "uuid" with a freshly generated UUID, and stores the original UUID into "template_uuid". Used when instantiating a prefab into a scene so each instance has its own identity but can still be matched back to the template.
| source | Object subtree (output of kObject::serialize()). |
| templateMap | Optional out: maps template_uuid -> instance_uuid for every node in the subtree. |
source, ready to be deserialized into a scene. | bool kemena::kPrefab::loadFromFile | ( | const kString & | path | ) |
Loads a .prefab JSON file from disk into this prefab.
| path | Filesystem path to the .prefab file. |
| bool kemena::kPrefab::saveToFile | ( | const kString & | path | ) |
Writes this prefab to a .prefab JSON file.
| path | Filesystem path to write to. |
|
inline |
Sets the display name of the prefab.
|
inline |
Replaces the object subtree JSON.
|
inline |
Sets the prefab asset UUID.