Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-07-09 00:20:26 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-07-15 17:12:36 +0300
commit35affaa971cfb2d1829031f49a6ef9fb19ca576f (patch)
treefa5ae8266a520c6c9b9682d87fdd6ba8b544f748 /source/blender/makesrna
parent3feb3ce32d7d1fddf745bf30592cf68d906c295f (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/makesrna')
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/intern/rna_asset.c32
-rw-r--r--source/blender/makesrna/intern/rna_context.c27
3 files changed, 60 insertions, 0 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 52bf80ee45b..97615016016 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -71,6 +71,7 @@ extern StructRNA RNA_ArrayGpencilModifier;
extern StructRNA RNA_ArrayModifier;
extern StructRNA RNA_Attribute;
extern StructRNA RNA_AttributeGroup;
+extern StructRNA RNA_AssetHandle;
extern StructRNA RNA_AssetLibraryReference;
extern StructRNA RNA_AssetMetaData;
extern StructRNA RNA_AssetTag;
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
index 54cc87b4eea..82430d3e174 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -125,6 +125,20 @@ static void rna_AssetMetaData_active_tag_range(
*max = *softmax = MAX2(asset_data->tot_tags - 1, 0);
}
+static PointerRNA rna_AssetHandle_file_data_get(PointerRNA *ptr)
+{
+ AssetHandle *asset_handle = ptr->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_FileSelectEntry, asset_handle->file_data);
+}
+
+static void rna_AssetHandle_file_data_set(PointerRNA *ptr,
+ PointerRNA value,
+ struct ReportList *UNUSED(reports))
+{
+ AssetHandle *asset_handle = ptr->data;
+ asset_handle->file_data = value.data;
+}
+
int rna_asset_library_reference_get(const AssetLibraryReference *library)
{
return ED_asset_library_reference_to_enum_value(library);
@@ -278,6 +292,23 @@ static void rna_def_asset_data(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Active Tag", "Index of the tag set for editing");
}
+static void rna_def_asset_handle(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "AssetHandle", "PropertyGroup");
+ RNA_def_struct_ui_text(srna, "Asset Handle", "Reference to some asset");
+
+ /* TODO why is this editable? There probably shouldn't be a setter. */
+ prop = RNA_def_property(srna, "file_data", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "FileSelectEntry");
+ RNA_def_property_pointer_funcs(
+ prop, "rna_AssetHandle_file_data_get", "rna_AssetHandle_file_data_set", NULL, NULL);
+ RNA_def_property_ui_text(prop, "File Entry", "File data used to refer to the asset");
+}
+
static void rna_def_asset_library_reference(BlenderRNA *brna)
{
StructRNA *srna = RNA_def_struct(brna, "AssetLibraryReference", NULL);
@@ -306,6 +337,7 @@ void RNA_def_asset(BlenderRNA *brna)
rna_def_asset_tag(brna);
rna_def_asset_data(brna);
rna_def_asset_library_reference(brna);
+ rna_def_asset_handle(brna);
RNA_define_animate_sdna(true);
}
diff --git a/source/blender/makesrna/intern/rna_context.c b/source/blender/makesrna/intern/rna_context.c
index 4079406e64b..9da08de2168 100644
--- a/source/blender/makesrna/intern/rna_context.c
+++ b/source/blender/makesrna/intern/rna_context.c
@@ -58,6 +58,8 @@ const EnumPropertyItem rna_enum_context_mode_items[] = {
#ifdef RNA_RUNTIME
+# include "DNA_asset_types.h"
+
# ifdef WITH_PYTHON
# include "BPY_extern.h"
# endif
@@ -134,6 +136,20 @@ static PointerRNA rna_Context_gizmo_group_get(PointerRNA *ptr)
return newptr;
}
+static PointerRNA rna_Context_asset_file_handle_get(PointerRNA *ptr)
+{
+ bContext *C = (bContext *)ptr->data;
+ bool is_handle_valid;
+ AssetHandle asset_handle = CTX_wm_asset_handle(C, &is_handle_valid);
+ if (!is_handle_valid) {
+ return PointerRNA_NULL;
+ }
+
+ PointerRNA newptr;
+ RNA_pointer_create(NULL, &RNA_FileSelectEntry, asset_handle.file_data, &newptr);
+ return newptr;
+}
+
static PointerRNA rna_Context_main_get(PointerRNA *ptr)
{
bContext *C = (bContext *)ptr->data;
@@ -281,6 +297,17 @@ void RNA_def_context(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "GizmoGroup");
RNA_def_property_pointer_funcs(prop, "rna_Context_gizmo_group_get", NULL, NULL, NULL);
+ /* TODO can't expose AssetHandle, since there is no permanent storage to it (so we can't
+ * return a pointer). Instead provide the FileDirEntry pointer it wraps. */
+ prop = RNA_def_property(srna, "asset_file_handle", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "FileSelectEntry");
+ RNA_def_property_pointer_funcs(prop, "rna_Context_asset_file_handle_get", NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop,
+ "",
+ "The file of an active asset. Avoid using this, it will be replaced by "
+ "a proper AssetHandle design");
+
/* Data */
prop = RNA_def_property(srna, "blend_data", PROP_POINTER, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);