LibOverride: Do not store some heavy data from override IDs.
This commit removes geometry from meshes and shapekeys, and embedded files, from liboverride IDs. This data is never overrideable, there is no reason to store extra useless copies of it in production files. See T78944. Note that we may add more data to be skipped on write for liboverrides in the future, but this commit should address all the most important cases already. Reviewed By: brecht Differential Revision: https://developer.blender.org/D9810
This commit is contained in:
parent
8e1b63d4bd
commit
f5a019ed43
|
@ -125,11 +125,17 @@ static void vfont_free_data(ID *id)
|
|||
static void vfont_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
VFont *vf = (VFont *)id;
|
||||
if (vf->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
const bool is_undo = BLO_write_is_undo(writer);
|
||||
if (vf->id.us > 0 || is_undo) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
vf->data = NULL;
|
||||
vf->temp_pf = NULL;
|
||||
|
||||
/* Do not store packed files in case this is a library override ID. */
|
||||
if (ID_IS_OVERRIDE_LIBRARY(vf) && !is_undo) {
|
||||
vf->packedfile = NULL;
|
||||
}
|
||||
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, VFont, id_address, &vf->id);
|
||||
BKE_id_blend_write(writer, &vf->id);
|
||||
|
|
|
@ -225,14 +225,21 @@ static void image_foreach_cache(ID *id,
|
|||
static void image_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
Image *ima = (Image *)id;
|
||||
if (ima->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
const bool is_undo = BLO_write_is_undo(writer);
|
||||
if (ima->id.us > 0 || is_undo) {
|
||||
ImagePackedFile *imapf;
|
||||
|
||||
/* Some trickery to keep forward compatibility of packed images. */
|
||||
BLI_assert(ima->packedfile == NULL);
|
||||
if (ima->packedfiles.first != NULL) {
|
||||
imapf = ima->packedfiles.first;
|
||||
ima->packedfile = imapf->packedfile;
|
||||
/* Do not store packed files in case this is a library override ID. */
|
||||
if (ID_IS_OVERRIDE_LIBRARY(ima) && !is_undo) {
|
||||
BLI_listbase_clear(&ima->packedfiles);
|
||||
}
|
||||
else {
|
||||
/* Some trickery to keep forward compatibility of packed images. */
|
||||
if (ima->packedfiles.first != NULL) {
|
||||
imapf = ima->packedfiles.first;
|
||||
ima->packedfile = imapf->packedfile;
|
||||
}
|
||||
}
|
||||
|
||||
/* write LibData */
|
||||
|
|
|
@ -108,7 +108,8 @@ static void shapekey_foreach_id(ID *id, LibraryForeachIDData *data)
|
|||
static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
Key *key = (Key *)id;
|
||||
if (key->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
const bool is_undo = BLO_write_is_undo(writer);
|
||||
if (key->id.us > 0 || is_undo) {
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, Key, id_address, &key->id);
|
||||
BKE_id_blend_write(writer, &key->id);
|
||||
|
@ -119,9 +120,15 @@ static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_add
|
|||
|
||||
/* direct data */
|
||||
LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
|
||||
BLO_write_struct(writer, KeyBlock, kb);
|
||||
if (kb->data) {
|
||||
BLO_write_raw(writer, kb->totelem * key->elemsize, kb->data);
|
||||
KeyBlock tmp_kb = *kb;
|
||||
/* Do not store actual geometry data in case this is a library override ID. */
|
||||
if (ID_IS_OVERRIDE_LIBRARY(key) && !is_undo) {
|
||||
tmp_kb.totelem = 0;
|
||||
tmp_kb.data = NULL;
|
||||
}
|
||||
BLO_write_struct_at_address(writer, KeyBlock, kb, &tmp_kb);
|
||||
if (tmp_kb.data != NULL) {
|
||||
BLO_write_raw(writer, tmp_kb.totelem * key->elemsize, tmp_kb.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,24 +173,53 @@ static void mesh_foreach_id(ID *id, LibraryForeachIDData *data)
|
|||
static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
Mesh *mesh = (Mesh *)id;
|
||||
if (mesh->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
/* cache only - don't write */
|
||||
mesh->mface = NULL;
|
||||
mesh->totface = 0;
|
||||
memset(&mesh->fdata, 0, sizeof(mesh->fdata));
|
||||
memset(&mesh->runtime, 0, sizeof(mesh->runtime));
|
||||
|
||||
const bool is_undo = BLO_write_is_undo(writer);
|
||||
if (mesh->id.us > 0 || is_undo) {
|
||||
CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE];
|
||||
CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE];
|
||||
CustomDataLayer *flayers = NULL, flayers_buff[CD_TEMP_CHUNK_SIZE];
|
||||
CustomDataLayer *llayers = NULL, llayers_buff[CD_TEMP_CHUNK_SIZE];
|
||||
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
|
||||
|
||||
CustomData_blend_write_prepare(&mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff));
|
||||
CustomData_blend_write_prepare(&mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff));
|
||||
/* cache only - don't write */
|
||||
mesh->mface = NULL;
|
||||
mesh->totface = 0;
|
||||
memset(&mesh->fdata, 0, sizeof(mesh->fdata));
|
||||
memset(&mesh->runtime, 0, sizeof(mesh->runtime));
|
||||
flayers = flayers_buff;
|
||||
CustomData_blend_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
|
||||
CustomData_blend_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
|
||||
|
||||
/* Do not store actual geometry data in case this is a library override ID. */
|
||||
if (ID_IS_OVERRIDE_LIBRARY(mesh) && !is_undo) {
|
||||
mesh->mvert = NULL;
|
||||
mesh->totvert = 0;
|
||||
memset(&mesh->vdata, 0, sizeof(mesh->vdata));
|
||||
vlayers = vlayers_buff;
|
||||
|
||||
mesh->medge = NULL;
|
||||
mesh->totedge = 0;
|
||||
memset(&mesh->edata, 0, sizeof(mesh->edata));
|
||||
elayers = elayers_buff;
|
||||
|
||||
mesh->mloop = NULL;
|
||||
mesh->totloop = 0;
|
||||
memset(&mesh->ldata, 0, sizeof(mesh->ldata));
|
||||
llayers = llayers_buff;
|
||||
|
||||
mesh->mpoly = NULL;
|
||||
mesh->totpoly = 0;
|
||||
memset(&mesh->pdata, 0, sizeof(mesh->pdata));
|
||||
players = players_buff;
|
||||
}
|
||||
else {
|
||||
CustomData_blend_write_prepare(
|
||||
&mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff));
|
||||
CustomData_blend_write_prepare(
|
||||
&mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff));
|
||||
CustomData_blend_write_prepare(
|
||||
&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
|
||||
CustomData_blend_write_prepare(
|
||||
&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
|
||||
}
|
||||
|
||||
BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
|
||||
BKE_id_blend_write(writer, &mesh->id);
|
||||
|
|
|
@ -135,13 +135,19 @@ static void sound_foreach_cache(ID *id,
|
|||
static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
bSound *sound = (bSound *)id;
|
||||
if (sound->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
const bool is_undo = BLO_write_is_undo(writer);
|
||||
if (sound->id.us > 0 || is_undo) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
sound->tags = 0;
|
||||
sound->handle = NULL;
|
||||
sound->playback_handle = NULL;
|
||||
sound->spinlock = NULL;
|
||||
|
||||
/* Do not store packed files in case this is a library override ID. */
|
||||
if (ID_IS_OVERRIDE_LIBRARY(sound) && !is_undo) {
|
||||
sound->packedfile = NULL;
|
||||
}
|
||||
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, bSound, id_address, &sound->id);
|
||||
BKE_id_blend_write(writer, &sound->id);
|
||||
|
|
|
@ -561,10 +561,16 @@ static void volume_foreach_cache(ID *id,
|
|||
static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
Volume *volume = (Volume *)id;
|
||||
if (volume->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
const bool is_undo = BLO_write_is_undo(writer);
|
||||
if (volume->id.us > 0 || is_undo) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
volume->runtime.grids = nullptr;
|
||||
|
||||
/* Do not store packed files in case this is a library override ID. */
|
||||
if (ID_IS_OVERRIDE_LIBRARY(volume) && !is_undo) {
|
||||
volume->packedfile = nullptr;
|
||||
}
|
||||
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, Volume, id_address, &volume->id);
|
||||
BKE_id_blend_write(writer, &volume->id);
|
||||
|
|
Loading…
Reference in New Issue