[Bf-blender-cvs] [1d4bae85669] master: Sculpt: Cloth Filter

Pablo Dobarro noreply at git.blender.org
Mon Jun 1 22:38:19 CEST 2020


Commit: 1d4bae856690c7a4603789509a5842dd6b5f8be1
Author: Pablo Dobarro
Date:   Mon Jun 1 22:36:26 2020 +0200
Branches: master
https://developer.blender.org/rB1d4bae856690c7a4603789509a5842dd6b5f8be1

Sculpt: Cloth Filter

This tool is similar to the cloth brush, but it applies the cloth
simulation deformation to the whole mesh in an uniform way. The
simulation can be controlled using the mask to pin vertices and the face
sets to define force action areas.

It uses the same solver as the cloth brush which now no longer depends
on StrokeCache.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D7857

===================================================================

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_automasking.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.c
M	source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h

===================================================================

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 0db7b79d8c9..08e81d89c4f 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -6272,6 +6272,16 @@ def km_3d_view_tool_sculpt_mesh_filter(params):
         ]},
     )
 
+def km_3d_view_tool_sculpt_cloth_filter(params):
+    return (
+        "3D View Tool: Sculpt, Cloth Filter",
+        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
+        {"items": [
+            ("sculpt.cloth_filter", {"type": params.tool_tweak, "value": 'ANY'},
+             None)
+        ]},
+    )
+
 def km_3d_view_tool_paint_weight_sample_weight(params):
     return (
         "3D View Tool: Paint Weight, Sample Weight",
@@ -6811,6 +6821,7 @@ def generate_keymaps(params=None):
         km_3d_view_tool_sculpt_box_mask(params),
         km_3d_view_tool_sculpt_lasso_mask(params),
         km_3d_view_tool_sculpt_mesh_filter(params),
+        km_3d_view_tool_sculpt_cloth_filter(params),
         km_3d_view_tool_paint_weight_sample_weight(params),
         km_3d_view_tool_paint_weight_sample_vertex_group(params),
         km_3d_view_tool_paint_weight_gradient(params),
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 1aa5dde168b..b4c1ea5163f 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1228,6 +1228,25 @@ class _defs_sculpt:
             draw_settings=draw_settings,
         )
 
+    @ToolDef.from_fn
+    def cloth_filter():
+        def draw_settings(_context, layout, tool):
+            props = tool.operator_properties("sculpt.cloth_filter")
+            layout.prop(props, "type", expand=False)
+            layout.prop(props, "strength")
+            layout.prop(props, "cloth_mass")
+            layout.prop(props, "cloth_damping")
+            layout.prop(props, "use_face_sets")
+
+        return dict(
+            idname="builtin.cloth_filter",
+            label="Cloth Filter",
+            icon="ops.sculpt.cloth_filter",
+            widget=None,
+            keymap=(),
+            draw_settings=draw_settings,
+        )
+
 
 class _defs_vertex_paint:
 
@@ -2402,6 +2421,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
             _defs_sculpt.hide_border,
             None,
             _defs_sculpt.mesh_filter,
+            _defs_sculpt.cloth_filter,
             None,
             _defs_transform.translate,
             _defs_transform.rotate,
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 4ad6bcc5d0f..6e56135ec83 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -7898,4 +7898,5 @@ void ED_operatortypes_sculpt(void)
   WM_operatortype_append(SCULPT_OT_face_sets_change_visibility);
   WM_operatortype_append(SCULPT_OT_face_sets_randomize_colors);
   WM_operatortype_append(SCULPT_OT_face_sets_init);
+  WM_operatortype_append(SCULPT_OT_cloth_filter);
 }
diff --git a/source/blender/editors/sculpt_paint/sculpt_automasking.c b/source/blender/editors/sculpt_paint/sculpt_automasking.c
index f0f6478d3a6..bfa657147fd 100644
--- a/source/blender/editors/sculpt_paint/sculpt_automasking.c
+++ b/source/blender/editors/sculpt_paint/sculpt_automasking.c
@@ -91,7 +91,7 @@ bool SCULPT_is_automasking_enabled(const Sculpt *sd, const SculptSession *ss, co
 
 float SCULPT_automasking_factor_get(SculptSession *ss, int vert)
 {
-  if (ss->cache->automask) {
+  if (ss->cache && ss->cache->automask) {
     return ss->cache->automask[vert];
   }
   else {
diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c
index 6dac2b51645..3203282c30c 100644
--- a/source/blender/editors/sculpt_paint/sculpt_cloth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c
@@ -106,9 +106,11 @@
 #define CLOTH_MAX_CONSTRAINTS_PER_VERTEX 1024
 #define CLOTH_SIMULATION_TIME_STEP 0.01f
 
-static void cloth_brush_add_length_constraint(SculptSession *ss, const int v1, const int v2)
+static void cloth_brush_add_length_constraint(SculptSession *ss,
+                                              SculptClothSimulation *cloth_sim,
+                                              const int v1,
+                                              const int v2)
 {
-  SculptClothSimulation *cloth_sim = ss->cache->cloth_sim;
   cloth_sim->length_constraints[cloth_sim->tot_length_constraints].v1 = v1;
   cloth_sim->length_constraints[cloth_sim->tot_length_constraints].v2 = v2;
   cloth_sim->length_constraints[cloth_sim->tot_length_constraints].length = len_v3v3(
@@ -133,12 +135,11 @@ static void do_cloth_brush_build_constraints_task_cb_ex(
   SculptSession *ss = data->ob->sculpt;
 
   PBVHVertexIter vd;
-  const float radius = ss->cache->initial_radius;
-  const float limit = radius + (radius * data->brush->cloth_sim_limit);
 
   BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
   {
-    if (len_squared_v3v3(vd.co, ss->cache->initial_location) < limit * limit) {
+    if (len_squared_v3v3(vd.co, data->cloth_sim_initial_location) <
+        data->cloth_sim_radius * data->cloth_sim_radius) {
 
       SculptVertexNeighborIter ni;
       int build_indices[CLOTH_MAX_CONSTRAINTS_PER_VERTEX];
@@ -159,7 +160,8 @@ static void do_cloth_brush_build_constraints_task_cb_ex(
       for (int c_i = 0; c_i < tot_indices; c_i++) {
         for (int c_j = 0; c_j < tot_indices; c_j++) {
           if (c_i != c_j) {
-            cloth_brush_add_length_constraint(ss, build_indices[c_i], build_indices[c_j]);
+            cloth_brush_add_length_constraint(
+                ss, data->cloth_sim, build_indices[c_i], build_indices[c_j]);
           }
         }
       }
@@ -192,11 +194,11 @@ static float cloth_brush_simulation_falloff_get(const Brush *brush,
   }
 }
 
-static void cloth_brush_apply_force_to_vertex(SculptSession *ss,
+static void cloth_brush_apply_force_to_vertex(SculptSession *UNUSED(ss),
+                                              SculptClothSimulation *cloth_sim,
                                               const float force[3],
                                               const int vertex_index)
 {
-  SculptClothSimulation *cloth_sim = ss->cache->cloth_sim;
   madd_v3_v3fl(cloth_sim->acceleration[vertex_index], force, 1.0f / cloth_sim->mass);
 }
 
@@ -290,7 +292,6 @@ static void do_cloth_brush_apply_forces_task_cb_ex(void *__restrict userdata,
 
       float brush_disp[3];
       float normal[3];
-
       if (vd.no) {
         normal_short_to_float_v3(normal, vd.no);
       }
@@ -348,13 +349,15 @@ static void do_cloth_brush_apply_forces_task_cb_ex(void *__restrict userdata,
 
       madd_v3_v3fl(force, gravity, fade);
 
-      cloth_brush_apply_force_to_vertex(ss, force, vd.index);
+      cloth_brush_apply_force_to_vertex(ss, ss->cache->cloth_sim, force, vd.index);
     }
   }
   BKE_pbvh_vertex_iter_end;
 }
 
-static SculptClothSimulation *cloth_brush_simulation_create(SculptSession *ss, Brush *brush)
+static SculptClothSimulation *cloth_brush_simulation_create(SculptSession *ss,
+                                                            const float cloth_mass,
+                                                            const float cloth_damping)
 {
   const int totverts = SCULPT_vertex_count_get(ss);
   SculptClothSimulation *cloth_sim;
@@ -373,8 +376,8 @@ static SculptClothSimulation *cloth_brush_simulation_create(SculptSession *ss, B
   cloth_sim->length_constraint_tweak = MEM_callocN(sizeof(float) * totverts,
                                                    "cloth sim length tweak");
 
-  cloth_sim->mass = brush->cloth_mass;
-  cloth_sim->damping = brush->cloth_damping;
+  cloth_sim->mass = cloth_mass;
+  cloth_sim->damping = cloth_damping;
 
   return cloth_sim;
 }
@@ -386,12 +389,16 @@ static void do_cloth_brush_solve_simulation_task_cb_ex(
   SculptSession *ss = data->ob->sculpt;
   const Brush *brush = data->brush;
   PBVHVertexIter vd;
-  SculptClothSimulation *cloth_sim = ss->cache->cloth_sim;
+  SculptClothSimulation *cloth_sim = data->cloth_sim;
   const float time_step = data->cloth_time_step;
   BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
   {
-    const float sim_factor = cloth_brush_simulation_falloff_get(
-        brush, ss->cache->radius, ss->cache->initial_location, cloth_sim->init_pos[vd.index]);
+    const float sim_factor = ss->cache ? cloth_brush_simulation_falloff_get(
+                                             brush,
+                                             ss->cache->radius,
+                                             ss->cache->initial_location,
+                                             cloth_sim->init_pos[vd.index]) :
+                                         1.0f;
     if (sim_factor > 0.0f) {
       int i = vd.index;
       float temp[3];
@@ -412,7 +419,7 @@ static void do_cloth_brush_solve_simulation_task_cb_ex(
 
       copy_v3_fl(cloth_sim->acceleration[i], 0.0f);
 
-      copy_v3_v3(vd.co, ss->cache->cloth_sim->pos[vd.index]);
+      copy_v3_v3(vd.co, cloth_sim->pos[vd.index]);
       if (vd.mvert) {
         vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
       }
@@ -424,7 +431,10 @@ static void do_cloth_brush_solve_simulation_task_cb_ex(
 static void cloth_brush_build_nodes_constraints(Sculpt *sd,
                                                 Object *ob,
                                                 PBVHNode **nodes,
-                                                int totnode)
+                                                int totnode,
+                                                SculptClothSimulation *cloth_sim,
+                                                float initial_location[3],
+                                                const float radius)
 {
   Brush *brush = BKE_paint_brush(&sd->paint);
 
@@ -440,6 +450,9 @@ static void cloth_brush_build_nodes_constraints(Sculpt *sd,
      

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list