[Bf-blender-cvs] [a2827eb] hair_system: Expose the bend smoothing factor in the UI and compute the average curve segment rest length for scaling.
Lukas Tönne
noreply at git.blender.org
Thu Aug 7 12:26:22 CEST 2014
Commit: a2827eb51a8b6bdc4f2b7e54247417955fc47ab2
Author: Lukas Tönne
Date: Thu Aug 7 12:23:29 2014 +0200
Branches: hair_system
https://developer.blender.org/rBa2827eb51a8b6bdc4f2b7e54247417955fc47ab2
Expose the bend smoothing factor in the UI and compute the average
curve segment rest length for scaling.
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/hair/intern/HAIR_curve.h
M source/blender/hair/intern/HAIR_solver.cpp
M source/blender/makesrna/intern/rna_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 6c5fc6a..6c6c126 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1235,6 +1235,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col2 = row.column()
col2.prop(params, "stretch_stiffness")
col2.prop(params, "bend_stiffness")
+ col2.prop(params, "bend_smoothing")
col2 = row.column()
col2.prop(params, "stretch_damping")
col2.prop(params, "bend_damping")
diff --git a/source/blender/hair/intern/HAIR_curve.h b/source/blender/hair/intern/HAIR_curve.h
index c84d304..a954de9 100644
--- a/source/blender/hair/intern/HAIR_curve.h
+++ b/source/blender/hair/intern/HAIR_curve.h
@@ -75,6 +75,7 @@ struct Curve {
Point *points;
int totpoints;
+ float avg_rest_length;
CurveRoot root0, root1;
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index b1ebb8b..830357e 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -113,23 +113,37 @@ void SolverData::precompute_rest_bend(const HairParams ¶ms)
Point *pt = curve->points;
Point *next_pt = pt + 1;
- /* XXX calculating a rest frame ad-hoc from identity here, should use the surface normal/tangent instead! */
- float3 normal, tangent;
- normalize_v3_v3(normal, next_pt->rest_co - pt->rest_co);
- normalize_v3_v3(tangent, float3(0,1,0) - dot_v3v3(float3(0,1,0), normal) * normal);
- Frame rest_frame(normal, tangent, cross_v3_v3(normal, tangent));
+ /* calculate average rest length */
+ curve->avg_rest_length = 0.0f;
+ if (curve->totpoints > 1) {
+ for (int k = 0; k < curve->totpoints - 1; ++k)
+ curve->avg_rest_length += len_v3(curve->points[k+1].rest_co - curve->points[k].rest_co);
+ curve->avg_rest_length /= curve->totpoints;
+ }
- FrameIterator<SolverDataRestLocWalker> iter(SolverDataRestLocWalker(curve), 1.0f / curve->totpoints, params.bend_smoothing, rest_frame);
- while (iter.index() < curve->totpoints - 1) {
- pt->rest_bend = calc_bend(iter.frame(), pt->rest_co, next_pt->rest_co);
+ if (curve->totpoints == 0)
+ continue;
+ else if (curve->totpoints == 1)
+ pt->rest_bend = float3(0.0f, 0.0f, 0.0f);
+ else {
+ /* XXX calculating a rest frame ad-hoc from identity here, should use the surface normal/tangent instead! */
+ float3 normal, tangent;
+ normalize_v3_v3(normal, next_pt->rest_co - pt->rest_co);
+ normalize_v3_v3(tangent, float3(0,1,0) - dot_v3v3(float3(0,1,0), normal) * normal);
+ Frame rest_frame(normal, tangent, cross_v3_v3(normal, tangent));
+
+ FrameIterator<SolverDataRestLocWalker> iter(SolverDataRestLocWalker(curve), curve->avg_rest_length, params.bend_smoothing, rest_frame);
+ while (iter.index() < curve->totpoints - 1) {
+ pt->rest_bend = calc_bend(iter.frame(), pt->rest_co, next_pt->rest_co);
+
+ iter.next();
+ ++pt;
+ ++next_pt;
+ }
- iter.next();
- ++pt;
- ++next_pt;
+ /* last point has no defined rest bending vector */
+ pt->rest_bend = float3(0.0f, 0.0f, 0.0f);
}
-
- /* last point has no defined rest bending vector */
- pt->rest_bend = float3(0.0f, 0.0f, 0.0f);
}
}
@@ -381,7 +395,7 @@ static void step(const HairParams ¶ms, const SolverForces &forces, float tim
tangent = float3(0,1,0);
}
Frame rest_frame(normal, tangent, cross_v3_v3(normal, tangent));
- FrameIterator<SolverDataLocWalker> frame_iter(SolverDataLocWalker(curve), 1.0f / numpoints, params.bend_smoothing, rest_frame);
+ FrameIterator<SolverDataLocWalker> frame_iter(SolverDataLocWalker(curve), curve->avg_rest_length, params.bend_smoothing, rest_frame);
if (k < numpoints-1) {
stretch = calc_stretch_force(params, curve, point, point+1, time);
diff --git a/source/blender/makesrna/intern/rna_hair.c b/source/blender/makesrna/intern/rna_hair.c
index b724d10..36bf111 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -83,6 +83,12 @@ static void rna_def_hair_params(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, 1.0e6f);
RNA_def_property_ui_range(prop, 0.0f, 20.0f, 0.1, 2);
RNA_def_property_ui_text(prop, "Bend Damping", "");
+
+ prop = RNA_def_property(srna, "bend_smoothing", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "bend_smoothing");
+ RNA_def_property_range(prop, 0.0f, 256.0f);
+ RNA_def_property_ui_range(prop, 0.0f, 8.0f, 0.1, 2);
+ RNA_def_property_ui_text(prop, "Bend Smoothing", "Smoothing amount to avoid rotation of hair curls");
}
static void rna_def_hair_system(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list