[Bf-blender-cvs] [c0f8d3c] hair_system: Expose friction and restitution of hair in the UI.
Lukas Tönne
noreply at git.blender.org
Thu Aug 7 23:36:51 CEST 2014
Commit: c0f8d3c2c7b9f15643d12c2f5bcbd7d7030d4ca0
Author: Lukas Tönne
Date: Thu Aug 7 23:36:54 2014 +0200
Branches: hair_system
https://developer.blender.org/rBc0f8d3c2c7b9f15643d12c2f5bcbd7d7030d4ca0
Expose friction and restitution of hair in the UI.
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/hair/HAIR_capi.cpp
M source/blender/hair/intern/HAIR_collision.cpp
M source/blender/hair/intern/HAIR_scene.cpp
M source/blender/hair/intern/HAIR_scene.h
M source/blender/hair/intern/HAIR_solver.h
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 1e88111..df2cc1f 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1238,6 +1238,14 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col.separator()
+ row = col.row()
+ col2 = row.column()
+ col2.prop(params, "restitution")
+ col2 = row.column()
+ col2.prop(params, "friction")
+
+ col.separator()
+
col.operator("hair.reset to rest location")
col.operator("hair.copy_from_particles")
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index d6464d7..7a6add5 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -87,7 +87,7 @@ void HAIR_solver_update_externals(struct HAIR_Solver *csolver, Scene *scene, Obj
Solver *solver = (Solver *)csolver;
SceneConverter::update_solver_data_externals(solver->data(), solver->forces(), scene, ob, dm, hsys, time);
- SceneConverter::sync_rigidbody_data(solver->data());
+ SceneConverter::sync_rigidbody_data(solver->data(), solver->params());
}
void HAIR_solver_rebuild_rigidbodyworld(struct HAIR_Solver *csolver, struct rbDynamicsWorld *world)
diff --git a/source/blender/hair/intern/HAIR_collision.cpp b/source/blender/hair/intern/HAIR_collision.cpp
index ff3c26c..3707614 100644
--- a/source/blender/hair/intern/HAIR_collision.cpp
+++ b/source/blender/hair/intern/HAIR_collision.cpp
@@ -36,17 +36,26 @@ extern "C" {
HAIR_NAMESPACE_BEGIN
-PointContactInfo::PointContactInfo(const btManifoldPoint &bt_point, int point_index) :
+PointContactInfo::PointContactInfo(const btManifoldPoint &bt_point, const btCollisionObject *ob0, const btCollisionObject *ob1, int point_index) :
point_index(point_index),
local_point_body(bt_point.m_localPointB.m_floats),
local_point_hair(bt_point.m_localPointA),
world_point_body(bt_point.m_positionWorldOnB),
world_point_hair(bt_point.m_positionWorldOnA),
world_normal_body(bt_point.m_normalWorldOnB),
- distance(bt_point.m_distance1),
- friction(bt_point.m_combinedFriction),
- restitution(bt_point.m_combinedRestitution)
+ distance(bt_point.m_distance1)
{
+ float3 lin_vel(ob1->getInterpolationLinearVelocity().m_floats);
+ float3 ang_vel(ob1->getInterpolationAngularVelocity().m_floats);
+ float3 p((ob1->getWorldTransform() * bt_point.m_localPointB).m_floats);
+
+ world_vel_body = dot_v3v3(lin_vel + cross_v3_v3(ang_vel, p), world_normal_body) * world_normal_body;
+
+ /* note: combined friction and restitution in the manifold point are not usable,
+ * have to calculate it manually here
+ */
+ friction = ob0->getFriction() * ob1->getFriction();
+ restitution = ob0->getRestitution() * ob1->getRestitution();
}
struct HairContactResultCallback : btCollisionWorld::ContactResultCallback {
@@ -61,16 +70,10 @@ struct HairContactResultCallback : btCollisionWorld::ContactResultCallback {
const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
{
if (cp.getDistance() < 0.f) {
- PointContactInfo info(cp, point_index);
-
+ const btCollisionObject *ob0 = colObj0Wrap->getCollisionObject();
const btCollisionObject *ob1 = colObj1Wrap->getCollisionObject();
- float3 lin_vel(ob1->getInterpolationLinearVelocity().m_floats);
- float3 ang_vel(ob1->getInterpolationAngularVelocity().m_floats);
- float3 p((ob1->getWorldTransform() * cp.m_localPointB).m_floats);
-
- info.world_vel_body = dot_v3v3(lin_vel + cross_v3_v3(ang_vel, p), info.world_normal_body) * info.world_normal_body;
-
+ PointContactInfo info(cp, ob0, ob1, point_index);
cache->push_back(info);
// const btVector3 &ptA = cp.getPositionWorldOnA();
diff --git a/source/blender/hair/intern/HAIR_scene.cpp b/source/blender/hair/intern/HAIR_scene.cpp
index a00dc6b..0a1cccf 100644
--- a/source/blender/hair/intern/HAIR_scene.cpp
+++ b/source/blender/hair/intern/HAIR_scene.cpp
@@ -60,6 +60,7 @@ static bool mesh_sample_eval(DerivedMesh *dm, const Transform &tfm, MSurfaceSamp
SolverData *SceneConverter::build_solver_data(Scene *scene, Object *ob, DerivedMesh *dm, HairSystem *hsys, float time)
{
+ HairParams ¶ms = hsys->params;
HairCurve *hair;
int i;
@@ -106,7 +107,7 @@ SolverData *SceneConverter::build_solver_data(Scene *scene, Object *ob, DerivedM
}
/* finalize */
- data->precompute_rest_bend(hsys->params);
+ data->precompute_rest_bend(params);
return data;
}
@@ -159,7 +160,7 @@ void SceneConverter::apply_solver_data(SolverData *data, Scene *scene, Object *o
}
}
-void SceneConverter::sync_rigidbody_data(SolverData *data)
+void SceneConverter::sync_rigidbody_data(SolverData *data, const HairParams ¶ms)
{
/* sync settings */
Curve *solver_curves = data->curves;
@@ -167,6 +168,9 @@ void SceneConverter::sync_rigidbody_data(SolverData *data)
btTransform trans;
btVector3 halfsize;
+ data->rb_ghost.ghost.setRestitution(params.restitution);
+ data->rb_ghost.ghost.setFriction(params.friction);
+
if (data->totpoints == 0) {
trans.setIdentity();
halfsize = btVector3(0.5f, 0.5f, 0.5f);
@@ -189,6 +193,9 @@ void SceneConverter::sync_rigidbody_data(SolverData *data)
co_max[2] = max_ff(co_max[2], point->cur.co.z + point->radius);
RB_ghost_set_loc_rot(&point->rb_ghost, point->cur.co.data(), unit_qt.data());
+
+ point->rb_ghost.ghost.setRestitution(params.restitution);
+ point->rb_ghost.ghost.setFriction(params.friction);
}
}
diff --git a/source/blender/hair/intern/HAIR_scene.h b/source/blender/hair/intern/HAIR_scene.h
index 741f157..3d1fec7 100644
--- a/source/blender/hair/intern/HAIR_scene.h
+++ b/source/blender/hair/intern/HAIR_scene.h
@@ -45,7 +45,7 @@ struct SceneConverter {
static void apply_solver_data(SolverData *data, Scene *scene, Object *ob, HairSystem *hsys);
- static void sync_rigidbody_data(SolverData *data);
+ static void sync_rigidbody_data(SolverData *data, const HairParams ¶ms);
};
HAIR_NAMESPACE_END
diff --git a/source/blender/hair/intern/HAIR_solver.h b/source/blender/hair/intern/HAIR_solver.h
index ad6874a..1f4c02b 100644
--- a/source/blender/hair/intern/HAIR_solver.h
+++ b/source/blender/hair/intern/HAIR_solver.h
@@ -129,7 +129,7 @@ struct SolverForces {
struct PointContactInfo {
PointContactInfo() {}
- PointContactInfo(const btManifoldPoint &bt_point, int point_index);
+ PointContactInfo(const btManifoldPoint &bt_point, const btCollisionObject *ob0, const btCollisionObject *ob1, int point_index);
int point_index;
diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h
index f6d4c71..8fa9999 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -58,6 +58,11 @@ typedef struct HairParams {
float bend_stiffness;
float bend_damping;
float bend_smoothing;
+
+ /* collision settings */
+ float restitution;
+ float friction;
+
int pad;
} HairParams;
diff --git a/source/blender/makesrna/intern/rna_hair.c b/source/blender/makesrna/intern/rna_hair.c
index 1b4edae..1f405c0 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -66,31 +66,45 @@ static void rna_def_hair_params(BlenderRNA *brna)
RNA_def_property_float_sdna(prop, NULL, "stretch_stiffness");
RNA_def_property_range(prop, 0.0f, 1.0e9f);
RNA_def_property_ui_range(prop, 0.0f, 3000.0f, 0.1, 2);
- RNA_def_property_ui_text(prop, "Stretch Stiffness", "");
+ RNA_def_property_ui_text(prop, "Stretch Stiffness", "Resistance to stretching");
prop = RNA_def_property(srna, "stretch_damping", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "stretch_damping");
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, "Stretch Damping", "");
+ RNA_def_property_ui_text(prop, "Stretch Damping", "Damping of stretch motion");
prop = RNA_def_property(srna, "bend_stiffness", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "bend_stiffness");
RNA_def_property_range(prop, 0.0f, 1.0e9f);
RNA_def_property_ui_range(prop, 0.0f, 500.0f, 0.1, 2);
- RNA_def_property_ui_text(prop, "Bend Stiffness", "");
+ RNA_def_property_ui_text(prop, "Bend Stiffness", "Resistance to bending");
prop = RNA_def_property(srna, "bend_damping", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "bend_damping");
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", "");
+ RNA_def_property_ui_text(prop, "Bend Damping", "Damping of bending motion");
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");
+
+ 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);
+ RNA_def_property_ui_range(prop, 0.0f, 1.0f, 1, 3);
+ RNA_def_property_float_default(prop, 0.5f);
+ RNA_def_property_ui_text(prop, "Friction", "Resistance of hair to sliding over objects");
+
+ prop = RNA_def_property(srna, "restitution", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "restitution");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.0f, 1.0f, 1, 3);
+ RNA_def_property_float_default(prop, 0.0f);
+ RNA_def_property_ui_text(prop, "Restitution", "Amount of energy retained after collision");
}
static void rna_def_hair_system(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list