[Bf-blender-cvs] [d99620f] alembic: Optional feature "Goal Deflect" to disable goal forces when hitting a deflector object.

Lukas Tönne noreply at git.blender.org
Wed May 13 16:49:42 CEST 2015


Commit: d99620f296a4612cf187031e4fc934ae84a41387
Author: Lukas Tönne
Date:   Wed May 13 16:49:12 2015 +0200
Branches: alembic
https://developer.blender.org/rBd99620f296a4612cf187031e4fc934ae84a41387

Optional feature "Goal Deflect" to disable goal forces when hitting a
deflector object.

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

M	release/scripts/startup/bl_ui/properties_object.py
M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/makesdna/DNA_cache_library_types.h
M	source/blender/makesrna/intern/rna_cache_library.c
M	source/blender/physics/intern/BPH_mass_spring.cpp

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

diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index fbcde95..f3f960d 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -531,7 +531,9 @@ class OBJECT_PT_cache_library(ObjectButtonsPanel, Panel):
         row = col.row(align=True)
         row.prop(params, "goal_stiffness")
         row.prop(params, "goal_damping")
+        row = col.row(align=True)
         row.prop(params, "use_goal_stiffness_curve")
+        row.prop(params, "use_goal_deflect")
         if params.use_goal_stiffness_curve:
             sub = col.column()
             sub.template_curve_mapping(params, "goal_stiffness_curve")
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index c7634fb..900d541 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -228,6 +228,8 @@ int BKE_cache_effectors_get(struct CacheEffector *effectors, int max, struct Cac
 void BKE_cache_effectors_free(struct CacheEffector *effectors, int tot);
 void BKE_cache_effector_velocity_update(struct CacheLibrary *cachelib, struct DupliCache *dupcache, float obmat[4][4], float frame);
 int BKE_cache_effectors_eval(struct CacheEffector *effectors, int tot, struct CacheEffectorPoint *point, struct CacheEffectorResult *result);
+int BKE_cache_effectors_eval_ex(struct CacheEffector *effectors, int tot, struct CacheEffectorPoint *point, struct CacheEffectorResult *result,
+                                bool (*filter)(void *, struct CacheEffector *), void *filter_data);
 
 /* ========================================================================= */
 
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index e1e8426..5ef771e 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -805,21 +805,25 @@ void BKE_cache_effector_velocity_update(CacheLibrary *cachelib, DupliCache *dupc
 	}
 }
 
-static float cache_effector_falloff(const CacheEffector *eff, float distance)
+static bool cache_effector_falloff(const CacheEffector *eff, float distance, float *r_factor)
 {
 	float mindist = eff->mindist;
 	float maxdist = eff->maxdist;
 	float falloff = eff->falloff;
 	float range = maxdist - mindist;
 	
+	if (r_factor) *r_factor = 0.0f;
+	
 	if (range <= 0.0f)
-		return 0.0f;
+		return false;
 	
+	if (distance > eff->maxdist)
+		return false;
 	CLAMP_MIN(distance, eff->mindist);
-	CLAMP_MAX(distance, eff->maxdist);
 	CLAMP_MIN(falloff, 0.0f);
 	
-	return powf(1.0f - (distance - mindist) / range, falloff);
+	if (r_factor) *r_factor = powf(1.0f - (distance - mindist) / range, falloff);
+	return true;
 }
 
 typedef struct CacheEffectorTessfaceData {
@@ -926,8 +930,9 @@ static bool cache_effector_deflect(CacheEffector *eff, CacheEffectorInstance *in
 	
 	if (!cache_effector_find_nearest(eff, inst, point, vec, NULL, &dist, &inside, NULL))
 		return false;
+	if (!cache_effector_falloff(eff, dist, &falloff))
+		return false;
 	
-	falloff = cache_effector_falloff(eff, dist);
 	mul_v3_v3fl(result->f, vec, eff->strength * falloff);
 	if (inside)
 		negate_v3(result->f);
@@ -942,8 +947,9 @@ static bool cache_effector_drag(CacheEffector *eff, CacheEffectorInstance *inst,
 	
 	if (!cache_effector_find_nearest(eff, inst, point, vec, NULL, &dist, NULL, &facedata))
 		return false;
+	if (!cache_effector_falloff(eff, dist, &falloff))
+		return false;
 	
-	falloff = cache_effector_falloff(eff, dist);
 	cache_effector_velocity(eff, inst, &facedata, vel);
 	
 	/* relative velocity */
@@ -964,7 +970,8 @@ static void cache_effector_result_add(CacheEffectorResult *result, const CacheEf
 	add_v3_v3(result->f, other->f);
 }
 
-int BKE_cache_effectors_eval(CacheEffector *effectors, int tot, CacheEffectorPoint *point, CacheEffectorResult *result)
+int BKE_cache_effectors_eval_ex(CacheEffector *effectors, int tot, CacheEffectorPoint *point, CacheEffectorResult *result,
+                                bool (*filter)(void *, CacheEffector *), void *filter_data)
 {
 	CacheEffector *eff;
 	int i, applied = 0;
@@ -979,6 +986,9 @@ int BKE_cache_effectors_eval(CacheEffector *effectors, int tot, CacheEffectorPoi
 			CacheEffectorResult inst_result;
 			cache_effector_result_init(&inst_result);
 			
+			if (filter && !filter(filter_data, eff))
+				continue;
+			
 			switch (type) {
 				case eCacheEffector_Type_Deflect:
 					if (cache_effector_deflect(eff, inst, point, &inst_result)) {
@@ -999,6 +1009,11 @@ int BKE_cache_effectors_eval(CacheEffector *effectors, int tot, CacheEffectorPoi
 	return applied;
 }
 
+int BKE_cache_effectors_eval(CacheEffector *effectors, int tot, CacheEffectorPoint *point, CacheEffectorResult *result)
+{
+	return BKE_cache_effectors_eval_ex(effectors, tot, point, result, NULL, NULL);
+}
+
 /* ========================================================================= */
 
 bool BKE_cache_modifier_find_object(DupliCache *dupcache, Object *ob, DupliObjectData **r_data)
diff --git a/source/blender/makesdna/DNA_cache_library_types.h b/source/blender/makesdna/DNA_cache_library_types.h
index 158a35a..9a16cee 100644
--- a/source/blender/makesdna/DNA_cache_library_types.h
+++ b/source/blender/makesdna/DNA_cache_library_types.h
@@ -170,7 +170,7 @@ typedef enum eCacheModifier_Type {
 	eCacheModifierType_HairSimulation               = 1,
 	eCacheModifierType_ForceField                   = 2,
 	eCacheModifierType_ShrinkWrap                   = 3,
-	eCacheModifierType_StrandsKey                      = 4,
+	eCacheModifierType_StrandsKey                   = 4,
 	
 	NUM_CACHE_MODIFIER_TYPES
 } eCacheModifier_Type;
@@ -195,6 +195,7 @@ typedef struct HairSimParams {
 typedef enum eHairSimParams_Flag {
 	eHairSimParams_Flag_UseGoalStiffnessCurve        = (1 << 0),
 	eHairSimParams_Flag_UseBendStiffnessCurve        = (1 << 1),
+	eHairSimParams_Flag_UseGoalDeflect               = (1 << 2),
 } eHairSimParams_Flag;
 
 typedef struct HairSimCacheModifier {
diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c
index 9db14aa..74bd4f2 100644
--- a/source/blender/makesrna/intern/rna_cache_library.c
+++ b/source/blender/makesrna/intern/rna_cache_library.c
@@ -459,6 +459,11 @@ static void rna_def_hair_sim_params(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Goal Stiffness Curve", "Stiffness of goal springs along the strand curves");
 	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
 	
+	prop = RNA_def_property(srna, "use_goal_deflect", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", eHairSimParams_Flag_UseGoalDeflect);
+	RNA_def_property_ui_text(prop, "Use Goal Deflect", "Disable goal springs inside deflectors, to avoid unstable deformations");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
 	prop = RNA_def_property(srna, "use_bend_stiffness_curve", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", eHairSimParams_Flag_UseBendStiffnessCurve);
 	RNA_def_property_ui_text(prop, "Use Bend Stiffness Curve", "Use a curve to define bend resistance along the strand");
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 7b3c55a..f8d4fa6 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -1413,8 +1413,24 @@ static float strands_goal_stiffness(Strands *UNUSED(strands), HairSimParams *par
 	return params->goal_stiffness * weight;
 }
 
+static bool strands_test_deflector(StrandsVertex *UNUSED(vertex), int index, CacheEffector *cache_effectors, int tot_cache_effectors,
+                                   Implicit_Data *data, StrandIterator *it_strand)
+{
+	CacheEffectorPoint point;
+	point.index = index;
+	BPH_mass_spring_get_motion_state(data, index, point.x, point.v);
+	
+	CacheEffectorResult result;
+	if (BKE_cache_effectors_eval(cache_effectors, tot_cache_effectors, &point, &result) > 0) {
+		return true;
+	}
+	
+	return false;
+}
+
 /* goal forces pull vertices toward their rest position */
-static void strands_calc_vertex_goal_forces(Strands *strands, float UNUSED(space[4][4]), HairSimParams *params, Implicit_Data *data, StrandIterator *it_strand)
+static void strands_calc_vertex_goal_forces(Strands *strands, float space[4][4], HairSimParams *params, CacheEffector *cache_effectors, int tot_cache_effectors,
+                                            Implicit_Data *data, StrandIterator *it_strand)
 {
 	const int goalstart = strands->totverts;
 	StrandEdgeIterator it_edge;
@@ -1430,6 +1446,11 @@ static void strands_calc_vertex_goal_forces(Strands *strands, float UNUSED(space
 		int numroots = it_strand->index + 1; /* roots don't have goal verts, skip this many */
 		int goalj = goalstart + vj - numroots;
 		
+		if (params->flag & eHairSimParams_Flag_UseGoalDeflect) {
+			if (strands_test_deflector(it_edge.vertex1, vj, cache_effectors, tot_cache_effectors, data, it_strand))
+				continue;
+		}
+		
 		float restlen = len_v3v3(it_edge.vertex1->co, it_edge.vertex0->co);
 		t += restlen;
 		
@@ -1469,11 +1490,12 @@ static void strands_calc_vertex_goal_forces(Strands *strands, float UNUSED(space
 }
 
 /* calculates internal forces for a single strand curve */
-static void strands_calc_curve_forces(Strands *strands, float space[4][4], HairSimParams *params, Implicit_Data *data, StrandIterator *it_strand)
+static void strands_calc_curve_forces(Strands *strands, float space[4][4], HairSimParams *params, CacheEffector *cache_effectors, int tot_cache_effectors,
+                                      Implicit_Data *data, StrandIterator *it_strand)
 {
 	strands_calc_curve_stretch_forces(strands, space, params, data, it_strand);
 	strands_calc_curve_bending_forces(strands, space, params, data, it_strand);
-	strands_calc_vertex_goal_forces(strands, space, params, data, it_strand);
+	strands_calc_vertex_goal_forces(strands, space, params, cache_effectors, tot_cache_effectors, data, it_strand);
 }
 
 /* Collect force

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list