[Bf-blender-cvs] [420ea44] fracture_modifier: particle system: allow changing vgroups over time, suppress emission on empty assigned density vgroups

Martin Felke noreply at git.blender.org
Thu Dec 22 00:38:29 CET 2016


Commit: 420ea4423e213cff26139fc7f4672f012ac5bf06
Author: Martin Felke
Date:   Thu Dec 22 00:31:42 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rB420ea4423e213cff26139fc7f4672f012ac5bf06

particle system: allow changing vgroups over time, suppress emission on empty assigned density vgroups

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

M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/particle_distribute.c
M	source/blender/blenkernel/intern/particle_system.c

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

diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index b3e3968..700bafc 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -423,7 +423,7 @@ void psys_particle_on_dm(struct DerivedMesh *dm_final, int from, int index, int
                          float orco[3], float ornor[3]);
 
 /* particle_system.c */
-void distribute_particles(struct ParticleSimulationData *sim, int from);
+int distribute_particles(struct ParticleSimulationData *sim, int from);
 void initialize_particle(struct ParticleSimulationData *sim, struct ParticleData *pa);
 void psys_calc_dmcache(struct Object *ob, struct DerivedMesh *dm_final, struct DerivedMesh *dm_deformed, struct ParticleSystem *psys);
 int psys_particle_dm_face_lookup(struct DerivedMesh *dm_final, struct DerivedMesh *dm_deformed, int findex, const float fw[4], struct LinkNode **poly_nodes);
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c
index 44cf5b1..3bcac8c 100644
--- a/source/blender/blenkernel/intern/particle_distribute.c
+++ b/source/blender/blenkernel/intern/particle_distribute.c
@@ -1163,7 +1163,7 @@ static void psys_task_init_distribute(ParticleTask *task, ParticleSimulationData
 	task->rng = BLI_rng_new(seed);
 }
 
-static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
+static int distribute_particles_on_dm(ParticleSimulationData *sim, int from)
 {
 	TaskScheduler *task_scheduler;
 	TaskPool *task_pool;
@@ -1174,7 +1174,7 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
 	
 	/* create a task pool for distribution tasks */
 	if (!psys_thread_context_init_distribute(&ctx, sim, from))
-		return;
+		return 0;
 	
 	task_scheduler = BLI_task_scheduler_get();
 	task_pool = BLI_task_pool_create(task_scheduler, &ctx);
@@ -1202,6 +1202,8 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
 	psys_tasks_free(tasks, numtasks);
 	
 	psys_thread_context_free(&ctx);
+
+	return 1;
 }
 
 /* ready for future use, to emit particles without geometry */
@@ -1212,14 +1214,15 @@ static void distribute_particles_on_shape(ParticleSimulationData *sim, int UNUSE
 	fprintf(stderr,"Shape emission not yet possible!\n");
 }
 
-void distribute_particles(ParticleSimulationData *sim, int from)
+int distribute_particles(ParticleSimulationData *sim, int from)
 {
 	PARTICLE_PSMD;
 	int distr_error=0;
+	int ret = 0;
 
 	if (psmd) {
 		if (psmd->dm_final)
-			distribute_particles_on_dm(sim, from);
+			ret = distribute_particles_on_dm(sim, from);
 		else
 			distr_error=1;
 	}
@@ -1231,6 +1234,8 @@ void distribute_particles(ParticleSimulationData *sim, int from)
 
 		fprintf(stderr,"Particle distribution error!\n");
 	}
+
+	return ret;
 }
 
 /* ======== Simplify ======== */
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index efaf1f9..6bc99a0 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -3859,7 +3859,9 @@ static int emit_particles(ParticleSimulationData *sim, PTCacheID *pid, float UNU
 	if (totpart != oldtotpart)
 		realloc_particles(sim, totpart);
 
-	return totpart - oldtotpart;
+	//always allow redistribution of particles !
+	//return totpart - oldtotpart;
+	return 1;
 }
 
 /* Calculates the next state for all particles of the system
@@ -3876,7 +3878,7 @@ 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;
+	int startframe = 0, endframe = 100, oldtotpart = 0, emitcount = 0;
 
 	/* cache shouldn't be used for hair or "continue physics" */
 	if (part->type != PART_HAIR) {
@@ -3903,11 +3905,21 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
 
 /* 1. emit particles and redo particles if needed */
 	oldtotpart = psys->totpart;
-	if (emit_particles(sim, pid, cfra) || psys->recalc & PSYS_RECALC_RESET) {
-		distribute_particles(sim, part->from);
-		initialize_all_particles(sim);
-		/* reset only just created particles (on startframe all particles are recreated) */
-		reset_all_particles(sim, 0.0, cfra, oldtotpart);
+	emitcount = emit_particles(sim, pid, cfra);
+	if (emitcount || psys->recalc & PSYS_RECALC_RESET) {
+		if (distribute_particles(sim, part->from)) {
+			initialize_all_particles(sim);
+			/* reset only just created particles (on startframe all particles are recreated) */
+			reset_all_particles(sim, 0.0, cfra, oldtotpart);
+		}
+		else {
+			//throw away...
+			int i;
+			for (i = 0; i < sim->psys->totpart; i++)
+			{
+				sim->psys->particles[i].flag |= PARS_UNEXIST;
+			}
+		}
 		free_unexisting_particles(sim);
 
 		if (psys->fluid_springs) {
@@ -3920,7 +3932,9 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
 		/* flag for possible explode modifiers after this system */
 		sim->psmd->flag |= eParticleSystemFlag_Pars;
 
-		BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_AFTER, cfra);
+		if (psys->recalc & PSYS_RECALC_RESET) {
+			BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_AFTER, cfra);
+		}
 	}
 
 /* 2. try to read from the cache */
@@ -4265,8 +4279,18 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys, cons
 
 					if (emit_particles(&sim, NULL, cfra) || (psys->recalc & PSYS_RECALC_RESET)) {
 						free_keyed_keys(psys);
-						distribute_particles(&sim, part->from);
-						initialize_all_particles(&sim);
+						if (distribute_particles(&sim, part->from)) {
+							initialize_all_particles(&sim);
+						}
+						else {
+							//throw away...
+							int i;
+							for (i = 0; i < sim.psys->totpart; i++)
+							{
+								sim.psys->particles[i].flag |= PARS_UNEXIST;
+							}
+						}
+
 						free_unexisting = true;
 
 						/* flag for possible explode modifiers after this system */




More information about the Bf-blender-cvs mailing list