From 416aef4e13ccc30e82ecaa691f26af54dbd5ee7e Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 30 Jun 2022 15:09:13 +0200 Subject: Curves: New tools for curves sculpt mode. This commit contains various new features for curves sculpt mode that have been developed in parallel. * Selection: * Operator to select points/curves randomly. * Operator to select endpoints of curves. * Operator to grow/shrink an existing selection. * New Brushes: * Pinch: Moves points towards the brush center. * Smooth: Makes individual curves straight without changing the root or tip position. * Puff: Makes curves stand up, aligning them with the surface normal. * Density: Add or remove curves to achieve a certain density defined by a minimum distance value. * Slide: Move root points on the surface. Differential Revision: https://developer.blender.org/D15134 --- source/blender/editors/sculpt_paint/paint_stroke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 63e6dc7e965..1ee26935dc9 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -995,7 +995,7 @@ static void stroke_done(bContext *C, wmOperator *op, PaintStroke *stroke) static bool curves_sculpt_brush_uses_spacing(const eBrushCurvesSculptTool tool) { - return ELEM(tool, CURVES_SCULPT_TOOL_ADD); + return ELEM(tool, CURVES_SCULPT_TOOL_ADD, CURVES_SCULPT_TOOL_DENSITY); } bool paint_space_stroke_enabled(Brush *br, ePaintMode mode) -- cgit v1.2.3 From 9a1488790532b6a64dea66cbe696ac35c70e6793 Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Sat, 16 Jul 2022 16:45:41 -0700 Subject: Sculpt: Fix scene spacing mode (phase 1) The scene spacing code was failing to check if a raycast failed, which can happen when sculpting the edges of objects in negative mode. Note I removed what I suspect was a hack put in to fix this, spacing was clamped to 0.001 scene units. Scene spacing mode is actually quite broken, so it will be fixed in a series of phases. --- source/blender/editors/sculpt_paint/paint_stroke.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 1ee26935dc9..a4c942796d8 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -79,6 +79,8 @@ typedef struct PaintStroke { float last_mouse_position[2]; float last_world_space_position[3]; + float last_scene_spacing_delta[3]; + bool stroke_over_mesh; /* space distance covered so far */ float stroke_distance; @@ -550,8 +552,15 @@ static void paint_brush_stroke_add_step( stroke->last_pressure = pressure; if (paint_stroke_use_scene_spacing(brush, mode)) { - SCULPT_stroke_get_location(C, stroke->last_world_space_position, stroke->last_mouse_position); - mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position); + float world_space_position[3]; + + if (SCULPT_stroke_get_location(C, world_space_position, stroke->last_mouse_position)) { + copy_v3_v3(stroke->last_world_space_position, world_space_position); + mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position); + } + else { + add_v3_v3(stroke->last_world_space_position, stroke->last_scene_spacing_delta); + } } if (paint_stroke_use_jitter(mode, brush, stroke->stroke_mode == BRUSH_STROKE_INVERT)) { @@ -698,7 +707,7 @@ static float paint_space_stroke_spacing(bContext *C, spacing *= stroke->zoom_2d; if (paint_stroke_use_scene_spacing(brush, mode)) { - return max_ff(0.001f, size_clamp * spacing / 50.0f); + return size_clamp * spacing / 50.0f; } return max_ff(stroke->zoom_2d, size_clamp * spacing / 50.0f); } @@ -838,6 +847,8 @@ static int paint_space_stroke(bContext *C, stroke->last_world_space_position, final_world_space_position); ED_view3d_project_v2(region, final_world_space_position, mouse); + + mul_v3_v3fl(stroke->last_scene_spacing_delta, d_world_space_position, spacing); } else { mouse[0] = stroke->last_mouse_position[0] + dmouse[0] * spacing; -- cgit v1.2.3 From cd1e4ae4483056157f238f56f19367ad98ae3f3d Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Sat, 16 Jul 2022 17:27:25 -0700 Subject: Fix T99644: Anchored brush mode fails for negative brushes The stroke code now supports raycasting the original mesh. This fixes anchored mode not working for negative brushes, which might move the mesh out of the initial mouse cursor position. --- source/blender/editors/sculpt_paint/paint_stroke.c | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index a4c942796d8..33a307376bb 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -122,6 +122,8 @@ typedef struct PaintStroke { StrokeUpdateStep update_step; StrokeRedraw redraw; StrokeDone done; + + bool original; /* Raycast original mesh at start of stroke */ } PaintStroke; /*** Cursors ***/ @@ -245,6 +247,11 @@ static bool paint_stroke_use_scene_spacing(Brush *brush, ePaintMode mode) return false; } +static bool paint_tool_raycast_original(Brush *brush, ePaintMode mode) +{ + return brush->flag & BRUSH_ANCHORED; +} + static bool paint_tool_require_inbetween_mouse_events(Brush *brush, ePaintMode mode) { if (brush->flag & BRUSH_ANCHORED) { @@ -394,7 +401,7 @@ static bool paint_brush_update(bContext *C, halfway[1] = dy * 0.5f + stroke->initial_mouse[1]; if (stroke->get_location) { - if (stroke->get_location(C, r_location, halfway)) { + if (stroke->get_location(C, r_location, halfway, stroke->original)) { hit = true; location_sampled = true; location_success = true; @@ -468,7 +475,7 @@ static bool paint_brush_update(bContext *C, if (!location_sampled) { if (stroke->get_location) { - if (stroke->get_location(C, r_location, mouse)) { + if (stroke->get_location(C, r_location, mouse, stroke->original)) { location_success = true; *r_location_is_set = true; } @@ -554,7 +561,8 @@ static void paint_brush_stroke_add_step( if (paint_stroke_use_scene_spacing(brush, mode)) { float world_space_position[3]; - if (SCULPT_stroke_get_location(C, world_space_position, stroke->last_mouse_position)) { + if (SCULPT_stroke_get_location( + C, world_space_position, stroke->last_mouse_position, stroke->original)) { copy_v3_v3(stroke->last_world_space_position, world_space_position); mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position); } @@ -816,7 +824,7 @@ static int paint_space_stroke(bContext *C, if (use_scene_spacing) { float world_space_position[3]; - bool hit = SCULPT_stroke_get_location(C, world_space_position, final_mouse); + bool hit = SCULPT_stroke_get_location(C, world_space_position, final_mouse, stroke->original); mul_m4_v3(stroke->vc.obact->obmat, world_space_position); if (hit && stroke->stroke_over_mesh) { sub_v3_v3v3(d_world_space_position, world_space_position, stroke->last_world_space_position); @@ -907,6 +915,8 @@ PaintStroke *paint_stroke_new(bContext *C, stroke->ups = ups; stroke->stroke_mode = RNA_enum_get(op->ptr, "mode"); + stroke->original = paint_tool_raycast_original(br, BKE_paintmode_get_active_from_context(C)); + get_imapaint_zoom(C, &zoomx, &zoomy); stroke->zoom_2d = max_ff(zoomx, zoomy); @@ -1202,8 +1212,10 @@ static void paint_line_strokes_spacing(bContext *C, copy_v2_v2(stroke->last_mouse_position, old_pos); if (use_scene_spacing) { - bool hit_old = SCULPT_stroke_get_location(C, world_space_position_old, old_pos); - bool hit_new = SCULPT_stroke_get_location(C, world_space_position_new, new_pos); + bool hit_old = SCULPT_stroke_get_location( + C, world_space_position_old, old_pos, stroke->original); + bool hit_new = SCULPT_stroke_get_location( + C, world_space_position_new, new_pos, stroke->original); mul_m4_v3(stroke->vc.obact->obmat, world_space_position_old); mul_m4_v3(stroke->vc.obact->obmat, world_space_position_new); if (hit_old && hit_new && stroke->stroke_over_mesh) { @@ -1347,7 +1359,7 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str if (paint_stroke_use_scene_spacing(br, BKE_paintmode_get_active_from_context(C))) { stroke->stroke_over_mesh = SCULPT_stroke_get_location( - C, stroke->last_world_space_position, data + 2 * j); + C, stroke->last_world_space_position, data + 2 * j, stroke->original); mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position); } @@ -1479,7 +1491,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintS copy_v2_v2(stroke->last_mouse_position, sample_average.mouse); if (paint_stroke_use_scene_spacing(br, mode)) { stroke->stroke_over_mesh = SCULPT_stroke_get_location( - C, stroke->last_world_space_position, sample_average.mouse); + C, stroke->last_world_space_position, sample_average.mouse, stroke->original); mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position); } stroke->stroke_started = stroke->test_start(C, op, sample_average.mouse); -- cgit v1.2.3 From 7ebd1f4b7960100ff9f4a1bfcf3e798fbec9dfbd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Jul 2022 13:32:23 +1000 Subject: Cleanup: quiet compiler warnings --- source/blender/editors/sculpt_paint/paint_stroke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 33a307376bb..88e7a786a47 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -247,7 +247,7 @@ static bool paint_stroke_use_scene_spacing(Brush *brush, ePaintMode mode) return false; } -static bool paint_tool_raycast_original(Brush *brush, ePaintMode mode) +static bool paint_tool_raycast_original(Brush *brush, ePaintMode UNUSED(mode)) { return brush->flag & BRUSH_ANCHORED; } -- cgit v1.2.3 From 46a2592eef90782bea6124767c072f275330bd00 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 21 Jul 2022 13:21:53 +1000 Subject: Cleanup: spelling in comments, typos in tool-tips --- source/blender/editors/sculpt_paint/paint_stroke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 88e7a786a47..736942b9f72 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -123,7 +123,7 @@ typedef struct PaintStroke { StrokeRedraw redraw; StrokeDone done; - bool original; /* Raycast original mesh at start of stroke */ + bool original; /* Ray-cast original mesh at start of stroke. */ } PaintStroke; /*** Cursors ***/ -- cgit v1.2.3 From 2eeedbbca96306971a7605ade18ee42053b17e41 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 21 Jul 2022 16:23:33 +1000 Subject: Cleanup: add ISMOUSE_MOTION macro Replace verbose ELEM(..) usage, now each kind of mouse event has it's own macro. --- source/blender/editors/sculpt_paint/paint_stroke.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 736942b9f72..97fa2b936e0 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -1550,8 +1550,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintS copy_v2_fl2(mouse, event->mval[0], event->mval[1]); paint_stroke_line_constrain(stroke, mouse); - if (stroke->stroke_started && - (first_modal || (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)))) { + if (stroke->stroke_started && (first_modal || ISMOUSE_MOTION(event->type))) { if ((br->mtex.brush_angle_mode & MTEX_ANGLE_RAKE) || (br->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) { copy_v2_v2(stroke->ups->last_rake, stroke->last_mouse_position); @@ -1561,7 +1560,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintS } else if (first_modal || /* regular dabs */ - (!(br->flag & BRUSH_AIRBRUSH) && (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE))) || + (!(br->flag & BRUSH_AIRBRUSH) && ISMOUSE_MOTION(event->type)) || /* airbrush */ ((br->flag & BRUSH_AIRBRUSH) && event->type == TIMER && event->customdata == stroke->timer)) { -- cgit v1.2.3 From 223665b994d785672c023432ac3861d4d2c0ffb6 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Thu, 1 Sep 2022 09:31:07 -0300 Subject: GPU: remove 'GPU_SHADER_2D_UNIFORM_COLOR' The only real difference between `GPU_SHADER_2D_UNIFORM_COLOR` and `GPU_SHADER_3D_UNIFORM_COLOR` is that in the vertex shader the 2D version uses `vec4(pos, 0.0, 1.0)` and the 3D version uses `vec4(pos, 1.0)`. But VBOs with 2D attributes work perfectly in shaders that use 3D attributes. Components not specified are filled with components from `vec4(0.0, 0.0, 0.0, 1.0)`. So there is no real benefit to having two different shader versions. This will simplify porting shaders to python as it will not be necessary to use a 3D and a 2D version of the shaders. In python the new name for '2D_UNIFORM_COLOR'' and '3D_UNIFORM_COLOR' is 'UNIFORM_COLOR', but the old names still work for backward compatibility. Differential Revision: https://developer.blender.org/D15836 --- source/blender/editors/sculpt_paint/paint_stroke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 97fa2b936e0..89f3579c341 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -140,7 +140,7 @@ static void paint_draw_smooth_cursor(bContext *C, int x, int y, void *customdata ARegion *region = stroke->vc.region; uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); immUniformColor4ubv(paint->paint_cursor_col); immBegin(GPU_PRIM_LINES, 2); -- cgit v1.2.3 From f0a36599007d2c5185d040202b84775ae1343785 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Mon, 5 Sep 2022 19:01:02 -0300 Subject: GPU: remove 'GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR' The only difference between `GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR` and `GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR` is that in the vertex shader the 2D version uses `vec4(pos, 0.0, 1.0)` and the 3D version uses `vec4(pos, 1.0)`. But VBOs with 2D attributes work perfectly in shaders that use 3D attributes. Components not specified are filled with components from `vec4(0.0, 0.0, 0.0, 1.0)`. So there is no real benefit to having two different shader versions. --- source/blender/editors/sculpt_paint/paint_stroke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 89f3579c341..60f4a9d59a5 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -168,7 +168,7 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata) uint shdr_pos = GPU_vertformat_attr_add( immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR); float viewport_size[4]; GPU_viewport_size_get_f(viewport_size); -- cgit v1.2.3