Cleanup: Blendwrite: Move code deciding if an ID should be written out of ID callbacks.

This was not really useful, and added estra useless steps in case and ID
should not actually be written.

Further more, it prevented clearing the usercount on write, which can be
cause a false positive 'chanhged' detection in undo/redo case.
This commit is contained in:
Bastien Montagne 2021-08-19 11:13:55 +02:00
parent d5776f4829
commit 0f49e4832c
35 changed files with 695 additions and 730 deletions

View File

@ -186,22 +186,21 @@ static void action_foreach_id(ID *id, LibraryForeachIDData *data)
static void action_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bAction *act = (bAction *)id;
if (act->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, bAction, id_address, &act->id);
BKE_id_blend_write(writer, &act->id);
BKE_fcurve_blend_write(writer, &act->curves);
BLO_write_id_struct(writer, bAction, id_address, &act->id);
BKE_id_blend_write(writer, &act->id);
LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
BLO_write_struct(writer, bActionGroup, grp);
}
BKE_fcurve_blend_write(writer, &act->curves);
LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
BLO_write_struct(writer, TimeMarker, marker);
}
BKE_previewimg_blend_write(writer, act->preview);
LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
BLO_write_struct(writer, bActionGroup, grp);
}
LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
BLO_write_struct(writer, TimeMarker, marker);
}
BKE_previewimg_blend_write(writer, act->preview);
}
static void action_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -212,25 +212,24 @@ static void write_bone(BlendWriter *writer, Bone *bone)
static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bArmature *arm = (bArmature *)id;
if (arm->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
arm->bonehash = NULL;
arm->edbo = NULL;
/* Must always be cleared (armatures don't have their own edit-data). */
arm->needs_flush_to_id = 0;
arm->act_edbone = NULL;
BLO_write_id_struct(writer, bArmature, id_address, &arm->id);
BKE_id_blend_write(writer, &arm->id);
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
arm->bonehash = NULL;
arm->edbo = NULL;
/* Must always be cleared (armatures don't have their own edit-data). */
arm->needs_flush_to_id = 0;
arm->act_edbone = NULL;
if (arm->adt) {
BKE_animdata_blend_write(writer, arm->adt);
}
BLO_write_id_struct(writer, bArmature, id_address, &arm->id);
BKE_id_blend_write(writer, &arm->id);
/* Direct data */
LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
write_bone(writer, bone);
}
if (arm->adt) {
BKE_animdata_blend_write(writer, arm->adt);
}
/* Direct data */
LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
write_bone(writer, bone);
}
}

View File

@ -202,48 +202,47 @@ static void brush_foreach_id(ID *id, LibraryForeachIDData *data)
static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Brush *brush = (Brush *)id;
if (brush->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, Brush, id_address, &brush->id);
BKE_id_blend_write(writer, &brush->id);
if (brush->curve) {
BKE_curvemapping_blend_write(writer, brush->curve);
}
BLO_write_id_struct(writer, Brush, id_address, &brush->id);
BKE_id_blend_write(writer, &brush->id);
if (brush->gpencil_settings) {
BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings);
if (brush->curve) {
BKE_curvemapping_blend_write(writer, brush->curve);
}
if (brush->gpencil_settings->curve_sensitivity) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity);
}
if (brush->gpencil_settings->curve_strength) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength);
}
if (brush->gpencil_settings->curve_jitter) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter);
}
if (brush->gpencil_settings->curve_rand_pressure) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure);
}
if (brush->gpencil_settings->curve_rand_strength) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength);
}
if (brush->gpencil_settings->curve_rand_uv) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv);
}
if (brush->gpencil_settings->curve_rand_hue) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue);
}
if (brush->gpencil_settings->curve_rand_saturation) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation);
}
if (brush->gpencil_settings->curve_rand_value) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value);
}
if (brush->gpencil_settings) {
BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings);
if (brush->gpencil_settings->curve_sensitivity) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity);
}
if (brush->gradient) {
BLO_write_struct(writer, ColorBand, brush->gradient);
if (brush->gpencil_settings->curve_strength) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength);
}
if (brush->gpencil_settings->curve_jitter) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter);
}
if (brush->gpencil_settings->curve_rand_pressure) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure);
}
if (brush->gpencil_settings->curve_rand_strength) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength);
}
if (brush->gpencil_settings->curve_rand_uv) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv);
}
if (brush->gpencil_settings->curve_rand_hue) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue);
}
if (brush->gpencil_settings->curve_rand_saturation) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation);
}
if (brush->gpencil_settings->curve_rand_value) {
BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value);
}
}
if (brush->gradient) {
BLO_write_struct(writer, ColorBand, brush->gradient);
}
}

View File

@ -97,19 +97,18 @@ static void cache_file_free_data(ID *id)
static void cache_file_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
CacheFile *cache_file = (CacheFile *)id;
if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&cache_file->object_paths);
cache_file->handle = NULL;
memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath));
cache_file->handle_readers = NULL;
BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
BKE_id_blend_write(writer, &cache_file->id);
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&cache_file->object_paths);
cache_file->handle = NULL;
memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath));
cache_file->handle_readers = NULL;
if (cache_file->adt) {
BKE_animdata_blend_write(writer, cache_file->adt);
}
BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
BKE_id_blend_write(writer, &cache_file->id);
if (cache_file->adt) {
BKE_animdata_blend_write(writer, cache_file->adt);
}
}

View File

@ -122,18 +122,17 @@ static void camera_foreach_id(ID *id, LibraryForeachIDData *data)
static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Camera *cam = (Camera *)id;
if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Camera, id_address, &cam->id);
BKE_id_blend_write(writer, &cam->id);
if (cam->adt) {
BKE_animdata_blend_write(writer, cam->adt);
}
/* write LibData */
BLO_write_id_struct(writer, Camera, id_address, &cam->id);
BKE_id_blend_write(writer, &cam->id);
LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
BLO_write_struct(writer, CameraBGImage, bgpic);
}
if (cam->adt) {
BKE_animdata_blend_write(writer, cam->adt);
}
LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
BLO_write_struct(writer, CameraBGImage, bgpic);
}
}

View File

@ -214,20 +214,19 @@ void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collectio
static void collection_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Collection *collection = (Collection *)id;
if (collection->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */
collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED;
collection->tag = 0;
BLI_listbase_clear(&collection->object_cache);
BLI_listbase_clear(&collection->object_cache_instanced);
BLI_listbase_clear(&collection->parents);
/* write LibData */
BLO_write_id_struct(writer, Collection, id_address, &collection->id);
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */
collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED;
collection->tag = 0;
BLI_listbase_clear(&collection->object_cache);
BLI_listbase_clear(&collection->object_cache_instanced);
BLI_listbase_clear(&collection->parents);
BKE_collection_blend_write_nolib(writer, collection);
}
/* write LibData */
BLO_write_id_struct(writer, Collection, id_address, &collection->id);
BKE_collection_blend_write_nolib(writer, collection);
}
#ifdef USE_COLLECTION_COMPAT_28

View File

@ -146,51 +146,50 @@ static void curve_foreach_id(ID *id, LibraryForeachIDData *data)
static void curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Curve *cu = (Curve *)id;
if (cu->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
cu->editnurb = NULL;
cu->editfont = NULL;
cu->batch_cache = NULL;
/* write LibData */
BLO_write_id_struct(writer, Curve, id_address, &cu->id);
BKE_id_blend_write(writer, &cu->id);
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
cu->editnurb = NULL;
cu->editfont = NULL;
cu->batch_cache = NULL;
/* direct data */
BLO_write_pointer_array(writer, cu->totcol, cu->mat);
if (cu->adt) {
BKE_animdata_blend_write(writer, cu->adt);
/* write LibData */
BLO_write_id_struct(writer, Curve, id_address, &cu->id);
BKE_id_blend_write(writer, &cu->id);
/* direct data */
BLO_write_pointer_array(writer, cu->totcol, cu->mat);
if (cu->adt) {
BKE_animdata_blend_write(writer, cu->adt);
}
if (cu->vfont) {
BLO_write_raw(writer, cu->len + 1, cu->str);
BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo);
BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb);
}
else {
/* is also the order of reading */
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
BLO_write_struct(writer, Nurb, nu);
}
if (cu->vfont) {
BLO_write_raw(writer, cu->len + 1, cu->str);
BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo);
BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb);
}
else {
/* is also the order of reading */
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
BLO_write_struct(writer, Nurb, nu);
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
if (nu->type == CU_BEZIER) {
BLO_write_struct_array(writer, BezTriple, nu->pntsu, nu->bezt);
}
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
if (nu->type == CU_BEZIER) {
BLO_write_struct_array(writer, BezTriple, nu->pntsu, nu->bezt);
else {
BLO_write_struct_array(writer, BPoint, nu->pntsu * nu->pntsv, nu->bp);
if (nu->knotsu) {
BLO_write_float_array(writer, KNOTSU(nu), nu->knotsu);
}
else {
BLO_write_struct_array(writer, BPoint, nu->pntsu * nu->pntsv, nu->bp);
if (nu->knotsu) {
BLO_write_float_array(writer, KNOTSU(nu), nu->knotsu);
}
if (nu->knotsv) {
BLO_write_float_array(writer, KNOTSV(nu), nu->knotsv);
}
if (nu->knotsv) {
BLO_write_float_array(writer, KNOTSV(nu), nu->knotsv);
}
}
}
}
if (cu->bevel_profile != NULL) {
BKE_curveprofile_blend_write(writer, cu->bevel_profile);
}
if (cu->bevel_profile != NULL) {
BKE_curveprofile_blend_write(writer, cu->bevel_profile);
}
}

View File

@ -126,23 +126,22 @@ static void vfont_blend_write(BlendWriter *writer, ID *id, const void *id_addres
{
VFont *vf = (VFont *)id;
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;
}
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
vf->data = NULL;
vf->temp_pf = NULL;
/* write LibData */
BLO_write_id_struct(writer, VFont, id_address, &vf->id);
BKE_id_blend_write(writer, &vf->id);
/* direct data */
BKE_packedfile_blend_write(writer, vf->packedfile);
/* 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);
/* direct data */
BKE_packedfile_blend_write(writer, vf->packedfile);
}
static void vfont_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -150,47 +150,46 @@ static void greasepencil_foreach_id(ID *id, LibraryForeachIDData *data)
static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bGPdata *gpd = (bGPdata *)id;
if (gpd->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */
/* XXX not sure why the whole run-time data is not cleared in reading code,
* for now mimicking it here. */
gpd->runtime.sbuffer = NULL;
gpd->runtime.sbuffer_used = 0;
gpd->runtime.sbuffer_size = 0;
gpd->runtime.tot_cp_points = 0;
/* write gpd data block to file */
BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id);
BKE_id_blend_write(writer, &gpd->id);
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */
/* XXX not sure why the whole run-time data is not cleared in reading code,
* for now mimicking it here. */
gpd->runtime.sbuffer = NULL;
gpd->runtime.sbuffer_used = 0;
gpd->runtime.sbuffer_size = 0;
gpd->runtime.tot_cp_points = 0;
if (gpd->adt) {
BKE_animdata_blend_write(writer, gpd->adt);
}
/* write gpd data block to file */
BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id);
BKE_id_blend_write(writer, &gpd->id);
BKE_defbase_blend_write(writer, &gpd->vertex_group_names);
if (gpd->adt) {
BKE_animdata_blend_write(writer, gpd->adt);
}
BLO_write_pointer_array(writer, gpd->totcol, gpd->mat);
BKE_defbase_blend_write(writer, &gpd->vertex_group_names);
/* write grease-pencil layers to file */
BLO_write_struct_list(writer, bGPDlayer, &gpd->layers);
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
/* Write mask list. */
BLO_write_struct_list(writer, bGPDlayer_Mask, &gpl->mask_layers);
/* write this layer's frames to file */
BLO_write_struct_list(writer, bGPDframe, &gpl->frames);
LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
/* write strokes */
BLO_write_struct_list(writer, bGPDstroke, &gpf->strokes);
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points);
BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles);
BKE_defvert_blend_write(writer, gps->totpoints, gps->dvert);
if (gps->editcurve != NULL) {
bGPDcurve *gpc = gps->editcurve;
BLO_write_struct(writer, bGPDcurve, gpc);
BLO_write_struct_array(
writer, bGPDcurve_point, gpc->tot_curve_points, gpc->curve_points);
}
BLO_write_pointer_array(writer, gpd->totcol, gpd->mat);
/* write grease-pencil layers to file */
BLO_write_struct_list(writer, bGPDlayer, &gpd->layers);
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
/* Write mask list. */
BLO_write_struct_list(writer, bGPDlayer_Mask, &gpl->mask_layers);
/* write this layer's frames to file */
BLO_write_struct_list(writer, bGPDframe, &gpl->frames);
LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
/* write strokes */
BLO_write_struct_list(writer, bGPDstroke, &gpf->strokes);
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points);
BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles);
BKE_defvert_blend_write(writer, gps->totpoints, gps->dvert);
if (gps->editcurve != NULL) {
bGPDcurve *gpc = gps->editcurve;
BLO_write_struct(writer, bGPDcurve, gpc);
BLO_write_struct_array(
writer, bGPDcurve_point, gpc->tot_curve_points, gpc->curve_points);
}
}
}

View File

@ -114,32 +114,31 @@ static void hair_foreach_id(ID *id, LibraryForeachIDData *data)
static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Hair *hair = (Hair *)id;
if (hair->id.us > 0 || BLO_write_is_undo(writer)) {
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
/* Write LibData */
BLO_write_id_struct(writer, Hair, id_address, &hair->id);
BKE_id_blend_write(writer, &hair->id);
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
/* Direct data */
CustomData_blend_write(writer, &hair->pdata, players, hair->totpoint, CD_MASK_ALL, &hair->id);
CustomData_blend_write(writer, &hair->cdata, clayers, hair->totcurve, CD_MASK_ALL, &hair->id);
/* Write LibData */
BLO_write_id_struct(writer, Hair, id_address, &hair->id);
BKE_id_blend_write(writer, &hair->id);
BLO_write_pointer_array(writer, hair->totcol, hair->mat);
if (hair->adt) {
BKE_animdata_blend_write(writer, hair->adt);
}
/* Direct data */
CustomData_blend_write(writer, &hair->pdata, players, hair->totpoint, CD_MASK_ALL, &hair->id);
CustomData_blend_write(writer, &hair->cdata, clayers, hair->totcurve, CD_MASK_ALL, &hair->id);
/* Remove temporary data. */
if (players && players != players_buff) {
MEM_freeN(players);
}
if (clayers && clayers != clayers_buff) {
MEM_freeN(clayers);
}
BLO_write_pointer_array(writer, hair->totcol, hair->mat);
if (hair->adt) {
BKE_animdata_blend_write(writer, hair->adt);
}
/* Remove temporary data. */
if (players && players != players_buff) {
MEM_freeN(players);
}
if (clayers && clayers != clayers_buff) {
MEM_freeN(clayers);
}
}

View File

@ -229,44 +229,43 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
{
Image *ima = (Image *)id;
const bool is_undo = BLO_write_is_undo(writer);
if (ima->id.us > 0 || is_undo) {
ImagePackedFile *imapf;
BLI_assert(ima->packedfile == NULL);
/* 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;
}
}
ImagePackedFile *imapf;
/* write LibData */
BLO_write_id_struct(writer, Image, id_address, &ima->id);
BKE_id_blend_write(writer, &ima->id);
for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
BLO_write_struct(writer, ImagePackedFile, imapf);
BKE_packedfile_blend_write(writer, imapf->packedfile);
}
BKE_previewimg_blend_write(writer, ima->preview);
LISTBASE_FOREACH (ImageView *, iv, &ima->views) {
BLO_write_struct(writer, ImageView, iv);
}
BLO_write_struct(writer, Stereo3dFormat, ima->stereo3d_format);
BLO_write_struct_list(writer, ImageTile, &ima->tiles);
ima->packedfile = NULL;
BLO_write_struct_list(writer, RenderSlot, &ima->renderslots);
BLI_assert(ima->packedfile == NULL);
/* 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 */
BLO_write_id_struct(writer, Image, id_address, &ima->id);
BKE_id_blend_write(writer, &ima->id);
for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
BLO_write_struct(writer, ImagePackedFile, imapf);
BKE_packedfile_blend_write(writer, imapf->packedfile);
}
BKE_previewimg_blend_write(writer, ima->preview);
LISTBASE_FOREACH (ImageView *, iv, &ima->views) {
BLO_write_struct(writer, ImageView, iv);
}
BLO_write_struct(writer, Stereo3dFormat, ima->stereo3d_format);
BLO_write_struct_list(writer, ImageTile, &ima->tiles);
ima->packedfile = NULL;
BLO_write_struct_list(writer, RenderSlot, &ima->renderslots);
}
static void image_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -114,27 +114,26 @@ static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_add
{
Key *key = (Key *)id;
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);
if (key->adt) {
BKE_animdata_blend_write(writer, key->adt);
/* write LibData */
BLO_write_id_struct(writer, Key, id_address, &key->id);
BKE_id_blend_write(writer, &key->id);
if (key->adt) {
BKE_animdata_blend_write(writer, key->adt);
}
/* direct data */
LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
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;
}
/* direct data */
LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
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);
}
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);
}
}
}

View File

@ -137,26 +137,25 @@ static void lattice_foreach_id(ID *id, LibraryForeachIDData *data)
static void lattice_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Lattice *lt = (Lattice *)id;
if (lt->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
lt->editlatt = NULL;
lt->batch_cache = NULL;
/* write LibData */
BLO_write_id_struct(writer, Lattice, id_address, &lt->id);
BKE_id_blend_write(writer, &lt->id);
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
lt->editlatt = NULL;
lt->batch_cache = NULL;
/* write animdata */
if (lt->adt) {
BKE_animdata_blend_write(writer, lt->adt);
}
/* write LibData */
BLO_write_id_struct(writer, Lattice, id_address, &lt->id);
BKE_id_blend_write(writer, &lt->id);
/* direct data */
BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
BKE_defbase_blend_write(writer, &lt->vertex_group_names);
BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
/* write animdata */
if (lt->adt) {
BKE_animdata_blend_write(writer, lt->adt);
}
/* direct data */
BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
BKE_defbase_blend_write(writer, &lt->vertex_group_names);
BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
}
static void lattice_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -136,27 +136,26 @@ static void light_foreach_id(ID *id, LibraryForeachIDData *data)
static void light_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Light *la = (Light *)id;
if (la->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Light, id_address, &la->id);
BKE_id_blend_write(writer, &la->id);
if (la->adt) {
BKE_animdata_blend_write(writer, la->adt);
}
/* write LibData */
BLO_write_id_struct(writer, Light, id_address, &la->id);
BKE_id_blend_write(writer, &la->id);
if (la->curfalloff) {
BKE_curvemapping_blend_write(writer, la->curfalloff);
}
/* Node-tree is integral part of lights, no libdata. */
if (la->nodetree) {
BLO_write_struct(writer, bNodeTree, la->nodetree);
ntreeBlendWrite(writer, la->nodetree);
}
BKE_previewimg_blend_write(writer, la->preview);
if (la->adt) {
BKE_animdata_blend_write(writer, la->adt);
}
if (la->curfalloff) {
BKE_curvemapping_blend_write(writer, la->curfalloff);
}
/* Node-tree is integral part of lights, no libdata. */
if (la->nodetree) {
BLO_write_struct(writer, bNodeTree, la->nodetree);
ntreeBlendWrite(writer, la->nodetree);
}
BKE_previewimg_blend_write(writer, la->preview);
}
static void light_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -60,14 +60,13 @@ static void lightprobe_foreach_id(ID *id, LibraryForeachIDData *data)
static void lightprobe_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
LightProbe *prb = (LightProbe *)id;
if (prb->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, LightProbe, id_address, &prb->id);
BKE_id_blend_write(writer, &prb->id);
if (prb->adt) {
BKE_animdata_blend_write(writer, prb->adt);
}
/* write LibData */
BLO_write_id_struct(writer, LightProbe, id_address, &prb->id);
BKE_id_blend_write(writer, &prb->id);
if (prb->adt) {
BKE_animdata_blend_write(writer, prb->adt);
}
}

View File

@ -457,28 +457,27 @@ static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *mo
static void linestyle_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id);
BKE_id_blend_write(writer, &linestyle->id);
if (linestyle->adt) {
BKE_animdata_blend_write(writer, linestyle->adt);
}
BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id);
BKE_id_blend_write(writer, &linestyle->id);
write_linestyle_color_modifiers(writer, &linestyle->color_modifiers);
write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers);
write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers);
write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers);
for (int a = 0; a < MAX_MTEX; a++) {
if (linestyle->mtex[a]) {
BLO_write_struct(writer, MTex, linestyle->mtex[a]);
}
}
if (linestyle->nodetree) {
BLO_write_struct(writer, bNodeTree, linestyle->nodetree);
ntreeBlendWrite(writer, linestyle->nodetree);
if (linestyle->adt) {
BKE_animdata_blend_write(writer, linestyle->adt);
}
write_linestyle_color_modifiers(writer, &linestyle->color_modifiers);
write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers);
write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers);
write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers);
for (int a = 0; a < MAX_MTEX; a++) {
if (linestyle->mtex[a]) {
BLO_write_struct(writer, MTex, linestyle->mtex[a]);
}
}
if (linestyle->nodetree) {
BLO_write_struct(writer, bNodeTree, linestyle->nodetree);
ntreeBlendWrite(writer, linestyle->nodetree);
}
}
static void direct_link_linestyle_color_modifier(BlendDataReader *reader,

View File

@ -101,48 +101,47 @@ static void mask_foreach_id(ID *id, LibraryForeachIDData *data)
static void mask_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Mask *mask = (Mask *)id;
if (mask->id.us > 0 || BLO_write_is_undo(writer)) {
MaskLayer *masklay;
BLO_write_id_struct(writer, Mask, id_address, &mask->id);
BKE_id_blend_write(writer, &mask->id);
MaskLayer *masklay;
if (mask->adt) {
BKE_animdata_blend_write(writer, mask->adt);
}
BLO_write_id_struct(writer, Mask, id_address, &mask->id);
BKE_id_blend_write(writer, &mask->id);
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
MaskSpline *spline;
MaskLayerShape *masklay_shape;
if (mask->adt) {
BKE_animdata_blend_write(writer, mask->adt);
}
BLO_write_struct(writer, MaskLayer, masklay);
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
MaskSpline *spline;
MaskLayerShape *masklay_shape;
for (spline = masklay->splines.first; spline; spline = spline->next) {
int i;
BLO_write_struct(writer, MaskLayer, masklay);
void *points_deform = spline->points_deform;
spline->points_deform = NULL;
for (spline = masklay->splines.first; spline; spline = spline->next) {
int i;
BLO_write_struct(writer, MaskSpline, spline);
BLO_write_struct_array(writer, MaskSplinePoint, spline->tot_point, spline->points);
void *points_deform = spline->points_deform;
spline->points_deform = NULL;
spline->points_deform = points_deform;
BLO_write_struct(writer, MaskSpline, spline);
BLO_write_struct_array(writer, MaskSplinePoint, spline->tot_point, spline->points);
for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i];
spline->points_deform = points_deform;
if (point->tot_uw) {
BLO_write_struct_array(writer, MaskSplinePointUW, point->tot_uw, point->uw);
}
for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i];
if (point->tot_uw) {
BLO_write_struct_array(writer, MaskSplinePointUW, point->tot_uw, point->uw);
}
}
}
for (masklay_shape = masklay->splines_shapes.first; masklay_shape;
masklay_shape = masklay_shape->next) {
BLO_write_struct(writer, MaskLayerShape, masklay_shape);
BLO_write_float_array(
writer, masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data);
}
for (masklay_shape = masklay->splines_shapes.first; masklay_shape;
masklay_shape = masklay_shape->next) {
BLO_write_struct(writer, MaskLayerShape, masklay_shape);
BLO_write_float_array(
writer, masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data);
}
}
}

View File

@ -179,31 +179,30 @@ static void material_foreach_id(ID *id, LibraryForeachIDData *data)
static void material_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Material *ma = (Material *)id;
if (ma->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
ma->texpaintslot = NULL;
BLI_listbase_clear(&ma->gpumaterial);
/* write LibData */
BLO_write_id_struct(writer, Material, id_address, &ma->id);
BKE_id_blend_write(writer, &ma->id);
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
ma->texpaintslot = NULL;
BLI_listbase_clear(&ma->gpumaterial);
if (ma->adt) {
BKE_animdata_blend_write(writer, ma->adt);
}
/* write LibData */
BLO_write_id_struct(writer, Material, id_address, &ma->id);
BKE_id_blend_write(writer, &ma->id);
/* nodetree is integral part of material, no libdata */
if (ma->nodetree) {
BLO_write_struct(writer, bNodeTree, ma->nodetree);
ntreeBlendWrite(writer, ma->nodetree);
}
if (ma->adt) {
BKE_animdata_blend_write(writer, ma->adt);
}
BKE_previewimg_blend_write(writer, ma->preview);
/* nodetree is integral part of material, no libdata */
if (ma->nodetree) {
BLO_write_struct(writer, bNodeTree, ma->nodetree);
ntreeBlendWrite(writer, ma->nodetree);
}
/* grease pencil settings */
if (ma->gp_style) {
BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style);
}
BKE_previewimg_blend_write(writer, ma->preview);
/* grease pencil settings */
if (ma->gp_style) {
BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style);
}
}

View File

@ -119,28 +119,27 @@ static void metaball_foreach_id(ID *id, LibraryForeachIDData *data)
static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
MetaBall *mb = (MetaBall *)id;
if (mb->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&mb->disp);
mb->editelems = NULL;
/* Must always be cleared (meta's don't have their own edit-data). */
mb->needs_flush_to_id = 0;
mb->lastelem = NULL;
mb->batch_cache = NULL;
/* write LibData */
BLO_write_id_struct(writer, MetaBall, id_address, &mb->id);
BKE_id_blend_write(writer, &mb->id);
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&mb->disp);
mb->editelems = NULL;
/* Must always be cleared (meta's don't have their own edit-data). */
mb->needs_flush_to_id = 0;
mb->lastelem = NULL;
mb->batch_cache = NULL;
/* direct data */
BLO_write_pointer_array(writer, mb->totcol, mb->mat);
if (mb->adt) {
BKE_animdata_blend_write(writer, mb->adt);
}
/* write LibData */
BLO_write_id_struct(writer, MetaBall, id_address, &mb->id);
BKE_id_blend_write(writer, &mb->id);
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
BLO_write_struct(writer, MetaElem, ml);
}
/* direct data */
BLO_write_pointer_array(writer, mb->totcol, mb->mat);
if (mb->adt) {
BKE_animdata_blend_write(writer, mb->adt);
}
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
BLO_write_struct(writer, MetaElem, ml);
}
}

View File

@ -179,95 +179,90 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
{
Mesh *mesh = (Mesh *)id;
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];
/* 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;
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];
/* 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;
/* 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;
mesh->medge = NULL;
mesh->totedge = 0;
memset(&mesh->edata, 0, sizeof(mesh->edata));
elayers = elayers_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->mloop = NULL;
mesh->totloop = 0;
memset(&mesh->ldata, 0, sizeof(mesh->ldata));
llayers = llayers_buff;
mesh->medge = NULL;
mesh->totedge = 0;
memset(&mesh->edata, 0, sizeof(mesh->edata));
elayers = elayers_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));
}
mesh->mloop = NULL;
mesh->totloop = 0;
memset(&mesh->ldata, 0, sizeof(mesh->ldata));
llayers = llayers_buff;
BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
BKE_id_blend_write(writer, &mesh->id);
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));
}
/* direct data */
if (mesh->adt) {
BKE_animdata_blend_write(writer, mesh->adt);
}
BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
BKE_id_blend_write(writer, &mesh->id);
BKE_defbase_blend_write(writer, &mesh->vertex_group_names);
/* direct data */
if (mesh->adt) {
BKE_animdata_blend_write(writer, mesh->adt);
}
BLO_write_pointer_array(writer, mesh->totcol, mesh->mat);
BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect);
BKE_defbase_blend_write(writer, &mesh->vertex_group_names);
CustomData_blend_write(
writer, &mesh->vdata, vlayers, mesh->totvert, CD_MASK_MESH.vmask, &mesh->id);
CustomData_blend_write(
writer, &mesh->edata, elayers, mesh->totedge, CD_MASK_MESH.emask, &mesh->id);
/* fdata is really a dummy - written so slots align */
CustomData_blend_write(
writer, &mesh->fdata, flayers, mesh->totface, CD_MASK_MESH.fmask, &mesh->id);
CustomData_blend_write(
writer, &mesh->ldata, llayers, mesh->totloop, CD_MASK_MESH.lmask, &mesh->id);
CustomData_blend_write(
writer, &mesh->pdata, players, mesh->totpoly, CD_MASK_MESH.pmask, &mesh->id);
BLO_write_pointer_array(writer, mesh->totcol, mesh->mat);
BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect);
/* Free temporary data */
CustomData_blend_write(
writer, &mesh->vdata, vlayers, mesh->totvert, CD_MASK_MESH.vmask, &mesh->id);
CustomData_blend_write(
writer, &mesh->edata, elayers, mesh->totedge, CD_MASK_MESH.emask, &mesh->id);
/* fdata is really a dummy - written so slots align */
CustomData_blend_write(
writer, &mesh->fdata, flayers, mesh->totface, CD_MASK_MESH.fmask, &mesh->id);
CustomData_blend_write(
writer, &mesh->ldata, llayers, mesh->totloop, CD_MASK_MESH.lmask, &mesh->id);
CustomData_blend_write(
writer, &mesh->pdata, players, mesh->totpoly, CD_MASK_MESH.pmask, &mesh->id);
/* Free custom-data layers, when not assigned a buffer value. */
/* Free temporary data */
/* Free custom-data layers, when not assigned a buffer value. */
#define CD_LAYERS_FREE(id) \
if (id && id != id##_buff) { \
MEM_freeN(id); \
} \
((void)0)
CD_LAYERS_FREE(vlayers);
CD_LAYERS_FREE(elayers);
// CD_LAYER_FREE(flayers); /* Never allocated. */
CD_LAYERS_FREE(llayers);
CD_LAYERS_FREE(players);
CD_LAYERS_FREE(vlayers);
CD_LAYERS_FREE(elayers);
// CD_LAYER_FREE(flayers); /* Never allocated. */
CD_LAYERS_FREE(llayers);
CD_LAYERS_FREE(players);
#undef CD_LAYERS_FREE
}
}
static void mesh_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -206,36 +206,35 @@ static void write_movieReconstruction(BlendWriter *writer,
static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
MovieClip *clip = (MovieClip *)id;
if (clip->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
clip->anim = NULL;
clip->tracking_context = NULL;
clip->tracking.stats = NULL;
MovieTracking *tracking = &clip->tracking;
MovieTrackingObject *object;
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
clip->anim = NULL;
clip->tracking_context = NULL;
clip->tracking.stats = NULL;
BLO_write_id_struct(writer, MovieClip, id_address, &clip->id);
BKE_id_blend_write(writer, &clip->id);
MovieTracking *tracking = &clip->tracking;
MovieTrackingObject *object;
if (clip->adt) {
BKE_animdata_blend_write(writer, clip->adt);
}
BLO_write_id_struct(writer, MovieClip, id_address, &clip->id);
BKE_id_blend_write(writer, &clip->id);
write_movieTracks(writer, &tracking->tracks);
write_moviePlaneTracks(writer, &tracking->plane_tracks);
write_movieReconstruction(writer, &tracking->reconstruction);
if (clip->adt) {
BKE_animdata_blend_write(writer, clip->adt);
}
object = tracking->objects.first;
while (object) {
BLO_write_struct(writer, MovieTrackingObject, object);
write_movieTracks(writer, &tracking->tracks);
write_moviePlaneTracks(writer, &tracking->plane_tracks);
write_movieReconstruction(writer, &tracking->reconstruction);
write_movieTracks(writer, &object->tracks);
write_moviePlaneTracks(writer, &object->plane_tracks);
write_movieReconstruction(writer, &object->reconstruction);
object = tracking->objects.first;
while (object) {
BLO_write_struct(writer, MovieTrackingObject, object);
object = object->next;
}
write_movieTracks(writer, &object->tracks);
write_moviePlaneTracks(writer, &object->plane_tracks);
write_movieReconstruction(writer, &object->reconstruction);
object = object->next;
}
}

View File

@ -606,19 +606,18 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bNodeTree *ntree = (bNodeTree *)id;
if (ntree->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
ntree->init = 0; /* to set callbacks and force setting types */
ntree->is_updating = false;
ntree->typeinfo = nullptr;
ntree->interface_type = nullptr;
ntree->progress = nullptr;
ntree->execdata = nullptr;
BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id);
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
ntree->init = 0; /* to set callbacks and force setting types */
ntree->is_updating = false;
ntree->typeinfo = nullptr;
ntree->interface_type = nullptr;
ntree->progress = nullptr;
ntree->execdata = nullptr;
ntreeBlendWrite(writer, ntree);
}
BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id);
ntreeBlendWrite(writer, ntree);
}
static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock)

View File

@ -523,74 +523,72 @@ static void object_blend_write(BlendWriter *writer, ID *id, const void *id_addre
Object *ob = (Object *)id;
const bool is_undo = BLO_write_is_undo(writer);
if (ob->id.us > 0 || is_undo) {
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */
BKE_object_runtime_reset(ob);
if (is_undo) {
/* For undo we stay in object mode during undo presses, so keep edit-mode disabled on save as
* well, can help reducing false detection of changed data-blocks. */
ob->mode &= ~OB_MODE_EDIT;
}
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */
BKE_object_runtime_reset(ob);
/* write LibData */
BLO_write_id_struct(writer, Object, id_address, &ob->id);
BKE_id_blend_write(writer, &ob->id);
if (ob->adt) {
BKE_animdata_blend_write(writer, ob->adt);
}
/* direct data */
BLO_write_pointer_array(writer, ob->totcol, ob->mat);
BLO_write_raw(writer, sizeof(char) * ob->totcol, ob->matbits);
bArmature *arm = NULL;
if (ob->type == OB_ARMATURE) {
arm = ob->data;
if (arm && ob->pose && arm->act_bone) {
BLI_strncpy(
ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone));
}
}
BKE_pose_blend_write(writer, ob->pose, arm);
write_fmaps(writer, &ob->fmaps);
BKE_constraint_blend_write(writer, &ob->constraints);
animviz_motionpath_blend_write(writer, ob->mpath);
BLO_write_struct(writer, PartDeflect, ob->pd);
if (ob->soft) {
/* Set deprecated pointers to prevent crashes of older Blenders */
ob->soft->pointcache = ob->soft->shared->pointcache;
ob->soft->ptcaches = ob->soft->shared->ptcaches;
BLO_write_struct(writer, SoftBody, ob->soft);
BLO_write_struct(writer, SoftBody_Shared, ob->soft->shared);
BKE_ptcache_blend_write(writer, &(ob->soft->shared->ptcaches));
BLO_write_struct(writer, EffectorWeights, ob->soft->effector_weights);
}
if (ob->rigidbody_object) {
/* TODO: if any extra data is added to handle duplis, will need separate function then */
BLO_write_struct(writer, RigidBodyOb, ob->rigidbody_object);
}
if (ob->rigidbody_constraint) {
BLO_write_struct(writer, RigidBodyCon, ob->rigidbody_constraint);
}
if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
BLO_write_struct(writer, ImageUser, ob->iuser);
}
BKE_particle_system_blend_write(writer, &ob->particlesystem);
BKE_modifier_blend_write(writer, &ob->modifiers);
BKE_gpencil_modifier_blend_write(writer, &ob->greasepencil_modifiers);
BKE_shaderfx_blend_write(writer, &ob->shader_fx);
BLO_write_struct_list(writer, LinkData, &ob->pc_ids);
BKE_previewimg_blend_write(writer, ob->preview);
if (is_undo) {
/* For undo we stay in object mode during undo presses, so keep edit-mode disabled on save as
* well, can help reducing false detection of changed data-blocks. */
ob->mode &= ~OB_MODE_EDIT;
}
/* write LibData */
BLO_write_id_struct(writer, Object, id_address, &ob->id);
BKE_id_blend_write(writer, &ob->id);
if (ob->adt) {
BKE_animdata_blend_write(writer, ob->adt);
}
/* direct data */
BLO_write_pointer_array(writer, ob->totcol, ob->mat);
BLO_write_raw(writer, sizeof(char) * ob->totcol, ob->matbits);
bArmature *arm = NULL;
if (ob->type == OB_ARMATURE) {
arm = ob->data;
if (arm && ob->pose && arm->act_bone) {
BLI_strncpy(ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone));
}
}
BKE_pose_blend_write(writer, ob->pose, arm);
write_fmaps(writer, &ob->fmaps);
BKE_constraint_blend_write(writer, &ob->constraints);
animviz_motionpath_blend_write(writer, ob->mpath);
BLO_write_struct(writer, PartDeflect, ob->pd);
if (ob->soft) {
/* Set deprecated pointers to prevent crashes of older Blenders */
ob->soft->pointcache = ob->soft->shared->pointcache;
ob->soft->ptcaches = ob->soft->shared->ptcaches;
BLO_write_struct(writer, SoftBody, ob->soft);
BLO_write_struct(writer, SoftBody_Shared, ob->soft->shared);
BKE_ptcache_blend_write(writer, &(ob->soft->shared->ptcaches));
BLO_write_struct(writer, EffectorWeights, ob->soft->effector_weights);
}
if (ob->rigidbody_object) {
/* TODO: if any extra data is added to handle duplis, will need separate function then */
BLO_write_struct(writer, RigidBodyOb, ob->rigidbody_object);
}
if (ob->rigidbody_constraint) {
BLO_write_struct(writer, RigidBodyCon, ob->rigidbody_constraint);
}
if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
BLO_write_struct(writer, ImageUser, ob->iuser);
}
BKE_particle_system_blend_write(writer, &ob->particlesystem);
BKE_modifier_blend_write(writer, &ob->modifiers);
BKE_gpencil_modifier_blend_write(writer, &ob->greasepencil_modifiers);
BKE_shaderfx_blend_write(writer, &ob->shader_fx);
BLO_write_struct_list(writer, LinkData, &ob->pc_ids);
BKE_previewimg_blend_write(writer, ob->preview);
}
/* XXX deprecated - old animation system */

View File

@ -108,14 +108,13 @@ static void palette_free_data(ID *id)
static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Palette *palette = (Palette *)id;
if (palette->id.us > 0 || BLO_write_is_undo(writer)) {
PaletteColor *color;
BLO_write_id_struct(writer, Palette, id_address, &palette->id);
BKE_id_blend_write(writer, &palette->id);
for (color = palette->colors.first; color; color = color->next) {
BLO_write_struct(writer, PaletteColor, color);
}
PaletteColor *color;
BLO_write_id_struct(writer, Palette, id_address, &palette->id);
BKE_id_blend_write(writer, &palette->id);
for (color = palette->colors.first; color; color = color->next) {
BLO_write_struct(writer, PaletteColor, color);
}
}
@ -187,12 +186,11 @@ static void paint_curve_free_data(ID *id)
static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
PaintCurve *pc = (PaintCurve *)id;
if (pc->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id);
BKE_id_blend_write(writer, &pc->id);
BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points);
}
BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id);
BKE_id_blend_write(writer, &pc->id);
BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points);
}
static void paint_curve_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -255,60 +255,59 @@ static void write_boid_state(BlendWriter *writer, BoidState *state)
static void particle_settings_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
ParticleSettings *part = (ParticleSettings *)id;
if (part->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id);
BKE_id_blend_write(writer, &part->id);
if (part->adt) {
BKE_animdata_blend_write(writer, part->adt);
}
BLO_write_struct(writer, PartDeflect, part->pd);
BLO_write_struct(writer, PartDeflect, part->pd2);
BLO_write_struct(writer, EffectorWeights, part->effector_weights);
/* write LibData */
BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id);
BKE_id_blend_write(writer, &part->id);
if (part->clumpcurve) {
BKE_curvemapping_blend_write(writer, part->clumpcurve);
}
if (part->roughcurve) {
BKE_curvemapping_blend_write(writer, part->roughcurve);
}
if (part->twistcurve) {
BKE_curvemapping_blend_write(writer, part->twistcurve);
}
if (part->adt) {
BKE_animdata_blend_write(writer, part->adt);
}
BLO_write_struct(writer, PartDeflect, part->pd);
BLO_write_struct(writer, PartDeflect, part->pd2);
BLO_write_struct(writer, EffectorWeights, part->effector_weights);
LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) {
/* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */
if (dw->ob != NULL) {
dw->index = 0;
if (part->instance_collection) { /* can be NULL if lining fails or set to None */
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (part->instance_collection, object) {
if (object == dw->ob) {
break;
}
dw->index++;
if (part->clumpcurve) {
BKE_curvemapping_blend_write(writer, part->clumpcurve);
}
if (part->roughcurve) {
BKE_curvemapping_blend_write(writer, part->roughcurve);
}
if (part->twistcurve) {
BKE_curvemapping_blend_write(writer, part->twistcurve);
}
LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) {
/* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */
if (dw->ob != NULL) {
dw->index = 0;
if (part->instance_collection) { /* can be NULL if lining fails or set to None */
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (part->instance_collection, object) {
if (object == dw->ob) {
break;
}
FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
dw->index++;
}
}
BLO_write_struct(writer, ParticleDupliWeight, dw);
}
if (part->boids && part->phystype == PART_PHYS_BOIDS) {
BLO_write_struct(writer, BoidSettings, part->boids);
LISTBASE_FOREACH (BoidState *, state, &part->boids->states) {
write_boid_state(writer, state);
FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
}
}
if (part->fluid && part->phystype == PART_PHYS_FLUID) {
BLO_write_struct(writer, SPHFluidSettings, part->fluid);
}
BLO_write_struct(writer, ParticleDupliWeight, dw);
}
for (int a = 0; a < MAX_MTEX; a++) {
if (part->mtex[a]) {
BLO_write_struct(writer, MTex, part->mtex[a]);
}
if (part->boids && part->phystype == PART_PHYS_BOIDS) {
BLO_write_struct(writer, BoidSettings, part->boids);
LISTBASE_FOREACH (BoidState *, state, &part->boids->states) {
write_boid_state(writer, state);
}
}
if (part->fluid && part->phystype == PART_PHYS_FLUID) {
BLO_write_struct(writer, SPHFluidSettings, part->fluid);
}
for (int a = 0; a < MAX_MTEX; a++) {
if (part->mtex[a]) {
BLO_write_struct(writer, MTex, part->mtex[a]);
}
}
}

View File

@ -112,28 +112,27 @@ static void pointcloud_foreach_id(ID *id, LibraryForeachIDData *data)
static void pointcloud_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
PointCloud *pointcloud = (PointCloud *)id;
if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) {
CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE];
CustomData_blend_write_prepare(
&pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
/* Write LibData */
BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id);
BKE_id_blend_write(writer, &pointcloud->id);
CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE];
CustomData_blend_write_prepare(
&pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
/* Direct data */
CustomData_blend_write(
writer, &pointcloud->pdata, players, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id);
/* Write LibData */
BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id);
BKE_id_blend_write(writer, &pointcloud->id);
BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat);
if (pointcloud->adt) {
BKE_animdata_blend_write(writer, pointcloud->adt);
}
/* Direct data */
CustomData_blend_write(
writer, &pointcloud->pdata, players, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id);
/* Remove temporary data. */
if (players && players != players_buff) {
MEM_freeN(players);
}
BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat);
if (pointcloud->adt) {
BKE_animdata_blend_write(writer, pointcloud->adt);
}
/* Remove temporary data. */
if (players && players != players_buff) {
MEM_freeN(players);
}
}

View File

@ -255,18 +255,16 @@ static void screen_foreach_id(ID *id, LibraryForeachIDData *data)
static void screen_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bScreen *screen = (bScreen *)id;
/* Screens are reference counted, only saved if used by a workspace. */
if (screen->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
/* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
BLO_write_struct_at_address_with_filecode(writer, ID_SCRN, bScreen, id_address, screen);
BKE_id_blend_write(writer, &screen->id);
BKE_previewimg_blend_write(writer, screen->preview);
/* write LibData */
/* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
BLO_write_struct_at_address_with_filecode(writer, ID_SCRN, bScreen, id_address, screen);
BKE_id_blend_write(writer, &screen->id);
/* direct data */
BKE_screen_area_map_blend_write(writer, AREAMAP_FROM_SCREEN(screen));
}
BKE_previewimg_blend_write(writer, screen->preview);
/* direct data */
BKE_screen_area_map_blend_write(writer, AREAMAP_FROM_SCREEN(screen));
}
/* Cannot use IDTypeInfo callback yet, because of the return value. */

View File

@ -114,19 +114,18 @@ static void simulation_foreach_id(ID *id, LibraryForeachIDData *data)
static void simulation_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Simulation *simulation = (Simulation *)id;
if (simulation->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, Simulation, id_address, &simulation->id);
BKE_id_blend_write(writer, &simulation->id);
if (simulation->adt) {
BKE_animdata_blend_write(writer, simulation->adt);
}
BLO_write_id_struct(writer, Simulation, id_address, &simulation->id);
BKE_id_blend_write(writer, &simulation->id);
/* nodetree is integral part of simulation, no libdata */
if (simulation->nodetree) {
BLO_write_struct(writer, bNodeTree, simulation->nodetree);
ntreeBlendWrite(writer, simulation->nodetree);
}
if (simulation->adt) {
BKE_animdata_blend_write(writer, simulation->adt);
}
/* nodetree is integral part of simulation, no libdata */
if (simulation->nodetree) {
BLO_write_struct(writer, bNodeTree, simulation->nodetree);
ntreeBlendWrite(writer, simulation->nodetree);
}
}

View File

@ -137,24 +137,23 @@ static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_addres
{
bSound *sound = (bSound *)id;
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;
}
/* 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;
/* write LibData */
BLO_write_id_struct(writer, bSound, id_address, &sound->id);
BKE_id_blend_write(writer, &sound->id);
BKE_packedfile_blend_write(writer, sound->packedfile);
/* 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);
BKE_packedfile_blend_write(writer, sound->packedfile);
}
static void sound_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -56,14 +56,13 @@ static void speaker_foreach_id(ID *id, LibraryForeachIDData *data)
static void speaker_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Speaker *spk = (Speaker *)id;
if (spk->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
BKE_id_blend_write(writer, &spk->id);
if (spk->adt) {
BKE_animdata_blend_write(writer, spk->adt);
}
/* write LibData */
BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
BKE_id_blend_write(writer, &spk->id);
if (spk->adt) {
BKE_animdata_blend_write(writer, spk->adt);
}
}

View File

@ -171,9 +171,6 @@ static void text_free_data(ID *id)
static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
if (id->us < 1 && !BLO_write_is_undo(writer)) {
return;
}
Text *text = (Text *)id;
/* NOTE: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */

View File

@ -150,28 +150,27 @@ static void texture_foreach_id(ID *id, LibraryForeachIDData *data)
static void texture_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Tex *tex = (Tex *)id;
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Tex, id_address, &tex->id);
BKE_id_blend_write(writer, &tex->id);
if (tex->adt) {
BKE_animdata_blend_write(writer, tex->adt);
}
/* write LibData */
BLO_write_id_struct(writer, Tex, id_address, &tex->id);
BKE_id_blend_write(writer, &tex->id);
/* direct data */
if (tex->coba) {
BLO_write_struct(writer, ColorBand, tex->coba);
}
/* nodetree is integral part of texture, no libdata */
if (tex->nodetree) {
BLO_write_struct(writer, bNodeTree, tex->nodetree);
ntreeBlendWrite(writer, tex->nodetree);
}
BKE_previewimg_blend_write(writer, tex->preview);
if (tex->adt) {
BKE_animdata_blend_write(writer, tex->adt);
}
/* direct data */
if (tex->coba) {
BLO_write_struct(writer, ColorBand, tex->coba);
}
/* nodetree is integral part of texture, no libdata */
if (tex->nodetree) {
BLO_write_struct(writer, bNodeTree, tex->nodetree);
ntreeBlendWrite(writer, tex->nodetree);
}
BKE_previewimg_blend_write(writer, tex->preview);
}
static void texture_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -578,27 +578,26 @@ static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_addre
{
Volume *volume = (Volume *)id;
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;
}
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
volume->runtime.grids = nullptr;
/* write LibData */
BLO_write_id_struct(writer, Volume, id_address, &volume->id);
BKE_id_blend_write(writer, &volume->id);
/* direct data */
BLO_write_pointer_array(writer, volume->totcol, volume->mat);
if (volume->adt) {
BKE_animdata_blend_write(writer, volume->adt);
}
BKE_packedfile_blend_write(writer, volume->packedfile);
/* 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);
/* direct data */
BLO_write_pointer_array(writer, volume->totcol, volume->mat);
if (volume->adt) {
BKE_animdata_blend_write(writer, volume->adt);
}
BKE_packedfile_blend_write(writer, volume->packedfile);
}
static void volume_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -138,26 +138,25 @@ static void world_foreach_id(ID *id, LibraryForeachIDData *data)
static void world_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
World *wrld = (World *)id;
if (wrld->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&wrld->gpumaterial);
/* write LibData */
BLO_write_id_struct(writer, World, id_address, &wrld->id);
BKE_id_blend_write(writer, &wrld->id);
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&wrld->gpumaterial);
if (wrld->adt) {
BKE_animdata_blend_write(writer, wrld->adt);
}
/* write LibData */
BLO_write_id_struct(writer, World, id_address, &wrld->id);
BKE_id_blend_write(writer, &wrld->id);
/* nodetree is integral part of world, no libdata */
if (wrld->nodetree) {
BLO_write_struct(writer, bNodeTree, wrld->nodetree);
ntreeBlendWrite(writer, wrld->nodetree);
}
BKE_previewimg_blend_write(writer, wrld->preview);
if (wrld->adt) {
BKE_animdata_blend_write(writer, wrld->adt);
}
/* nodetree is integral part of world, no libdata */
if (wrld->nodetree) {
BLO_write_struct(writer, bNodeTree, wrld->nodetree);
ntreeBlendWrite(writer, wrld->nodetree);
}
BKE_previewimg_blend_write(writer, wrld->preview);
}
static void world_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -982,6 +982,14 @@ static bool write_file_handle(Main *mainvar,
BLI_assert(
(id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
/* We only write unused IDs in undo case.
* NOTE: All Scenes, WindowManagers and WorkSpaces should always be written to disk, so
* their usercount should never be NULL currently. */
if (id->us == 0 && !wd->use_memfile) {
BLI_assert(!ELEM(GS(id->name), ID_SCE, ID_WM, ID_WS));
continue;
}
const bool do_override = !ELEM(override_storage, NULL, bmain) &&
ID_IS_OVERRIDE_LIBRARY_REAL(id);