[Bf-blender-cvs] [f1940bdab71] asset-browser: Sync with review branches, adds "Remove Asset-Data" support

Julian Eisel noreply at git.blender.org
Thu Dec 3 22:56:34 CET 2020


Commit: f1940bdab71468f44c87f80f39539d68f490c600
Author: Julian Eisel
Date:   Thu Dec 3 22:54:35 2020 +0100
Branches: asset-browser
https://developer.blender.org/rBf1940bdab71468f44c87f80f39539d68f490c600

Sync with review branches, adds "Remove Asset-Data" support

Mostly internal changes. But also adds removing of asset data via the "Remove
Asset-Data" operator in the Outliner and button context menus, as well as
through deleting asset files in the Asset Browser.

===================================================================

M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/intern/asset.c
M	source/blender/blenkernel/intern/idtype.c
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/asset/asset_edit.c
M	source/blender/editors/asset/asset_ops.c
M	source/blender/editors/include/ED_asset.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_context_menu.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/makesdna/DNA_ID.h
M	source/blender/makesdna/DNA_asset_types.h
M	source/blender/makesdna/DNA_text_types.h

===================================================================

diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index 1298e3c2bbf..fa516e03e7b 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -268,6 +268,7 @@ const char *BKE_idtype_idcode_to_name(const short idcode);
 const char *BKE_idtype_idcode_to_name_plural(const short idcode);
 const char *BKE_idtype_idcode_to_translation_context(const short idcode);
 bool BKE_idtype_idcode_is_linkable(const short idcode);
+bool BKE_idtype_idcode_can_be_asset(const short idcode);
 bool BKE_idtype_idcode_is_valid(const short idcode);
 
 short BKE_idtype_idcode_from_name(const char *idtype_name);
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index c68e4106fcc..7ccb0aa2b57 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -39,7 +39,7 @@
 
 AssetMetaData *BKE_asset_metadata_create(void)
 {
-  AssetMetaData *asset_data = MEM_callocN(sizeof(AssetMetaData), __func__);
+  AssetMetaData *asset_data = MEM_callocN(sizeof(*asset_data), __func__);
   memcpy(asset_data, DNA_struct_default_get(AssetMetaData), sizeof(*asset_data));
   return asset_data;
 }
@@ -55,20 +55,23 @@ void BKE_asset_metadata_free(AssetMetaData **asset_data)
   MEM_SAFE_FREE(*asset_data);
 }
 
-static AssetTag *asset_metadata_tag_create(const char *const name)
+static AssetTag *asset_metadata_tag_add(AssetMetaData *asset_data, const char *const name)
 {
   AssetTag *tag = MEM_callocN(sizeof(*tag), __func__);
   BLI_strncpy(tag->name, name, sizeof(tag->name));
+
+  BLI_addtail(&asset_data->tags, tag);
+  asset_data->tot_tags++;
+  /* Invariant! */
+  BLI_assert(BLI_listbase_count(&asset_data->tags) == asset_data->tot_tags);
+
   return tag;
 }
 
 AssetTag *BKE_asset_metadata_tag_add(AssetMetaData *asset_data, const char *name)
 {
-  AssetTag *tag = asset_metadata_tag_create(name);
-
-  BLI_addtail(&asset_data->tags, tag);
+  AssetTag *tag = asset_metadata_tag_add(asset_data, name);
   BLI_uniquename(&asset_data->tags, tag, name, '.', offsetof(AssetTag, name), sizeof(tag->name));
-
   return tag;
 }
 
@@ -91,8 +94,7 @@ struct AssetTagEnsureResult BKE_asset_metadata_tag_ensure(AssetMetaData *asset_d
     return result;
   }
 
-  tag = asset_metadata_tag_create(name);
-  BLI_addtail(&asset_data->tags, tag);
+  tag = asset_metadata_tag_add(asset_data, name);
 
   result.tag = tag;
   result.is_new = true;
@@ -101,7 +103,11 @@ struct AssetTagEnsureResult BKE_asset_metadata_tag_ensure(AssetMetaData *asset_d
 
 void BKE_asset_metadata_tag_remove(AssetMetaData *asset_data, AssetTag *tag)
 {
+  BLI_assert(BLI_findindex(&asset_data->tags, tag) >= 0);
   BLI_freelinkN(&asset_data->tags, tag);
+  asset_data->tot_tags--;
+  /* Invariant! */
+  BLI_assert(BLI_listbase_count(&asset_data->tags) == asset_data->tot_tags);
 }
 
 /* Queries -------------------------------------------- */
@@ -141,4 +147,5 @@ void BKE_asset_metadata_read(BlendDataReader *reader, AssetMetaData *asset_data)
 
   BLO_read_data_address(reader, &asset_data->description);
   BLO_read_list(reader, &asset_data->tags);
+  BLI_assert(BLI_listbase_count(&asset_data->tags) == asset_data->tot_tags);
 }
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index 44bf8f0e4db..5c9d91efb8f 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -235,6 +235,11 @@ bool BKE_idtype_idcode_is_linkable(const short idcode)
   return id_type != NULL ? (id_type->flags & IDTYPE_FLAGS_NO_LIBLINKING) == 0 : false;
 }
 
+bool BKE_idtype_idcode_can_be_asset(const short idcode)
+{
+  return BKE_idtype_idcode_is_linkable(idcode);
+}
+
 /**
  * Convert an \a idcode into an \a idfilter (e.g. ID_OB -> FILTER_ID_OB).
  */
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 788ecc64bd6..1d7c5d8a1d3 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -132,7 +132,7 @@ struct LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh,
                                                      int *tot_names);
 struct LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh,
                                                     int ofblocktype,
-                                                    int *tot_names);
+                                                    int *tot_info_items);
 struct LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *tot_prev);
 struct LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh);
 
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 21e76d679a4..f395633ffa9 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -165,10 +165,10 @@ LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh, int ofblocktype,
  *
  * \param bh: The blendhandle to access.
  * \param ofblocktype: The type of names to get.
- * \param tot_names: The length of the returned list.
+ * \param tot_info_items: The length of the returned list.
  * \return A BLI_linklist of BLODataBlockInfo *. The links should be freed with MEM_freeN.
  */
-LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh, int ofblocktype, int *tot_names)
+LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh, int ofblocktype, int *tot_info_items)
 {
   FileData *fd = (FileData *)bh;
   LinkNode *infos = NULL;
@@ -199,7 +199,7 @@ LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh, int ofblocktype, i
     }
   }
 
-  *tot_names = tot;
+  *tot_info_items = tot;
   return infos;
 }
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index fa1077469b3..39c69c40528 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -967,7 +967,7 @@ const char *blo_bhead_id_name(const FileData *fd, const BHead *bhead)
 AssetMetaData *blo_bhead_id_asset_data_address(const FileData *fd, const BHead *bhead)
 {
   BLI_assert(BKE_idtype_idcode_is_valid(bhead->code));
-  return (fd->id_asset_data_offs > 0) ?
+  return (fd->id_asset_data_offs >= 0) ?
              *(AssetMetaData **)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_asset_data_offs) :
              NULL;
 }
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 1d81512f36e..3e7cdb30e1f 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -113,7 +113,7 @@ typedef struct FileData {
   /** Used to retrieve ID names from (bhead+1). */
   int id_name_offs;
   /** Used to retrieve asset data from (bhead+1). NOTE: This may not be available in old files,
-   * will be 0 then! */
+   * will be -1 then! */
   int id_asset_data_offs;
   /** For do_versions patching. */
   int globalf, fileflags;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index d6c15d70034..1757b2d020d 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -93,7 +93,6 @@
 /* allow writefile to use deprecated functionality (for forward compatibility code) */
 #define DNA_DEPRECATED_ALLOW
 
-#include "DNA_asset_types.h"
 #include "DNA_fileglobal_types.h"
 #include "DNA_genfile.h"
 #include "DNA_sdna_types.h"
diff --git a/source/blender/editors/asset/asset_edit.c b/source/blender/editors/asset/asset_edit.c
index ab4f40cca98..ba3cea3042a 100644
--- a/source/blender/editors/asset/asset_edit.c
+++ b/source/blender/editors/asset/asset_edit.c
@@ -20,6 +20,7 @@
 
 #include "BKE_asset.h"
 #include "BKE_context.h"
+#include "BKE_idtype.h"
 #include "BKE_lib_id.h"
 
 #include "DNA_ID.h"
@@ -36,6 +37,9 @@ bool ED_asset_make_for_id(const bContext *C, ID *id)
   if (id->asset_data) {
     return false;
   }
+  if (!BKE_idtype_idcode_can_be_asset(GS(id->name))) {
+    return false;
+  }
 
   id_fake_user_set(id);
 
@@ -46,8 +50,19 @@ bool ED_asset_make_for_id(const bContext *C, ID *id)
   return true;
 }
 
+bool ED_asset_unmake_from_id(ID *id)
+{
+  if (!id->asset_data) {
+    return false;
+  }
+  BKE_asset_metadata_free(&id->asset_data);
+  /* TODO What about user-count? */
+
+  return true;
+}
+
 bool ED_asset_can_make_single_from_context(const bContext *C)
 {
-  /* Context needs a "focused_id" pointer to be set for #ASSET_OT_make() to use. */
-  return CTX_data_pointer_get_type_silent(C, "focused_id", &RNA_ID).data != NULL;
+  /* Context needs a "id" pointer to be set for #ASSET_OT_make()/#ASSET_OT_unmake() to use. */
+  return CTX_data_pointer_get_type_silent(C, "id", &RNA_ID).data != NULL;
 }
diff --git a/source/blender/editors/asset/asset_ops.c b/source/blender/editors/asset/asset_ops.c
index 10010b6485e..2e403ba20e9 100644
--- a/source/blender/editors/asset/asset_ops.c
+++ b/source/blender/editors/asset/asset_ops.c
@@ -41,14 +41,20 @@
 
 /* -------------------------------------------------------------------- */
 
+struct AssetMakeResultStats {
+  int tot_created;
+  int tot_already_asset;
+  ID *last_id;
+};
+
 /**
  * Return the IDs to operate on as list of #CollectionPointerLink links. Needs freeing.
  */
-static ListBase asset_make_get_ids_from_context(const bContext *C)
+static ListBase /* CollectionPointerLink */ asset_operation_get_ids_from_context(const bContext *C)
 {
   ListBase list = {0};
 
-  PointerRNA idptr = CTX_data_pointer_get_type(C, "focused_id", &RNA_ID);
+  PointerRNA idptr = CTX_data_pointer_get_type(C, "id", &RNA_ID);
 
   if (idptr.data) {
     CollectionPointerLink *ctx_link = MEM_callocN(sizeof(*ctx_link), __func__);
@@ -62,22 +68,14 @@ static ListBase asset_make_get_ids_from_context(const bContext *C)
   return list;
 }
 
-struct AssetMakeResultStats {
-  int tot_created;
-  int tot_selected_ids;
-  int tot_already_asset;
-  ID *last_id;
-};
-
 static void asset_make_for_idptr_list(const bContext *C,
-                                      const ListBase *ids,
+                             

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list