[Bf-blender-cvs] [3083e3fd26c] sculpt-dev: Sculpt: experimental bending constraints for cloth brush.

Joseph Eagar noreply at git.blender.org
Mon Oct 11 00:38:30 CEST 2021


Commit: 3083e3fd26c8aecfa1bd0d04f31d85977af35c79
Author: Joseph Eagar
Date:   Sun Oct 10 14:37:26 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rB3083e3fd26c8aecfa1bd0d04f31d85977af35c79

Sculpt: experimental bending constraints for cloth
        brush.

See "bending" checkmark in the cloth settings.

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/brush_channel_define.h
M	source/blender/blenkernel/intern/brush_engine.c
M	source/blender/blenkernel/intern/brush_engine_presets.c
M	source/blender/blenloader/intern/versioning_300.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.c
M	source/blender/editors/sculpt_paint/sculpt_expand.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_smooth.c

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 6329ce4bae6..33cf5fbf462 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -23,6 +23,14 @@ from bpy.types import Menu, Panel
 
 classes = []
 
+builtin_channel_categories = ["Cloth Tool",
+    "Color",
+    "Clay",
+    "Pose Tool",
+    "Basic",
+    "Smoothing",
+    "Stroke",
+    "Automasking"]
 
 class DynamicBrushCategoryPanel(Panel):
     bl_space_type = 'VIEW_3D'
@@ -184,6 +192,11 @@ classes.append(CLASSNAME)
 
         exec(code)
 
+#pre create category panels in correct order
+for cat in builtin_channel_categories:
+    DynamicPaintPanelGen.ensureCategory(cat, cat, parent="VIEW3D_PT_tools_brush_settings_channels", prefix="VIEW3D_PT_brush_category_")
+    DynamicPaintPanelGen.ensureCategory(cat, cat,  prefix="VIEW3D_PT_brush_category_edit_",
+                                parent="VIEW3D_PT_tools_brush_settings_channels_preview")
 
 channel_name_map = {
     "size": "radius",
@@ -194,7 +207,8 @@ channel_name_map = {
     "boundary_smooth_factor": "boundary_smooth",
     "autosmooth_fset_slide": "fset_slide",
     "topology_rake_factor": "topology_rake",
-    "use_locked_size": "radius_unit"
+    "use_locked_size": "radius_unit",
+    "use_cloth_collision" : "cloth_use_collision"
 }
 expand_channels = {"direction", "radius_unit", "automasking"}
 
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 456d845613c..97f52d70779 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -302,43 +302,73 @@ typedef enum eSculptClothConstraintType {
   SCULPT_CLOTH_CONSTRAINT_PIN = 3,
 } eSculptClothConstraintType;
 
-typedef struct SculptClothLengthConstraint {
-  /* Elements that are affected by the constraint. */
-  /* Element a should always be a mesh vertex with the index stored in elem_index_a as it is always
-   * deformed. Element b could be another vertex of the same mesh or any other position (arbitrary
-   * point, position for a previous state). In that case, elem_index_a and elem_index_b should be
-   * the same to avoid affecting two different vertices when solving the constraints.
-   * *elem_position points to the position which is owned by the element. */
-  int elem_index_a;
-  float *elem_position_a;
+typedef struct SculptClothConstraint {
+  signed char ctype, thread_nr;
 
-  int elem_index_b;
-  float *elem_position_b;
+  /* Index in #SculptClothSimulation.node_state of the node from where this constraint was
+   * created. This constraints will only be used by the solver if the state is active. */
+  short node;
 
-  float length;
   float strength;
 
-  /* Index in #SculptClothSimulation.node_state of the node from where this constraint was created.
-   * This constraints will only be used by the solver if the state is active. */
-  int node;
-  int thread_nr;
+  /* Elements that are affected by the constraint. */
+  /* Element a should always be a mesh vertex
+   * with the index stored in elem_index_a as
+   * it is \
+   * always deformed. Element b could be
+   * another vertex of the same mesh or any
+   * other position \
+   * (arbitrary point, position for a previous
+   * state). In that case, elem_index_a and \
+   * elem_index_b should be the same to avoid
+   * affecting two different vertices when
+   * solving the \
+   * constraints. *elem_position points to the
+   * position which is owned by the element. */
+
+  struct {
+    int index;
+    float *co;
+  } elems[];
+} SculptClothConstraint;
+
+#define MAKE_CONSTRAINT_STRUCT(totelem) \
+  signed char ctype, thread_nr; \
+  short node; \
+  float strength; \
+  struct { \
+    int index; \
+    float *position; \
+  } elems[totelem]
+
+typedef struct SculptClothLengthConstraint {
+  MAKE_CONSTRAINT_STRUCT(2);
 
+  float length;
   eSculptClothConstraintType type;
 } SculptClothLengthConstraint;
 
-typedef struct SculptClothTaskData {
-  SculptClothLengthConstraint **length_constraints;
-  int tot_length_constraints;
-} SculptClothTaskData;
+typedef struct SculptClothBendConstraint {
+  MAKE_CONSTRAINT_STRUCT(4);
+
+  float rest_angle, stiffness;
+} SculptClothBendConstraint;
+
+struct SculptClothTaskData;
 
 typedef struct SculptClothSimulation {
-  SculptClothLengthConstraint *length_constraints;
-  int tot_length_constraints;
+  SculptClothConstraint *constraints[2];
+  int tot_constraints[2];
+  int capacity_constraints[2];
+
   struct EdgeSet *created_length_constraints;
-  int capacity_length_constraints;
+  struct EdgeSet *created_bend_constraints;
   float *length_constraint_tweak;
 
-  SculptClothTaskData *constraint_tasks;
+  SculptClothBendConstraint *bend_constraints;
+  int tot_bend_constraints, capacity_bend_constraints;
+
+  struct SculptClothTaskData *constraint_tasks;
 
   /* final task always run in main thread, after all the others
    * have completed
@@ -380,6 +410,9 @@ typedef struct SculptClothSimulation {
   int cd_pers_co;
   int cd_pers_no;
   int cd_pers_disp;
+
+  bool use_bending;
+  float bend_stiffness;
 } SculptClothSimulation;
 
 typedef struct SculptVertexInfo {
diff --git a/source/blender/blenkernel/intern/brush_channel_define.h b/source/blender/blenkernel/intern/brush_channel_define.h
index 1011fccedfe..c46d149db25 100644
--- a/source/blender/blenkernel/intern/brush_channel_define.h
+++ b/source/blender/blenkernel/intern/brush_channel_define.h
@@ -403,7 +403,9 @@ MAKE_BOOL(cloth_use_collision,  "Enable Collision", "Collide with objects during
 MAKE_BOOL(use_frontface, "Use Front-Face", "Brush only affects vertexes that face the viewer", false)
 MAKE_BOOL(cloth_pin_simulation_boundary, "Pin Simulation Boundary",
       "Lock the position of the vertices in the simulation falloff area to avoid artifacts and "
-      "create a softer transition with unaffected areas", false)
+      "create a softer transition with unaffected areas", true)
+MAKE_BOOL(cloth_solve_bending, "Bending", "Solve for bending", false)
+MAKE_FLOAT(cloth_bending_stiffness, "Bending Stiffness", "", 0.5f, 0.0f, 1.0f)
 
 MAKE_FLOAT(boundary_offset, "Boundary Origin Offset",
                            "Offset of the boundary origin in relation to the brush radius", 0.05f, 0.0f, 10.0f)
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index 3075e3a9758..ec0b6f305f2 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -1586,8 +1586,8 @@ void BKE_builtin_commandlist_create(Brush *brush,
   float cloth_radius_mul = 1.0f;
 
   if (is_cloth && (ch = BRUSHSET_LOOKUP(chset, cloth_sim_limit))) {
-    autosmooth_scale *= ch->fvalue;
-    cloth_radius_mul = ch->fvalue;
+    cloth_radius_mul += ch->fvalue;
+    autosmooth_scale *= cloth_radius_mul;
   }
 
   float autosmooth_spacing;
diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index 19ec44abb85..4f27042a751 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -329,6 +329,8 @@ static bool check_builtin_init()
   SETCAT(cloth_constraint_softbody_strength, "Cloth Tool");
   SETCAT(cloth_use_collision, "Cloth Tool");
   SETCAT(cloth_pin_simulation_boundary, "Cloth Tool");
+  SETCAT(cloth_solve_bending, "Cloth Tool");
+  SETCAT(cloth_bending_stiffness, "Cloth Tool");
 
   SETCAT(pose_offset, "Pose Tool");
   SETCAT(pose_smooth_iterations, "Pose Tool");
@@ -1151,6 +1153,8 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
       ADDCH(slide_deform_type);
       break;
     case SCULPT_TOOL_CLOTH:
+      ADDCH(cloth_solve_bending);
+      ADDCH(cloth_bending_stiffness);
       ADDCH(cloth_mass);
       ADDCH(cloth_damping);
       ADDCH(cloth_sim_limit);
@@ -1161,6 +1165,7 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
       ADDCH(cloth_deform_type);
       ADDCH(cloth_use_collision);
       ADDCH(cloth_pin_simulation_boundary);
+      ADDCH(cloth_constraint_softbody_strength);
 
       break;
     case SCULPT_TOOL_SNAKE_HOOK:
@@ -1408,6 +1413,10 @@ void BKE_brush_channelset_ui_init(Brush *brush, int tool)
       SHOWCTX(height);
       break;
     case SCULPT_TOOL_CLOTH:
+      SHOWWRK(spacing);
+      SHOWCTX(spacing);
+      SHOWWRK(cloth_solve_bending);
+      SHOWWRK(cloth_bending_stiffness);
       SHOWWRK(cloth_deform_type);
       SHOWWRK(cloth_force_falloff_type);
       SHOWWRK(cloth_simulation_area_type);
@@ -1711,6 +1720,7 @@ void BKE_brush_builtin_create(Brush *brush, int tool)
       GETCH(dyntopo_disabled)->ivalue = true;
       break;
     case SCULPT_TOOL_CLOTH:
+      BRUSHSET_SET_BOOL(chset, cloth_pin_simulation_boundary, true);
       BRUSHSET_SET_BOOL(chset, use_space_attenuation, false);
       GETCH(radius)->mappings[BRUSH_MAPPING_PRESSURE].flag &= ~BRUSH_MAPPING_ENABLED;
       GETCH(strength)->mappings[BRUSH_MAPPING_PRESSURE].flag &= ~BRUSH_MAPPING_ENABLED;
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 781c17b3a4f..939a9cb26af 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -1836,6 +1836,14 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
       }
     }
   }
+
+  if (!MAIN_VERSION_ATLEAST(bmain, 300, 36)) {
+    LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
+      if (brush->channels && brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
+        BKE_brush_channelset_ui_init(brush, brush->sculpt_tool);
+      }
+    }
+  }
   /**
    * Versioning code until next subversion bump goes here.
    *
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 41793243d9c..62b97f6a49e 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -36,6 +36,7 @@
 #include "BLI_listbase.h"
 #include "BLI_math.h"
 #include "BLI_math_color_bl

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list