diff options
Diffstat (limited to 'source/blender/blenkernel/intern/object.c')
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 97 |
1 files changed, 84 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index f8fe53063bc..365a5d838eb 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -38,6 +38,7 @@ #include "DNA_anim_types.h" #include "DNA_armature_types.h" +#include "DNA_cache_library_types.h" #include "DNA_camera_types.h" #include "DNA_constraint_types.h" #include "DNA_group_types.h" @@ -76,6 +77,7 @@ #include "BKE_armature.h" #include "BKE_action.h" #include "BKE_bullet.h" +#include "BKE_cache_library.h" #include "BKE_deform.h" #include "BKE_depsgraph.h" #include "BKE_DerivedMesh.h" @@ -85,6 +87,7 @@ #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_effect.h" +#include "BKE_facemap.h" #include "BKE_fcurve.h" #include "BKE_group.h" #include "BKE_key.h" @@ -99,6 +102,7 @@ #include "BKE_multires.h" #include "BKE_node.h" #include "BKE_object.h" +#include "BKE_object_deform.h" #include "BKE_paint.h" #include "BKE_particle.h" #include "BKE_pointcache.h" @@ -107,6 +111,7 @@ #include "BKE_sca.h" #include "BKE_scene.h" #include "BKE_sequencer.h" +#include "BKE_smoke.h" #include "BKE_speaker.h" #include "BKE_softbody.h" #include "BKE_subsurf.h" @@ -325,9 +330,12 @@ void BKE_object_free_derived_caches(Object *ob) } if (ob->derivedFinal) { - ob->derivedFinal->needsFree = 1; - ob->derivedFinal->release(ob->derivedFinal); - ob->derivedFinal = NULL; + /* dupli cache owns the derivedFinal, is freed by duplicator object */ + if (!(ob->transflag & OB_IS_DUPLI_CACHE)) { + ob->derivedFinal->needsFree = 1; + ob->derivedFinal->release(ob->derivedFinal); + ob->derivedFinal = NULL; + } } if (ob->derivedDeform) { ob->derivedDeform->needsFree = 1; @@ -336,9 +344,11 @@ void BKE_object_free_derived_caches(Object *ob) } BKE_object_free_curve_cache(ob); + + BKE_object_dupli_cache_clear(ob); } -void BKE_object_free_caches(Object *object) +void BKE_object_free_caches(Object *object, bool free_smoke_sim) { ModifierData *md; short update_flag = 0; @@ -351,7 +361,7 @@ void BKE_object_free_caches(Object *object) psys = psys->next) { psys_free_path_cache(psys, psys->edit); - update_flag |= PSYS_RECALC; + update_flag |= PSYS_RECALC_REDO; } } @@ -363,9 +373,32 @@ void BKE_object_free_caches(Object *object) psmd->dm->needsFree = 1; psmd->dm->release(psmd->dm); psmd->dm = NULL; + psmd->flag |= eParticleSystemFlag_file_loaded; update_flag |= OB_RECALC_DATA; } } + else if (md->type == eModifierType_Smoke) { + if (free_smoke_sim) { + SmokeModifierData *smd = (SmokeModifierData *) md; + SmokeDomainSettings *sds = smd->domain; + if (sds != NULL) { + bool use_sim = sds->point_cache[0] == NULL; + PointCache *cache; + /* We only reset cache if all the point caches are baked to file. */ + for (cache = sds->ptcaches[0].first; + cache != NULL && use_sim == false; + cache = cache->next) + { + use_sim |= ((cache->flag & (PTCACHE_BAKED|PTCACHE_DISK_CACHE)) != (PTCACHE_BAKED|PTCACHE_DISK_CACHE)); + } + if (!use_sim) { + smokeModifier_reset(smd); + smokeModifier_reset_turbulence(smd); + update_flag |= OB_RECALC_DATA; + } + } + } + } } /* Tag object for update, so once memory critical operation is over and @@ -422,6 +455,8 @@ void BKE_object_free_ex(Object *ob, bool do_id_user) if (ob->gpd) ((ID *)ob->gpd)->us--; if (ob->defbase.first) BLI_freelistN(&ob->defbase); + if (ob->fmaps.first) + BLI_freelistN(&ob->fmaps); if (ob->pose) BKE_pose_free_ex(ob->pose, do_id_user); if (ob->mpath) @@ -456,6 +491,8 @@ void BKE_object_free_ex(Object *ob, bool do_id_user) free_path(ob->curve_cache->path); MEM_freeN(ob->curve_cache); } + + BKE_object_dupli_cache_free(ob); } void BKE_object_free(Object *ob) @@ -474,6 +511,15 @@ static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Objec } } +static void unlink_object__unlinkCacheModifierLinks(void *userData, CacheLibrary *UNUSED(cachelib), CacheModifier *UNUSED(md), ID **idpoin) +{ + Object *unlinkOb = userData; + + if (*idpoin == (ID *)unlinkOb) { + *idpoin = NULL; + } +} + void BKE_object_unlink(Object *ob) { Main *bmain = G.main; @@ -495,6 +541,7 @@ void BKE_object_unlink(Object *ob) ARegion *ar; RegionView3D *rv3d; LodLevel *lod; + CacheLibrary *cachelib; int a, found; unlink_controllers(&ob->controllers); @@ -682,6 +729,10 @@ void BKE_object_unlink(Object *ob) lod->source = NULL; } + /* dupli cache is cleared entirely if the object in question is duplified to keep it simple */ + if (BKE_object_dupli_cache_contains(obt, ob)) + BKE_object_dupli_cache_clear(obt); + obt = obt->id.next; } @@ -844,6 +895,15 @@ void BKE_object_unlink(Object *ob) } camera = camera->id.next; } + + /* cache libraries */ + for (cachelib = bmain->cache_library.first; cachelib; cachelib = cachelib->id.next) { + CacheModifier *md; + + for (md = cachelib->modifiers.first; md; md = md->next) { + BKE_cache_modifier_foreachIDLink(cachelib, md, unlink_object__unlinkCacheModifierLinks, ob); + } + } } /* actual check for internal data, not context or flags */ @@ -1311,6 +1371,7 @@ ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys) psysn->pathcache = NULL; psysn->childcache = NULL; psysn->edit = NULL; + psysn->hairedit = NULL; psysn->pdd = NULL; psysn->effectors = NULL; psysn->tree = NULL; @@ -1322,13 +1383,8 @@ ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys) psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches, false); - /* XXX - from reading existing code this seems correct but intended usage of - * pointcache should /w cloth should be added in 'ParticleSystem' - campbell */ - if (psysn->clmd) { - psysn->clmd->point_cache = psysn->pointcache; - } - id_us_plus((ID *)psysn->part); + id_us_plus((ID *)psysn->key); return psysn; } @@ -1512,6 +1568,7 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches) BKE_pose_rebuild(obn, obn->data); } defgroup_copy_list(&obn->defbase, &ob->defbase); + fmap_copy_list(&obn->fmaps, &ob->fmaps); BKE_constraints_copy(&obn->constraints, &ob->constraints, true); obn->mode = OB_MODE_OBJECT; @@ -1521,6 +1578,7 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches) id_us_plus((ID *)obn->data); id_us_plus((ID *)obn->gpd); id_lib_extern((ID *)obn->dup_group); + id_lib_extern((ID *)obn->cache_library); for (a = 0; a < obn->totcol; a++) id_us_plus((ID *)obn->mat[a]); @@ -1552,6 +1610,8 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches) /* Copy runtime surve data. */ obn->curve_cache = NULL; + obn->dup_cache = NULL; + if (ob->id.lib) { BKE_id_lib_local_paths(bmain, ob->id.lib, &obn->id); } @@ -1583,13 +1643,16 @@ static void extern_local_object(Object *ob) id_lib_extern((ID *)ob->data); id_lib_extern((ID *)ob->dup_group); + id_lib_extern((ID *)ob->cache_library); id_lib_extern((ID *)ob->poselib); id_lib_extern((ID *)ob->gpd); extern_local_matarar(ob->mat, ob->totcol); - for (psys = ob->particlesystem.first; psys; psys = psys->next) + for (psys = ob->particlesystem.first; psys; psys = psys->next) { id_lib_extern((ID *)psys->part); + id_lib_extern((ID *)psys->key); + } modifiers_foreachIDLink(ob, extern_local_object__modifiersForeachIDLink, NULL); } @@ -2838,7 +2901,15 @@ bool BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_m /* pass */ } else { - BoundBox *bb = BKE_object_boundbox_get(dob->ob); + BoundBox *bb = NULL; + if (ob->dup_cache) { + DupliObjectData *dob_data = BKE_dupli_cache_find_data(ob->dup_cache, dob->ob); + if (dob_data && dob_data->dm) { + bb = &dob_data->bb; + } + } + if (!bb) + bb = BKE_object_boundbox_get(dob->ob); if (bb) { int i; |