[Bf-blender-cvs] [268e18e9a3a] sculpt-dev: Sculpt-dev: More improvements to detail enhance

Joseph Eagar noreply at git.blender.org
Tue Dec 14 19:19:46 CET 2021


Commit: 268e18e9a3a01131f2459459b536742d0f9a4c2e
Author: Joseph Eagar
Date:   Sun Dec 12 05:03:24 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rB268e18e9a3a01131f2459459b536742d0f9a4c2e

Sculpt-dev: More improvements to detail enhance

* Detail enhance is now it's own dedicated toolslot.
  This makes it possible to use autosmooth with
  detail enhance.

  Note the behavior of the smooth brush (which
  invokes enhance when pressing control)
  is unchanged.

* Fixed a bug with temporary attribute layers being constantly
  cleared and reallocated with multires.

* Cleaned up velocity smooth code a bit.
* Pruned various dead #if blocks.
* generate_from_enum_ex in space_toolsystem.py
  now takes a special argument to combine enum
  items.  This is used to make enhance a subtool
  of smooth.

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

M	release/datafiles/blender_icons_geom.py
A	release/datafiles/icons/brush.sculpt.enhance_details.dat
M	release/scripts/startup/bl_ui/properties_paint_common.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/brush_channel_define.h
M	source/blender/blenkernel/intern/brush_engine_presets.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenlib/intern/BLI_kdopbvh.c
M	source/blender/editors/datafiles/CMakeLists.txt
M	source/blender/editors/include/UI_icons.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/editors/sculpt_paint/sculpt_smooth.c
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/datafiles/blender_icons_geom.py b/release/datafiles/blender_icons_geom.py
index 8280728c658..b2eb26bb2c6 100644
--- a/release/datafiles/blender_icons_geom.py
+++ b/release/datafiles/blender_icons_geom.py
@@ -132,7 +132,8 @@ def mesh_data_lists_from_mesh(me, material_colors):
   
     tris_data = []
     
-    white = [1, 1, 1, 1]
+    class white:
+        color = [1, 1, 1, 1]
     
     for p in me_polys:
         # Note, all faces are handled, backfacing/zero area is checked just before writing.
@@ -162,7 +163,7 @@ def mesh_data_lists_from_mesh(me, material_colors):
               c1 = color_poly[i1]
               c2 = color_poly[i2]
             else:
-              c1 = c2 = c3 = white
+              c0 = c1 = c2 = white
               
             v0 = me_verts[l0.vertex_index]
             v1 = me_verts[l1.vertex_index]
diff --git a/release/datafiles/icons/brush.sculpt.enhance_details.dat b/release/datafiles/icons/brush.sculpt.enhance_details.dat
new file mode 100644
index 00000000000..fab88c4a8c6
Binary files /dev/null and b/release/datafiles/icons/brush.sculpt.enhance_details.dat differ
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 0aa747e2dcc..ee55a2c1f7b 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -1266,6 +1266,13 @@ def brush_settings(layout, context, brush, popover=False):
         capabilities = brush.sculpt_capabilities
         sculpt_tool = brush.sculpt_tool
 
+        if sculpt_tool in ["SMOOTH", "ENHANCE_DETAILS"]:
+            UnifiedPaintPanel.channel_unified(layout,
+                context,
+                brush,
+                "enhance_detail_presteps",
+                slider=False)
+
         if advanced:
             # normal_radius_factor
             UnifiedPaintPanel.prop_unified(layout,
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 8f6596c1e52..da185b53544 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -49,19 +49,74 @@ def generate_from_enum_ex(_context, *,
         attr,
         cursor='DEFAULT',
         tooldef_keywords={},
-        exclude_filter={}):
+        exclude_filter={},
+        combine_map={}):
+    """
+    combine_map combines items, takes the form of a dict:
+
+        combine_map = {
+            "PARENT KEY" : (
+              "CHILD KEY"
+            )
+        }
+
+    """
+
+    combinekeys = {}
+    parentmap = {}
+
+    for k, v in combine_map.items():
+        combinekeys[k] = []
+
+        for child in v:
+            parentmap[child] = k
+
     tool_defs = []
+
+    #build combine key owners first
     for enum in type.bl_rna.properties[attr].enum_items_static:
         name = enum.name
         idname = enum.identifier
         if idname in exclude_filter:
             continue
-        tool_defs.append(ToolDef.from_dict(dict(idname=idname_prefix + name,
+
+        if idname in combinekeys:
+            combinekeys[idname].append(ToolDef.from_dict(dict(idname=idname_prefix + name,
                     label=name,
                     icon=icon_prefix + idname.lower(),
                     cursor=cursor,
                     data_block=idname,
                     **tooldef_keywords,)))
+
+    for enum in type.bl_rna.properties[attr].enum_items_static:
+        name = enum.name
+        idname = enum.identifier
+        if idname in exclude_filter:
+            continue
+
+        if idname in combinekeys:
+            tool_defs.append(combinekeys[idname])
+        elif idname in parentmap:
+            parentkey = parentmap[idname]
+
+            combinekeys[parentkey].append(ToolDef.from_dict(dict(idname=idname_prefix + name,
+                        label=name,
+                        icon=icon_prefix + idname.lower(),
+                        cursor=cursor,
+                        data_block=idname,
+                        **tooldef_keywords,)))
+        else:
+            tool_defs.append(ToolDef.from_dict(dict(idname=idname_prefix + name,
+                        label=name,
+                        icon=icon_prefix + idname.lower(),
+                        cursor=cursor,
+                        data_block=idname,
+                        **tooldef_keywords,)))
+
+    # finalize combined keys
+    for k, v in combinekeys.items():
+        tool_defs[tool_defs.index(v)] = tuple(v)
+
     return tuple(tool_defs)
 
 
@@ -1170,12 +1225,17 @@ class _defs_sculpt:
         #if not prefs.experimental.use_sculpt_uvsmooth:
         #    exclude_filter["UV_SMOOTH"] = True
 
+        combine_map = {
+            "SMOOTH" : ("ENHANCE_DETAILS",)
+        }
+
         return generate_from_enum_ex(context,
             idname_prefix="builtin_brush.",
             icon_prefix="brush.sculpt.",
             type=bpy.types.Brush,
             attr="sculpt_tool",
-            exclude_filter=exclude_filter,)
+            exclude_filter=exclude_filter,
+            combine_map=combine_map)
 
     @ToolDef.from_fn
     def hide_border():
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 62b31ddddcc..e7cee8c2b46 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -713,6 +713,7 @@ typedef struct SculptSession {
 
   // for grids
   CustomData temp_vdata, temp_pdata;
+  int temp_vdata_elems, temp_pdata_elems;
 
   /* These contain the vertex and poly counts of the final mesh. */
   int totvert, totpoly;
diff --git a/source/blender/blenkernel/intern/brush_channel_define.h b/source/blender/blenkernel/intern/brush_channel_define.h
index 9cf50ab38d6..2a661561eb8 100644
--- a/source/blender/blenkernel/intern/brush_channel_define.h
+++ b/source/blender/blenkernel/intern/brush_channel_define.h
@@ -630,6 +630,7 @@ MAKE_ENUM(blend,"Blending Mode","Brush blending mode",IMB_BLEND_MIX,{\
   MAKE_INT_EX(autofset_start,"Face Set Start","",2,1,1024,1,1024)
   MAKE_FLOAT_EX_FLAG(autofset_spacing,"Spacing","Spacing for auto face set",4,1,1000,1,300,false,0)
   MAKE_BOOL_EX(autofset_use_spacing,"Use Spacing","Use spacing for auto face set",false,0)
+  MAKE_INT_EX(enhance_detail_presteps, "Detail Filter", "", 1, 0, 50, 0, 50)
 
   //MAKE_FLOAT3_EX
 /* clang-format on */
diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index 96ef4a4aa88..e3feb3136f9 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -301,6 +301,7 @@ static bool check_builtin_init()
     mdef->blendmode = MA_RAMP_ADD;
   }
 
+  //SETCAT(enhance_detail_presteps, "Enhancement");
   SETCAT(concave_mask_factor, "Automasking");
   SETCAT(automasking, "Automasking");
   SETCAT(automasking_boundary_edges_propagation_steps, "Automasking");
@@ -1203,7 +1204,7 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
   ADDCH(cloth_use_collision);
   ADDCH(cloth_solve_bending);
   ADDCH(cloth_bending_stiffness);
-  
+
   switch (tool) {
     case SCULPT_TOOL_CLAY:
       if (set_mappings) {
@@ -1280,6 +1281,10 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
     case SCULPT_TOOL_CREASE:
       ADDCH(crease_pinch_factor);
       break;
+    case SCULPT_TOOL_SMOOTH:
+    case SCULPT_TOOL_ENHANCE_DETAILS:
+      ADDCH(enhance_detail_presteps);
+      break;
     case SCULPT_TOOL_POSE:
       ADDCH(deform_target);
       ADDCH(disconnected_distance_max);
@@ -1379,6 +1384,7 @@ void BKE_brush_channelset_ui_init(Brush *brush, int tool)
             SCULPT_TOOL_FAIRING,
             SCULPT_TOOL_DRAW_FACE_SETS,
             SCULPT_TOOL_SMOOTH,
+            SCULPT_TOOL_ENHANCE_DETAILS,
             SCULPT_TOOL_SIMPLIFY)) {
 
     SHOWALL(accumulate);
@@ -1434,7 +1440,13 @@ void BKE_brush_channelset_ui_init(Brush *brush, int tool)
       SHOWCTX(autosmooth);
       SHOWALL(crease_pinch_factor);
       SHOWWRK(autosmooth);
+      break;
+    case SCULPT_TOOL_ENHANCE_DETAILS:
+      SHOWCTX(dyntopo_disabled);
+      SHOWALL(enhance_detail_presteps);
+      break;
     case SCULPT_TOOL_SMOOTH:
+      SHOWALL(enhance_detail_presteps);
       SHOWWRK(surface_smooth_shape_preservation);
       SHOWWRK(surface_smooth_current_vertex);
       SHOWWRK(surface_smooth_iterations);
@@ -1836,6 +1848,12 @@ void BKE_brush_builtin_create(Brush *brush, int tool)
 
       break;
     }
+    case SCULPT_TOOL_ENHANCE_DETAILS:
+      BRUSHSET_SET_BOOL(chset, use_space_attenuation, false);
+      BRUSHSET_SET_BOOL(chset, dyntopo_disabled, true);
+      BRUSHSET_SET_FLOAT(chset, spacing, 5.0f);
+      BRUSHSET_SET_FLOAT(chset, strength, 0.3f);
+      break;
     case SCULPT_TOOL_SMOOTH:
       BRUSHSET_SET_BOOL(chset, use_space_attenuation, false);
       BRUSHSET_SET_FLOAT(chset, spacing, 5.0f);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 47906ecab72..89ba9430869 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1510,6 +1510,9 @@ void BKE_sculptsession_free(Object *ob)
       BM_mesh_free(ss->bm);
     }
 
+    CustomData_free(&ss->temp_vdata, ss->temp_vdata_elems);
+    CustomData_free(&ss->temp_pdata, ss->temp_pdata_elems);
+
     sculptsession_free_pbvh(ob);
 
     for (int i = 0; i < SCULPT_SCL_LAYER_MAX; i++) {
@@ -2470,6 +2473,9 @@ static PBVH *build_pbvh_from_ccg(Object *ob, SubdivCCG *subdiv_ccg, bool respect
   MEM_SAFE_FREE(ss->face_areas);
   ss->face_areas = MEM_calloc_arrayN(totgridfaces, sizeof(float) * 2, "ss->face_areas");
 
+  CustomData_reset(&ob->sculpt->temp_vdata);
+  CustomData_reset(&ob->sculpt->temp_pdata);
+
   BKE_pbvh_build_grids(pbvh,
                        subdiv_ccg->grids,
                        subdiv_ccg->num_grids,
@@ -2480,10 +2486,14 @@ static PBVH *build_pbvh_from_ccg(Object *ob, SubdivCCG *subdiv_ccg, bool respect
                        ob->sculpt->fast_draw,
                        ss->face_areas);
 
+  ss->temp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list