Sculpt: Adjust inactive cursor display based on tilt

Part of #82877

This commit applies the same calculation used when tilting the normal to
the inactive cursor display inside sculpt mode, as a way to indicate to
users how the normal is affected by the current tilt settings and pen
orientation.

Pull Request: https://projects.blender.org/blender/blender/pulls/137250
This commit is contained in:
Sean Kim
2025-04-15 22:26:40 +02:00
committed by Sean Kim
parent e1e250aa84
commit a49cb2777c
3 changed files with 38 additions and 10 deletions

View File

@@ -1287,6 +1287,8 @@ struct PaintCursorContext {
/* TODO: Figure out why this and mval are used interchangeably */
float2 translation;
float2 tilt;
float final_radius;
int pixel_radius;
};
@@ -1294,6 +1296,8 @@ struct PaintCursorContext {
static bool paint_cursor_context_init(bContext *C,
const int x,
const int y,
const float x_tilt,
const float y_tilt,
PaintCursorContext &pcontext)
{
ARegion *region = CTX_wm_region(C);
@@ -1332,6 +1336,7 @@ static bool paint_cursor_context_init(bContext *C,
pcontext.mval = {x, y};
pcontext.translation = {float(x), float(y)};
pcontext.tilt = {x_tilt, y_tilt};
float zoomx, zoomy;
get_imapaint_zoom(C, &zoomx, &zoomy);
@@ -1671,7 +1676,16 @@ static void paint_cursor_drawing_setup_cursor_space(const PaintCursorContext &pc
pcontext.location);
const float3 z_axis = {0.0f, 0.0f, 1.0f};
const math::AxisAngle between_vecs(z_axis, pcontext.normal);
const float3 normal = bke::brush::supports_tilt(*pcontext.brush) ?
tilt_apply_to_normal(*pcontext.vc.obact,
float4x4(pcontext.vc.rv3d->viewinv),
pcontext.normal,
pcontext.tilt,
pcontext.brush->tilt_strength_factor) :
pcontext.normal;
const math::AxisAngle between_vecs(z_axis, normal);
const float4x4 cursor_rot = math::from_rotation<float4x4>(between_vecs);
GPU_matrix_mul(cursor_trans.ptr());
@@ -2119,10 +2133,10 @@ static void paint_cursor_restore_drawing_state()
}
static void paint_draw_cursor(
bContext *C, int x, int y, float /*x_tilt*/, float /*y_tilt*/, void * /*unused*/)
bContext *C, int x, int y, float x_tilt, float y_tilt, void * /*unused*/)
{
PaintCursorContext pcontext;
if (!paint_cursor_context_init(C, x, y, pcontext)) {
if (!paint_cursor_context_init(C, x, y, x_tilt, y_tilt, pcontext)) {
return;
}

View File

@@ -2700,24 +2700,33 @@ static void calc_brush_local_mat(const float rotation,
invert_m4_m4(local_mat, tmat);
}
float3 tilt_apply_to_normal(const float3 &normal,
const StrokeCache &cache,
float3 tilt_apply_to_normal(const Object &object,
const float4x4 &view_inverse,
const float3 &normal,
const float2 &tilt,
const float tilt_strength)
{
if (!USER_EXPERIMENTAL_TEST(&U, use_sculpt_tools_tilt)) {
return normal;
}
const float3 world_space = math::transform_direction(cache.vc->obact->object_to_world(), normal);
const float3 world_space = math::transform_direction(object.object_to_world(), normal);
constexpr float tilt_sensitivity = 0.7f;
const float rot_max = M_PI_2 * tilt_strength * tilt_sensitivity;
const float3 normal_tilt_y = math::rotate_direction_around_axis(
world_space, cache.vc->rv3d->viewinv[0], cache.tilt.y * rot_max);
world_space, view_inverse.x_axis(), tilt.y * rot_max);
const float3 normal_tilt_xy = math::rotate_direction_around_axis(
normal_tilt_y, cache.vc->rv3d->viewinv[1], cache.tilt.x * rot_max);
normal_tilt_y, view_inverse.y_axis(), tilt.x * rot_max);
return math::normalize(
math::transform_direction(cache.vc->obact->world_to_object(), normal_tilt_xy));
return math::normalize(math::transform_direction(object.world_to_object(), normal_tilt_xy));
}
float3 tilt_apply_to_normal(const float3 &normal,
const StrokeCache &cache,
const float tilt_strength)
{
return tilt_apply_to_normal(
*cache.vc->obact, float4x4(cache.vc->rv3d->viewinv), normal, cache.tilt, tilt_strength);
}
float3 tilt_effective_normal_get(const SculptSession &ss, const Brush &brush)

View File

@@ -744,6 +744,11 @@ namespace blender::ed::sculpt_paint {
/**
* Tilts a normal by the x and y tilt values using the view axis.
*/
float3 tilt_apply_to_normal(const Object &object,
const float4x4 &view_inverse,
const float3 &normal,
const float2 &tilt,
float tilt_strength);
float3 tilt_apply_to_normal(const float3 &normal, const StrokeCache &cache, float tilt_strength);
/**