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>2020-12-11 20:15:25 +0300
committerJulian Eisel <julian@blender.org>2020-12-15 19:03:00 +0300
commitb71eb3a105b8f7fb216a48082386215a6ea81cc4 (patch)
treebb23ee7e71f10dd2ed10d71f27f2c1beeb571afc /source/blender/makesrna
parent82645ff739687e4d58715869778c8860e832513c (diff)
Asset System: Data-block asset metadata storage, reading and API
Asset metadata is what turns a regular data-block into an asset. It is a small data-structure, but a key part of the technical design of the asset system. The design foresees that asset data-blocks store an `ID.asset_data` pointer of type `AssetMetaData`. This data **must not** have dependencies on other data-blocks or data-block data, it must be an independent unit. That way we can read asset-metadata from .blends without reading anything else from the file. The Asset Browser will use this metadata (together with the data-block name, preview and file path) to represent assets in the file list. Includes: * New `ID.asset_data` for asset metadata. * Asset tags, description and custom properties. * BKE code to manage asset meta-data and asset tags. * Code to read asset data from files, without reading IDs. * RNA for asset metadata (including tags) Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1 project milestone on developer.blender.org. Differential Revision: https://developer.blender.org/D9716 Reviewed by: Bastien Montagne, Brecht Van Lommel
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/RNA_access.h2
-rw-r--r--source/blender/makesrna/intern/CMakeLists.txt1
-rw-r--r--source/blender/makesrna/intern/makesrna.c1
-rw-r--r--source/blender/makesrna/intern/rna_ID.c5
-rw-r--r--source/blender/makesrna/intern/rna_asset.c228
-rw-r--r--source/blender/makesrna/intern/rna_internal.h1
6 files changed, 238 insertions, 0 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 4aeb9b9e5f7..da15489370a 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -70,6 +70,8 @@ extern StructRNA RNA_ArrayGpencilModifier;
extern StructRNA RNA_ArrayModifier;
extern StructRNA RNA_Attribute;
extern StructRNA RNA_AttributeGroup;
+extern StructRNA RNA_AssetMetaData;
+extern StructRNA RNA_AssetTag;
extern StructRNA RNA_BackgroundImage;
extern StructRNA RNA_BevelModifier;
extern StructRNA RNA_BezierSplinePoint;
diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt
index 3ebbb98934e..2ce1acb0074 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -31,6 +31,7 @@ set(DEFSRC
rna_animviz.c
rna_armature.c
rna_attribute.c
+ rna_asset.c
rna_boid.c
rna_brush.c
rna_cachefile.c
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 8b861d20e4e..c2c95c59002 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -4270,6 +4270,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
{"rna_animviz.c", NULL, RNA_def_animviz},
{"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
{"rna_attribute.c", NULL, RNA_def_attribute},
+ {"rna_asset.c", NULL, RNA_def_asset},
{"rna_boid.c", NULL, RNA_def_boid},
{"rna_brush.c", NULL, RNA_def_brush},
{"rna_cachefile.c", NULL, RNA_def_cachefile},
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index f63cf0271b8..7c67bfc360b 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -1528,6 +1528,11 @@ static void rna_def_ID(BlenderRNA *brna)
RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
RNA_def_property_ui_text(prop, "Library", "Library file the data-block is linked from");
+ prop = RNA_def_property(srna, "asset_data", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
+ RNA_def_property_ui_text(prop, "Asset Data", "Additional data for an asset data-block");
+
prop = RNA_def_pointer(
srna, "override_library", "IDOverrideLibrary", "Library Override", "Library override data");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
new file mode 100644
index 00000000000..1af53e95cc9
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -0,0 +1,228 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup RNA
+ */
+
+#include <stdlib.h>
+
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "DNA_asset_types.h"
+#include "DNA_defs.h"
+
+#include "rna_internal.h"
+
+#ifdef RNA_RUNTIME
+
+# include "BKE_asset.h"
+# include "BKE_idprop.h"
+
+# include "BLI_listbase.h"
+
+# include "RNA_access.h"
+
+static AssetTag *rna_AssetMetaData_tag_new(AssetMetaData *asset_data,
+ ReportList *reports,
+ const char *name,
+ bool skip_if_exists)
+{
+ AssetTag *tag = NULL;
+
+ if (skip_if_exists) {
+ struct AssetTagEnsureResult result = BKE_asset_metadata_tag_ensure(asset_data, name);
+
+ if (!result.is_new) {
+ BKE_reportf(
+ reports, RPT_WARNING, "Tag '%s' already present for given asset", result.tag->name);
+ /* Report, but still return valid item. */
+ }
+ tag = result.tag;
+ }
+ else {
+ tag = BKE_asset_metadata_tag_add(asset_data, name);
+ }
+
+ return tag;
+}
+
+static void rna_AssetMetaData_tag_remove(AssetMetaData *asset_data,
+ ReportList *reports,
+ PointerRNA *tag_ptr)
+{
+ AssetTag *tag = tag_ptr->data;
+ if (BLI_findindex(&asset_data->tags, tag) == -1) {
+ BKE_reportf(reports, RPT_ERROR, "Tag '%s' not found in given asset", tag->name);
+ return;
+ }
+
+ BKE_asset_metadata_tag_remove(asset_data, tag);
+ RNA_POINTER_INVALIDATE(tag_ptr);
+}
+
+static IDProperty *rna_AssetMetaData_idprops(PointerRNA *ptr, bool create)
+{
+ AssetMetaData *asset_data = ptr->data;
+
+ if (create && !asset_data->properties) {
+ IDPropertyTemplate val = {0};
+ asset_data->properties = IDP_New(IDP_GROUP, &val, "RNA_AssetMetaData group");
+ }
+
+ return asset_data->properties;
+}
+
+static void rna_AssetMetaData_description_get(PointerRNA *ptr, char *value)
+{
+ AssetMetaData *asset_data = ptr->data;
+
+ if (asset_data->description) {
+ strcpy(value, asset_data->description);
+ }
+ else {
+ value[0] = '\0';
+ }
+}
+
+static int rna_AssetMetaData_description_length(PointerRNA *ptr)
+{
+ AssetMetaData *asset_data = ptr->data;
+ return asset_data->description ? strlen(asset_data->description) : 0;
+}
+
+static void rna_AssetMetaData_description_set(PointerRNA *ptr, const char *value)
+{
+ AssetMetaData *asset_data = ptr->data;
+
+ if (asset_data->description) {
+ MEM_freeN(asset_data->description);
+ }
+
+ if (value[0]) {
+ asset_data->description = BLI_strdup(value);
+ }
+ else {
+ asset_data->description = NULL;
+ }
+}
+
+static void rna_AssetMetaData_active_tag_range(
+ PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
+{
+ const AssetMetaData *asset_data = ptr->data;
+ *min = *softmin = 0;
+ *max = *softmax = MAX2(asset_data->tot_tags - 1, 0);
+}
+
+#else
+
+static void rna_def_asset_tag(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "AssetTag", NULL);
+ RNA_def_struct_ui_text(srna, "Asset Tag", "User defined tag (name token)");
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_maxlength(prop, MAX_NAME);
+ RNA_def_property_ui_text(prop, "Name", "The identifier that makes up this tag");
+ RNA_def_struct_name_property(srna, prop);
+}
+
+static void rna_def_asset_tags_api(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "AssetTags");
+ srna = RNA_def_struct(brna, "AssetTags", NULL);
+ RNA_def_struct_sdna(srna, "AssetMetaData");
+ RNA_def_struct_ui_text(srna, "Asset Tags", "Collection of custom asset tags");
+
+ /* Tag collection */
+ func = RNA_def_function(srna, "new", "rna_AssetMetaData_tag_new");
+ RNA_def_function_ui_description(func, "Add a new tag to this asset");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_string(func, "name", NULL, MAX_NAME, "Name", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_boolean(func,
+ "skip_if_exists",
+ false,
+ "Skip if Exists",
+ "Do not add a new tag if one of the same type already exists");
+ /* return type */
+ parm = RNA_def_pointer(func, "tag", "AssetTag", "", "New tag");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "rna_AssetMetaData_tag_remove");
+ RNA_def_function_ui_description(func, "Remove an existing tag from this asset");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ /* tag to remove */
+ parm = RNA_def_pointer(func, "tag", "AssetTag", "", "Removed tag");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+}
+
+static void rna_def_asset_data(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "AssetMetaData", NULL);
+ RNA_def_struct_ui_text(srna, "Asset Data", "Additional data stored for an asset data-block");
+ // RNA_def_struct_ui_icon(srna, ICON_ASSET); /* TODO: Icon doesn't exist!. */
+ /* The struct has custom properties, but no pointer properties to other IDs! */
+ RNA_def_struct_idprops_func(srna, "rna_AssetMetaData_idprops");
+ RNA_def_struct_flag(srna, STRUCT_NO_DATABLOCK_IDPROPERTIES); /* Mandatory! */
+
+ prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop,
+ "rna_AssetMetaData_description_get",
+ "rna_AssetMetaData_description_length",
+ "rna_AssetMetaData_description_set");
+ RNA_def_property_ui_text(
+ prop, "Description", "A description of the asset to be displayed for the user");
+
+ prop = RNA_def_property(srna, "tags", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_struct_type(prop, "AssetTag");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop,
+ "Tags",
+ "Custom tags (name tokens) for the asset, used for filtering and "
+ "general asset management");
+ rna_def_asset_tags_api(brna, prop);
+
+ prop = RNA_def_property(srna, "active_tag", PROP_INT, PROP_NONE);
+ RNA_def_property_int_funcs(prop, NULL, NULL, "rna_AssetMetaData_active_tag_range");
+ RNA_def_property_ui_text(prop, "Active Tag", "Index of the tag set for editing");
+}
+
+void RNA_def_asset(BlenderRNA *brna)
+{
+ RNA_define_animate_sdna(false);
+
+ rna_def_asset_tag(brna);
+ rna_def_asset_data(brna);
+
+ RNA_define_animate_sdna(true);
+}
+
+#endif
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index d4fdac390b2..76c3e17e128 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -152,6 +152,7 @@ void RNA_def_animation(struct BlenderRNA *brna);
void RNA_def_animviz(struct BlenderRNA *brna);
void RNA_def_armature(struct BlenderRNA *brna);
void RNA_def_attribute(struct BlenderRNA *brna);
+void RNA_def_asset(struct BlenderRNA *brna);
void RNA_def_boid(struct BlenderRNA *brna);
void RNA_def_brush(struct BlenderRNA *brna);
void RNA_def_cachefile(struct BlenderRNA *brna);