Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenloader/intern/writefile.c')
-rw-r--r--source/blender/blenloader/intern/writefile.c801
1 files changed, 148 insertions, 653 deletions
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index b6f0d5bd70b..3f968b513bb 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -152,6 +152,7 @@
#include "MEM_guardedalloc.h" // MEM_freeN
#include "BKE_action.h"
+#include "BKE_anim_data.h"
#include "BKE_armature.h"
#include "BKE_blender_version.h"
#include "BKE_bpath.h"
@@ -160,10 +161,12 @@
#include "BKE_constraint.h"
#include "BKE_curve.h"
#include "BKE_curveprofile.h"
+#include "BKE_deform.h"
#include "BKE_fcurve.h"
#include "BKE_fcurve_driver.h"
#include "BKE_global.h" // for G
#include "BKE_gpencil_modifier.h"
+#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
@@ -656,108 +659,6 @@ static void writelist_id(WriteData *wd, int filecode, const char *structname, co
* These functions are used by blender's .blend system for file saving/loading.
* \{ */
-void IDP_WriteProperty_OnlyData(const IDProperty *prop, BlendWriter *writer);
-void IDP_WriteProperty(const IDProperty *prop, BlendWriter *writer);
-
-static void IDP_WriteArray(const IDProperty *prop, BlendWriter *writer)
-{
- /*REMEMBER to set totalen to len in the linking code!!*/
- if (prop->data.pointer) {
- BLO_write_raw(writer, MEM_allocN_len(prop->data.pointer), prop->data.pointer);
-
- if (prop->subtype == IDP_GROUP) {
- IDProperty **array = prop->data.pointer;
- int a;
-
- for (a = 0; a < prop->len; a++) {
- IDP_WriteProperty(array[a], writer);
- }
- }
- }
-}
-
-static void IDP_WriteIDPArray(const IDProperty *prop, BlendWriter *writer)
-{
- /*REMEMBER to set totalen to len in the linking code!!*/
- if (prop->data.pointer) {
- const IDProperty *array = prop->data.pointer;
- int a;
-
- BLO_write_struct_array(writer, IDProperty, prop->len, array);
-
- for (a = 0; a < prop->len; a++) {
- IDP_WriteProperty_OnlyData(&array[a], writer);
- }
- }
-}
-
-static void IDP_WriteString(const IDProperty *prop, BlendWriter *writer)
-{
- /*REMEMBER to set totalen to len in the linking code!!*/
- BLO_write_raw(writer, prop->len, prop->data.pointer);
-}
-
-static void IDP_WriteGroup(const IDProperty *prop, BlendWriter *writer)
-{
- IDProperty *loop;
-
- for (loop = prop->data.group.first; loop; loop = loop->next) {
- IDP_WriteProperty(loop, writer);
- }
-}
-
-/* Functions to read/write ID Properties */
-void IDP_WriteProperty_OnlyData(const IDProperty *prop, BlendWriter *writer)
-{
- switch (prop->type) {
- case IDP_GROUP:
- IDP_WriteGroup(prop, writer);
- break;
- case IDP_STRING:
- IDP_WriteString(prop, writer);
- break;
- case IDP_ARRAY:
- IDP_WriteArray(prop, writer);
- break;
- case IDP_IDPARRAY:
- IDP_WriteIDPArray(prop, writer);
- break;
- }
-}
-
-void IDP_WriteProperty(const IDProperty *prop, BlendWriter *writer)
-{
- BLO_write_struct(writer, IDProperty, prop);
- IDP_WriteProperty_OnlyData(prop, writer);
-}
-
-static void write_iddata(BlendWriter *writer, ID *id)
-{
- /* ID_WM's id->properties are considered runtime only, and never written in .blend file. */
- if (id->properties && !ELEM(GS(id->name), ID_WM)) {
- IDP_WriteProperty(id->properties, writer);
- }
-
- if (id->override_library) {
- BLO_write_struct(writer, IDOverrideLibrary, id->override_library);
-
- BLO_write_struct_list(writer, IDOverrideLibraryProperty, &id->override_library->properties);
- LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &id->override_library->properties) {
- BLO_write_string(writer, op->rna_path);
-
- BLO_write_struct_list(writer, IDOverrideLibraryPropertyOperation, &op->operations);
- LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
- if (opop->subitem_reference_name) {
- BLO_write_string(writer, opop->subitem_reference_name);
- }
- if (opop->subitem_local_name) {
- BLO_write_string(writer, opop->subitem_local_name);
- }
- }
- }
- }
-}
-
static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig)
{
/* Note we write previews also for undo steps. It takes up some memory,
@@ -782,107 +683,13 @@ static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig)
}
}
-static void write_fmodifiers(BlendWriter *writer, ListBase *fmodifiers)
-{
- FModifier *fcm;
-
- /* Write all modifiers first (for faster reloading) */
- BLO_write_struct_list(writer, FModifier, fmodifiers);
-
- /* Modifiers */
- for (fcm = fmodifiers->first; fcm; fcm = fcm->next) {
- const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm);
-
- /* Write the specific data */
- if (fmi && fcm->data) {
- /* firstly, just write the plain fmi->data struct */
- BLO_write_struct_by_name(writer, fmi->structName, fcm->data);
-
- /* do any modifier specific stuff */
- switch (fcm->type) {
- case FMODIFIER_TYPE_GENERATOR: {
- FMod_Generator *data = fcm->data;
-
- /* write coefficients array */
- if (data->coefficients) {
- BLO_write_float_array(writer, data->arraysize, data->coefficients);
- }
-
- break;
- }
- case FMODIFIER_TYPE_ENVELOPE: {
- FMod_Envelope *data = fcm->data;
-
- /* write envelope data */
- if (data->data) {
- BLO_write_struct_array(writer, FCM_EnvelopeData, data->totvert, data->data);
- }
-
- break;
- }
- case FMODIFIER_TYPE_PYTHON: {
- FMod_Python *data = fcm->data;
-
- /* Write ID Properties -- and copy this comment EXACTLY for easy finding
- * of library blocks that implement this.*/
- IDP_WriteProperty(data->prop, writer);
-
- break;
- }
- }
- }
- }
-}
-
-static void write_fcurves(BlendWriter *writer, ListBase *fcurves)
-{
- FCurve *fcu;
-
- BLO_write_struct_list(writer, FCurve, fcurves);
- for (fcu = fcurves->first; fcu; fcu = fcu->next) {
- /* curve data */
- if (fcu->bezt) {
- BLO_write_struct_array(writer, BezTriple, fcu->totvert, fcu->bezt);
- }
- if (fcu->fpt) {
- BLO_write_struct_array(writer, FPoint, fcu->totvert, fcu->fpt);
- }
-
- if (fcu->rna_path) {
- BLO_write_string(writer, fcu->rna_path);
- }
-
- /* driver data */
- if (fcu->driver) {
- ChannelDriver *driver = fcu->driver;
- DriverVar *dvar;
-
- BLO_write_struct(writer, ChannelDriver, driver);
-
- /* variables */
- BLO_write_struct_list(writer, DriverVar, &driver->variables);
- for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
- DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
- if (dtar->rna_path) {
- BLO_write_string(writer, dtar->rna_path);
- }
- }
- DRIVER_TARGETS_LOOPER_END;
- }
- }
-
- /* write F-Modifiers */
- write_fmodifiers(writer, &fcu->modifiers);
- }
-}
-
static void write_action(BlendWriter *writer, bAction *act, const void *id_address)
{
if (act->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, bAction, id_address, &act->id);
- write_iddata(writer, &act->id);
+ BKE_id_blend_write(writer, &act->id);
- write_fcurves(writer, &act->curves);
+ BKE_fcurve_blend_write(writer, &act->curves);
LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
BLO_write_struct(writer, bActionGroup, grp);
@@ -896,15 +703,12 @@ static void write_action(BlendWriter *writer, bAction *act, const void *id_addre
static void write_keyingsets(BlendWriter *writer, ListBase *list)
{
- KeyingSet *ks;
- KS_Path *ksp;
-
- for (ks = list->first; ks; ks = ks->next) {
+ LISTBASE_FOREACH (KeyingSet *, ks, list) {
/* KeyingSet */
BLO_write_struct(writer, KeyingSet, ks);
/* Paths */
- for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
+ LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) {
/* Path */
BLO_write_struct(writer, KS_Path, ksp);
@@ -915,59 +719,6 @@ static void write_keyingsets(BlendWriter *writer, ListBase *list)
}
}
-static void write_nlastrips(BlendWriter *writer, ListBase *strips)
-{
- NlaStrip *strip;
-
- BLO_write_struct_list(writer, NlaStrip, strips);
- for (strip = strips->first; strip; strip = strip->next) {
- /* write the strip's F-Curves and modifiers */
- write_fcurves(writer, &strip->fcurves);
- write_fmodifiers(writer, &strip->modifiers);
-
- /* write the strip's children */
- write_nlastrips(writer, &strip->strips);
- }
-}
-
-static void write_nladata(BlendWriter *writer, ListBase *nlabase)
-{
- NlaTrack *nlt;
-
- /* write all the tracks */
- for (nlt = nlabase->first; nlt; nlt = nlt->next) {
- /* write the track first */
- BLO_write_struct(writer, NlaTrack, nlt);
-
- /* write the track's strips */
- write_nlastrips(writer, &nlt->strips);
- }
-}
-
-static void write_animdata(BlendWriter *writer, AnimData *adt)
-{
- AnimOverride *aor;
-
- /* firstly, just write the AnimData block */
- BLO_write_struct(writer, AnimData, adt);
-
- /* write drivers */
- write_fcurves(writer, &adt->drivers);
-
- /* write overrides */
- // FIXME: are these needed?
- for (aor = adt->overrides.first; aor; aor = aor->next) {
- /* overrides consist of base data + rna_path */
- BLO_write_struct(writer, AnimOverride, aor);
- BLO_write_string(writer, aor->rna_path);
- }
-
- // TODO write the remaps (if they are needed)
-
- /* write NLA data */
- write_nladata(writer, &adt->nla_tracks);
-}
-
static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock)
{
if (sock->default_value == NULL) {
@@ -1017,7 +768,7 @@ static void write_node_socket(BlendWriter *writer, bNodeSocket *sock)
BLO_write_struct(writer, bNodeSocket, sock);
if (sock->prop) {
- IDP_WriteProperty(sock->prop, writer);
+ IDP_BlendWrite(writer, sock->prop);
}
write_node_socket_default_value(writer, sock);
@@ -1028,7 +779,7 @@ static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock)
BLO_write_struct(writer, bNodeSocket, sock);
if (sock->prop) {
- IDP_WriteProperty(sock->prop, writer);
+ IDP_BlendWrite(writer, sock->prop);
}
write_node_socket_default_value(writer, sock);
@@ -1036,31 +787,27 @@ static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock)
/* this is only direct data, tree itself should have been written */
static void write_nodetree_nolib(BlendWriter *writer, bNodeTree *ntree)
{
- bNode *node;
- bNodeSocket *sock;
- bNodeLink *link;
-
/* for link_list() speed, we write per list */
if (ntree->adt) {
- write_animdata(writer, ntree->adt);
+ BKE_animdata_blend_write(writer, ntree->adt);
}
- for (node = ntree->nodes.first; node; node = node->next) {
+ LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
BLO_write_struct(writer, bNode, node);
if (node->prop) {
- IDP_WriteProperty(node->prop, writer);
+ IDP_BlendWrite(writer, node->prop);
}
- for (sock = node->inputs.first; sock; sock = sock->next) {
+ LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
write_node_socket(writer, sock);
}
- for (sock = node->outputs.first; sock; sock = sock->next) {
+ LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
write_node_socket(writer, sock);
}
- for (link = node->internal_links.first; link; link = link->next) {
+ LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) {
BLO_write_struct(writer, bNodeLink, link);
}
@@ -1124,26 +871,26 @@ static void write_nodetree_nolib(BlendWriter *writer, bNodeTree *ntree)
if (node->type == CMP_NODE_OUTPUT_FILE) {
/* inputs have own storage data */
- for (sock = node->inputs.first; sock; sock = sock->next) {
+ LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
BLO_write_struct(writer, NodeImageMultiFileSocket, sock->storage);
}
}
if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) {
/* write extra socket info */
- for (sock = node->outputs.first; sock; sock = sock->next) {
+ LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
BLO_write_struct(writer, NodeImageLayer, sock->storage);
}
}
}
- for (link = ntree->links.first; link; link = link->next) {
+ LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
BLO_write_struct(writer, bNodeLink, link);
}
- for (sock = ntree->inputs.first; sock; sock = sock->next) {
+ LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) {
write_node_socket_interface(writer, sock);
}
- for (sock = ntree->outputs.first; sock; sock = sock->next) {
+ LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) {
write_node_socket_interface(writer, sock);
}
}
@@ -1205,15 +952,15 @@ typedef struct RenderInfo {
static void write_renderinfo(WriteData *wd, Main *mainvar)
{
bScreen *curscreen;
- Scene *sce, *curscene = NULL;
+ Scene *curscene = NULL;
ViewLayer *view_layer;
- RenderInfo data;
/* XXX in future, handle multiple windows with multiple screens? */
current_screen_compat(mainvar, false, &curscreen, &curscene, &view_layer);
- for (sce = mainvar->scenes.first; sce; sce = sce->id.next) {
+ LISTBASE_FOREACH (Scene *, sce, &mainvar->scenes) {
if (sce->id.lib == NULL && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) {
+ RenderInfo data;
data.sfra = sce->r.sfra;
data.efra = sce->r.efra;
memset(data.scene_name, 0, sizeof(data.scene_name));
@@ -1229,7 +976,7 @@ static void write_keymapitem(BlendWriter *writer, const wmKeyMapItem *kmi)
{
BLO_write_struct(writer, wmKeyMapItem, kmi);
if (kmi->properties) {
- IDP_WriteProperty(kmi->properties, writer);
+ IDP_BlendWrite(writer, kmi->properties);
}
}
@@ -1262,7 +1009,7 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef)
LISTBASE_FOREACH (const wmKeyConfigPref *, kpt, &userdef->user_keyconfig_prefs) {
BLO_write_struct(writer, wmKeyConfigPref, kpt);
if (kpt->prop) {
- IDP_WriteProperty(kpt->prop, writer);
+ IDP_BlendWrite(writer, kpt->prop);
}
}
@@ -1273,7 +1020,7 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef)
const bUserMenuItem_Op *umi_op = (const bUserMenuItem_Op *)umi;
BLO_write_struct(writer, bUserMenuItem_Op, umi_op);
if (umi_op->prop) {
- IDP_WriteProperty(umi_op->prop, writer);
+ IDP_BlendWrite(writer, umi_op->prop);
}
}
else if (umi->type == USER_MENU_TYPE_MENU) {
@@ -1293,7 +1040,7 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef)
LISTBASE_FOREACH (const bAddon *, bext, &userdef->addons) {
BLO_write_struct(writer, bAddon, bext);
if (bext->prop) {
- IDP_WriteProperty(bext->prop, writer);
+ IDP_BlendWrite(writer, bext->prop);
}
}
@@ -1308,11 +1055,9 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef)
static void write_boid_state(BlendWriter *writer, BoidState *state)
{
- BoidRule *rule = state->rules.first;
-
BLO_write_struct(writer, BoidState, state);
- for (; rule; rule = rule->next) {
+ LISTBASE_FOREACH (BoidRule *, rule, &state->rules) {
switch (rule->type) {
case eBoidRuleType_Goal:
case eBoidRuleType_Avoid:
@@ -1361,21 +1106,14 @@ static const char *ptcache_extra_struct[] = {
};
static void write_pointcaches(BlendWriter *writer, ListBase *ptcaches)
{
- PointCache *cache = ptcaches->first;
- int i;
-
- for (; cache; cache = cache->next) {
+ LISTBASE_FOREACH (PointCache *, cache, ptcaches) {
BLO_write_struct(writer, PointCache, cache);
if ((cache->flag & PTCACHE_DISK_CACHE) == 0) {
- PTCacheMem *pm = cache->mem_cache.first;
-
- for (; pm; pm = pm->next) {
- PTCacheExtra *extra = pm->extradata.first;
-
+ LISTBASE_FOREACH (PTCacheMem *, pm, &cache->mem_cache) {
BLO_write_struct(writer, PTCacheMem, pm);
- for (i = 0; i < BPHYS_TOT_DATA; i++) {
+ for (int i = 0; i < BPHYS_TOT_DATA; i++) {
if (pm->data[i] && pm->data_types & (1 << i)) {
if (ptcache_data_struct[i][0] == '\0') {
BLO_write_raw(writer, MEM_allocN_len(pm->data[i]), pm->data[i]);
@@ -1387,7 +1125,7 @@ static void write_pointcaches(BlendWriter *writer, ListBase *ptcaches)
}
}
- for (; extra; extra = extra->next) {
+ LISTBASE_FOREACH (PTCacheExtra *, extra, &pm->extradata) {
if (ptcache_extra_struct[extra->type][0] == '\0') {
continue;
}
@@ -1407,10 +1145,10 @@ static void write_particlesettings(BlendWriter *writer,
if (part->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id);
- write_iddata(writer, &part->id);
+ BKE_id_blend_write(writer, &part->id);
if (part->adt) {
- write_animdata(writer, part->adt);
+ BKE_animdata_blend_write(writer, part->adt);
}
BLO_write_struct(writer, PartDeflect, part->pd);
BLO_write_struct(writer, PartDeflect, part->pd2);
@@ -1464,11 +1202,7 @@ static void write_particlesettings(BlendWriter *writer,
static void write_particlesystems(BlendWriter *writer, ListBase *particles)
{
- ParticleSystem *psys = particles->first;
- ParticleTarget *pt;
- int a;
-
- for (; psys; psys = psys->next) {
+ LISTBASE_FOREACH (ParticleSystem *, psys, particles) {
BLO_write_struct(writer, ParticleSystem, psys);
if (psys->particles) {
@@ -1477,7 +1211,7 @@ static void write_particlesystems(BlendWriter *writer, ListBase *particles)
if (psys->particles->hair) {
ParticleData *pa = psys->particles;
- for (a = 0; a < psys->totpart; a++, pa++) {
+ for (int a = 0; a < psys->totpart; a++, pa++) {
BLO_write_struct_array(writer, HairKey, pa->totkey, pa->hair);
}
}
@@ -1492,8 +1226,7 @@ static void write_particlesystems(BlendWriter *writer, ListBase *particles)
writer, ParticleSpring, psys->tot_fluidsprings, psys->fluid_springs);
}
}
- pt = psys->targets.first;
- for (; pt; pt = pt->next) {
+ LISTBASE_FOREACH (ParticleTarget *, pt, &psys->targets) {
BLO_write_struct(writer, ParticleTarget, pt);
}
@@ -1527,9 +1260,7 @@ static void write_motionpath(BlendWriter *writer, bMotionPath *mpath)
static void write_constraints(BlendWriter *writer, ListBase *conlist)
{
- bConstraint *con;
-
- for (con = conlist->first; con; con = con->next) {
+ LISTBASE_FOREACH (bConstraint *, con, conlist) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
/* Write the specific data */
@@ -1541,25 +1272,23 @@ static void write_constraints(BlendWriter *writer, ListBase *conlist)
switch (con->type) {
case CONSTRAINT_TYPE_PYTHON: {
bPythonConstraint *data = con->data;
- bConstraintTarget *ct;
/* write targets */
- for (ct = data->targets.first; ct; ct = ct->next) {
+ LISTBASE_FOREACH (bConstraintTarget *, ct, &data->targets) {
BLO_write_struct(writer, bConstraintTarget, ct);
}
/* Write ID Properties -- and copy this comment EXACTLY for easy finding
* of library blocks that implement this.*/
- IDP_WriteProperty(data->prop, writer);
+ IDP_BlendWrite(writer, data->prop);
break;
}
case CONSTRAINT_TYPE_ARMATURE: {
bArmatureConstraint *data = con->data;
- bConstraintTarget *ct;
/* write targets */
- for (ct = data->targets.first; ct; ct = ct->next) {
+ LISTBASE_FOREACH (bConstraintTarget *, ct, &data->targets) {
BLO_write_struct(writer, bConstraintTarget, ct);
}
@@ -1583,9 +1312,6 @@ static void write_constraints(BlendWriter *writer, ListBase *conlist)
static void write_pose(BlendWriter *writer, bPose *pose, bArmature *arm)
{
- bPoseChannel *chan;
- bActionGroup *grp;
-
/* Write each channel */
if (pose == NULL) {
return;
@@ -1594,11 +1320,11 @@ static void write_pose(BlendWriter *writer, bPose *pose, bArmature *arm)
BLI_assert(arm != NULL);
/* Write channels */
- for (chan = pose->chanbase.first; chan; chan = chan->next) {
+ LISTBASE_FOREACH (bPoseChannel *, chan, &pose->chanbase) {
/* Write ID Properties -- and copy this comment EXACTLY for easy finding
* of library blocks that implement this.*/
if (chan->prop) {
- IDP_WriteProperty(chan->prop, writer);
+ IDP_BlendWrite(writer, chan->prop);
}
write_constraints(writer, &chan->constraints);
@@ -1620,7 +1346,7 @@ static void write_pose(BlendWriter *writer, bPose *pose, bArmature *arm)
}
/* Write groups */
- for (grp = pose->agroups.first; grp; grp = grp->next) {
+ LISTBASE_FOREACH (bActionGroup *, grp, &pose->agroups) {
BLO_write_struct(writer, bActionGroup, grp);
}
@@ -1652,13 +1378,11 @@ static void write_fmaps(BlendWriter *writer, ListBase *fbase)
static void write_modifiers(BlendWriter *writer, ListBase *modbase)
{
- ModifierData *md;
-
if (modbase == NULL) {
return;
}
- for (md = modbase->first; md; md = md->next) {
+ LISTBASE_FOREACH (ModifierData *, md, modbase) {
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
if (mti == NULL) {
return;
@@ -1717,15 +1441,14 @@ static void write_modifiers(BlendWriter *writer, ListBase *modbase)
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
if (pmd->canvas) {
- DynamicPaintSurface *surface;
BLO_write_struct(writer, DynamicPaintCanvasSettings, pmd->canvas);
/* write surfaces */
- for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
+ LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) {
BLO_write_struct(writer, DynamicPaintSurface, surface);
}
/* write caches and effector weights */
- for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
+ LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) {
write_pointcaches(writer, &(surface->ptcaches));
BLO_write_struct(writer, EffectorWeights, surface->effector_weights);
@@ -1757,13 +1480,11 @@ static void write_modifiers(BlendWriter *writer, ListBase *modbase)
static void write_gpencil_modifiers(BlendWriter *writer, ListBase *modbase)
{
- GpencilModifierData *md;
-
if (modbase == NULL) {
return;
}
- for (md = modbase->first; md; md = md->next) {
+ LISTBASE_FOREACH (GpencilModifierData *, md, modbase) {
const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type);
if (mti == NULL) {
return;
@@ -1824,13 +1545,11 @@ static void write_gpencil_modifiers(BlendWriter *writer, ListBase *modbase)
static void write_shaderfxs(BlendWriter *writer, ListBase *fxbase)
{
- ShaderFxData *fx;
-
if (fxbase == NULL) {
return;
}
- for (fx = fxbase->first; fx; fx = fx->next) {
+ LISTBASE_FOREACH (ShaderFxData *, fx, fxbase) {
const ShaderFxTypeInfo *fxi = BKE_shaderfx_get_info(fx->type);
if (fxi == NULL) {
return;
@@ -1848,10 +1567,10 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address
/* write LibData */
BLO_write_id_struct(writer, Object, id_address, &ob->id);
- write_iddata(writer, &ob->id);
+ BKE_id_blend_write(writer, &ob->id);
if (ob->adt) {
- write_animdata(writer, ob->adt);
+ BKE_animdata_blend_write(writer, ob->adt);
}
/* direct data */
@@ -1875,9 +1594,9 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address
BLO_write_struct(writer, PartDeflect, ob->pd);
if (ob->soft) {
- /* Don't write ADMM-PD data. */
- ADMMPDInterfaceData *admmpd = ob->soft->admmpd;
- ob->soft->admmpd = NULL;
+ /* Don't write ADMM-PD data. Just recompute when needed. */
+ ListBase *admmpd_list = ob->soft->shared->admmpd_list;
+ ob->soft->shared->admmpd_list = NULL;
/* Set deprecated pointers to prevent crashes of older Blenders */
ob->soft->pointcache = ob->soft->shared->pointcache;
ob->soft->ptcaches = ob->soft->shared->ptcaches;
@@ -1885,8 +1604,8 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address
BLO_write_struct(writer, SoftBody_Shared, ob->soft->shared);
write_pointcaches(writer, &(ob->soft->shared->ptcaches));
BLO_write_struct(writer, EffectorWeights, ob->soft->effector_weights);
- /* Reset the ADMM-PD data pointer */
- ob->soft->admmpd = admmpd;
+ /* Reset the ADMM-PD data pointer. */
+ ob->soft->shared->admmpd_list = admmpd_list;
}
if (ob->rigidbody_object) {
@@ -1907,7 +1626,6 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address
write_shaderfxs(writer, &ob->shader_fx);
BLO_write_struct_list(writer, LinkData, &ob->pc_ids);
- BLO_write_struct_list(writer, LodLevel, &ob->lodlevels);
write_previews(writer, ob->preview);
}
@@ -1922,7 +1640,7 @@ static void write_vfont(BlendWriter *writer, VFont *vf, const void *id_address)
/* write LibData */
BLO_write_id_struct(writer, VFont, id_address, &vf->id);
- write_iddata(writer, &vf->id);
+ BKE_id_blend_write(writer, &vf->id);
/* direct data */
if (vf->packedfile) {
@@ -1938,10 +1656,10 @@ static void write_key(BlendWriter *writer, Key *key, const void *id_address)
if (key->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Key, id_address, &key->id);
- write_iddata(writer, &key->id);
+ BKE_id_blend_write(writer, &key->id);
if (key->adt) {
- write_animdata(writer, key->adt);
+ BKE_animdata_blend_write(writer, key->adt);
}
/* direct data */
@@ -1959,10 +1677,10 @@ static void write_camera(BlendWriter *writer, Camera *cam, const void *id_addres
if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Camera, id_address, &cam->id);
- write_iddata(writer, &cam->id);
+ BKE_id_blend_write(writer, &cam->id);
if (cam->adt) {
- write_animdata(writer, cam->adt);
+ BKE_animdata_blend_write(writer, cam->adt);
}
LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
@@ -1984,12 +1702,12 @@ static void write_mball(BlendWriter *writer, MetaBall *mb, const void *id_addres
/* write LibData */
BLO_write_id_struct(writer, MetaBall, id_address, &mb->id);
- write_iddata(writer, &mb->id);
+ BKE_id_blend_write(writer, &mb->id);
/* direct data */
BLO_write_pointer_array(writer, mb->totcol, mb->mat);
if (mb->adt) {
- write_animdata(writer, mb->adt);
+ BKE_animdata_blend_write(writer, mb->adt);
}
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
@@ -2008,12 +1726,12 @@ static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address)
/* write LibData */
BLO_write_id_struct(writer, Curve, id_address, &cu->id);
- write_iddata(writer, &cu->id);
+ BKE_id_blend_write(writer, &cu->id);
/* direct data */
BLO_write_pointer_array(writer, cu->totcol, cu->mat);
if (cu->adt) {
- write_animdata(writer, cu->adt);
+ BKE_animdata_blend_write(writer, cu->adt);
}
if (cu->vfont) {
@@ -2045,206 +1763,6 @@ static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address)
}
}
-static void write_dverts(BlendWriter *writer, int count, MDeformVert *dvlist)
-{
- if (dvlist) {
-
- /* Write the dvert list */
- BLO_write_struct_array(writer, MDeformVert, count, dvlist);
-
- /* Write deformation data for each dvert */
- for (int i = 0; i < count; i++) {
- if (dvlist[i].dw) {
- BLO_write_struct_array(writer, MDeformWeight, dvlist[i].totweight, dvlist[i].dw);
- }
- }
- }
-}
-
-static void write_mdisps(BlendWriter *writer, int count, MDisps *mdlist, int external)
-{
- if (mdlist) {
- int i;
-
- BLO_write_struct_array(writer, MDisps, count, mdlist);
- for (i = 0; i < count; i++) {
- MDisps *md = &mdlist[i];
- if (md->disps) {
- if (!external) {
- BLO_write_float3_array(writer, md->totdisp, &md->disps[0][0]);
- }
- }
-
- if (md->hidden) {
- BLO_write_raw(writer, BLI_BITMAP_SIZE(md->totdisp), md->hidden);
- }
- }
- }
-}
-
-static void write_grid_paint_mask(BlendWriter *writer, int count, GridPaintMask *grid_paint_mask)
-{
- if (grid_paint_mask) {
- int i;
-
- BLO_write_struct_array(writer, GridPaintMask, count, grid_paint_mask);
- for (i = 0; i < count; i++) {
- GridPaintMask *gpm = &grid_paint_mask[i];
- if (gpm->data) {
- const int gridsize = BKE_ccg_gridsize(gpm->level);
- BLO_write_raw(writer, sizeof(*gpm->data) * gridsize * gridsize, gpm->data);
- }
- }
- }
-}
-
-static void write_customdata(BlendWriter *writer,
- ID *id,
- int count,
- CustomData *data,
- CustomDataLayer *layers,
- CustomDataMask cddata_mask)
-{
- int i;
-
- /* write external customdata (not for undo) */
- if (data->external && !BLO_write_is_undo(writer)) {
- CustomData_external_write(data, id, cddata_mask, count, 0);
- }
-
- BLO_write_struct_array_at_address(writer, CustomDataLayer, data->totlayer, data->layers, layers);
-
- for (i = 0; i < data->totlayer; i++) {
- CustomDataLayer *layer = &layers[i];
- const char *structname;
- int structnum, datasize;
-
- if (layer->type == CD_MDEFORMVERT) {
- /* layer types that allocate own memory need special handling */
- write_dverts(writer, count, layer->data);
- }
- else if (layer->type == CD_MDISPS) {
- write_mdisps(writer, count, layer->data, layer->flag & CD_FLAG_EXTERNAL);
- }
- else if (layer->type == CD_PAINT_MASK) {
- const float *layer_data = layer->data;
- BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data);
- }
- else if (layer->type == CD_SCULPT_FACE_SETS) {
- const float *layer_data = layer->data;
- BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data);
- }
- else if (layer->type == CD_GRID_PAINT_MASK) {
- write_grid_paint_mask(writer, count, layer->data);
- }
- else if (layer->type == CD_FACEMAP) {
- const int *layer_data = layer->data;
- BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data);
- }
- else {
- CustomData_file_write_info(layer->type, &structname, &structnum);
- if (structnum) {
- datasize = structnum * count;
- BLO_write_struct_array_by_name(writer, structname, datasize, layer->data);
- }
- else if (!BLO_write_is_undo(writer)) { /* Do not warn on undo. */
- printf("%s error: layer '%s':%d - can't be written to file\n",
- __func__,
- structname,
- layer->type);
- }
- }
- }
-
- if (data->external) {
- BLO_write_struct(writer, CustomDataExternal, data->external);
- }
-}
-
-static void write_mesh(BlendWriter *writer, Mesh *mesh, const void *id_address)
-{
- 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));
-
- /* Reduce xdata layers, fill xlayers with layers to be written.
- * This makes xdata invalid for Blender, which is why we made a
- * temporary local copy. */
- 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_file_write_prepare(&mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff));
- CustomData_file_write_prepare(&mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff));
- flayers = flayers_buff;
- CustomData_file_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
- CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
-
- BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
- write_iddata(writer, &mesh->id);
-
- /* direct data */
- if (mesh->adt) {
- write_animdata(writer, mesh->adt);
- }
-
- BLO_write_pointer_array(writer, mesh->totcol, mesh->mat);
- BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect);
-
- write_customdata(writer, &mesh->id, mesh->totvert, &mesh->vdata, vlayers, CD_MASK_MESH.vmask);
- write_customdata(writer, &mesh->id, mesh->totedge, &mesh->edata, elayers, CD_MASK_MESH.emask);
- /* fdata is really a dummy - written so slots align */
- write_customdata(writer, &mesh->id, mesh->totface, &mesh->fdata, flayers, CD_MASK_MESH.fmask);
- write_customdata(writer, &mesh->id, mesh->totloop, &mesh->ldata, llayers, CD_MASK_MESH.lmask);
- write_customdata(writer, &mesh->id, mesh->totpoly, &mesh->pdata, players, CD_MASK_MESH.pmask);
-
- /* free temporary data */
- if (vlayers && vlayers != vlayers_buff) {
- MEM_freeN(vlayers);
- }
- if (elayers && elayers != elayers_buff) {
- MEM_freeN(elayers);
- }
- if (flayers && flayers != flayers_buff) {
- MEM_freeN(flayers);
- }
- if (llayers && llayers != llayers_buff) {
- MEM_freeN(llayers);
- }
- if (players && players != players_buff) {
- MEM_freeN(players);
- }
- }
-}
-
-static void write_lattice(BlendWriter *writer, Lattice *lt, const void *id_address)
-{
- 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);
- write_iddata(writer, &lt->id);
-
- /* write animdata */
- if (lt->adt) {
- write_animdata(writer, lt->adt);
- }
-
- /* direct data */
- BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
-
- write_dverts(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
- }
-}
-
static void write_image(BlendWriter *writer, Image *ima, const void *id_address)
{
if (ima->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -2259,7 +1777,7 @@ static void write_image(BlendWriter *writer, Image *ima, const void *id_address)
/* write LibData */
BLO_write_id_struct(writer, Image, id_address, &ima->id);
- write_iddata(writer, &ima->id);
+ BKE_id_blend_write(writer, &ima->id);
for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
BLO_write_struct(writer, ImagePackedFile, imapf);
@@ -2290,10 +1808,10 @@ static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Tex, id_address, &tex->id);
- write_iddata(writer, &tex->id);
+ BKE_id_blend_write(writer, &tex->id);
if (tex->adt) {
- write_animdata(writer, tex->adt);
+ BKE_animdata_blend_write(writer, tex->adt);
}
/* direct data */
@@ -2320,10 +1838,10 @@ static void write_material(BlendWriter *writer, Material *ma, const void *id_add
/* write LibData */
BLO_write_id_struct(writer, Material, id_address, &ma->id);
- write_iddata(writer, &ma->id);
+ BKE_id_blend_write(writer, &ma->id);
if (ma->adt) {
- write_animdata(writer, ma->adt);
+ BKE_animdata_blend_write(writer, ma->adt);
}
/* nodetree is integral part of material, no libdata */
@@ -2349,10 +1867,10 @@ static void write_world(BlendWriter *writer, World *wrld, const void *id_address
/* write LibData */
BLO_write_id_struct(writer, World, id_address, &wrld->id);
- write_iddata(writer, &wrld->id);
+ BKE_id_blend_write(writer, &wrld->id);
if (wrld->adt) {
- write_animdata(writer, wrld->adt);
+ BKE_animdata_blend_write(writer, wrld->adt);
}
/* nodetree is integral part of world, no libdata */
@@ -2370,10 +1888,10 @@ static void write_light(BlendWriter *writer, Light *la, const void *id_address)
if (la->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Light, id_address, &la->id);
- write_iddata(writer, &la->id);
+ BKE_id_blend_write(writer, &la->id);
if (la->adt) {
- write_animdata(writer, la->adt);
+ BKE_animdata_blend_write(writer, la->adt);
}
if (la->curfalloff) {
@@ -2415,7 +1933,7 @@ static void write_collection(BlendWriter *writer, Collection *collection, const
/* write LibData */
BLO_write_id_struct(writer, Collection, id_address, &collection->id);
- write_iddata(writer, &collection->id);
+ BKE_id_blend_write(writer, &collection->id);
write_collection_nolib(writer, collection);
}
@@ -2423,9 +1941,7 @@ static void write_collection(BlendWriter *writer, Collection *collection, const
static void write_sequence_modifiers(BlendWriter *writer, ListBase *modbase)
{
- SequenceModifierData *smd;
-
- for (smd = modbase->first; smd; smd = smd->next) {
+ LISTBASE_FOREACH (SequenceModifierData *, smd, modbase) {
const SequenceModifierTypeInfo *smti = BKE_sequence_modifier_type_info_get(smd->type);
if (smti) {
@@ -2458,7 +1974,7 @@ static void write_view_settings(BlendWriter *writer, ColorManagedViewSettings *v
static void write_view3dshading(BlendWriter *writer, View3DShading *shading)
{
if (shading->prop) {
- IDP_WriteProperty(shading->prop, writer);
+ IDP_BlendWrite(writer, shading->prop);
}
}
@@ -2485,7 +2001,7 @@ static void write_view_layer(BlendWriter *writer, ViewLayer *view_layer)
BLO_write_struct_list(writer, Base, &view_layer->object_bases);
if (view_layer->id_properties) {
- IDP_WriteProperty(view_layer->id_properties, writer);
+ IDP_BlendWrite(writer, view_layer->id_properties);
}
LISTBASE_FOREACH (FreestyleModuleConfig *, fmc, &view_layer->freestyle_config.modules) {
@@ -2543,10 +2059,10 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address)
/* write LibData */
BLO_write_id_struct(writer, Scene, id_address, &sce->id);
- write_iddata(writer, &sce->id);
+ BKE_id_blend_write(writer, &sce->id);
if (sce->adt) {
- write_animdata(writer, sce->adt);
+ BKE_animdata_blend_write(writer, sce->adt);
}
write_keyingsets(writer, &sce->keyingsets);
@@ -2612,15 +2128,15 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address)
/* reset write flags too */
- SEQ_BEGIN (ed, seq) {
+ SEQ_ALL_BEGIN (ed, seq) {
if (seq->strip) {
seq->strip->done = false;
}
BLO_write_struct(writer, Sequence, seq);
}
- SEQ_END;
+ SEQ_ALL_END;
- SEQ_BEGIN (ed, seq) {
+ SEQ_ALL_BEGIN (ed, seq) {
if (seq->strip && seq->strip->done == 0) {
/* write strip with 'done' at 0 because readfile */
@@ -2680,12 +2196,12 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address)
}
if (seq->prop) {
- IDP_WriteProperty(seq->prop, writer);
+ IDP_BlendWrite(writer, seq->prop);
}
write_sequence_modifiers(writer, &seq->modifiers);
}
- SEQ_END;
+ SEQ_ALL_END;
/* new; meta stack too, even when its nasty restore code */
LISTBASE_FOREACH (MetaStack *, ms, &ed->metastack) {
@@ -2703,7 +2219,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address)
}
}
if (sce->r.ffcodecdata.properties) {
- IDP_WriteProperty(sce->r.ffcodecdata.properties, writer);
+ IDP_BlendWrite(writer, sce->r.ffcodecdata.properties);
}
/* writing dynamic list of TimeMarkers to the blend file */
@@ -2777,10 +2293,10 @@ static void write_gpencil(BlendWriter *writer, bGPdata *gpd, const void *id_addr
/* write gpd data block to file */
BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id);
- write_iddata(writer, &gpd->id);
+ BKE_id_blend_write(writer, &gpd->id);
if (gpd->adt) {
- write_animdata(writer, gpd->adt);
+ BKE_animdata_blend_write(writer, gpd->adt);
}
BLO_write_pointer_array(writer, gpd->totcol, gpd->mat);
@@ -2798,7 +2314,7 @@ static void write_gpencil(BlendWriter *writer, bGPdata *gpd, const void *id_addr
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);
- write_dverts(writer, gps->totpoints, gps->dvert);
+ BKE_defvert_blend_write(writer, gps->totpoints, gps->dvert);
}
}
}
@@ -2847,7 +2363,7 @@ static void write_uilist(BlendWriter *writer, uiList *ui_list)
BLO_write_struct(writer, uiList, ui_list);
if (ui_list->properties) {
- IDP_WriteProperty(ui_list->properties, writer);
+ IDP_BlendWrite(writer, ui_list->properties);
}
}
@@ -2993,18 +2509,16 @@ static void write_area_regions(BlendWriter *writer, ScrArea *area)
}
else if (sl->spacetype == SPACE_NODE) {
SpaceNode *snode = (SpaceNode *)sl;
- bNodeTreePath *path;
BLO_write_struct(writer, SpaceNode, snode);
- for (path = snode->treepath.first; path; path = path->next) {
+ LISTBASE_FOREACH (bNodeTreePath *, path, &snode->treepath) {
BLO_write_struct(writer, bNodeTreePath, path);
}
}
else if (sl->spacetype == SPACE_CONSOLE) {
SpaceConsole *con = (SpaceConsole *)sl;
- ConsoleLine *cl;
- for (cl = con->history.first; cl; cl = cl->next) {
+ LISTBASE_FOREACH (ConsoleLine *, cl, &con->history) {
/* 'len_alloc' is invalid on write, set from 'len' on read */
BLO_write_struct(writer, ConsoleLine, cl);
BLO_write_raw(writer, cl->len + 1, cl->line);
@@ -3053,7 +2567,7 @@ static void write_area_map(BlendWriter *writer, ScrAreaMap *area_map)
static void write_windowmanager(BlendWriter *writer, wmWindowManager *wm, const void *id_address)
{
BLO_write_id_struct(writer, wmWindowManager, id_address, &wm->id);
- write_iddata(writer, &wm->id);
+ BKE_id_blend_write(writer, &wm->id);
write_wm_xr_data(writer, &wm->xr);
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
@@ -3088,7 +2602,7 @@ static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_ad
/* write LibData */
/* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
writestruct_at_address(writer->wd, ID_SCRN, bScreen, 1, id_address, screen);
- write_iddata(writer, &screen->id);
+ BKE_id_blend_write(writer, &screen->id);
write_previews(writer, screen->preview);
@@ -3108,7 +2622,7 @@ static void write_bone(BlendWriter *writer, Bone *bone)
/* Write ID Properties -- and copy this comment EXACTLY for easy finding
* of library blocks that implement this.*/
if (bone->prop) {
- IDP_WriteProperty(bone->prop, writer);
+ IDP_BlendWrite(writer, bone->prop);
}
/* Write Children */
@@ -3128,10 +2642,10 @@ static void write_armature(BlendWriter *writer, bArmature *arm, const void *id_a
arm->act_edbone = NULL;
BLO_write_id_struct(writer, bArmature, id_address, &arm->id);
- write_iddata(writer, &arm->id);
+ BKE_id_blend_write(writer, &arm->id);
if (arm->adt) {
- write_animdata(writer, arm->adt);
+ BKE_animdata_blend_write(writer, arm->adt);
}
/* Direct data */
@@ -3153,7 +2667,7 @@ static void write_text(BlendWriter *writer, Text *text, const void *id_address)
/* write LibData */
BLO_write_id_struct(writer, Text, id_address, &text->id);
- write_iddata(writer, &text->id);
+ BKE_id_blend_write(writer, &text->id);
if (text->filepath) {
BLO_write_string(writer, text->filepath);
@@ -3176,10 +2690,10 @@ static void write_speaker(BlendWriter *writer, Speaker *spk, const void *id_addr
if (spk->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
- write_iddata(writer, &spk->id);
+ BKE_id_blend_write(writer, &spk->id);
if (spk->adt) {
- write_animdata(writer, spk->adt);
+ BKE_animdata_blend_write(writer, spk->adt);
}
}
}
@@ -3195,7 +2709,7 @@ static void write_sound(BlendWriter *writer, bSound *sound, const void *id_addre
/* write LibData */
BLO_write_id_struct(writer, bSound, id_address, &sound->id);
- write_iddata(writer, &sound->id);
+ BKE_id_blend_write(writer, &sound->id);
if (sound->packedfile) {
PackedFile *pf = sound->packedfile;
@@ -3210,10 +2724,10 @@ static void write_probe(BlendWriter *writer, LightProbe *prb, const void *id_add
if (prb->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, LightProbe, id_address, &prb->id);
- write_iddata(writer, &prb->id);
+ BKE_id_blend_write(writer, &prb->id);
if (prb->adt) {
- write_animdata(writer, prb->adt);
+ BKE_animdata_blend_write(writer, prb->adt);
}
}
}
@@ -3232,7 +2746,7 @@ static void write_nodetree(BlendWriter *writer, bNodeTree *ntree, const void *id
BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id);
/* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot
* be linked, etc., so we write actual id data here only, for 'real' ID trees. */
- write_iddata(writer, &ntree->id);
+ BKE_id_blend_write(writer, &ntree->id);
write_nodetree_nolib(writer, ntree);
}
@@ -3242,7 +2756,7 @@ static void write_brush(BlendWriter *writer, Brush *brush, const void *id_addres
{
if (brush->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, Brush, id_address, &brush->id);
- write_iddata(writer, &brush->id);
+ BKE_id_blend_write(writer, &brush->id);
if (brush->curve) {
BKE_curvemapping_blend_write(writer, brush->curve);
@@ -3290,7 +2804,7 @@ static void write_palette(BlendWriter *writer, Palette *palette, const void *id_
if (palette->id.us > 0 || BLO_write_is_undo(writer)) {
PaletteColor *color;
BLO_write_id_struct(writer, Palette, id_address, &palette->id);
- write_iddata(writer, &palette->id);
+ BKE_id_blend_write(writer, &palette->id);
for (color = palette->colors.first; color; color = color->next) {
BLO_write_struct(writer, PaletteColor, color);
@@ -3302,7 +2816,7 @@ static void write_paintcurve(BlendWriter *writer, PaintCurve *pc, const void *id
{
if (pc->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id);
- write_iddata(writer, &pc->id);
+ BKE_id_blend_write(writer, &pc->id);
BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points);
}
@@ -3358,10 +2872,10 @@ static void write_movieclip(BlendWriter *writer, MovieClip *clip, const void *id
MovieTrackingObject *object;
BLO_write_id_struct(writer, MovieClip, id_address, &clip->id);
- write_iddata(writer, &clip->id);
+ BKE_id_blend_write(writer, &clip->id);
if (clip->adt) {
- write_animdata(writer, clip->adt);
+ BKE_animdata_blend_write(writer, clip->adt);
}
write_movieTracks(writer, &tracking->tracks);
@@ -3387,10 +2901,10 @@ static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address)
MaskLayer *masklay;
BLO_write_id_struct(writer, Mask, id_address, &mask->id);
- write_iddata(writer, &mask->id);
+ BKE_id_blend_write(writer, &mask->id);
if (mask->adt) {
- write_animdata(writer, mask->adt);
+ BKE_animdata_blend_write(writer, mask->adt);
}
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
@@ -3697,10 +3211,10 @@ static void write_linestyle(BlendWriter *writer,
{
if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id);
- write_iddata(writer, &linestyle->id);
+ BKE_id_blend_write(writer, &linestyle->id);
if (linestyle->adt) {
- write_animdata(writer, linestyle->adt);
+ BKE_animdata_blend_write(writer, linestyle->adt);
}
write_linestyle_color_modifiers(writer, &linestyle->color_modifiers);
@@ -3731,7 +3245,7 @@ static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const vo
BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
if (cache_file->adt) {
- write_animdata(writer, cache_file->adt);
+ BKE_animdata_blend_write(writer, cache_file->adt);
}
}
}
@@ -3739,14 +3253,14 @@ static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const vo
static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const void *id_address)
{
BLO_write_id_struct(writer, WorkSpace, id_address, &workspace->id);
- write_iddata(writer, &workspace->id);
+ BKE_id_blend_write(writer, &workspace->id);
BLO_write_struct_list(writer, WorkSpaceLayout, &workspace->layouts);
BLO_write_struct_list(writer, WorkSpaceDataRelation, &workspace->hook_layout_relations);
BLO_write_struct_list(writer, wmOwnerID, &workspace->owner_ids);
BLO_write_struct_list(writer, bToolRef, &workspace->tools);
LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
if (tref->properties) {
- IDP_WriteProperty(tref->properties, writer);
+ IDP_BlendWrite(writer, tref->properties);
}
}
}
@@ -3754,29 +3268,16 @@ static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const voi
static void write_hair(BlendWriter *writer, Hair *hair, const void *id_address)
{
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_file_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
- CustomData_file_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
-
/* Write LibData */
BLO_write_id_struct(writer, Hair, id_address, &hair->id);
- write_iddata(writer, &hair->id);
+ BKE_id_blend_write(writer, &hair->id);
/* Direct data */
- write_customdata(writer, &hair->id, hair->totpoint, &hair->pdata, players, CD_MASK_ALL);
- write_customdata(writer, &hair->id, hair->totcurve, &hair->cdata, clayers, CD_MASK_ALL);
+ CustomData_blend_write(writer, &hair->pdata, hair->totpoint, CD_MASK_ALL, &hair->id);
+ CustomData_blend_write(writer, &hair->cdata, hair->totcurve, CD_MASK_ALL, &hair->id);
BLO_write_pointer_array(writer, hair->totcol, hair->mat);
if (hair->adt) {
- write_animdata(writer, hair->adt);
- }
-
- /* Remove temporary data. */
- if (players && players != players_buff) {
- MEM_freeN(players);
- }
- if (clayers && clayers != clayers_buff) {
- MEM_freeN(clayers);
+ BKE_animdata_blend_write(writer, hair->adt);
}
}
}
@@ -3790,14 +3291,14 @@ static void write_pointcloud(BlendWriter *writer, PointCloud *pointcloud, const
/* Write LibData */
BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id);
- write_iddata(writer, &pointcloud->id);
+ BKE_id_blend_write(writer, &pointcloud->id);
/* Direct data */
- write_customdata(
- writer, &pointcloud->id, pointcloud->totpoint, &pointcloud->pdata, players, CD_MASK_ALL);
+ CustomData_blend_write(
+ writer, &pointcloud->pdata, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id);
BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat);
if (pointcloud->adt) {
- write_animdata(writer, pointcloud->adt);
+ BKE_animdata_blend_write(writer, pointcloud->adt);
}
/* Remove temporary data. */
@@ -3815,12 +3316,12 @@ static void write_volume(BlendWriter *writer, Volume *volume, const void *id_add
/* write LibData */
BLO_write_id_struct(writer, Volume, id_address, &volume->id);
- write_iddata(writer, &volume->id);
+ BKE_id_blend_write(writer, &volume->id);
/* direct data */
BLO_write_pointer_array(writer, volume->totcol, volume->mat);
if (volume->adt) {
- write_animdata(writer, volume->adt);
+ BKE_animdata_blend_write(writer, volume->adt);
}
if (volume->packedfile) {
@@ -3835,10 +3336,10 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const
{
if (simulation->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, Simulation, id_address, &simulation->id);
- write_iddata(writer, &simulation->id);
+ BKE_id_blend_write(writer, &simulation->id);
if (simulation->adt) {
- write_animdata(writer, simulation->adt);
+ BKE_animdata_blend_write(writer, simulation->adt);
}
/* nodetree is integral part of simulation, no libdata */
@@ -3855,21 +3356,11 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const
ParticleSimulationState *particle_state = (ParticleSimulationState *)state;
BLO_write_struct(writer, ParticleSimulationState, particle_state);
- CustomDataLayer *layers = NULL;
- CustomDataLayer layers_buff[CD_TEMP_CHUNK_SIZE];
- CustomData_file_write_prepare(
- &particle_state->attributes, &layers, layers_buff, ARRAY_SIZE(layers_buff));
-
- write_customdata(writer,
- &simulation->id,
- particle_state->tot_particles,
- &particle_state->attributes,
- layers,
- CD_MASK_ALL);
-
- if (layers != NULL && layers != layers_buff) {
- MEM_freeN(layers);
- }
+ CustomData_blend_write(writer,
+ &particle_state->attributes,
+ particle_state->tot_particles,
+ CD_MASK_ALL,
+ &simulation->id);
}
else if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_MESH_EMITTER)) {
ParticleMeshEmitterSimulationState *emitter_state = (ParticleMeshEmitterSimulationState *)
@@ -3925,7 +3416,7 @@ static void write_libraries(WriteData *wd, Main *main)
BlendWriter writer = {wd};
writestruct(wd, ID_LI, Library, 1, main->curlib);
- write_iddata(&writer, &main->curlib->id);
+ BKE_id_blend_write(&writer, &main->curlib->id);
if (main->curlib->packedfile) {
PackedFile *pf = main->curlib->packedfile;
@@ -4130,12 +3621,17 @@ static bool write_file_handle(Main *mainvar,
memcpy(id_buffer, id, idtype_struct_size);
((ID *)id_buffer)->tag = 0;
- /* Those listbase data change every time we add/remove an ID, and also often when renaming
- * one (due to re-sorting). This avoids generating a lot of false 'is changed' detections
- * between undo steps. */
+ /* Those listbase data change every time we add/remove an ID, and also often when
+ * renaming one (due to re-sorting). This avoids generating a lot of false 'is changed'
+ * detections between undo steps. */
((ID *)id_buffer)->prev = NULL;
((ID *)id_buffer)->next = NULL;
+ const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
+ if (id_type->blend_write != NULL) {
+ id_type->blend_write(&writer, (ID *)id_buffer, id);
+ }
+
switch ((ID_Type)GS(id->name)) {
case ID_WM:
write_windowmanager(&writer, (wmWindowManager *)id_buffer, id);
@@ -4170,9 +3666,6 @@ static bool write_file_handle(Main *mainvar,
case ID_LA:
write_light(&writer, (Light *)id_buffer, id);
break;
- case ID_LT:
- write_lattice(&writer, (Lattice *)id_buffer, id);
- break;
case ID_VF:
write_vfont(&writer, (VFont *)id_buffer, id);
break;
@@ -4212,9 +3705,6 @@ static bool write_file_handle(Main *mainvar,
case ID_TE:
write_texture(&writer, (Tex *)id_buffer, id);
break;
- case ID_ME:
- write_mesh(&writer, (Mesh *)id_buffer, id);
- break;
case ID_PA:
write_particlesettings(&writer, (ParticleSettings *)id_buffer, id);
break;
@@ -4251,6 +3741,10 @@ static bool write_file_handle(Main *mainvar,
case ID_SIM:
write_simulation(&writer, (Simulation *)id_buffer, id);
break;
+ case ID_ME:
+ case ID_LT:
+ /* Do nothing, handled in IDTypeInfo callback. */
+ break;
case ID_LI:
/* Do nothing, handled below - and should never be reached. */
BLI_assert(0);
@@ -4409,7 +3903,8 @@ bool BLO_write_file(Main *mainvar,
if (remap_mode != BLO_WRITE_PATH_REMAP_NONE) {
if (remap_mode == BLO_WRITE_PATH_REMAP_RELATIVE) {
- /* Make all relative as none of the existing paths can be relative in an unsaved document. */
+ /* Make all relative as none of the existing paths can be relative in an unsaved document.
+ */
if (G.relbase_valid == false) {
remap_mode = BLO_WRITE_PATH_REMAP_RELATIVE_ALL;
}