Sculpt dyntopo: Added a 'hard edge mode' option

to forcibly set autosmooth_fset_slide to zero
(i.e. treat face set boundaries as hard edges
and not project them on the surface).
This commit is contained in:
Joseph Eagar 2021-09-09 10:06:24 -08:00
parent a52f89a446
commit f52a03dd71
12 changed files with 87 additions and 7 deletions

View File

@ -549,7 +549,17 @@ def brush_settings(layout, context, brush, popover=False):
if context.preferences.experimental.use_sculpt_tools_tilt and capabilities.has_tilt:
layout.prop(brush, "tilt_strength_factor", slider=True)
UnifiedPaintPanel.prop_unified(
layout,
context,
brush,
"hard_edge_mode",
slider=True,
unified_name="use_unified_hard_edge_mode",
)
row = layout.row(align=True)
row.prop(brush, "hardness", slider=True)
row.prop(brush, "invert_hardness_pressure", text="")
row.prop(brush, "use_hardness_pressure", text="")

View File

@ -39,7 +39,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 21
#define BLENDER_FILE_SUBVERSION 22
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file

View File

@ -155,6 +155,11 @@ void BKE_brush_debug_print_state(struct Brush *br);
void BKE_brush_get_dyntopo(struct Brush *brush, struct Sculpt *sd, struct DynTopoSettings *out);
bool BKE_brush_hard_edge_mode_get(const struct Scene *scene, const struct Brush *brush);
void BKE_brush_hard_edge_mode_set(struct Scene *scene, struct Brush *brush, bool val);
float BKE_brush_fset_slide_get(const struct Scene *scene, const struct Brush *brush);
#ifdef __cplusplus
}
#endif

View File

@ -2755,3 +2755,36 @@ void BKE_brush_get_dyntopo(Brush *brush, Sculpt *sd, DynTopoSettings *out)
}
}
};
bool BKE_brush_hard_edge_mode_get(const Scene *scene, const Brush *brush)
{
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
bool ret = (ups->flag & UNIFIED_PAINT_FLAG_HARD_EDGE_MODE) ? ups->hard_edge_mode :
brush->flag2 & BRUSH_HARD_EDGE_MODE;
return ret;
}
void BKE_brush_hard_edge_mode_set(Scene *scene, Brush *brush, bool val)
{
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
if (ups->flag & UNIFIED_PAINT_FLAG_HARD_EDGE_MODE) {
ups->hard_edge_mode = val;
}
else {
if (val) {
brush->flag2 |= BRUSH_HARD_EDGE_MODE;
}
else {
brush->flag2 &= ~BRUSH_HARD_EDGE_MODE;
}
}
}
float BKE_brush_fset_slide_get(const Scene *scene, const Brush *brush)
{
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
return BKE_brush_hard_edge_mode_get(scene, brush) ? 0.0f : brush->autosmooth_fset_slide;
}

View File

@ -4424,7 +4424,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
ToolSettings *ts = scene->toolsettings;
UnifiedPaintSettings *ups = &ts->unified_paint_settings;
ups->flag &= ~(UNIFIED_PAINT_FLAG_UNUSED_0 | UNIFIED_PAINT_FLAG_UNUSED_1);
ups->flag &= ~(UNIFIED_PAINT_FLAG_UNUSED_1);
}
/* Set the default render pass in the viewport to Combined. */

View File

@ -1169,6 +1169,15 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
if (!MAIN_VERSION_ATLEAST(bmain, 300, 22)) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
ToolSettings *ts = scene->toolsettings;
if (ts) {
ts->unified_paint_settings.flag |= UNIFIED_PAINT_FLAG_HARD_EDGE_MODE;
}
}
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@ -87,7 +87,7 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
int bflag = SCULPT_BOUNDARY_MESH | SCULPT_BOUNDARY_SHARP;
float bound_smooth = powf(ss->cache->brush->boundary_smooth_factor, BOUNDARY_SMOOTH_EXP);
float slide_fset = ss->cache->brush->autosmooth_fset_slide;
float slide_fset = BKE_brush_fset_slide_get(ss->scene, ss->cache->brush);
slide_fset = MAX2(slide_fset, bound_smooth);
@ -1046,7 +1046,7 @@ static void do_smooth_brush_task_cb_ex(void *__restrict userdata,
bool modified = false;
const float bound_smooth = powf(ss->cache->brush->boundary_smooth_factor, BOUNDARY_SMOOTH_EXP);
const float slide_fset = ss->cache->brush->autosmooth_fset_slide;
const float slide_fset = BKE_brush_fset_slide_get(ss->scene, ss->cache->brush);
SculptCustomLayer *bound_scl = data->scl2;

View File

@ -420,6 +420,9 @@ typedef enum eBrushFlags2 {
/*topology rake in dynamic mode*/
BRUSH_DYNAMIC_RAKE = (1 << 15),
/* sets face set slide to 0.0 */
BRUSH_HARD_EDGE_MODE = (1 << 16),
} eBrushFlags2;
typedef enum {

View File

@ -290,7 +290,7 @@
.unprojected_radius = 0.29, \
.alpha = 0.5f, \
.weight = 0.5f, \
.flag = UNIFIED_PAINT_SIZE | UNIFIED_PAINT_ALPHA, \
.flag = UNIFIED_PAINT_SIZE | UNIFIED_PAINT_ALPHA | UNIFIED_PAINT_FLAG_HARD_EDGE_MODE, \
}
#define _DNA_DEFAULTS_ParticleEditSettings \

View File

@ -1244,7 +1244,8 @@ typedef struct UnifiedPaintSettings {
float pixel_radius;
float initial_pixel_radius;
char _pad[4];
char _pad[3];
char hard_edge_mode;
/* drawing pressure */
float size_pressure_value;
@ -1268,7 +1269,7 @@ typedef enum {
/* only used if unified size is enabled, mirrors the brush flag BRUSH_LOCK_SIZE */
UNIFIED_PAINT_BRUSH_LOCK_SIZE = (1 << 2),
UNIFIED_PAINT_FLAG_UNUSED_0 = (1 << 3),
UNIFIED_PAINT_FLAG_HARD_EDGE_MODE = (1 << 3),
UNIFIED_PAINT_FLAG_UNUSED_1 = (1 << 4),
} eUnifiedPaintSettingsFlags;

View File

@ -3349,6 +3349,12 @@ static void rna_def_brush(BlenderRNA *brna)
prop, "Preserve Face Sets", "Preserve face set boundaries when smoothing");
RNA_def_property_update(prop, 0, "rna_Brush_update");
prop = RNA_def_property(srna, "hard_edge_mode", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag2", BRUSH_HARD_EDGE_MODE);
RNA_def_property_ui_text(
prop, "Hard Edge Mode", "Hard edge mode; treat all face set boundaries as hard edges");
RNA_def_property_update(prop, 0, "rna_Brush_update");
prop = RNA_def_property(srna, "use_grab_silhouette", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag2", BRUSH_GRAB_SILHOUETTE);
RNA_def_property_ui_text(

View File

@ -3597,6 +3597,12 @@ static void rna_def_unified_paint_settings(BlenderRNA *brna)
"Use Unified Radius",
"Instead of per-brush radius, the radius is shared across brushes");
/* high-level flags to enable or disable unified paint settings */
prop = RNA_def_property(srna, "use_unified_hard_edge_mode", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", UNIFIED_PAINT_FLAG_HARD_EDGE_MODE);
RNA_def_property_ui_text(
prop, "Use Unified Hard Edge Mode", "Use global setting for hard edge mode");
prop = RNA_def_property(srna, "use_unified_strength", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", UNIFIED_PAINT_ALPHA);
RNA_def_property_ui_text(prop,
@ -3669,6 +3675,13 @@ static void rna_def_unified_paint_settings(BlenderRNA *brna)
RNA_def_property_enum_items(prop, brush_size_unit_items);
RNA_def_property_ui_text(
prop, "Radius Unit", "Measure brush size relative to the view or the scene");
prop = RNA_def_property(srna, "hard_edge_mode", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "hard_edge_mode", 1);
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(
prop, "Hard Edge Mode", "Hard edge mode; treat all face set boundaries as hard edges");
RNA_def_property_update(prop, 0, "rna_UnifiedPaintSettings_update");
}
static void rna_def_curve_paint_settings(BlenderRNA *brna)