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:
-rw-r--r--release/scripts/startup/bl_ui/properties_paint_common.py1
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_cloth.c58
-rw-r--r--source/blender/makesdna/DNA_brush_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_brush.c9
4 files changed, 47 insertions, 22 deletions
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 8cadad7e0d7..62c5bac91f8 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -656,6 +656,7 @@ def brush_settings(layout, context, brush, popover=False):
layout.separator()
layout.prop(brush, "cloth_sim_limit")
layout.prop(brush, "cloth_sim_falloff")
+ layout.prop(brush, "use_cloth_pin_simulation_boundary")
layout.separator()
layout.prop(brush, "cloth_deform_type")
layout.prop(brush, "cloth_force_falloff_type")
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),
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 152c5e25910..000b61fb39b 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -726,6 +726,7 @@ typedef enum eBrushFlags2 {
BRUSH_MULTIPLANE_SCRAPE_PLANES_PREVIEW = (1 << 1),
BRUSH_POSE_IK_ANCHORED = (1 << 2),
BRUSH_USE_CONNECTED_ONLY = (1 << 3),
+ BRUSH_CLOTH_PIN_SIMULATION_BOUNDARY = (1 << 4),
} eBrushFlags2;
typedef enum {
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index f28222d0947..efc712544ca 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -2793,6 +2793,15 @@ static void rna_def_brush(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Connected Only", "Affect only topologically connected elements");
RNA_def_property_update(prop, 0, "rna_Brush_update");
+ prop = RNA_def_property(srna, "use_cloth_pin_simulation_boundary", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag2", BRUSH_CLOTH_PIN_SIMULATION_BOUNDARY);
+ RNA_def_property_ui_text(
+ prop,
+ "Pin Simulation Boundary",
+ "Lock the position of the vertices in the simulation falloff area to avoid artifacts and "
+ "create a softer transitionwith with unnafected areas");
+ RNA_def_property_update(prop, 0, "rna_Brush_update");
+
prop = RNA_def_property(srna, "invert_to_scrape_fill", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_INVERT_TO_SCRAPE_FILL);
RNA_def_property_ui_text(prop,