[Bf-blender-cvs] [76e114180d5] fracture_modifier: fix attempt for particle systems supporting dynamicly changing vertexgroups

Martin Felke noreply at git.blender.org
Sun Jun 4 19:35:51 CEST 2017


Commit: 76e114180d5538a8a6a67be227e33a669f848241
Author: Martin Felke
Date:   Sun Jun 4 19:35:26 2017 +0200
Branches: fracture_modifier
https://developer.blender.org/rB76e114180d5538a8a6a67be227e33a669f848241

fix attempt for particle systems supporting dynamicly changing vertexgroups

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

M	source/blender/blenkernel/intern/particle_system.c

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

diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index e4b97004167..0d13dafae6a 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -3865,7 +3865,7 @@ static int emit_particles(ParticleSimulationData *sim, PTCacheID *pid, float UNU
 		return totpart - oldtotpart;
 	}
 
-	return 1;
+	return totpart;
 }
 
 /* Calculates the next state for all particles of the system
@@ -3882,7 +3882,8 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
 	PTCacheID ptcacheid, *pid = NULL;
 	PARTICLE_P;
 	float disp, cache_cfra = cfra; /*, *vg_vel= 0, *vg_tan= 0, *vg_rot= 0, *vg_size= 0; */
-	int startframe = 0, endframe = 100, oldtotpart = 0, emitcount = 0, cache_check = 0;
+	int startframe = 0, endframe = 100, oldtotpart = 0, emitcount = 0;
+	bool suppressed = false;
 
 	/* cache shouldn't be used for hair or "continue physics" */
 	if (part->type != PART_HAIR) {
@@ -3910,28 +3911,28 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
 /* 1. emit particles and redo particles if needed */
 	oldtotpart = psys->totpart;
 	emitcount = emit_particles(sim, pid, cfra, part);
-	if (pid) {
-		cache_check = BKE_ptcache_read(pid, cache_cfra, true);
-	}
-	if ((emitcount && !ELEM(cache_check, PTCACHE_READ_EXACT, PTCACHE_READ_INTERPOLATED)) ||
-	    psys->recalc & PSYS_RECALC_RESET)
+	if (emitcount || psys->recalc & PSYS_RECALC_RESET)
 	{
 		if (distribute_particles(sim, part->from) || part->distr == PART_DISTR_GRID) {
 			initialize_all_particles(sim);
 			/* reset only just created particles (on startframe all particles are recreated) */
 			reset_all_particles(sim, 0.0, cfra, oldtotpart);
 		}
-		else {
+		else if (emitcount == oldtotpart || oldtotpart == 0){
 			//throw away...
 			int i;
+			suppressed = true;
 			for (i = 0; i < sim->psys->totpart; i++)
 			{
-				if (sim->psys->particles[i].alive == PARS_UNBORN) {
+				if (sim->psys->particles[i].state.time <= 0)
+				{
 					sim->psys->particles[i].flag |= PARS_UNEXIST;
 				}
 			}
 		}
-		free_unexisting_particles(sim);
+
+		if (!suppressed)
+			free_unexisting_particles(sim);
 
 		if (psys->fluid_springs) {
 			MEM_freeN(psys->fluid_springs);
@@ -3949,7 +3950,7 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
 	}
 
 /* 2. try to read from the cache */
-	if (pid) {
+	if (pid && !suppressed) {
 		int cache_result = BKE_ptcache_read(pid, cache_cfra, true);
 
 		if (ELEM(cache_result, PTCACHE_READ_EXACT, PTCACHE_READ_INTERPOLATED)) {
@@ -4046,6 +4047,11 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
 		end_latt_deform(psys->lattice_deform_data);
 		psys->lattice_deform_data = NULL;
 	}
+
+	if (suppressed) {
+		//need dummy cache data, so free suppressed particles later
+		free_unexisting_particles(sim);
+	}
 }
 
 /* system type has changed so set sensible defaults and clear non applicable flags */




More information about the Bf-blender-cvs mailing list