[Bf-blender-cvs] [34058c4ff16] blender2.8: Fix T57105: Baked Particles could not be rendered as expected

Sergey Sharybin noreply at git.blender.org
Tue Nov 13 11:41:20 CET 2018


Commit: 34058c4ff1684b4d2e4d8619e2a7b690d9286140
Author: Sergey Sharybin
Date:   Mon Nov 12 16:24:53 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB34058c4ff1684b4d2e4d8619e2a7b690d9286140

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.

===================================================================

M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_system.c
M	source/blender/makesdna/DNA_particle_types.h

===================================================================

diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index bd14de144da..d36a5838630 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -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 */
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index cec27b8f187..360dcd7b26a 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index c363d9f29c2..39298130130 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -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);
 		}
 	}
 
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index 037e9b9c499..ebccb36a671 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -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



More information about the Bf-blender-cvs mailing list