Commit: 7eac931b51c6fa0fc8d1f33febc5311bcdc01db3
Author: Lukas Tönne
Date: Fri Aug 8 11:52:53 2014 +0200
Branches: hair_system
https://developer.blender.org/rB7eac931b51c6fa0fc8d1f33febc5311bcdc01db3
Expose substeps for the force and damping loops in the UI.
Split the integrator loop into 2 parts, so we can actually perform the
collision response in the correct place.
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/intern/hair.c
M source/blender/hair/intern/HAIR_solver.cpp
M source/blender/makesdna/DNA_hair_types.h
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 df2cc1f..837c86a 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1227,6 +1227,14 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
params = hsys.params
col = layout.column()
+ col.separator()
+
+ row = col.row()
+ col2 = row.column()
+ col2.prop(params, "substeps_forces")
+ col2 = row.column()
+ col2.prop(params, "substeps_damping")
+
row = col.row()
col2 = row.column()
col2.prop(params, "stretch_stiffness")
diff --git a/source/blender/blenkernel/intern/hair.c
b/source/blender/blenkernel/intern/hair.c
index 5411c4b..548637b 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -44,6 +44,8 @@ HairSystem *BKE_hairsys_new(void)
{
HairSystem *hsys = MEM_callocN(sizeof(HairSystem), "hair system");
+ hsys->params.substeps_forces = 30;
+ hsys->params.substeps_damping = 10;
hsys->params.stretch_stiffness = 2000.0f;
hsys->params.stretch_damping = 10.0f;
hsys->params.bend_stiffness = 40.0f;
diff --git a/source/blender/hair/intern/HAIR_solver.cpp
b/source/blender/hair/intern/HAIR_solver.cpp
index 4349480..6f6d588 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -353,7 +353,7 @@ static void do_collision(const HairParams ¶ms, const
SolverForces &forces, f
void Solver::do_integration(float time, float timestep, const SolverTaskData
&data) const
{
- const int totsteps = 1; /* XXX TODO can have multiple integration steps
per tick for accuracy */
+ const int totsteps = m_params.substeps_forces; /* can have multiple
integration steps per tick for accuracy */
float dt = timestep / (float)totsteps;
int totcurve = data.totcurves;
@@ -369,9 +369,6 @@ void Solver::do_integration(float time, float timestep,
const SolverTaskData &da
data.points[k].force_accum = float3(0.0f, 0.0f, 0.0f);
}
- do_collision(m_params, m_forces, time, dt, data, contacts);
-
- int ktot = 0; /* global point counter over all curves */
Curve *curve = data.curves;
for (int i = 0; i < totcurve; ++i, ++curve) {
int numpoints = curve->totpoints;
@@ -397,35 +394,62 @@ void Solver::do_integration(float time, float timestep,
const SolverTaskData &da
do_external_forces(m_params, m_forces, time,
dt, point, point_next, frame_iter.frame(), extern_force);
do_damping(m_params, m_forces, time, dt, point,
point_next, frame_iter.frame(), damping, damping_next);
- point->next.co = root_co;
- point->next.vel = root_vel;
-
frame_iter.next();
acc_prev = intern_force_next + damping_next;
++k;
- ++ktot;
++point;
}
/* Integrate free points */
- for (; k < numpoints; ++k, ++ktot, ++point) {
+ for (; k < numpoints; ++k, ++point) {
Point *point_next = k < numpoints-1 ? point+1 :
NULL;
do_internal_forces(m_params, m_forces, time,
dt, point, point_next, frame_iter.frame(), intern_force, intern_force_next);
do_external_forces(m_params, m_forces, time,
dt, point, point_next, frame_iter.frame(), extern_force);
do_damping(m_params, m_forces, time, dt, point,
point_next, frame_iter.frame(), damping, damping_next);
- float3 acc = intern_force + extern_force +
damping + acc_prev + point->force_accum;
- point->next.vel = point->cur.vel + acc *
timestep;
-
- float3 vel = point->next.vel;
- point->next.co = point->cur.co + vel * timestep;
+ point->force_accum = point->force_accum +
intern_force + extern_force + damping + acc_prev;
frame_iter.next();
acc_prev = intern_force_next + damping_next;
}
+
}
- time += dt;
+ do_collision(m_params, m_forces, time, dt, data, contacts);
+
+ /* integrate */
+ {
+ Curve *curve = data.curves;
+ for (int i = 0; i < totcurve; ++i, ++curve) {
+ int numpoints = curve->totpoints;
+
+ /* note: roots are evaluated at the end of the
timestep: time + timestep
+ * so the hair points align perfectly with them
+ */
+ float3 root_co, root_vel, normal, tangent;
+ calc_root_animation(m_data->t0, m_data->t1,
time + timestep, curve, root_co, root_vel, normal, tangent);
+
+ /* Root point animation */
+ Point *point = curve->points;
+ int k = 0;
+ if (numpoints > 0) {
+ point->next.co = root_co;
+ point->next.vel = root_vel;
+
+ ++k;
+ ++point;
+ }
+
+ /* Integrate free points */
+ for (; k < numpoints; ++k, ++point) {
+ /* semi-implicit Euler step */
+ point->next.vel = point->cur.vel +
point->force_accum * timestep;
+ point->next.co = point->cur.co +
point->next.vel * timestep;
+ }
+ }
+
+ time += dt;
+ }
}
}
diff --git a/source/blender/makesdna/DNA_hair_types.h
b/source/blender/makesdna/DNA_hair_types.h
index 8fa9999..b4b210d 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -53,6 +53,9 @@ typedef struct HairCurve {
} HairCurve;
typedef struct HairParams {
+ int substeps_forces;
+ int substeps_damping;
+
float stretch_stiffness;
float stretch_damping;
float bend_stiffness;
diff --git a/source/blender/makesrna/intern/rna_hair.c
b/source/blender/makesrna/intern/rna_hair.c
index 1f405c0..90b9184 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -62,6 +62,20 @@ static void rna_def_hair_params(BlenderRNA *brna)
srna = RNA_def_struct(brna, "HairParams", NULL);
RNA_def_struct_ui_text(srna, "Hair Parameters", "Hair simulation
parameters");
+ prop = RNA_def_property(srna, "substeps_forces", PROP_INT,
PROP_UNSIGNED);
+ RNA_def_property_int_sdna(prop, NULL, "substeps_forces");
+ RNA_def_property_range(prop, 1, 1000);
+ RNA_def_property_ui_range(prop, 1, 120, 1, 1);
+ RNA_def_property_int_default(prop, 30);
+ RNA_def_property_ui_text(prop, "Substeps Forces", "Substeps for force
integration");
+
+ prop = RNA_def_property(srna, "substeps_damping", PROP_INT,
PROP_UNSIGNED);
+ RNA_def_property_int_sdna(prop, NULL, "substeps_damping");
+ RNA_def_property_range(prop, 1, 100);
+ RNA_def_property_ui_range(prop, 1, 30, 1, 1);
+ RNA_def_property_int_default(prop, 10);
+ RNA_def_property_ui_text(prop, "Substeps Damping", "Substeps for
damping force integration (on top of force substeps)");
+
prop = RNA_def_property(srna, "stretch_stiffness", PROP_FLOAT,
PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "stretch_stiffness");
RNA_def_property_range(prop, 0.0f, 1.0e9f);
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs