diff options
author | Pablo Dobarro <pablodp606@gmail.com> | 2020-05-19 01:00:21 +0300 |
---|---|---|
committer | Pablo Dobarro <pablodp606@gmail.com> | 2020-05-26 21:48:46 +0300 |
commit | 18f33f293bfe08e87c50cad4a9d628592d7a3d15 (patch) | |
tree | 54e35573245a6dc0b8f238b5b4e66f739ead011e /source/blender/editors/sculpt_paint/sculpt_cloth.c | |
parent | 9aea7dc7c65b94aff0dda299c7269a252bf04b05 (diff) |
Fix Cloth Brush grab deformation mode
The grab mode was not correctly implemented, so the way it was working
was confusing for users.
- Grab delta was calculated in increments from the last stroke position, so it did not match the behavior of a grab brush. I refactored the grab delta calculation to make this change more explicit.
- Grab displacement was not calculated from the original coordinates
- Grab was using an incorrect strength
Grab is now setting the position of the affected vertices directly and
the constraints solve the rest of the cloth. I also tried to implement
an alternative version based on applying forces to move the vertices to
the grab position, but I think this is more controllable and the grab
falloff can be adjusted by tweaking the simulation falloff.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D7756
Diffstat (limited to 'source/blender/editors/sculpt_paint/sculpt_cloth.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_cloth.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c index b1cc6d02bbb..84d575c92d1 100644 --- a/source/blender/editors/sculpt_paint/sculpt_cloth.c +++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c @@ -212,8 +212,9 @@ static void do_cloth_brush_apply_forces_task_cb_ex(void *__restrict userdata, const float *grab_delta = data->grab_delta; float(*imat)[4] = data->mat; - const bool use_falloff_plane = brush->cloth_force_falloff_type == - BRUSH_CLOTH_FORCE_FALLOFF_PLANE; + const bool use_falloff_plane = !SCULPT_is_cloth_deform_brush(brush) && + brush->cloth_force_falloff_type == + BRUSH_CLOTH_FORCE_FALLOFF_PLANE; PBVHVertexIter vd; const float bstrength = ss->cache->bstrength; @@ -245,14 +246,29 @@ static void do_cloth_brush_apply_forces_task_cb_ex(void *__restrict userdata, gravity, ss->cache->gravity_direction, -ss->cache->radius * data->sd->gravity_factor); } + /* Original data for deform brushes. */ + SculptOrigVertData orig_data; + if (SCULPT_is_cloth_deform_brush(brush)) { + SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); + } + BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { float force[3]; const float sim_factor = cloth_brush_simulation_falloff_get( brush, ss->cache->radius, ss->cache->initial_location, cloth_sim->init_pos[vd.index]); + float current_vertex_location[3]; + if (SCULPT_is_cloth_deform_brush(brush)) { + SCULPT_orig_vert_data_update(&orig_data, &vd); + copy_v3_v3(current_vertex_location, orig_data.co); + } + else { + copy_v3_v3(current_vertex_location, vd.co); + } + /* When using the plane falloff mode the falloff is not constrained by the brush radius. */ - if (sculpt_brush_test_sq_fn(&test, vd.co) || use_falloff_plane) { + if (sculpt_brush_test_sq_fn(&test, current_vertex_location) || use_falloff_plane) { float dist = sqrtf(test.dist); @@ -263,7 +279,7 @@ static void do_cloth_brush_apply_forces_task_cb_ex(void *__restrict userdata, const float fade = sim_factor * bstrength * SCULPT_brush_strength_factor(ss, brush, - vd.co, + current_vertex_location, dist, vd.no, vd.fno, @@ -292,7 +308,10 @@ static void do_cloth_brush_apply_forces_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(force, offset, -fade); break; case BRUSH_CLOTH_DEFORM_GRAB: - mul_v3_v3fl(force, grab_delta, fade); + /* Grab writes the positions in the simulation directly without applying forces. */ + madd_v3_v3v3fl( + cloth_sim->pos[vd.index], orig_data.co, ss->cache->grab_delta_symmetry, fade); + zero_v3(force); break; case BRUSH_CLOTH_DEFORM_PINCH_POINT: if (use_falloff_plane) { |