Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Dobarro <pablodp606@gmail.com>2020-07-31 02:12:06 +0300
committerPablo Dobarro <pablodp606@gmail.com>2020-08-05 00:06:14 +0300
commitbf65820782a7b67c294587fa6f670bd9c7678b51 (patch)
treefe83edfdf9ba47eec47a61e88bae8d623f1c0ea7 /source/blender/editors/sculpt_paint/sculpt_cloth.c
parent6faa765af8954948de3cec75a2261a5aa139b4e5 (diff)
Sculpt: Cloth brush Pin Simulation Boundary property
The cloth brush has a defined simulated area with a falloff. In the falloff area (the area between the dashed white circle and the exterior white circle), simulation properties change in order to fade out the simulation deformation effects towards the boundary. With some brushes and stroke types (like anchored strokes with pinching or grabbing with full strength), it is possible to apply more force than what the boundary falloff can compensate, so the simulation breaks when this happens. This option pins the falloff area with softbody constraints, This produces a much better deformation falloff and it is no longer possible to move the vertices near the simulation boundary, so the simulation won't break no matter the strength of the forces applied inside the simulated areas. This is an option as it is particularly useful for some brushes to add localized details, but for brushes that are supposed to deform the entire mesh (like the grab brush in D8424), this can add unwanted softbody constraints that affect the simulation result. Reviewed By: sergey Differential Revision: https://developer.blender.org/D8435
Diffstat (limited to 'source/blender/editors/sculpt_paint/sculpt_cloth.c')
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_cloth.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c
index 371f673625e..51b2d50e73b 100644
--- a/source/blender/editors/sculpt_paint/sculpt_cloth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c
@@ -100,6 +100,28 @@
#include <stdlib.h>
#include <string.h>
+static float cloth_brush_simulation_falloff_get(const Brush *brush,
+ const float radius,
+ const float location[3],
+ const float co[3])
+{
+ const float distance = len_v3v3(location, co);
+ const float limit = radius + (radius * brush->cloth_sim_limit);
+ const float falloff = radius + (radius * brush->cloth_sim_limit * brush->cloth_sim_falloff);
+
+ if (distance > limit) {
+ /* Outiside the limits. */
+ return 0.0f;
+ }
+ if (distance < falloff) {
+ /* Before the falloff area. */
+ return 1.0f;
+ }
+ /* Do a smoothstep transition inside the falloff area. */
+ float p = 1.0f - ((distance - falloff) / (limit - falloff));
+ return 3.0f * p * p - 2.0f * p * p * p;
+}
+
#define CLOTH_LENGTH_CONSTRAINTS_BLOCK 100000
#define CLOTH_SIMULATION_ITERATIONS 5
#define CLOTH_MAX_CONSTRAINTS_PER_VERTEX 1024
@@ -210,6 +232,9 @@ static void do_cloth_brush_build_constraints_task_cb_ex(
PBVHVertexIter vd;
+ const bool pin_simulation_boundary = ss->cache != NULL && brush != NULL &&
+ brush->flag2 & BRUSH_CLOTH_PIN_SIMULATION_BOUNDARY;
+
const bool use_persistent = brush != NULL && brush->flag & BRUSH_PERSISTENT;
/* Brush can be NULL in tools that use the solver without relying of constraints with deformation
@@ -264,30 +289,19 @@ static void do_cloth_brush_build_constraints_task_cb_ex(
const float fade = BKE_brush_curve_strength(brush, sqrtf(len_squared), ss->cache->radius);
cloth_brush_add_deformation_constraint(data->cloth_sim, vd.index, fade);
}
- }
- BKE_pbvh_vertex_iter_end;
-}
-
-static float cloth_brush_simulation_falloff_get(const Brush *brush,
- const float radius,
- const float location[3],
- const float co[3])
-{
- const float distance = len_v3v3(location, co);
- const float limit = radius + (radius * brush->cloth_sim_limit);
- const float falloff = radius + (radius * brush->cloth_sim_limit * brush->cloth_sim_falloff);
- if (distance > limit) {
- /* Outiside the limits. */
- return 0.0f;
- }
- if (distance < falloff) {
- /* Before the falloff area. */
- return 1.0f;
+ if (pin_simulation_boundary) {
+ const float sim_falloff = cloth_brush_simulation_falloff_get(
+ brush, ss->cache->initial_radius, ss->cache->location, vd.co);
+ /* Vertex is inside the area of the simulation without any falloff aplied. */
+ if (sim_falloff < 1.0f) {
+ /* Create constraints with more strength the closer the vertex is to the simulation
+ * boundary. */
+ cloth_brush_add_softbody_constraint(data->cloth_sim, vd.index, 1.0f - sim_falloff);
+ }
+ }
}
- /* Do a smoothstep transition inside the falloff area. */
- float p = 1.0f - ((distance - falloff) / (limit - falloff));
- return 3.0f * p * p - 2.0f * p * p * p;
+ BKE_pbvh_vertex_iter_end;
}
static void cloth_brush_apply_force_to_vertex(SculptSession *UNUSED(ss),