Commit: 268682527fd90dad2b692ef96482c62070951424 Author: Joseph Eagar Date: Fri Aug 27 14:18:50 2021 -0700 Branches: temp_bmesh_multires https://developer.blender.org/rB268682527fd90dad2b692ef96482c62070951424
Sculpt dyntopo: added a smoothing factor for sharp boundaries Works by projecting non-boundary verts onto boundary vert normals and weighting by boundary_smooth_Factor. =================================================================== M release/scripts/startup/bl_ui/properties_paint_common.py M source/blender/blenkernel/intern/dyntopo.c M source/blender/editors/sculpt_paint/sculpt_smooth.c M source/blender/makesdna/DNA_brush_types.h M source/blender/makesrna/intern/rna_brush.c =================================================================== diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py index 8025caa8bf9..8bdfab02afb 100644 --- a/release/scripts/startup/bl_ui/properties_paint_common.py +++ b/release/scripts/startup/bl_ui/properties_paint_common.py @@ -567,6 +567,7 @@ def brush_settings(layout, context, brush, popover=False): slider=True, ) + box.prop(brush, "boundary_smooth_factor"); box.prop(brush, "use_weighted_smooth") box.prop(brush, "preserve_faceset_boundary") diff --git a/source/blender/blenkernel/intern/dyntopo.c b/source/blender/blenkernel/intern/dyntopo.c index 18e3c8bcb89..e7ec51a2c62 100644 --- a/source/blender/blenkernel/intern/dyntopo.c +++ b/source/blender/blenkernel/intern/dyntopo.c @@ -2570,6 +2570,22 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh, // BM_iter_as_array(NULL, BM_VERTS_OF_FACE, f, (void **)v_tri, 3); BMFace *f = l->f; + bool ok = true; + + for (int j = 0; j < (int)deleted_faces->count; j++) { + if (BLI_buffer_at(deleted_faces, BMFace *, j) == f) { + ok = false; + } + } + + if (ok) { + BLI_buffer_append(deleted_faces, BMFace *, f); + } + else { + printf("tried to add same face to deleted list twice. %x %d\n", f, f->len); + continue; + } + /* Check if a face using these vertices already exists. If so, * skip adding this face and mark the existing one for * deletion as well. Prevents extraneous "flaps" from being @@ -2580,17 +2596,17 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh, if (UNLIKELY(existing_face = bm_face_exists_tri_from_loop_vert(l->next, v_conn))) # endif { - bool ok = true; + bool ok2 = true; // check we're not already in deleted_faces for (int i = 0; i < (int)deleted_faces->count; i++) { if (BLI_buffer_at(deleted_faces, BMFace *, i) == existing_face) { - ok = false; + ok2 = false; break; } } - if (ok) { + if (ok2) { BLI_buffer_append(deleted_faces, BMFace *, existing_face); } } @@ -2638,8 +2654,6 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh, CustomData_bmesh_copy_data( &pbvh->bm->ldata, &pbvh->bm->ldata, l->prev->head.data, &l2->prev->head.data); } - - BLI_buffer_append(deleted_faces, BMFace *, f); } BM_LOOPS_OF_VERT_ITER_END; #endif diff --git a/source/blender/editors/sculpt_paint/sculpt_smooth.c b/source/blender/editors/sculpt_paint/sculpt_smooth.c index 10cb81abbba..2b5e07eb861 100644 --- a/source/blender/editors/sculpt_paint/sculpt_smooth.c +++ b/source/blender/editors/sculpt_paint/sculpt_smooth.c @@ -82,6 +82,7 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss, bool check_fsets = ss->cache->brush->flag2 & BRUSH_SMOOTH_PRESERVE_FACE_SETS; int bflag = SCULPT_BOUNDARY_MESH | SCULPT_BOUNDARY_SHARP; + float bound_smooth = ss->cache->brush->boundary_smooth_factor; if (check_fsets) { bflag |= SCULPT_BOUNDARY_FACE_SET; @@ -92,13 +93,18 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss, const float *co = SCULPT_vertex_co_get(ss, vertex); float no[3]; - if (projection > 0.0f) { + if (true || projection > 0.0f) { SCULPT_vertex_normal_get(ss, vertex, no); } const bool weighted = (ss->cache->brush->flag2 & BRUSH_SMOOTH_USE_AREA_WEIGHT) && !is_boundary; float *areas; + SculptCornerType ctype = SCULPT_CORNER_MESH | SCULPT_CORNER_SHARP; + if (check_fsets) { + ctype |= SCULPT_CORNER_FACE_SET; + } + if (weighted) { int val = SCULPT_vertex_valence_get(ss, vertex); areas = BLI_array_alloca(areas, val); @@ -126,6 +132,15 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss, copy_v3_v3(tmp, SCULPT_vertex_co_get(ss, ni.vertex)); ok = true; } + else { + float t[3]; + + w *= bound_smooth; + + sub_v3_v3v3(t, SCULPT_vertex_co_get(ss, ni.vertex), co); + madd_v3_v3v3fl(tmp, co, no, dot_v3v3(t, no)); + ok = true; + } } else { /* Interior vertices use all neighbors. */ @@ -168,6 +183,10 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss, if (projection > 0.0f) { add_v3_v3(result, co); } + + if (SCULPT_vertex_is_corner(ss, vertex, ctype)) { + interp_v3_v3v3(result, result, co, 1.0f - bound_smooth); + } } void SCULPT_neighbor_coords_average_interior_velocity(SculptSession *ss, @@ -691,6 +710,7 @@ static void do_smooth_brush_task_cb_ex(void *__restrict userdata, } bool modified = false; + const float bound_smooth = ss->cache->brush->boundary_smooth_factor; BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (!sculpt_brush_test_sq_fn(&test, vd.co)) { @@ -715,7 +735,7 @@ static void do_smooth_brush_task_cb_ex(void *__restrict userdata, else { float avg[3], val[3]; - if (SCULPT_vertex_is_corner(ss, vd.vertex, ctype)) { + if (bound_smooth == 0.0f && SCULPT_vertex_is_corner(ss, vd.vertex, ctype)) { continue; } diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index 1f23f0eb65a..21eb29171ba 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -283,12 +283,13 @@ typedef struct Brush { char gpencil_sculpt_tool; /** Active grease pencil weight tool. */ char gpencil_weight_tool; - char _pad1[6]; + char _pad1[2]; float autosmooth_factor; float autosmooth_radius_factor; float autosmooth_projection; - int autosmooth_spacing; //spacing for BRUSH_CUSTOM_AUTOSMOOTH_SPACING + int autosmooth_spacing; // spacing for BRUSH_CUSTOM_AUTOSMOOTH_SPACING + float boundary_smooth_factor; float tilt_strength_factor; diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 8d1d362b949..0c914aab040 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -3099,6 +3099,14 @@ static void rna_def_brush(BlenderRNA *brna) "to generate sharper features. "); RNA_def_property_update(prop, 0, "rna_Brush_update"); + prop = RNA_def_property(srna, "boundary_smooth_factor", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "boundary_smooth_factor"); + RNA_def_property_float_default(prop, 0); + RNA_def_property_range(prop, -2.0f, 2.0f); + RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.001, 3); + RNA_def_property_ui_text(prop, "Boundary Smoothing", "How much to smooth sharp boundaries "); + RNA_def_property_update(prop, 0, "rna_Brush_update"); + prop = RNA_def_property(srna, "vcol_boundary_exponent", PROP_FLOAT, PROP_FACTOR); RNA_def_property_float_sdna(prop, NULL, "vcol_boundary_exponent"); RNA_def_property_float_default(prop, 0); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs