[Bf-blender-cvs] [0d6ddd2] hair_system: Apply gravity in the new hair solver setup.

Lukas Tönne noreply at git.blender.org
Sun Oct 5 14:57:04 CEST 2014


Commit: 0d6ddd2acfbe579c0b1e08e5e1f3df708fb1cf19
Author: Lukas Tönne
Date:   Sat Oct 4 14:10:48 2014 +0200
Branches: hair_system
https://developer.blender.org/rB0d6ddd2acfbe579c0b1e08e5e1f3df708fb1cf19

Apply gravity in the new hair solver setup.

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

M	release/scripts/startup/bl_ui/properties_physics_hair.py
M	source/blender/blenkernel/intern/object.c
M	source/blender/makesrna/intern/rna_hair.c
M	source/blender/physics/BPH_mass_spring.h
M	source/blender/physics/intern/BPH_mass_spring.cpp

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_hair.py b/release/scripts/startup/bl_ui/properties_physics_hair.py
index 763c489..39d50bf 100644
--- a/release/scripts/startup/bl_ui/properties_physics_hair.py
+++ b/release/scripts/startup/bl_ui/properties_physics_hair.py
@@ -72,6 +72,19 @@ class PHYSICS_PT_hair_simulation(PhysicButtonsPanel, Panel):
         col.prop(params, "stretch_damping")
         col.prop(params, "bend_damping")
 
+class PHYSICS_PT_hair_field_weights(PhysicButtonsPanel, Panel):
+    bl_label = "Field Weights"
+    bl_options = {'DEFAULT_CLOSED'}
+    COMPAT_ENGINES = {'BLENDER_RENDER'}
+
+    def draw(self, context):
+        layout = self.layout
+        md = context.hair
+        hsys = md.hair_system
+        params = hsys.params
+
+        effector_weights_ui(self, context, params.effector_weights, 'HAIR')
+
 
 class PHYSICS_PT_hair_collision(PhysicButtonsPanel, Panel):
     bl_label = "Hair Collision"
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index be1f7e6..8c1f024 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -3235,7 +3235,7 @@ void BKE_object_sim_post_step(Scene *scene, Object *ob, float UNUSED(ctime))
 		if (md->type == eModifierType_Hair) {
 			HairModifierData *hmd = (HairModifierData*) md;
 			
-			BPH_hair_solver_free_effectors(hmd->solver_data);
+			BPH_hair_solver_clear_externals(hmd->solver_data);
 			
 			BPH_hair_solver_apply_positions(hmd->solver_data, scene, ob, hmd->hairsys);
 		}
diff --git a/source/blender/makesrna/intern/rna_hair.c b/source/blender/makesrna/intern/rna_hair.c
index abb5813..d731d0e 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -268,6 +268,11 @@ static void rna_def_hair_params(BlenderRNA *brna)
 	RNA_def_property_float_default(prop, 0.0f);
 	RNA_def_property_ui_text(prop, "Drag", "Air drag factor");
 
+	prop = RNA_def_property(srna, "effector_weights", PROP_POINTER, PROP_NONE);
+	RNA_def_property_struct_type(prop, "EffectorWeights");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Effector Weights", "");
+
 	prop = RNA_def_property(srna, "friction", PROP_FLOAT, PROP_FACTOR);
 	RNA_def_property_float_sdna(prop, NULL, "friction");
 	RNA_def_property_range(prop, 0.0f, FLT_MAX);
diff --git a/source/blender/physics/BPH_mass_spring.h b/source/blender/physics/BPH_mass_spring.h
index aa2676f..c5bf0c2 100644
--- a/source/blender/physics/BPH_mass_spring.h
+++ b/source/blender/physics/BPH_mass_spring.h
@@ -62,7 +62,7 @@ struct HairSolverData *BPH_hair_solver_create(struct Object *ob, struct HairSyst
 void BPH_hair_solver_free(struct HairSolverData *data);
 
 void BPH_hair_solver_set_externals(struct HairSolverData *data, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, struct EffectorWeights *effector_weights);
-void BPH_hair_solver_free_effectors(struct HairSolverData *data);
+void BPH_hair_solver_clear_externals(struct HairSolverData *data);
 
 void BPH_hair_solver_set_positions(struct HairSolverData *data, struct Scene *scene, struct Object *ob, struct HairSystem *hsys);
 void BPH_hair_solve(struct HairSolverData *data, struct HairParams *params, float time, float timestep, struct SimDebugData *debug_data);
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 3487aa9..645878a 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -742,10 +742,13 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
 	return 1;
 }
 
-/* ======== Cloth Solver ======== */
+/* ======== Hair Solver ======== */
 
 struct HairSolverData {
-	Implicit_Data *id;
+	Implicit_Data *id; /* internal solver data */
+	
+	/* externals (updated for every step) */
+	float gravity[3];
 	ListBase *effectors;
 };
 
@@ -780,6 +783,16 @@ HairSolverData *BPH_hair_solver_create(Object *UNUSED(ob), HairSystem *hsys)
 	hair_solver_count(hsys, &totverts, &totsprings);
 	data->id = BPH_mass_spring_solver_create(totverts, totsprings);
 	
+	int ktot = 0;
+	HairCurve *curve = hsys->curves;
+	for (int i = 0; i < hsys->totcurves; ++i, ++curve) {
+		HairPoint *point = curve->points;
+		for (int k = 0; k < curve->totpoints; ++k, ++ktot, ++point) {
+			/* XXX is individual hair point mass needed? */
+			BPH_mass_spring_set_vertex_mass(data->id, ktot, 1.0f);
+		}
+	}
+	
 	return data;
 }
 
@@ -795,9 +808,14 @@ void BPH_hair_solver_free(HairSolverData *data)
 void BPH_hair_solver_set_externals(HairSolverData *data, Scene *scene, Object *ob, DerivedMesh *dm, EffectorWeights *effector_weights)
 {
 	data->effectors = pdInitEffectors(scene, ob, NULL, effector_weights, true);
+	
+	if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY)
+		copy_v3_v3(data->gravity, scene->physics_settings.gravity);
+	else
+		zero_v3(data->gravity);
 }
 
-void BPH_hair_solver_free_effectors(HairSolverData *data)
+void BPH_hair_solver_clear_externals(HairSolverData *data)
 {
 	pdEndEffectors(&data->effectors);
 }
@@ -834,6 +852,71 @@ void BPH_hair_solver_set_positions(HairSolverData *data, Scene *scene, Object *o
 	}
 }
 
+static void hair_calc_force(HairSolverData *data, HairParams *params, float time, SimDebugData *debug_data)
+{
+	/* Collect forces and derivatives:  F, dFdX, dFdV */
+//	Cloth *cloth = clmd->clothObject;
+//	Implicit_Data *data = cloth->implicit;
+//	unsigned int i	= 0;
+//	MFace 		*mfaces 	= cloth->mfaces;
+//	unsigned int numverts = cloth->numverts;
+	
+#ifdef CLOTH_FORCE_GRAVITY
+	/* global acceleration (gravitation) */
+	float gravity[3];
+//	mul_v3_v3fl(gravity, data->gravity, 0.001f * params->effector_weights->global_gravity);
+	mul_v3_v3fl(gravity, data->gravity, params->effector_weights->global_gravity);
+	BPH_mass_spring_force_gravity(data->id, gravity);
+#endif
+
+#if 0
+	cloth_calc_volume_force(clmd);
+
+#ifdef CLOTH_FORCE_DRAG
+	float drag = params->drag;
+	BPH_mass_spring_force_drag(data->id, drag);
+#endif
+	
+	/* handle external forces like wind */
+	if (effectors) {
+		/* cache per-vertex forces to avoid redundant calculation */
+		float (*winvec)[3] = (float (*)[3])MEM_callocN(sizeof(float) * 3 * numverts, "effector forces");
+		for (i = 0; i < cloth->numverts; i++) {
+			float x[3], v[3];
+			EffectedPoint epoint;
+			
+			BPH_mass_spring_get_motion_state(data, i, x, v);
+			pd_point_from_loc(clmd->scene, x, v, i, &epoint);
+			pdDoEffectors(effectors, NULL, clmd->sim_parms->effector_weights, &epoint, winvec[i], NULL);
+		}
+		
+		for (i = 0; i < cloth->numfaces; i++) {
+			MFace *mf = &mfaces[i];
+			BPH_mass_spring_force_face_wind(data, mf->v1, mf->v2, mf->v3, mf->v4, winvec);
+		}
+
+		/* Hair has only edges */
+		if (cloth->numfaces == 0) {
+			for (LinkNode *link = cloth->springs; link; link = link->next) {
+				ClothSpring *spring = (ClothSpring *)link->link;
+				if (spring->type == CLOTH_SPRING_TYPE_STRUCTURAL)
+					BPH_mass_spring_force_edge_wind(data, spring->ij, spring->kl, winvec);
+			}
+		}
+
+		MEM_freeN(winvec);
+	}
+	
+	// calculate spring forces
+	for (LinkNode *link = cloth->springs; link; link = link->next) {
+		ClothSpring *spring = (ClothSpring *)link->link;
+		// only handle active springs
+		if (!(spring->flags & CLOTH_SPRING_FLAG_DEACTIVATE))
+			cloth_calc_spring_force(clmd, spring, time);
+	}
+#endif
+}
+
 void BPH_hair_solve(struct HairSolverData *data, HairParams *params, float time, float timestep, SimDebugData *debug_data)
 {
 	float dt = timestep / (float)params->substeps;
@@ -841,9 +924,9 @@ void BPH_hair_solve(struct HairSolverData *data, HairParams *params, float time,
 	ColliderContacts *contacts = NULL;
 	int totcolliders = 0;
 	
-//	BPH_mass_spring_solver_debug_data(id, clmd->debug_data);
+	BPH_mass_spring_solver_debug_data(data->id, debug_data);
 	
-//	BKE_sim_debug_data_clear_category(clmd->debug_data, "collision");
+	BKE_sim_debug_data_clear_category(debug_data, "collision");
 	
 //	if (!clmd->solver_result)
 //		clmd->solver_result = (ClothSolverResult *)MEM_callocN(sizeof(ClothSolverResult), "cloth solver result");
@@ -883,7 +966,7 @@ void BPH_hair_solve(struct HairSolverData *data, HairParams *params, float time,
 #endif
 		
 		// calculate forces
-//		cloth_calc_force(clmd, frame, effectors, step);
+		hair_calc_force(data, params, time, debug_data);
 		
 		// calculate new velocity and position
 		BPH_mass_spring_solve(data->id, dt, &result);
@@ -912,7 +995,7 @@ void BPH_hair_solve(struct HairSolverData *data, HairParams *params, float time,
 		}
 	}
 	
-//	BPH_mass_spring_solver_debug_data(id, NULL);
+	BPH_mass_spring_solver_debug_data(data->id, NULL);
 }
 
 void BPH_hair_solver_apply_positions(HairSolverData *data, Scene *scene, Object *ob, HairSystem *hsys)




More information about the Bf-blender-cvs mailing list