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:
authorJacques Lucke <jacques@blender.org>2020-11-06 20:25:44 +0300
committerJacques Lucke <jacques@blender.org>2020-11-06 20:25:51 +0300
commit638913a3c08990697e08195e00f5f9cf472c04be (patch)
treecd93247443e3afbdb7a762391f7dc02e10436f4d /source/blender/blenloader/intern/readfile.c
parent16732def37c5a66f3ea28dbe247b09cc6bca6677 (diff)
Refactor: move Object .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r--source/blender/blenloader/intern/readfile.c515
1 files changed, 2 insertions, 513 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 69b95c5c972..9cb7ed7c71c 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2535,37 +2535,6 @@ static void direct_link_ipo(BlendDataReader *reader, Ipo *ipo)
}
}
-/* XXX deprecated - old animation system */
-static void lib_link_nlastrips(BlendLibReader *reader, ID *id, ListBase *striplist)
-{
- LISTBASE_FOREACH (bActionStrip *, strip, striplist) {
- BLO_read_id_address(reader, id->lib, &strip->object);
- BLO_read_id_address(reader, id->lib, &strip->act);
- BLO_read_id_address(reader, id->lib, &strip->ipo);
- LISTBASE_FOREACH (bActionModifier *, amod, &strip->modifiers) {
- BLO_read_id_address(reader, id->lib, &amod->ob);
- }
- }
-}
-
-/* XXX deprecated - old animation system */
-static void direct_link_nlastrips(BlendDataReader *reader, ListBase *strips)
-{
- BLO_read_list(reader, strips);
-
- LISTBASE_FOREACH (bActionStrip *, strip, strips) {
- BLO_read_list(reader, &strip->modifiers);
- }
-}
-
-/* XXX deprecated - old animation system */
-static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBase *chanbase)
-{
- LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) {
- BLO_read_id_address(reader, id->lib, &chan->ipo);
- }
-}
-
/** \} */
/* -------------------------------------------------------------------- */
@@ -2583,381 +2552,6 @@ void blo_do_versions_key_uidgen(Key *key)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Read ID: Object
- * \{ */
-
-static void lib_link_object(BlendLibReader *reader, Object *ob)
-{
- bool warn = false;
-
- /* XXX deprecated - old animation system <<< */
- BLO_read_id_address(reader, ob->id.lib, &ob->ipo);
- BLO_read_id_address(reader, ob->id.lib, &ob->action);
- /* >>> XXX deprecated - old animation system */
-
- BLO_read_id_address(reader, ob->id.lib, &ob->parent);
- BLO_read_id_address(reader, ob->id.lib, &ob->track);
- BLO_read_id_address(reader, ob->id.lib, &ob->poselib);
-
- /* 2.8x drops support for non-empty dupli instances. */
- if (ob->type == OB_EMPTY) {
- BLO_read_id_address(reader, ob->id.lib, &ob->instance_collection);
- }
- else {
- if (ob->instance_collection != NULL) {
- ID *id = BLO_read_get_new_id_address(reader, ob->id.lib, &ob->instance_collection->id);
- BLO_reportf_wrap(BLO_read_lib_reports(reader),
- RPT_WARNING,
- TIP_("Non-Empty object '%s' cannot duplicate collection '%s' "
- "anymore in Blender 2.80, removed instancing"),
- ob->id.name + 2,
- id->name + 2);
- }
- ob->instance_collection = NULL;
- ob->transflag &= ~OB_DUPLICOLLECTION;
- }
-
- BLO_read_id_address(reader, ob->id.lib, &ob->proxy);
- if (ob->proxy) {
- /* paranoia check, actually a proxy_from pointer should never be written... */
- if (ob->proxy->id.lib == NULL) {
- ob->proxy->proxy_from = NULL;
- ob->proxy = NULL;
-
- if (ob->id.lib) {
- printf("Proxy lost from object %s lib %s\n", ob->id.name + 2, ob->id.lib->filepath);
- }
- else {
- printf("Proxy lost from object %s lib <NONE>\n", ob->id.name + 2);
- }
- }
- else {
- /* this triggers object_update to always use a copy */
- ob->proxy->proxy_from = ob;
- }
- }
- BLO_read_id_address(reader, ob->id.lib, &ob->proxy_group);
-
- void *poin = ob->data;
- BLO_read_id_address(reader, ob->id.lib, &ob->data);
-
- if (ob->data == NULL && poin != NULL) {
- if (ob->id.lib) {
- printf("Can't find obdata of %s lib %s\n", ob->id.name + 2, ob->id.lib->filepath);
- }
- else {
- printf("Object %s lost data.\n", ob->id.name + 2);
- }
-
- ob->type = OB_EMPTY;
- warn = true;
-
- if (ob->pose) {
- /* we can't call #BKE_pose_free() here because of library linking
- * freeing will recurse down into every pose constraints ID pointers
- * which are not always valid, so for now free directly and suffer
- * some leaked memory rather than crashing immediately
- * while bad this _is_ an exceptional case - campbell */
-#if 0
- BKE_pose_free(ob->pose);
-#else
- MEM_freeN(ob->pose);
-#endif
- ob->pose = NULL;
- ob->mode &= ~OB_MODE_POSE;
- }
- }
- for (int a = 0; a < ob->totcol; a++) {
- BLO_read_id_address(reader, ob->id.lib, &ob->mat[a]);
- }
-
- /* When the object is local and the data is library its possible
- * the material list size gets out of sync. T22663. */
- if (ob->data && ob->id.lib != ((ID *)ob->data)->lib) {
- const short *totcol_data = BKE_object_material_len_p(ob);
- /* Only expand so as not to lose any object materials that might be set. */
- if (totcol_data && (*totcol_data > ob->totcol)) {
- /* printf("'%s' %d -> %d\n", ob->id.name, ob->totcol, *totcol_data); */
- BKE_object_material_resize(reader->main, ob, *totcol_data, false);
- }
- }
-
- BLO_read_id_address(reader, ob->id.lib, &ob->gpd);
-
- /* if id.us==0 a new base will be created later on */
-
- /* WARNING! Also check expand_object(), should reflect the stuff below. */
- BKE_pose_blend_read_lib(reader, ob, ob->pose);
- BKE_constraint_blend_read_lib(reader, &ob->id, &ob->constraints);
-
- /* XXX deprecated - old animation system <<< */
- lib_link_constraint_channels(reader, &ob->id, &ob->constraintChannels);
- lib_link_nlastrips(reader, &ob->id, &ob->nlastrips);
- /* >>> XXX deprecated - old animation system */
-
- LISTBASE_FOREACH (PartEff *, paf, &ob->effect) {
- if (paf->type == EFF_PARTICLE) {
- BLO_read_id_address(reader, ob->id.lib, &paf->group);
- }
- }
-
- {
- FluidsimModifierData *fluidmd = (FluidsimModifierData *)BKE_modifiers_findby_type(
- ob, eModifierType_Fluidsim);
-
- if (fluidmd && fluidmd->fss) {
- BLO_read_id_address(
- reader, ob->id.lib, &fluidmd->fss->ipo); /* XXX deprecated - old animation system */
- }
- }
-
- {
- FluidModifierData *fmd = (FluidModifierData *)BKE_modifiers_findby_type(ob,
- eModifierType_Fluid);
-
- if (fmd && (fmd->type == MOD_FLUID_TYPE_DOMAIN) && fmd->domain) {
- /* Flag for refreshing the simulation after loading */
- fmd->domain->flags |= FLUID_DOMAIN_FILE_LOAD;
- }
- else if (fmd && (fmd->type == MOD_FLUID_TYPE_FLOW) && fmd->flow) {
- fmd->flow->flags &= ~FLUID_FLOW_NEEDS_UPDATE;
- }
- else if (fmd && (fmd->type == MOD_FLUID_TYPE_EFFEC) && fmd->effector) {
- fmd->effector->flags &= ~FLUID_EFFECTOR_NEEDS_UPDATE;
- }
- }
-
- /* texture field */
- if (ob->pd) {
- BKE_particle_partdeflect_blend_read_lib(reader, &ob->id, ob->pd);
- }
-
- if (ob->soft) {
- BLO_read_id_address(reader, ob->id.lib, &ob->soft->collision_group);
-
- BLO_read_id_address(reader, ob->id.lib, &ob->soft->effector_weights->group);
- }
-
- BKE_particle_system_blend_read_lib(reader, ob, &ob->id, &ob->particlesystem);
- BKE_modifier_blend_read_lib(reader, ob);
- BKE_gpencil_modifier_blend_read_lib(reader, ob);
- BKE_shaderfx_blend_read_lib(reader, ob);
-
- if (ob->rigidbody_constraint) {
- BLO_read_id_address(reader, ob->id.lib, &ob->rigidbody_constraint->ob1);
- BLO_read_id_address(reader, ob->id.lib, &ob->rigidbody_constraint->ob2);
- }
-
- if (warn) {
- BKE_report(reader->fd->reports, RPT_WARNING, "Warning in console");
- }
-}
-
-static void direct_link_object(BlendDataReader *reader, Object *ob)
-{
- PartEff *paf;
-
- /* XXX This should not be needed - but seems like it can happen in some cases,
- * so for now play safe. */
- ob->proxy_from = NULL;
-
- const bool is_undo = BLO_read_data_is_undo(reader);
- if (ob->id.tag & (LIB_TAG_EXTERN | LIB_TAG_INDIRECT)) {
- /* Do not allow any non-object mode for linked data.
- * See T34776, T42780, T81027 for more information. */
- ob->mode &= ~OB_MODE_ALL_MODE_DATA;
- }
- else if (is_undo) {
- /* For undo we want to stay in object mode during undo presses, so keep some edit modes
- * disabled.
- * TODO: Check if we should not disable more edit modes here? */
- ob->mode &= ~(OB_MODE_EDIT | OB_MODE_PARTICLE_EDIT);
- }
-
- BLO_read_data_address(reader, &ob->adt);
- BKE_animdata_blend_read_data(reader, ob->adt);
-
- BLO_read_data_address(reader, &ob->pose);
- BKE_pose_blend_read_data(reader, ob->pose);
-
- BLO_read_data_address(reader, &ob->mpath);
- if (ob->mpath) {
- animviz_motionpath_blend_read_data(reader, ob->mpath);
- }
-
- BLO_read_list(reader, &ob->defbase);
- BLO_read_list(reader, &ob->fmaps);
- /* XXX deprecated - old animation system <<< */
- direct_link_nlastrips(reader, &ob->nlastrips);
- BLO_read_list(reader, &ob->constraintChannels);
- /* >>> XXX deprecated - old animation system */
-
- BLO_read_pointer_array(reader, (void **)&ob->mat);
- BLO_read_data_address(reader, &ob->matbits);
-
- /* do it here, below old data gets converted */
- BKE_modifier_blend_read_data(reader, &ob->modifiers, ob);
- BKE_gpencil_modifier_blend_read_data(reader, &ob->greasepencil_modifiers);
- BKE_shaderfx_blend_read_data(reader, &ob->shader_fx);
-
- BLO_read_list(reader, &ob->effect);
- paf = ob->effect.first;
- while (paf) {
- if (paf->type == EFF_PARTICLE) {
- paf->keys = NULL;
- }
- if (paf->type == EFF_WAVE) {
- WaveEff *wav = (WaveEff *)paf;
- PartEff *next = paf->next;
- WaveModifierData *wmd = (WaveModifierData *)BKE_modifier_new(eModifierType_Wave);
-
- wmd->damp = wav->damp;
- wmd->flag = wav->flag;
- wmd->height = wav->height;
- wmd->lifetime = wav->lifetime;
- wmd->narrow = wav->narrow;
- wmd->speed = wav->speed;
- wmd->startx = wav->startx;
- wmd->starty = wav->startx;
- wmd->timeoffs = wav->timeoffs;
- wmd->width = wav->width;
-
- BLI_addtail(&ob->modifiers, wmd);
-
- BLI_remlink(&ob->effect, paf);
- MEM_freeN(paf);
-
- paf = next;
- continue;
- }
- if (paf->type == EFF_BUILD) {
- BuildEff *baf = (BuildEff *)paf;
- PartEff *next = paf->next;
- BuildModifierData *bmd = (BuildModifierData *)BKE_modifier_new(eModifierType_Build);
-
- bmd->start = baf->sfra;
- bmd->length = baf->len;
- bmd->randomize = 0;
- bmd->seed = 1;
-
- BLI_addtail(&ob->modifiers, bmd);
-
- BLI_remlink(&ob->effect, paf);
- MEM_freeN(paf);
-
- paf = next;
- continue;
- }
- paf = paf->next;
- }
-
- BLO_read_data_address(reader, &ob->pd);
- BKE_particle_partdeflect_blend_read_data(reader, ob->pd);
- BLO_read_data_address(reader, &ob->soft);
- if (ob->soft) {
- SoftBody *sb = ob->soft;
-
- sb->bpoint = NULL; /* init pointers so it gets rebuilt nicely */
- sb->bspring = NULL;
- sb->scratch = NULL;
- /* although not used anymore */
- /* still have to be loaded to be compatible with old files */
- BLO_read_pointer_array(reader, (void **)&sb->keys);
- if (sb->keys) {
- for (int a = 0; a < sb->totkey; a++) {
- BLO_read_data_address(reader, &sb->keys[a]);
- }
- }
-
- BLO_read_data_address(reader, &sb->effector_weights);
- if (!sb->effector_weights) {
- sb->effector_weights = BKE_effector_add_weights(NULL);
- }
-
- BLO_read_data_address(reader, &sb->shared);
- if (sb->shared == NULL) {
- /* Link deprecated caches if they exist, so we can use them for versioning.
- * We should only do this when sb->shared == NULL, because those pointers
- * are always set (for compatibility with older Blenders). We mustn't link
- * the same pointcache twice. */
- BKE_ptcache_blend_read_data(reader, &sb->ptcaches, &sb->pointcache, false);
- }
- else {
- /* link caches */
- BKE_ptcache_blend_read_data(reader, &sb->shared->ptcaches, &sb->shared->pointcache, false);
- }
- }
- BLO_read_data_address(reader, &ob->fluidsimSettings); /* NT */
-
- BLO_read_data_address(reader, &ob->rigidbody_object);
- if (ob->rigidbody_object) {
- RigidBodyOb *rbo = ob->rigidbody_object;
- /* Allocate runtime-only struct */
- rbo->shared = MEM_callocN(sizeof(*rbo->shared), "RigidBodyObShared");
- }
- BLO_read_data_address(reader, &ob->rigidbody_constraint);
- if (ob->rigidbody_constraint) {
- ob->rigidbody_constraint->physics_constraint = NULL;
- }
-
- BLO_read_list(reader, &ob->particlesystem);
- BKE_particle_system_blend_read_data(reader, &ob->particlesystem);
-
- BKE_constraint_blend_read_data(reader, &ob->constraints);
-
- BLO_read_list(reader, &ob->hooks);
- while (ob->hooks.first) {
- ObHook *hook = ob->hooks.first;
- HookModifierData *hmd = (HookModifierData *)BKE_modifier_new(eModifierType_Hook);
-
- BLO_read_int32_array(reader, hook->totindex, &hook->indexar);
-
- /* Do conversion here because if we have loaded
- * a hook we need to make sure it gets converted
- * and freed, regardless of version.
- */
- copy_v3_v3(hmd->cent, hook->cent);
- hmd->falloff = hook->falloff;
- hmd->force = hook->force;
- hmd->indexar = hook->indexar;
- hmd->object = hook->parent;
- memcpy(hmd->parentinv, hook->parentinv, sizeof(hmd->parentinv));
- hmd->totindex = hook->totindex;
-
- BLI_addhead(&ob->modifiers, hmd);
- BLI_remlink(&ob->hooks, hook);
-
- BKE_modifier_unique_name(&ob->modifiers, (ModifierData *)hmd);
-
- MEM_freeN(hook);
- }
-
- BLO_read_data_address(reader, &ob->iuser);
- if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE && !ob->iuser) {
- BKE_object_empty_draw_type_set(ob, ob->empty_drawtype);
- }
-
- BKE_object_runtime_reset(ob);
- BLO_read_list(reader, &ob->pc_ids);
-
- /* in case this value changes in future, clamp else we get undefined behavior */
- CLAMP(ob->rotmode, ROT_MODE_MIN, ROT_MODE_MAX);
-
- if (ob->sculpt) {
- ob->sculpt = NULL;
- /* Only create data on undo, otherwise rely on editor mode switching. */
- if (BLO_read_data_is_undo(reader) && (ob->mode & OB_MODE_ALL_SCULPT)) {
- BKE_object_sculpt_data_create(ob);
- }
- }
-
- BLO_read_data_address(reader, &ob->preview);
- BKE_previewimg_blend_read(reader, ob->preview);
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
/** \name Read ID: Scene
* \{ */
@@ -3763,15 +3357,13 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_SCR:
success = direct_link_screen(&reader, (bScreen *)id);
break;
- case ID_OB:
- direct_link_object(&reader, (Object *)id);
- break;
case ID_IP:
direct_link_ipo(&reader, (Ipo *)id);
break;
case ID_LI:
direct_link_library(fd, (Library *)id, main);
break;
+ case ID_OB:
case ID_SCE:
case ID_WM:
case ID_WS:
@@ -4388,9 +3980,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
* Please keep order of entries in that switch matching that order, it's easier to quickly see
* whether something is wrong then. */
switch (GS(id->name)) {
- case ID_OB:
- lib_link_object(&reader, (Object *)id);
- break;
case ID_IP:
/* XXX deprecated... still needs to be maintained for version patches still. */
lib_link_ipo(&reader, (Ipo *)id);
@@ -4398,6 +3987,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_LI:
lib_link_library(&reader, (Library *)id); /* Only init users. */
break;
+ case ID_OB:
case ID_SCE:
case ID_WM:
case ID_WS:
@@ -5021,14 +4611,6 @@ static void expand_ipo(BlendExpander *expander, Ipo *ipo)
}
}
-/* XXX deprecated - old animation system */
-static void expand_constraint_channels(BlendExpander *expander, ListBase *chanbase)
-{
- LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) {
- BLO_expand(expander, chan->ipo);
- }
-}
-
static void expand_id(BlendExpander *expander, ID *id);
static void expand_id_embedded_id(BlendExpander *expander, ID *id)
@@ -5066,96 +4648,6 @@ static void expand_id(BlendExpander *expander, ID *id)
expand_id_embedded_id(expander, id);
}
-static void expand_object_expandModifiers(void *userData,
- Object *UNUSED(ob),
- ID **idpoin,
- int UNUSED(cb_flag))
-{
- BlendExpander *expander = userData;
- BLO_expand(expander, *idpoin);
-}
-
-static void expand_object(BlendExpander *expander, Object *ob)
-{
- BLO_expand(expander, ob->data);
-
- /* expand_object_expandModifier() */
- if (ob->modifiers.first) {
- BKE_modifiers_foreach_ID_link(ob, expand_object_expandModifiers, expander);
- }
-
- /* expand_object_expandModifier() */
- if (ob->greasepencil_modifiers.first) {
- BKE_gpencil_modifiers_foreach_ID_link(ob, expand_object_expandModifiers, expander);
- }
-
- /* expand_object_expandShaderFx() */
- if (ob->shader_fx.first) {
- BKE_shaderfx_foreach_ID_link(ob, expand_object_expandModifiers, expander);
- }
-
- BKE_pose_blend_read_expand(expander, ob->pose);
- BLO_expand(expander, ob->poselib);
- BKE_constraint_blend_read_expand(expander, &ob->constraints);
-
- BLO_expand(expander, ob->gpd);
-
- /* XXX deprecated - old animation system (for version patching only) */
- BLO_expand(expander, ob->ipo);
- BLO_expand(expander, ob->action);
-
- expand_constraint_channels(expander, &ob->constraintChannels);
-
- LISTBASE_FOREACH (bActionStrip *, strip, &ob->nlastrips) {
- BLO_expand(expander, strip->object);
- BLO_expand(expander, strip->act);
- BLO_expand(expander, strip->ipo);
- }
- /* XXX deprecated - old animation system (for version patching only) */
-
- for (int a = 0; a < ob->totcol; a++) {
- BLO_expand(expander, ob->mat[a]);
- }
-
- PartEff *paf = blo_do_version_give_parteff_245(ob);
- if (paf && paf->group) {
- BLO_expand(expander, paf->group);
- }
-
- if (ob->instance_collection) {
- BLO_expand(expander, ob->instance_collection);
- }
-
- if (ob->proxy) {
- BLO_expand(expander, ob->proxy);
- }
- if (ob->proxy_group) {
- BLO_expand(expander, ob->proxy_group);
- }
-
- LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) {
- BLO_expand(expander, psys->part);
- }
-
- if (ob->pd) {
- BLO_expand(expander, ob->pd->tex);
- BLO_expand(expander, ob->pd->f_source);
- }
-
- if (ob->soft) {
- BLO_expand(expander, ob->soft->collision_group);
-
- if (ob->soft->effector_weights) {
- BLO_expand(expander, ob->soft->effector_weights->group);
- }
- }
-
- if (ob->rigidbody_constraint) {
- BLO_expand(expander, ob->rigidbody_constraint->ob1);
- BLO_expand(expander, ob->rigidbody_constraint->ob2);
- }
-}
-
/**
* Set the callback func used over all ID data found by \a BLO_expand_main func.
*
@@ -5199,9 +4691,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
}
switch (GS(id->name)) {
- case ID_OB:
- expand_object(&expander, (Object *)id);
- break;
case ID_IP:
expand_ipo(&expander, (Ipo *)id); /* XXX deprecated - old animation system */
break;