[Bf-blender-cvs] [3417af0ebe8] asset-metadata: Add new asset data-block type

Julian Eisel noreply at git.blender.org
Mon Jul 6 15:42:52 CEST 2020


Commit: 3417af0ebe89cb235398716b1d74d8b10120284f
Author: Julian Eisel
Date:   Mon Jul 6 15:16:27 2020 +0200
Branches: asset-metadata
https://developer.blender.org/rB3417af0ebe89cb235398716b1d74d8b10120284f

Add new asset data-block type

With this we can read asset data in .blends more efficiently, e.g. for browsing
files or assets (where we avoid reading more than we have to). But there are
other things besides performance that I'd like to play with.
Basically I see the asset information a bit similar to library information,
which we also deal with as a separate data-block.

The "Create Asset" operator doesn't actually create these data-blocks yet.
That'll be added in a followup commit.

Of course this is not set in stone, but I think a reasonable design to work
with for now.

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

M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/BKE_main.h
M	source/blender/blenkernel/intern/asset.c
M	source/blender/blenkernel/intern/idtype.c
M	source/blender/blenkernel/intern/lib_query.c
M	source/blender/blenkernel/intern/main.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/blentranslation/BLT_translation.h
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/render/render_opengl.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/makesdna/DNA_ID.h
A	source/blender/makesdna/DNA_asset_defaults.h
M	source/blender/makesdna/DNA_asset_types.h
M	source/blender/makesdna/intern/CMakeLists.txt
M	source/blender/makesdna/intern/dna_defaults.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_ID.c
A	source/blender/makesrna/intern/rna_asset.c
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_main.c
M	source/blender/makesrna/intern/rna_main_api.c

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

diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index a823693e126..e5dc823fd0f 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -163,6 +163,7 @@ typedef struct IDTypeInfo {
 /* Those are defined in the respective BKE files. */
 extern IDTypeInfo IDType_ID_SCE;
 extern IDTypeInfo IDType_ID_LI;
+extern IDTypeInfo IDType_ID_AST;
 extern IDTypeInfo IDType_ID_OB;
 extern IDTypeInfo IDType_ID_ME;
 extern IDTypeInfo IDType_ID_CU;
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index b7c70168a49..7f875ca4d74 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -116,6 +116,7 @@ typedef struct Main {
   struct Library *curlib;
   ListBase scenes;
   ListBase libraries;
+  ListBase assets;
   ListBase objects;
   ListBase meshes;
   ListBase curves;
@@ -228,7 +229,7 @@ const char *BKE_main_blendfile_path_from_global(void);
 
 struct ListBase *which_libbase(struct Main *mainlib, short type);
 
-#define MAX_LIBARRAY 41
+#define MAX_LIBARRAY 42
 int set_listbasepointers(struct Main *main, struct ListBase *lb[MAX_LIBARRAY]);
 
 #define MAIN_VERSION_ATLEAST(main, ver, subver) \
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index e12a3a248ba..04ad12375bc 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -18,12 +18,50 @@
  * \ingroup bke
  */
 
+#include <string.h>
+
 #include "BKE_asset.h"
+#include "BKE_idtype.h"
+
+#include "BLT_translation.h"
 
+#include "DNA_ID.h"
 #include "DNA_asset_types.h"
+#include "DNA_defaults.h"
 
 #include "MEM_guardedalloc.h"
 
+static void asset_init_data(ID *id)
+{
+  Asset *asset = (Asset *)id;
+  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(asset, id));
+
+  MEMCPY_STRUCT_AFTER(asset, DNA_struct_default_get(Asset), id);
+}
+
+static void asset_free_data(ID *id)
+{
+  Asset *asset = (Asset *)id;
+  UNUSED_VARS(asset);
+}
+
+IDTypeInfo IDType_ID_AST = {
+    /* id_code */ ID_AST,
+    /* id_filter */ FILTER_ID_AST,
+    /* main_listbase_index */ INDEX_ID_AST,
+    /* struct_size */ sizeof(Asset),
+    /* name */ "Asset",
+    /* name_plural */ "assets",
+    /* translation_context */ BLT_I18NCONTEXT_ID_SIMULATION,
+    /* flags */ 0,
+
+    /* init_data */ asset_init_data,
+    /* copy_data */ NULL,
+    /* free_data */ asset_free_data,
+    /* make_local */ NULL,
+    /* foreach_id */ NULL,
+};
+
 AssetData *BKE_asset_data_create(void)
 {
   return MEM_callocN(sizeof(AssetData), __func__);
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index 2684e964eb1..61e8332f727 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -72,6 +72,7 @@ static void id_type_init(void)
 
   INIT_TYPE(ID_SCE);
   INIT_TYPE(ID_LI);
+  INIT_TYPE(ID_AST);
   INIT_TYPE(ID_OB);
   INIT_TYPE(ID_ME);
   INIT_TYPE(ID_CU);
@@ -242,9 +243,10 @@ uint64_t BKE_idtype_idcode_to_idfilter(const short idcode)
   case ID_##_id: \
     return FILTER_ID_##_id
 
-  switch (idcode) {
+  switch ((ID_Type)idcode) {
     CASE_IDFILTER(AC);
     CASE_IDFILTER(AR);
+    CASE_IDFILTER(AST);
     CASE_IDFILTER(BR);
     CASE_IDFILTER(CA);
     CASE_IDFILTER(CF);
@@ -297,6 +299,7 @@ short BKE_idtype_idcode_from_idfilter(const uint64_t idfilter)
   switch (idfilter) {
     CASE_IDFILTER(AC);
     CASE_IDFILTER(AR);
+    CASE_IDFILTER(AST);
     CASE_IDFILTER(BR);
     CASE_IDFILTER(CA);
     CASE_IDFILTER(CF);
@@ -348,6 +351,7 @@ int BKE_idtype_idcode_to_index(const short idcode)
   switch ((ID_Type)idcode) {
     CASE_IDINDEX(AC);
     CASE_IDINDEX(AR);
+    CASE_IDINDEX(AST);
     CASE_IDINDEX(BR);
     CASE_IDINDEX(CA);
     CASE_IDINDEX(CF);
@@ -410,6 +414,7 @@ short BKE_idtype_idcode_from_index(const int index)
   switch (index) {
     CASE_IDCODE(AC);
     CASE_IDCODE(AR);
+    CASE_IDCODE(AST);
     CASE_IDCODE(BR);
     CASE_IDCODE(CA);
     CASE_IDCODE(CF);
diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c
index 00a42b12e07..9fe6689848b 100644
--- a/source/blender/blenkernel/intern/lib_query.c
+++ b/source/blender/blenkernel/intern/lib_query.c
@@ -339,6 +339,8 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
   switch ((ID_Type)id_type_owner) {
     case ID_LI:
       return ELEM(id_type_used, ID_LI);
+    case ID_AST:
+      return ELEM(id_type_used, ID_AST);
     case ID_SCE:
       return (ELEM(id_type_used,
                    ID_OB,
diff --git a/source/blender/blenkernel/intern/main.c b/source/blender/blenkernel/intern/main.c
index 4b577ccec2c..dad4ffd8e0c 100644
--- a/source/blender/blenkernel/intern/main.c
+++ b/source/blender/blenkernel/intern/main.c
@@ -428,6 +428,8 @@ ListBase *which_libbase(Main *bmain, short type)
       return &(bmain->scenes);
     case ID_LI:
       return &(bmain->libraries);
+    case ID_AST:
+      return &(bmain->assets);
     case ID_OB:
       return &(bmain->objects);
     case ID_ME:
@@ -524,6 +526,8 @@ int set_listbasepointers(Main *bmain, ListBase **lb)
   /* Libraries may be accessed from pretty much any other ID. */
   lb[INDEX_ID_LI] = &(bmain->libraries);
 
+  lb[INDEX_ID_AST] = &(bmain->assets);
+
   lb[INDEX_ID_IP] = &(bmain->ipo);
 
   /* Moved here to avoid problems when freeing with animato (aligorith). */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 0659353ebfd..3115ba41ce9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8336,6 +8336,21 @@ static void fix_relpaths_library(const char *basepath, Main *main)
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Read ID: Asset
+ * \{ */
+
+static void direct_link_asset(FileData *UNUSED(fd), Asset *asset, Main *UNUSED(main))
+{
+  id_fake_user_set(&asset->id);
+}
+
+static void lib_link_asset(BlendLibReader *UNUSED(reader), Asset *UNUSED(asset))
+{
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Read ID: Light Probe
  * \{ */
@@ -9034,6 +9049,8 @@ static const char *dataname(short id_code)
       return "Data from AC";
     case ID_LI:
       return "Data from LI";
+    case ID_AST:
+      return "Data from AST";
     case ID_MB:
       return "Data from MB";
     case ID_IM:
@@ -9170,6 +9187,9 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_LI:
       direct_link_library(fd, (Library *)id, main);
       break;
+    case ID_AST:
+      direct_link_asset(fd, (Asset *)id, main);
+      break;
     case ID_CA:
       direct_link_camera(&reader, (Camera *)id);
       break;
@@ -9956,6 +9976,9 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_LI:
         lib_link_library(&reader, (Library *)id); /* Only init users. */
         break;
+      case ID_AST:
+        lib_link_asset(&reader, (Asset *)id);
+        break;
     }
 
     id->tag &= ~LIB_TAG_NEED_LINK;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index d70df842263..030a4a663d6 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3862,6 +3862,13 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const
   }
 }
 
+static void write_asset(BlendWriter *writer, Asset *asset, const void *id_address)
+{
+  if (asset->id.us > 0 || BLO_write_is_undo(writer)) {
+    BLO_write_id_struct(writer, Asset, id_address, &asset->id);
+    write_iddata(writer, &asset->id);
+  }
+}
 /* Keep it last of write_foodata functions. */
 static void write_libraries(WriteData *wd, Main *main)
 {
@@ -4230,6 +4237,9 @@ static bool write_file_handle(Main *mainvar,
           case ID_SIM:
             write_simulation(&writer, (Simulation *)id_buffer, id);
             break;
+          case ID_AST:
+            write_asset(&writer, (Asset *)id_buffer, id);
+            break;
           case ID_LI:
             /* Do nothing, handled below - and should never be reached. */
             BLI_assert(0);
diff --git a/source/blender/blentranslation/BLT_translation.h b/source/blender/blentranslation/BLT_translation.h
index 817b99e8b91..c0217f21c80 100644
--- a/source/blender/blentranslation/BLT_translation.h
+++ b/source/blender/blentranslation/BLT_translation.h
@@ -110,6 +110,7 @@ bool BLT_lang_is_ime_supported(void);
 /* WARNING! Keep it in sync with idtypes in blenkernel/intern/idcode.c */
 #define BLT_I18NCONTEXT_ID_ACTION "Action"
 #define BLT_I18NCONTEXT_ID_ARMATURE "Armature"
+#define BLT_I18NCONTEXT_ID_ASSET "Asset"
 #define BLT_I18NCONTEXT_ID_BRUSH "Brush"
 #define BLT_I18NCONTEXT_ID_CAMERA "Camera"
 #define BLT_I18NCONTEXT_ID_CACHEFILE "CacheFile"
@@ -172,6 +173,7 @@ typedef struct {
         BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_PLURAL, "plural"), \
         BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ACTION, "id_action"), \
         BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ARMATURE, "id_armature"), \
+        BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ASSET, "id_asset"), \
         BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_BRUSH, "id_brush"), \
         BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_CAMERA, "id_camera"), \
         BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_CACHEFILE, "id_cachefile"), \
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 19742a142c2..676ad39016e 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -2270,6 +2270,9 @@ int UI_idcode_icon_get(const int idcode)
       return ICON_ACTION;
     case ID_AR:
       return ICON_ARMATURE_DATA;
+    case ID_AST:
+      /* TODO: icon */
+      return ICON_BLANK1;
     case ID_BR:
       return ICON_BRUSH_DATA;
     case ID_CA:
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 19

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list