[Bf-blender-cvs] [98ef119dcf9] asset-metadata: Support arbitrary descriptions for assets
Julian Eisel
noreply at git.blender.org
Wed Jul 8 18:45:46 CEST 2020
Commit: 98ef119dcf9bc5d289ab4d75eb6b2d138b4a2b4d
Author: Julian Eisel
Date: Wed Jul 8 18:42:35 2020 +0200
Branches: asset-metadata
https://developer.blender.org/rB98ef119dcf9bc5d289ab4d75eb6b2d138b4a2b4d
Support arbitrary descriptions for assets
Simply have a dynamic string in the asset data-block. That can be set and
updated at any point.
===================================================================
M source/blender/blenkernel/intern/asset.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_asset_types.h
M source/blender/makesrna/intern/rna_asset.c
===================================================================
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index d2208dc9acb..b243b8a50e6 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -49,6 +49,8 @@ static void asset_free_data(ID *id)
BKE_icon_id_delete((ID *)asset);
BKE_previewimg_free(&asset->preview);
+
+ MEM_SAFE_FREE(asset->description);
}
static void asset_foreach_id(ID *id, LibraryForeachIDData *data)
@@ -69,7 +71,7 @@ IDTypeInfo IDType_ID_AST = {
/* flags */ 0,
/* init_data */ asset_init_data,
- /* copy_data */ NULL,
+ /* copy_data */ NULL, /* TODO */
/* free_data */ asset_free_data,
/* make_local */ NULL,
/* foreach_id */ asset_foreach_id,
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index b23f5884719..3272e426fa6 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8078,6 +8078,7 @@ static void direct_link_asset(BlendDataReader *reader, Asset *asset)
id_fake_user_set(&asset->id);
asset->preview = direct_link_preview_image(reader, asset->preview);
+ BLO_read_data_address(reader, &asset->description);
}
static void lib_link_asset(BlendLibReader *reader, Asset *asset)
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index fee411b381c..994d2f87fac 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3869,6 +3869,9 @@ static void write_asset(BlendWriter *writer, Asset *asset, const void *id_addres
write_iddata(writer, &asset->id);
write_previews(writer, asset->preview);
+ if (asset->description) {
+ BLO_write_string(writer, asset->description);
+ }
}
}
/* Keep it last of write_foodata functions. */
diff --git a/source/blender/makesdna/DNA_asset_types.h b/source/blender/makesdna/DNA_asset_types.h
index d5d32d9adca..bf5e5276cc4 100644
--- a/source/blender/makesdna/DNA_asset_types.h
+++ b/source/blender/makesdna/DNA_asset_types.h
@@ -28,7 +28,10 @@ typedef struct Asset {
/** Thumbnail image of the data-block. Duplicate of the referenced ID preview. */
struct PreviewImage *preview;
+ /** Optional description of this asset for display in the UI. Dynamic length. */
+ char *description;
+ /** The ID this asset was created for. */
ID *referenced_id;
} Asset;
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
index 3cf872707d6..cad608d096d 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -29,16 +29,58 @@
#ifdef RNA_RUNTIME
+static void rna_Asset_description_get(PointerRNA *ptr, char *value)
+{
+ Asset *asset = ptr->data;
+
+ if (asset->description) {
+ strcpy(value, asset->description);
+ }
+ else {
+ value[0] = '\0';
+ }
+}
+
+static int rna_Asset_description_length(PointerRNA *ptr)
+{
+ Asset *asset = ptr->data;
+ return asset->description ? strlen(asset->description) : 0;
+}
+
+static void rna_Asset_description_set(PointerRNA *ptr, const char *value)
+{
+ Asset *asset = ptr->data;
+
+ if (asset->description) {
+ MEM_freeN(asset->description);
+ }
+
+ if (value[0]) {
+ asset->description = BLI_strdup(value);
+ }
+ else {
+ asset->description = NULL;
+ }
+}
+
#else
static void rna_def_asset(BlenderRNA *brna)
{
StructRNA *srna;
+ PropertyRNA *prop;
srna = RNA_def_struct(brna, "Asset", "ID");
RNA_def_struct_ui_text(srna, "Asset", "Asset data-block");
-// RNA_def_struct_ui_icon(srna, ICON_ASSET); /* TODO: Icon doesn't exist!. */
+ // RNA_def_struct_ui_icon(srna, ICON_ASSET); /* TODO: Icon doesn't exist!. */
+ prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop,
+ "rna_Asset_description_get",
+ "rna_Asset_description_length",
+ "rna_Asset_description_set");
+ RNA_def_property_ui_text(
+ prop, "Description", "A description of the asset to be displayed for the user");
}
void RNA_def_asset(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list