[Bf-blender-cvs] [ef29bf9023f] master: Assets: Expose option to reuse data-block data when appending

Julian Eisel noreply at git.blender.org
Wed Sep 29 15:03:06 CEST 2021


Commit: ef29bf9023f54667db7a0c2898d12a3bce0873ed
Author: Julian Eisel
Date:   Wed Sep 29 15:01:36 2021 +0200
Branches: master
https://developer.blender.org/rBef29bf9023f54667db7a0c2898d12a3bce0873ed

Assets: Expose option to reuse data-block data when appending

With 794c2828af60 & f48a4aa0f915 it's possible to reuse possibly
expensive, nested data of a data-block when appending. E.g. the
texture of a material, or the mesh of an object. Without this it's easy
to bloat memory and the file size. Duplicated textures also cause
unnecessary shader recompilations.

The feature was intended to be the new default behavior for the Asset
Browser, but it wasn't actually added to the UI yet. This patch adds a
new import type option to the Asset Browser. So from the menu in the
header, you can now choose between:

* Link
* Append
* Append (Reuse Data)

The latter is the new default.

Maniphest Task: https://developer.blender.org/T91741

Differential Revision: https://developer.blender.org/D12647

Reviewed by: Sybren Stüvel, Bastien Montagne

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

M	source/blender/blenloader/intern/versioning_300.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/intern/wm_dragdrop.c

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

diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 8b8b7218c0e..e65fd3e6754 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -1554,6 +1554,11 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
                 sfile->params->flag &= ~(FILE_PARAMS_FLAG_UNUSED_1 | FILE_PARAMS_FLAG_UNUSED_2 |
                                          FILE_PARAMS_FLAG_UNUSED_3 | FILE_PARAMS_FLAG_UNUSED_4);
               }
+
+              /* New default import type: Append with reuse. */
+              if (sfile->asset_params) {
+                sfile->asset_params->import_type = FILE_ASSET_IMPORT_APPEND_REUSE;
+              }
               break;
             }
             default:
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index a741f2582ee..2ca08a3105c 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -120,7 +120,7 @@ static void fileselect_ensure_updated_asset_params(SpaceFile *sfile)
     asset_params->base_params.details_flags = U_default.file_space_data.details_flags;
     asset_params->asset_library_ref.type = ASSET_LIBRARY_LOCAL;
     asset_params->asset_library_ref.custom_library_index = -1;
-    asset_params->import_type = FILE_ASSET_IMPORT_APPEND;
+    asset_params->import_type = FILE_ASSET_IMPORT_APPEND_REUSE;
   }
 
   FileSelectParams *base_params = &asset_params->base_params;
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index a7fcf2cfb89..2f3f52a6b82 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -812,8 +812,14 @@ typedef struct FileAssetSelectParams {
 } FileAssetSelectParams;
 
 typedef enum eFileAssetImportType {
+  /** Regular data-block linking. */
   FILE_ASSET_IMPORT_LINK = 0,
+  /** Regular data-block appending (basically linking + "Make Local"). */
   FILE_ASSET_IMPORT_APPEND = 1,
+  /** Append data-block with the #BLO_LIBLINK_APPEND_LOCAL_ID_REUSE flag enabled. Some typically
+   * heavy data dependencies (e.g. the image data-blocks of a material, the mesh of an object) may
+   * be reused from an earlier append. */
+  FILE_ASSET_IMPORT_APPEND_REUSE = 2,
 } eFileAssetImportType;
 
 /**
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index a4f79696276..9e06533d41b 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -6643,6 +6643,14 @@ static void rna_def_fileselect_asset_params(BlenderRNA *brna)
        0,
        "Append",
        "Import the assets as copied data-block, with no link to the original asset data-block"},
+      {FILE_ASSET_IMPORT_APPEND_REUSE,
+       "APPEND_REUSE",
+       0,
+       "Append (Reuse Data)",
+       "Import the assets as copied data-block while avoiding multiple copies of nested, "
+       "typically heavy data. For example the textures of a material asset, or the mesh of an "
+       "object asset, don't have to be copied every time this asset is imported. The instances of "
+       "the asset share the data instead"},
       {0, NULL, 0, NULL, NULL},
   };
 
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index f3a57b72095..93038b5709c 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -398,6 +398,16 @@ static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag)
     case FILE_ASSET_IMPORT_APPEND:
       return WM_file_append_datablock(
           G_MAIN, NULL, NULL, NULL, asset_drag->path, idtype, name, BLO_LIBLINK_APPEND_RECURSIVE);
+    case FILE_ASSET_IMPORT_APPEND_REUSE:
+      return WM_file_append_datablock(G_MAIN,
+                                      NULL,
+                                      NULL,
+                                      NULL,
+                                      asset_drag->path,
+                                      idtype,
+                                      name,
+                                      BLO_LIBLINK_APPEND_RECURSIVE |
+                                          BLO_LIBLINK_APPEND_LOCAL_ID_REUSE);
   }
 
   BLI_assert_unreachable();



More information about the Bf-blender-cvs mailing list