[Bf-blender-cvs] [0e071e015e7] ui-asset-view-template: Store active asset library at workspace level

Julian Eisel noreply at git.blender.org
Tue Mar 16 13:09:42 CET 2021


Commit: 0e071e015e76b723dd3ae573ec9aef70ad059902
Author: Julian Eisel
Date:   Tue Mar 16 13:06:50 2021 +0100
Branches: ui-asset-view-template
https://developer.blender.org/rB0e071e015e76b723dd3ae573ec9aef70ad059902

Store active asset library at workspace level

The Asset Browser still has its own active asset library. But for the UI
(e.g. the asset view UI template), there is one active asset library per
workspace now. This is needed because for technical reasons the property
has to be registered in C, ideally you could just register it as custom
property for any use-case and pass that to the asset view template.
Since this isn't possible, an active asset library per workspace seems
reasonable.

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_asset.h
M	source/blender/blenkernel/intern/asset.cc
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/makesdna/DNA_asset_defaults.h
M	source/blender/makesdna/DNA_view3d_defaults.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesdna/DNA_workspace_types.h
M	source/blender/makesdna/intern/dna_defaults.c
M	source/blender/makesrna/intern/rna_asset.c
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_ui_api.c
M	source/blender/makesrna/intern/rna_workspace.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 9f596bb0618..800e20b251a 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -7015,9 +7015,9 @@ class VIEW3D_PT_asset_testing(Panel):
     def draw(self, context):
         layout = self.layout
 
-        v3d = context.space_data
+        workspace = context.workspace
 
-        layout.template_asset_view(v3d, "active_asset_library")
+        layout.template_asset_view(workspace, "active_asset_library")
 
 
 # Grease Pencil Object - Multiframe falloff tools
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index d1f543b1f38..50eb2859279 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -26,6 +26,7 @@
 extern "C" {
 #endif
 
+struct AssetLibraryReference;
 struct BlendDataReader;
 struct BlendWriter;
 struct ID;
@@ -45,6 +46,8 @@ struct AssetTagEnsureResult BKE_asset_metadata_tag_ensure(struct AssetMetaData *
                                                           const char *name);
 void BKE_asset_metadata_tag_remove(struct AssetMetaData *asset_data, struct AssetTag *tag);
 
+void BKE_asset_library_reference_init_default(struct AssetLibraryReference *library_ref);
+
 struct PreviewImage *BKE_asset_metadata_preview_get_from_id(const struct AssetMetaData *asset_data,
                                                             const struct ID *owner_id);
 
diff --git a/source/blender/blenkernel/intern/asset.cc b/source/blender/blenkernel/intern/asset.cc
index b5a7f5e37a6..f74018b20c5 100644
--- a/source/blender/blenkernel/intern/asset.cc
+++ b/source/blender/blenkernel/intern/asset.cc
@@ -110,6 +110,11 @@ void BKE_asset_metadata_tag_remove(AssetMetaData *asset_data, AssetTag *tag)
   BLI_assert(BLI_listbase_count(&asset_data->tags) == asset_data->tot_tags);
 }
 
+void BKE_asset_library_reference_init_default(AssetLibraryReference *library_ref)
+{
+  memcpy(library_ref, DNA_struct_default_get(AssetLibraryReference), sizeof(*library_ref));
+}
+
 /* Queries -------------------------------------------- */
 
 PreviewImage *BKE_asset_metadata_preview_get_from_id(const AssetMetaData *UNUSED(asset_data),
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 481d190952f..023488fd7dc 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -28,6 +28,7 @@
 
 #include "BLT_translation.h"
 
+#include "BKE_asset.h"
 #include "BKE_global.h"
 #include "BKE_idprop.h"
 #include "BKE_idtype.h"
@@ -52,6 +53,13 @@
 
 /* -------------------------------------------------------------------- */
 
+static void workspace_init_data(ID *id)
+{
+  WorkSpace *workspace = (WorkSpace *)id;
+
+  BKE_asset_library_reference_init_default(&workspace->active_asset_library);
+}
+
 static void workspace_free_data(ID *id)
 {
   WorkSpace *workspace = (WorkSpace *)id;
@@ -179,7 +187,7 @@ IDTypeInfo IDType_ID_WS = {
     .translation_context = BLT_I18NCONTEXT_ID_WORKSPACE,
     .flags = IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_NO_MAKELOCAL | IDTYPE_FLAGS_NO_ANIMDATA,
 
-    .init_data = NULL,
+    .init_data = workspace_init_data,
     .copy_data = NULL,
     .free_data = workspace_free_data,
     .make_local = NULL,
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 9eb6206396d..5f6fe262a8c 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -51,6 +51,7 @@
 
 #include "BKE_animsys.h"
 #include "BKE_armature.h"
+#include "BKE_asset.h"
 #include "BKE_collection.h"
 #include "BKE_colortools.h"
 #include "BKE_cryptomatte.h"
@@ -1873,17 +1874,9 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
 
   {
     if (!DNA_struct_elem_find(
-            fd->filesdna, "View3D", "AssetLibraryReference", "active_asset_library")) {
-      LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
-        LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
-          LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) {
-            if (space->spacetype == SPACE_VIEW3D) {
-              View3D *v3d = (View3D *)space;
-              v3d->active_asset_library.type = ASSET_LIBRARY_LOCAL;
-              v3d->active_asset_library.custom_library_index = -1;
-            }
-          }
-        }
+            fd->filesdna, "WorkSpace", "AssetLibraryReference", "active_asset_library")) {
+      LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
+        BKE_asset_library_reference_init_default(&workspace->active_asset_library);
       }
     }
   }
diff --git a/source/blender/makesdna/DNA_asset_defaults.h b/source/blender/makesdna/DNA_asset_defaults.h
index ff00ba79cf0..ce01563f619 100644
--- a/source/blender/makesdna/DNA_asset_defaults.h
+++ b/source/blender/makesdna/DNA_asset_defaults.h
@@ -32,6 +32,13 @@
     0 \
   }
 
+#define _DNA_DEFAULT_AssetLibraryReference \
+  { \
+    .type = ASSET_LIBRARY_LOCAL, \
+    /* Not needed really (should be ignored for #ASSET_LIBRARY_LOCAL), but helps debugging. */ \
+    .custom_library_index = -1, \
+  }
+
 /** \} */
 
 /* clang-format on */
diff --git a/source/blender/makesdna/DNA_view3d_defaults.h b/source/blender/makesdna/DNA_view3d_defaults.h
index 963de6e584b..10d0bafec61 100644
--- a/source/blender/makesdna/DNA_view3d_defaults.h
+++ b/source/blender/makesdna/DNA_view3d_defaults.h
@@ -79,12 +79,6 @@
     .rotation_axis = {0, 1, 0}, \
   }
 
-#define _DNA_DEFAULT_AssetLibraryReference \
-{ \
-    .type = ASSET_LIBRARY_LOCAL, \
-    .custom_library_index = -1, \
-}
-
 #define _DNA_DEFAULT_View3D \
   { \
     .spacetype = SPACE_VIEW3D, \
@@ -94,7 +88,6 @@
     .gridsubdiv = 10, \
     .shading = _DNA_DEFAULT_View3DShading, \
     .overlay = _DNA_DEFAULT_View3DOverlay, \
-    .active_asset_library = _DNA_DEFAULT_AssetLibraryReference, \
  \
     .gridflag = V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_FLOOR | V3D_SHOW_ORTHO_GRID, \
  \
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index f7a3b86d92a..b8e2256c3c6 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -32,7 +32,6 @@ struct ViewDepths;
 struct bGPdata;
 struct wmTimer;
 
-#include "DNA_asset_types.h"
 #include "DNA_defs.h"
 #include "DNA_image_types.h"
 #include "DNA_listBase.h"
@@ -351,9 +350,6 @@ typedef struct View3D {
   float stereo3d_volume_alpha;
   float stereo3d_convergence_alpha;
 
-  /** Asset-viewer settings. */
-  AssetLibraryReference active_asset_library;
-
   /** Display settings. */
   View3DShading shading;
   View3DOverlay overlay;
diff --git a/source/blender/makesdna/DNA_workspace_types.h b/source/blender/makesdna/DNA_workspace_types.h
index c5c2351c718..e49146ad429 100644
--- a/source/blender/makesdna/DNA_workspace_types.h
+++ b/source/blender/makesdna/DNA_workspace_types.h
@@ -23,6 +23,7 @@
 #pragma once
 
 #include "DNA_ID.h"
+#include "DNA_asset_types.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -135,6 +136,10 @@ typedef struct WorkSpace {
 
   /** Info text from modal operators (runtime). */
   char *status_text;
+
+  /** Workspace-wide active asset library, for asset UIs to use (e.g. asset view UI template). The
+   * Asset Browser has its own and doesn't use this. */
+  AssetLibraryReference active_asset_library;
 } WorkSpace;
 
 /**
diff --git a/source/blender/makesdna/intern/dna_defaults.c b/source/blender/makesdna/intern/dna_defaults.c
index 7aca742a8e6..2ae80bd860b 100644
--- a/source/blender/makesdna/intern/dna_defaults.c
+++ b/source/blender/makesdna/intern/dna_defaults.c
@@ -152,6 +152,7 @@
 
 /* DNA_asset_defaults.h */
 SDNA_DEFAULT_DECL_STRUCT(AssetMetaData);
+SDNA_DEFAULT_DECL_STRUCT(AssetLibraryReference);
 
 /* DNA_armature_defaults.h */
 SDNA_DEFAULT_DECL_STRUCT(bArmature);
@@ -345,6 +346,7 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = {
 
     /* DNA_asset_defaults.h */
     SDNA_DEFAULT_DECL(AssetMetaData),
+    SDNA_DEFAULT_DECL(AssetLibraryReference),
 
     /* DNA_armature_defaults.h */
     SDNA_DEFAULT_DECL(bArmature),
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
index b7d3663cc3b..9a038763921 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -311,16 +311,18 @@ static void rna_def_asset_data(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Active Tag", "Index of the tag set for editing");
 }
 
-void rna_def_asset_library_reference_common(struct StructRNA *srna,
-                                            int update_flag,
-                                            const char *get,
-                                            const char *set)
+/**
+ * \note the UI text and updating has to be set by the caller.
+ */
+PropertyRNA *rna_def_asset_library_reference_common(struct StructRNA *srna,
+                                                    const char *get,
+                                                    const char *set)
 {
   PropertyRNA *prop = RNA_def_property(srna, "active_asset_library", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_items(prop, DummyRNA_NULL_items);
   RNA_def_property_enum_funcs(prop, get, set, "rna_asset_library_reference_itemf");
-  RNA_def_property_ui_text(prop, "Asset Library", "");
-  RNA_def_property_update(prop, update_flag, NULL);
+
+  return prop;
 }
 
 void RNA_def_asset(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 4f0fcd93ddb..eb52944e769 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -267,10 +267,9 @@ void rna_def_mtex_common(struct BlenderRNA *brna,
 void rna_def_texpaint_slots(struct BlenderRNA *brna, struct StructRNA *srna);
 void rna_def_view_layer_common(struct BlenderRNA *brna, struct StructRNA *srna, const bool scene);
 
-void rna_def_asset_library_reference_common(struct StructRNA *srna,
-         

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list