Commit: 4814836120e50cce4a23e037a9bbb6a1e53de890
Author: Pablo Dobarro
Date:   Tue Aug 18 13:27:58 2020 +0200
Branches: master
https://developer.blender.org/rB4814836120e50cce4a23e037a9bbb6a1e53de890

Sculpt: Option to limit the forces axis in the Cloth Filter

This uses the same concept of the Mesh Filter but for applying the cloth
filter forces, so now it can be limited to a specific axis.

Reviewed By: sergey

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

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

M       release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M       source/blender/editors/sculpt_paint/sculpt_cloth.c
M       source/blender/editors/sculpt_paint/sculpt_intern.h

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

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py 
b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 666a0d70970..361619eb5dd 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1286,6 +1286,8 @@ class _defs_sculpt:
             props = tool.operator_properties("sculpt.cloth_filter")
             layout.prop(props, "type", expand=False)
             layout.prop(props, "strength")
+            row = layout.row(align=True)
+            row.prop(props, "force_axis")
             layout.prop(props, "cloth_mass")
             layout.prop(props, "cloth_damping")
             layout.prop(props, "use_face_sets")
diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c 
b/source/blender/editors/sculpt_paint/sculpt_cloth.c
index bdc7d7520ea..080124d2445 100644
--- a/source/blender/editors/sculpt_paint/sculpt_cloth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c
@@ -1060,6 +1060,19 @@ static EnumPropertyItem prop_cloth_filter_type[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+typedef enum eClothFilterForceAxis {
+  CLOTH_FILTER_FORCE_X = 1 << 0,
+  CLOTH_FILTER_FORCE_Y = 1 << 1,
+  CLOTH_FILTER_FORCE_Z = 1 << 2,
+} eClothFilterForceAxis;
+
+static EnumPropertyItem prop_cloth_filter_force_axis_items[] = {
+    {CLOTH_FILTER_FORCE_X, "X", 0, "X", "Apply force in the X axis"},
+    {CLOTH_FILTER_FORCE_Y, "Y", 0, "Y", "Apply force in the Y axis"},
+    {CLOTH_FILTER_FORCE_Z, "Z", 0, "Z", "Apply force in the Z axis"},
+    {0, NULL, 0, NULL, NULL},
+};
+
 static void cloth_filter_apply_forces_task_cb(void *__restrict userdata,
                                               const int i,
                                               const TaskParallelTLS 
*__restrict UNUSED(tls))
@@ -1114,6 +1127,12 @@ static void cloth_filter_apply_forces_task_cb(void 
*__restrict userdata,
         break;
     }
 
+    for (int axis = 0; axis < 3; axis++) {
+      if (!ss->filter_cache->enabled_force_axis[axis]) {
+        force[axis] = 0.0f;
+      }
+    }
+
     add_v3_v3(force, sculpt_gravity);
 
     cloth_brush_apply_force_to_vertex(ss, cloth_sim, force, vd.index);
@@ -1229,6 +1248,11 @@ static int sculpt_cloth_filter_invoke(bContext *C, 
wmOperator *op, const wmEvent
     ss->filter_cache->active_face_set = SCULPT_FACE_SET_NONE;
   }
 
+  const int force_axis = RNA_enum_get(op->ptr, "force_axis");
+  ss->filter_cache->enabled_force_axis[0] = force_axis & CLOTH_FILTER_FORCE_X;
+  ss->filter_cache->enabled_force_axis[1] = force_axis & CLOTH_FILTER_FORCE_Y;
+  ss->filter_cache->enabled_force_axis[2] = force_axis & CLOTH_FILTER_FORCE_Z;
+
   WM_event_add_modal_handler(C, op);
   return OPERATOR_RUNNING_MODAL;
 }
@@ -1256,6 +1280,12 @@ void SCULPT_OT_cloth_filter(struct wmOperatorType *ot)
                "Operation that is going to be applied to the mesh");
   RNA_def_float(
       ot->srna, "strength", 1.0f, -10.0f, 10.0f, "Strength", "Filter 
Strength", -10.0f, 10.0f);
+  RNA_def_enum_flag(ot->srna,
+                    "force_axis",
+                    prop_cloth_filter_force_axis_items,
+                    CLOTH_FILTER_FORCE_X | CLOTH_FILTER_FORCE_Y | 
CLOTH_FILTER_FORCE_Z,
+                    "Force axis",
+                    "Apply the force in the selected axis");
   RNA_def_float(ot->srna,
                 "cloth_mass",
                 1.0f,
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h 
b/source/blender/editors/sculpt_paint/sculpt_intern.h
index f233a9085e2..14928ba933a 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -946,6 +946,7 @@ typedef struct StrokeCache {
 
 typedef struct FilterCache {
   bool enabled_axis[3];
+  bool enabled_force_axis[3];
   int random_seed;
 
   /* Used for alternating between filter operations in filters that need to 
apply different ones to

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to