[Bf-blender-cvs] [0d2dfcb] hair_immediate_fixes: Solved various update issues with the hair preview factor.

Lukas Tönne noreply at git.blender.org
Fri Oct 10 10:32:13 CEST 2014


Commit: 0d2dfcb2124e666eb746cf4769073cf172ee69dd
Author: Lukas Tönne
Date:   Thu Oct 9 12:14:36 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rB0d2dfcb2124e666eb746cf4769073cf172ee69dd

Solved various update issues with the hair preview factor.

This is still terribly messy, especially because every change of the
particle system has to be piped through the dummy cloth modifier somehow.
The automatic caching system also tends to get in the way a lot; after
changing the preview factor one basically always has to start at frame 1
currently because the cloth modifier has to be reconstructed and forgets
about all caching.

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

M	source/blender/blenkernel/BKE_cloth.h
M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/cloth.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_system.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/makesdna/DNA_particle_types.h
M	source/blender/makesrna/intern/rna_particle.c

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

diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 9a0f7ce..f09bf03 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -254,25 +254,5 @@ void cloth_parallel_transport_hair_frame(float mat[3][3], const float dir_old[3]
 
 ////////////////////////////////////////////////
 
-
-/* This enum provides the IDs for our solvers. */
-// only one available in the moment
-typedef enum {
-	CM_IMPLICIT = 0,
-} CM_SOLVER_ID;
-
-
-/* This structure defines how to call the solver.
- */
-typedef struct {
-	const char		*name;
-	CM_SOLVER_ID	id;
-	int ( *init ) (struct Object *ob, struct ClothModifierData *clmd );
-	int ( *solver ) (struct Object *ob, float framenr, struct ClothModifierData *clmd, struct ListBase *effectors );
-	void ( *free ) (struct ClothModifierData *clmd );
-}
-CM_SOLVER_DEF;
-
-
 #endif
 
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index f698be2..a7fce3b 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -325,7 +325,7 @@ void BKE_particlesettings_make_local(struct ParticleSettings *part);
 
 void psys_reset(struct ParticleSystem *psys, int mode);
 
-void psys_hair_update_preview(struct ParticleSimulationData *sim);
+bool psys_hair_update_preview(struct ParticleSimulationData *sim);
 void psys_find_parents(struct ParticleSimulationData *sim);
 
 void psys_cache_paths(struct ParticleSimulationData *sim, float cfra);
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 737574d..bb91c2b 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -51,15 +51,6 @@
 
 // #include "PIL_time.h"  /* timing for debug prints */
 
-/* Our available solvers. */
-// 255 is the magic reserved number, so NEVER try to put 255 solvers in here!
-// 254 = MAX!
-static CM_SOLVER_DEF	solvers [] =
-{
-	{ "Implicit", CM_IMPLICIT, BPH_cloth_solver_init, BPH_cloth_solve, BPH_cloth_solver_free },
-	// { "Implicit C++", CM_IMPLICITCPP, implicitcpp_init, implicitcpp_solver, implicitcpp_free },
-};
-
 /* ********** cloth engine ******* */
 /* Prototypes for internal functions.
  */
@@ -419,8 +410,7 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
 	// TIMEIT_START(cloth_step)
 
 	/* call the solver. */
-	if (solvers [clmd->sim_parms->solver_type].solver)
-		ret = solvers[clmd->sim_parms->solver_type].solver(ob, framenr, clmd, effectors);
+	ret = BPH_cloth_solve(ob, framenr, clmd, effectors);
 
 	// TIMEIT_END(cloth_step)
 
@@ -615,10 +605,7 @@ void cloth_free_modifier(ClothModifierData *clmd )
 
 	
 	if ( cloth ) {
-		// If our solver provides a free function, call it
-		if ( solvers [clmd->sim_parms->solver_type].free ) {
-			solvers [clmd->sim_parms->solver_type].free ( clmd );
-		}
+		BPH_cloth_solver_free(clmd);
 
 		// Free the verts.
 		if ( cloth->verts != NULL )
@@ -684,10 +671,7 @@ void cloth_free_modifier_extern(ClothModifierData *clmd )
 		if (G.debug_value > 0)
 			printf("cloth_free_modifier_extern in\n");
 
-		// If our solver provides a free function, call it
-		if ( solvers [clmd->sim_parms->solver_type].free ) {
-			solvers [clmd->sim_parms->solver_type].free ( clmd );
-		}
+		BPH_cloth_solver_free(clmd);
 
 		// Free the verts.
 		if ( cloth->verts != NULL )
@@ -972,9 +956,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
 	}
 	
 	// init our solver
-	if ( solvers [clmd->sim_parms->solver_type].init ) {
-		solvers [clmd->sim_parms->solver_type].init ( ob, clmd );
-	}
+	BPH_cloth_solver_init(ob, clmd);
 	
 	if (!first)
 		BPH_cloth_solver_set_positions(clmd);
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 0c981e1..7a26d67 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3556,6 +3556,8 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n
 	psys->flag = PSYS_CURRENT;
 	psys->cfra = BKE_scene_frame_get_from_ctime(scene, CFRA + 1);
 
+	psys->hair_preview_factor = 100.0f;
+
 	DAG_relations_tag_update(G.main);
 	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index faee4f5..aee3a65 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -4059,25 +4059,40 @@ static MDeformVert *hair_set_pinning(MDeformVert *dvert, float weight)
 	return dvert;
 }
 
-void psys_hair_update_preview(ParticleSimulationData *sim)
+bool psys_hair_update_preview(ParticleSimulationData *sim)
 {
 	ParticleSystem *psys = sim->psys;
 	ParticleSettings *part = psys->part;
-	float factor = psys->hair_preview_factor * 0.01f;
+	const float ratio = psys->hair_preview_factor * 0.01f;
+	/* target number of simulated hairs
+	 * NOTE: this has to be reached exactly, in order to allow
+	 * comparison with the psys->hair_num_simulated value!
+	 */
+	const int num_simulated = psys->totpart * ratio;
 	
-	if (!part->type == PART_HAIR)
-		return;
+	if (!(part->type == PART_HAIR))
+		return false;
+	if (num_simulated == psys->hair_num_simulated)
+		return false;
 	
 	{ /* Random hair selection method */
 		RNG *rng = BLI_rng_new(98250 + psys->seed);
 		ParticleData *pa;
+		int cur_simulated = 0;
 		int i;
 		
 		pa = psys->particles;
 		for (i = 0; i < psys->totpart; ++i, ++pa) {
-			if (BLI_rng_get_float(rng) < factor) {
-				pa->flag |= PARS_HAIR_BLEND;
-				// XXX TODO
+			bool simulate = true;
+			/* only allow disabling if the target sim number
+			 * can be reached with the remaining hairs
+			 */
+			if (num_simulated - cur_simulated <= psys->totpart - i) {
+				simulate = BLI_rng_get_float(rng) < ratio;
+			}
+			
+			if (simulate) {
+				pa->flag &= ~PARS_HAIR_BLEND;
 				pa->blend_index[0] = -1;
 				pa->blend_index[1] = -1;
 				pa->blend_index[2] = -1;
@@ -4088,7 +4103,8 @@ void psys_hair_update_preview(ParticleSimulationData *sim)
 				pa->blend_weight[3] = 0.0f;
 			}
 			else {
-				pa->flag &= ~PARS_HAIR_BLEND;
+				pa->flag |= PARS_HAIR_BLEND;
+				// XXX TODO
 				pa->blend_index[0] = -1;
 				pa->blend_index[1] = -1;
 				pa->blend_index[2] = -1;
@@ -4102,6 +4118,9 @@ void psys_hair_update_preview(ParticleSimulationData *sim)
 		
 		BLI_rng_free(rng);
 	}
+	
+	psys->hair_num_simulated = num_simulated;
+	return true;
 }
 
 static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int totedge, DerivedMesh **r_dm, ClothHairRoot **r_roots)
@@ -4243,8 +4262,10 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
 	float (*deformedVerts)[3];
 	bool realloc_roots;
 	
-	if (psys->recalc & PSYS_RECALC_REDO) {
-		psys_hair_update_preview(sim);
+	if (psys_hair_update_preview(sim)) {
+		printf("updating cloth ...\n");
+		if (psys->clmd)
+			cloth_free_modifier(psys->clmd);
 	}
 	
 	if (!psys->clmd) {
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 000155d..a13f9f2 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -452,4 +452,13 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 			BKE_key_set_from_id(key, key->from);
 		}
 	}
+
+	if (!DNA_struct_elem_find(fd->filesdna, "ParticleSystem", "float", "hair_preview_factor")) {
+		Object *ob;
+		ParticleSystem *psys;
+		for (ob = main->object.first; ob; ob = ob->id.next) {
+			for(psys = ob->particlesystem.first; psys; psys = psys->next)
+				psys->hair_preview_factor = 100.0f;
+		}
+	}
 }
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index 6ebbea2..3a3b3a6 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -293,8 +293,8 @@ typedef struct ParticleSystem {
 	int seed, child_seed;
 	int flag, totpart, totunexist, totchild, totcached, totchildcache;
 	short recalc, target_psys, totkeyed, bakespace;
-	float hair_preview_factor;
-	int pad3;
+	float hair_preview_factor;				/* ratio of simulated to overall hairs */
+	int hair_num_simulated;					/* current number of hairs tagged for simulation (for update check) */
 
 	char bb_uvname[3][64];					/* billboard uv name, MAX_CUSTOMDATA_LAYER_NAME */
 
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index 9a19431..6c8c64b 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -3222,7 +3222,7 @@ static void rna_def_particle_system(BlenderRNA *brna)
 	RNA_def_property_range(prop, 0.0f, 100.0f);
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	RNA_def_property_ui_text(prop, "Preview Factor", "Part of hair particles to use for simulation preview");
-	RNA_def_property_update(prop, 0, "rna_Particle_redo");
+	RNA_def_property_update(prop, 0, "rna_Particle_reset");
 
 	prop = RNA_def_property(srna, "shape_keys", PROP_POINTER, PROP_NONE);
 	RNA_def_property_pointer_sdna(prop, NULL, "key");




More information about the Bf-blender-cvs mailing list