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

With 794c2828af & f48a4aa0f9 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
This commit is contained in:
Julian Eisel 2021-09-29 15:01:36 +02:00
parent 5cebcb415e
commit ef29bf9023
Notes: blender-bot 2023-02-14 11:07:28 +01:00
Referenced by issue #91741, Expose deduplication support in the UI (enabled by default)
5 changed files with 30 additions and 1 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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;
/**

View File

@ -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},
};

View File

@ -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();