[Bf-blender-cvs] [faf414a] hair_system: Fix problem of hair root animation by keeping the solver around as a runtime instance.

Lukas Tönne noreply at git.blender.org
Wed Jul 30 18:03:00 CEST 2014


Commit: faf414ad9351c17c8d085f811237ae302474d893
Author: Lukas Tönne
Date:   Wed Jul 30 16:55:48 2014 +0200
Branches: hair_system
https://developer.blender.org/rBfaf414ad9351c17c8d085f811237ae302474d893

Fix problem of hair root animation by keeping the solver around as a
runtime instance.

The SolverData also functions as a short-term history for constructing
the hair root animation/deformation curves. This is necessary because
the DerivedMesh data on its own does not have interpolation intervals
nor velocity information.

It also means that we have to keep this data alive over multiple frames
in order to do root animation properly. So now the solver is created as
a runtime instance.

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/modifiers/intern/MOD_hair.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 0ddea30..417ac6f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4861,6 +4861,8 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 			hmd->hairsys = newdataadr(fd, hmd->hairsys);
 			if (hmd->hairsys)
 				direct_link_hair_system(fd, hmd->hairsys);
+
+			hmd->solver = NULL;
 		}
 	}
 }
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 1d0cb11..5a8f772 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1370,6 +1370,8 @@ typedef struct HairModifierData {
 	ModifierData modifier;
 	
 	struct HairSystem *hairsys;
+	
+	struct HAIR_Solver *solver;     /* runtime instance */
 	float prev_cfra;
 	int steps_per_second;
 } HairModifierData;
diff --git a/source/blender/modifiers/intern/MOD_hair.c b/source/blender/modifiers/intern/MOD_hair.c
index 8cd2fb0..fc60b13 100644
--- a/source/blender/modifiers/intern/MOD_hair.c
+++ b/source/blender/modifiers/intern/MOD_hair.c
@@ -60,6 +60,9 @@ static void freeData(ModifierData *md)
 {
 	HairModifierData *hmd = (HairModifierData *) md;
 	
+	if (hmd->solver)
+		HAIR_solver_free(hmd->solver);
+	
 	BKE_hairsys_free(hmd->hairsys);
 }
 
@@ -72,6 +75,8 @@ static void copyData(ModifierData *md, ModifierData *target)
 		BKE_hairsys_free(thmd->hairsys);
 	
 	thmd->hairsys = BKE_hairsys_copy(hmd->hairsys);
+	
+	thmd->solver = NULL;
 	thmd->prev_cfra = hmd->prev_cfra;
 }
 
@@ -83,7 +88,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 	HairSystem *hsys = hmd->hairsys;
 	Scene *scene = md->scene;
 	float cfra = BKE_scene_frame_get(scene), dfra;
-	struct HAIR_Solver *solver;
 	
 	dfra = cfra - hmd->prev_cfra;
 	if (dfra > 0.0f && FPS > 0.0f) {
@@ -93,22 +97,25 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 		int s;
 		
 		float dt = 1.0f / (float)hmd->steps_per_second;
-		float prev_time = floorf(prev_steps) * dt;
+		/*float prev_time = floorf(prev_steps) * dt;*/
 		float time = floorf(steps) * dt;
 		
-		solver = HAIR_solver_new(&hsys->params);
-		HAIR_solver_init(solver, scene, ob, dm, hsys, prev_time);
-		HAIR_solver_update_externals(solver, scene, ob, dm, hsys, time);
+		if (!hmd->solver) {
+			hmd->solver = HAIR_solver_new(&hsys->params);
+			HAIR_solver_init(hmd->solver, scene, ob, dm, hsys, time);
+		}
+		
+		HAIR_solver_update_externals(hmd->solver, scene, ob, dm, hsys, time);
 		
 		if (num_steps < 10000) {
+			struct HAIR_Solver *solver = hmd->solver;
 			for (s = 0; s < num_steps; ++s) {
 				HAIR_solver_step(solver, time, dt);
 				time += dt;
 			}
 		}
-		HAIR_solver_apply(solver, scene, ob, hsys);
 		
-		HAIR_solver_free(solver);
+		HAIR_solver_apply(hmd->solver, scene, ob, hsys);
 	}
 	
 	hmd->prev_cfra = cfra;




More information about the Bf-blender-cvs mailing list