diff options
author | Julian Eisel <julian@blender.org> | 2021-07-09 00:20:26 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-07-15 17:12:36 +0300 |
commit | 35affaa971cfb2d1829031f49a6ef9fb19ca576f (patch) | |
tree | fa5ae8266a520c6c9b9682d87fdd6ba8b544f748 /source/blender/blenkernel/intern/context.c | |
parent | 3feb3ce32d7d1fddf745bf30592cf68d906c295f (diff) |
Assets: AssetHandle type as temporary design to reference assets
With temporary I mean that this is not intended to be part of the
eventual asset system design. For that we are planning to have an
`AssetRepresentation` instead, see T87235. Once the `AssetList` is
implemented (see T88184), that would be the owner of the asset
representations.
However for the upcoming asset system, asset browser, asset view and
pose library commits we need some kind of asset handle to pass around.
That is what this commit introduces.
Idea is a handle to wrap the `FileDirEntry` representing the asset, and
an API to access its data (currently very small, will be extended in
further commits). So the fact that an asset is currently a file
internally is abstracted away. However: We have to expose it as file in
the Python API, because we can't return the asset-handle directly there,
for reasons explained in the code. So the active asset file is exposed
as `bpy.context.asset_file_handle`.
Diffstat (limited to 'source/blender/blenkernel/intern/context.c')
-rw-r--r-- | source/blender/blenkernel/intern/context.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 4c91a3f3387..dced945bea0 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -1453,6 +1453,31 @@ const AssetLibraryReference *CTX_wm_asset_library(const bContext *C) return ctx_data_pointer_get(C, "asset_library"); } +AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid) +{ + AssetHandle *asset_handle_p = + (AssetHandle *)CTX_data_pointer_get_type(C, "asset_handle", &RNA_AssetHandle).data; + if (asset_handle_p) { + *r_is_valid = true; + return *asset_handle_p; + } + + /* If the asset handle was not found in context directly, try if there's an active file with + * asset data there instead. Not nice to have this here, would be better to have this in + * `ED_asset.h`, but we can't include that in BKE. Even better would be not needing this at all + * and being able to have editors return this in the usual `context` callback. But that would + * require returning a non-owning pointer, which we don't have in the Asset Browser (yet). */ + FileDirEntry *file = + (FileDirEntry *)CTX_data_pointer_get_type(C, "active_file", &RNA_FileSelectEntry).data; + if (file && file->asset_data) { + *r_is_valid = true; + return (AssetHandle){.file_data = file}; + } + + *r_is_valid = false; + return (AssetHandle){0}; +} + Depsgraph *CTX_data_depsgraph_pointer(const bContext *C) { Main *bmain = CTX_data_main(C); |