Fix: #126515: Brush radius sensitivity not consisted at different zoom levels

The problem was that the screen space size of the brush was not updated.
This was not fully noticeable because the radius control operator was using
a not working scale correction.
The solution remove the scale correction and just update the brush size.

Note: This update currently happens when the cursor is drawn.

Pull Request: https://projects.blender.org/blender/blender/pulls/126773
This commit is contained in:
Casey Bianco-Davis
2024-10-16 11:17:26 +02:00
committed by Falk David
parent 931469484e
commit b2cff223a1
2 changed files with 1 additions and 41 deletions

View File

@@ -1567,6 +1567,7 @@ static void grease_pencil_brush_cursor_draw(PaintCursorContext *pcontext)
const float3 location = placement.project(float2(pcontext->x, pcontext->y));
pcontext->pixel_radius = project_brush_radius(
&pcontext->vc, brush->unprojected_radius, location);
brush->size = pcontext->pixel_radius;
}
else {
pcontext->pixel_radius = brush->size;

View File

@@ -2525,7 +2525,6 @@ struct RadialControl {
int initial_co[2];
int slow_mouse[2];
bool slow_mode;
float scale_fac;
Dial *dial;
GPUTexture *texture;
ListBase orig_paintcursors;
@@ -2575,31 +2574,6 @@ static void radial_control_update_header(wmOperator *op, bContext *C)
ED_area_status_text(area, msg);
}
/* Helper: Compute the brush radius in pixels at the mouse position. */
static float grease_pencil_unprojected_brush_radius_pixel_size(const bContext *C,
const Brush *brush,
const blender::float2 mval)
{
using namespace blender;
Scene *scene = CTX_data_scene(C);
ARegion *region = CTX_wm_region(C);
View3D *view3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
Object *object = CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
Object *eval_object = DEG_get_evaluated_object(depsgraph, object);
BLI_assert(object->type == OB_GREASE_PENCIL);
GreasePencil *grease_pencil = static_cast<GreasePencil *>(eval_object->data);
ed::greasepencil::DrawingPlacement placement(
*scene, *region, *view3d, *eval_object, grease_pencil->get_active_layer());
const float3 position = placement.project(mval);
const float pixel_size = ED_view3d_pixel_size(
rv3d, math::transform_point(placement.to_world_space(), position));
return brush->unprojected_radius / pixel_size;
}
static void radial_control_set_initial_mouse(bContext *C, RadialControl *rc, const wmEvent *event)
{
float d[2] = {0, 0};
@@ -2635,18 +2609,6 @@ static void radial_control_set_initial_mouse(bContext *C, RadialControl *rc, con
d[0] *= zoom[0];
d[1] *= zoom[1];
}
rc->scale_fac = 1.0f;
if (rc->ptr.owner_id && GS(rc->ptr.owner_id->name) == ID_BR && rc->prop == &rna_Brush_size) {
Brush *brush = reinterpret_cast<Brush *>(rc->ptr.owner_id);
if ((brush && brush->gpencil_settings) && (brush->ob_mode == OB_MODE_PAINT_GREASE_PENCIL) &&
(brush->gpencil_brush_type == GPAINT_BRUSH_TYPE_DRAW) &&
(brush->flag & BRUSH_LOCK_SIZE) != 0)
{
const float radius_px = grease_pencil_unprojected_brush_radius_pixel_size(
C, brush, blender::float2(event->mval));
rc->scale_fac = max_ff(radius_px, 1.0f) / max_ff(rc->initial_value, 1.0f);
}
}
rc->initial_mouse[0] -= d[0];
rc->initial_mouse[1] -= d[1];
@@ -2852,9 +2814,6 @@ static void radial_control_paint_cursor(bContext * /*C*/, int x, int y, void *cu
GPU_matrix_scale_2fv(zoom);
}
/* Apply scale correction (used by grease pencil brushes). */
GPU_matrix_scale_2f(rc->scale_fac, rc->scale_fac);
/* Draw rotated texture. */
radial_control_paint_tex(rc, tex_radius, alpha);