Fix T57105: Baked Particles could not be rendered as expected

Same fix as for smoke (and is what caching proposal is AFAIK):
share cache between copied and original objects.

One thing which is still missing to be fixed is to make auto-cache
more reliable. It was already kind of broken, so don't think it
should be a stopping factor for this fix.
This commit is contained in:
Sergey Sharybin 2018-11-12 16:24:53 +01:00
parent 647a798076
commit 34058c4ff1
Notes: blender-bot 2023-02-14 08:06:33 +01:00
Referenced by issue #57105, Baked Particles could not be rendering as expected
4 changed files with 32 additions and 11 deletions

View File

@ -1065,7 +1065,14 @@ ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys, const int f
BLI_listbase_clear(&psysn->pathcachebufs);
BLI_listbase_clear(&psysn->childcachebufs);
psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches, flag);
if (flag & LIB_ID_CREATE_NO_MAIN) {
BLI_assert((psys->flag & PSYS_SHARED_CACHES) == 0);
psysn->flag |= PSYS_SHARED_CACHES;
BLI_assert(psysn->pointcache != NULL);
}
else {
psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches, flag);
}
/* XXX - from reading existing code this seems correct but intended usage of
* pointcache should /w cloth should be added in 'ParticleSystem' - campbell */

View File

@ -453,7 +453,7 @@ void BKE_particlesettings_free(ParticleSettings *part)
fluid_free_settings(part->fluid);
}
void free_hair(Object *UNUSED(ob), ParticleSystem *psys, int dynamics)
void free_hair(Object *object, ParticleSystem *psys, int dynamics)
{
PARTICLE_P;
@ -468,13 +468,10 @@ void free_hair(Object *UNUSED(ob), ParticleSystem *psys, int dynamics)
if (psys->clmd) {
if (dynamics) {
BKE_ptcache_free_list(&psys->ptcaches);
psys->pointcache = NULL;
modifier_free((ModifierData *)psys->clmd);
psys->clmd = NULL;
psys->pointcache = BKE_ptcache_add(&psys->ptcaches);
PTCacheID pid;
BKE_ptcache_id_from_particles(&pid, object, psys);
BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_ALL, 0);
}
else {
cloth_free_modifier(psys->clmd);
@ -596,7 +593,21 @@ void psys_free(Object *ob, ParticleSystem *psys)
psys_free_path_cache(psys, NULL);
free_hair(ob, psys, 1);
/* NOTE: We pass dynamics=0 to free_hair() to prevent it from doing an
* unneeded clear of the cache. But for historical reason that code path
* was only clearing cloth part of modifier data.
*
* Part of the story there is that particle evaluation is trying to not
* re-allocate thew ModifierData itself, and limits all allocations to
* the cloth part of it.
*
* Why evaluation is relying on hair_free() and in some specific code
* paths there is beyond me.
*/
free_hair(ob, psys, 0);
if (psys->clmd != NULL) {
modifier_free((ModifierData *)psys->clmd);
}
psys_free_particles(psys);
@ -624,7 +635,9 @@ void psys_free(Object *ob, ParticleSystem *psys)
psys->part = NULL;
BKE_ptcache_free_list(&psys->ptcaches);
if ((psys->flag & PSYS_SHARED_CACHES) == 0) {
BKE_ptcache_free_list(&psys->ptcaches);
}
psys->pointcache = NULL;
BLI_freelistN(&psys->targets);

View File

@ -4386,7 +4386,7 @@ void particle_system_update(struct Depsgraph *depsgraph, Scene *scene, Object *o
psys_orig->edit->psys_eval = psys;
psys_orig->edit->psmd_eval = psmd;
}
psys_orig->flag = psys->flag;
psys_orig->flag = (psys->flag & ~PSYS_SHARED_CACHES);
}
}

View File

@ -567,6 +567,7 @@ typedef enum eParticleShapeFlag {
//#define PSYS_PROTECT_CACHE 4096 /* deprecated */
#define PSYS_DISABLED 8192
#define PSYS_OB_ANIM_RESTORE 16384 /* runtime flag */
#define PSYS_SHARED_CACHES 32768
/* pars->flag */
#define PARS_UNEXIST 1