[Bf-blender-cvs] [a99781c] hair_system: Added time stepping in the modifier, like all the other simulations do.

Lukas Tönne noreply at git.blender.org
Sun Jul 27 18:12:16 CEST 2014


Commit: a99781c28e42c9329409e86dce8e87349b449e9c
Author: Lukas Tönne
Date:   Sun Jul 27 18:10:15 2014 +0200
Branches: hair_system
https://developer.blender.org/rBa99781c28e42c9329409e86dce8e87349b449e9c

Added time stepping in the modifier, like all the other simulations do.

This is pretty crappy in general, but there is no good alternative so
far. Eventually we'd like to separate simulation stepping from the
keyframe animation system, so that simulations can be advanced
independently. This would be very useful for tweaking (in a otherwise
constant environment), doing pre-roll, setting start frame in the cache
etc.

For now this modifier update approach is just a quick hack to get
visual feedback for the integrator.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/editors/physics/hair_ops.c
M	source/blender/editors/physics/physics_intern.h
M	source/blender/editors/physics/physics_ops.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/intern/MOD_hair.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index e94fd11..2e6f884 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1224,12 +1224,12 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
     def HAIR(self, layout, ob, md):
         hsys = md.hair_system
-
         col = layout.column()
-        col.prop(hsys, "smooth")
 
+        col.prop(md, "steps_per_second")
+        col.separator()
+        col.prop(hsys, "smooth")
         col.separator()
-
         col.operator("hair.copy_from_particles")
 
 
diff --git a/source/blender/editors/physics/hair_ops.c b/source/blender/editors/physics/hair_ops.c
index a41991d..35af3cd 100644
--- a/source/blender/editors/physics/hair_ops.c
+++ b/source/blender/editors/physics/hair_ops.c
@@ -50,6 +50,8 @@
 
 #include "HAIR_capi.h"
 
+#include "RNA_define.h"
+
 #include "ED_screen.h"
 
 #include "WM_types.h"
@@ -80,43 +82,6 @@ static int ED_hair_active_poll(bContext *C)
 	return ED_hair_get(C, NULL, NULL);
 }
 
-/************************ run simulation *********************/
-
-static int hair_simulate_exec(bContext *C, wmOperator *UNUSED(op))
-{
-	Object *ob;
-	HairSystem *hsys;
-	struct HAIR_Solver *solver;
-	ED_hair_get(C, &ob, &hsys);
-	
-	solver = HAIR_solver_new();
-	HAIR_solver_init(solver, hsys);
-	
-	HAIR_solver_step(solver, 0.1f);
-	
-	HAIR_solver_apply(solver, hsys);
-	
-	HAIR_solver_free(solver);
-	
-	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-	return OPERATOR_FINISHED;
-}
-
-void HAIR_OT_simulate(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->idname = "HAIR_OT_simulate";
-	ot->name = "Simulate Hair";
-	ot->description = "Evaluate a number of discrete simulation time steps in the hair system";
-
-	/* callbacks */
-	ot->exec = hair_simulate_exec;
-	ot->poll = ED_hair_active_poll;
-
-	/* flags */
-	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
 /************************ copy hair data from old particles *********************/
 
 static void hair_copy_from_particles_psys(Object *ob, HairSystem *hsys, Object *UNUSED(pob), ParticleSystem *psys)
diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h
index 073a376..4b69c56 100644
--- a/source/blender/editors/physics/physics_intern.h
+++ b/source/blender/editors/physics/physics_intern.h
@@ -125,7 +125,6 @@ void RIGIDBODY_OT_world_remove(struct wmOperatorType *ot);
 void RIGIDBODY_OT_world_export(struct wmOperatorType *ot);
 
 /* hair_ops.c */
-void HAIR_OT_simulate(struct wmOperatorType *ot);
 void HAIR_OT_copy_from_particles(struct wmOperatorType *ot);
 
 #endif /* __PHYSICS_INTERN_H__ */
diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c
index be7be06..32d27a2 100644
--- a/source/blender/editors/physics/physics_ops.c
+++ b/source/blender/editors/physics/physics_ops.c
@@ -104,7 +104,6 @@ static void operatortypes_particle(void)
 //	WM_operatortype_append(RIGIDBODY_OT_world_export);
 
 	WM_operatortype_append(HAIR_OT_copy_from_particles);
-	WM_operatortype_append(HAIR_OT_simulate);
 }
 
 static void keymap_particle(wmKeyConfig *keyconf)
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 31b11d0..1d0cb11 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;
+	float prev_cfra;
+	int steps_per_second;
 } HairModifierData;
 
 
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 0bc4ed8..9e57c5a 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -3676,6 +3676,13 @@ static void rna_def_modifier_hair(BlenderRNA *brna)
 	RNA_def_property_pointer_sdna(prop, NULL, "hairsys");
 	RNA_def_property_struct_type(prop, "HairSystem");
 	RNA_def_property_ui_text(prop, "Hair System", "");
+
+	prop = RNA_def_property(srna, "steps_per_second", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_int_sdna(prop, NULL, "steps_per_second");
+	RNA_def_property_int_default(prop, 30);
+	RNA_def_property_range(prop, 1, 512);
+	RNA_def_property_ui_text(prop, "Steps", "Steps per second");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index e300469..0533d98 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -33,6 +33,7 @@ set(INC
 	../makesdna
 	../makesrna
 	../bmesh
+	../hair
 	../render/extern/include
 	../../../intern/elbeem/extern
 	../../../intern/guardedalloc
diff --git a/source/blender/modifiers/intern/MOD_hair.c b/source/blender/modifiers/intern/MOD_hair.c
index e22896e..c8d05f5 100644
--- a/source/blender/modifiers/intern/MOD_hair.c
+++ b/source/blender/modifiers/intern/MOD_hair.c
@@ -37,9 +37,12 @@
 #include "BKE_DerivedMesh.h"
 #include "BKE_hair.h"
 #include "BKE_modifier.h"
+#include "BKE_scene.h"
 
 #include "depsgraph_private.h"
 
+#include "HAIR_capi.h"
+
 #include "MOD_util.h"
 #include "MEM_guardedalloc.h"
 
@@ -48,6 +51,9 @@ static void initData(ModifierData *md)
 	HairModifierData *hmd = (HairModifierData *) md;
 	
 	hmd->hairsys = BKE_hairsys_new();
+	hmd->prev_cfra = 1.0f; /* XXX where to get this properly ... md-> is not initialized at this point */
+	
+	hmd->steps_per_second = 30;
 }
 static void freeData(ModifierData *md)
 {
@@ -65,13 +71,40 @@ static void copyData(ModifierData *md, ModifierData *target)
 		BKE_hairsys_free(thmd->hairsys);
 	
 	thmd->hairsys = BKE_hairsys_copy(hmd->hairsys);
+	thmd->prev_cfra = hmd->prev_cfra;
 }
 
-static DerivedMesh *applyModifier(ModifierData *UNUSED(md), Object *UNUSED(ob),
+static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
                                   DerivedMesh *dm,
                                   ModifierApplyFlag UNUSED(flag))
 {
-	/*HairModifierData *hmd = (HairModifierData *) md;*/
+	HairModifierData *hmd = (HairModifierData *) md;
+	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) {
+		float prev_steps = hmd->prev_cfra / FPS * (float)hmd->steps_per_second;
+		float steps = cfra / FPS * (float)hmd->steps_per_second;
+		int num_steps = (int)steps - (int)prev_steps;
+		float dt = 1.0f / (float)hmd->steps_per_second;
+		int s;
+		
+		if (num_steps < 10000) {
+			for (s = 0; s < num_steps; ++s) {
+				solver = HAIR_solver_new();
+				HAIR_solver_init(solver, hsys);
+				
+				HAIR_solver_step(solver, dt);
+				
+				HAIR_solver_apply(solver, hsys);
+				
+				HAIR_solver_free(solver);
+			}
+		}
+	}
 	
 	return dm;
 }




More information about the Bf-blender-cvs mailing list