Fix T73947: Support radial symmetry in Multiplane Scrape

This includes the following changes:
- Use always the angle stored in the StrokeCache when deforming
- Interpolate between the previous and the new sampled angles
- Calculate the cursor matrix only on the 0 radial symmetry iteration

Reviewed By: brecht

Maniphest Tasks: T73947

Differential Revision: https://developer.blender.org/D6901
This commit is contained in:
Pablo Dobarro 2020-03-01 19:12:30 +01:00 committed by Pablo Dobarro
parent f2557d137a
commit c04c5ac4f6
Notes: blender-bot 2023-12-22 20:14:11 +01:00
Referenced by issue #73947, Strange behavior when using multiplane scrape and radial
3 changed files with 17 additions and 15 deletions

View File

@ -1231,7 +1231,7 @@ static void sculpt_multiplane_scrape_preview_draw(const uint gpuattr,
float local_mat_inv[4][4];
invert_m4_m4(local_mat_inv, ss->cache->stroke_local_mat);
GPU_matrix_mul(local_mat_inv);
float angle = ss->cache->multiplane_scrape_sampled_angle;
float angle = ss->cache->multiplane_scrape_angle;
if (ss->cache->pen_flip || ss->cache->invert) {
angle = -angle;
}

View File

@ -5510,6 +5510,7 @@ static void do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes,
/* Delay the first daub because grab delta is not setup. */
if (ss->cache->first_time) {
ss->cache->multiplane_scrape_angle = 0.0f;
return;
}
@ -5533,10 +5534,8 @@ static void do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes,
normalize_m4(mat);
invert_m4(mat);
float angle = brush->multiplane_scrape_angle;
/* Update matrix for the cursor preview. */
if (ss->cache->mirror_symmetry_pass == 0) {
if (ss->cache->mirror_symmetry_pass == 0 && ss->cache->radial_symmetry_pass == 0) {
copy_m4_m4(ss->cache->stroke_local_mat, mat);
}
@ -5593,8 +5592,8 @@ static void do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes,
sampled_angle = -sampled_angle;
}
/* In dynamic mode, set the angle to 0 when inverting the brush, so you can trim plane surfaces
* without changing the brush. */
/* In dynamic mode, set the angle to 0 when inverting the brush, so you can trim plane
* surfaces without changing the brush. */
if (flip) {
sampled_angle = 0.0f;
}
@ -5602,27 +5601,28 @@ static void do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes,
copy_v3_v3(area_co, ss->cache->location);
}
angle = RAD2DEGF(sampled_angle);
/* Interpolate between the previous and new sampled angles to avoid artifacts when if angle
* difference between two samples is too big. */
ss->cache->multiplane_scrape_angle = interpf(
RAD2DEGF(sampled_angle), ss->cache->multiplane_scrape_angle, 0.2f);
}
else {
/* Standard mode: Scrape with the brush property fixed angle. */
copy_v3_v3(area_co, ss->cache->location);
ss->cache->multiplane_scrape_angle = brush->multiplane_scrape_angle;
if (flip) {
angle = -angle;
ss->cache->multiplane_scrape_angle *= -1.0f;
}
}
/* Set the angle for the cursor preview. */
ss->cache->multiplane_scrape_sampled_angle = angle;
SculptThreadedTaskData data = {
.sd = sd,
.ob = ob,
.brush = brush,
.nodes = nodes,
.mat = mat,
.multiplane_scrape_angle = angle,
.multiplane_scrape_angle = ss->cache->multiplane_scrape_angle,
};
/* Calculate the final left and right scrape planes. */
@ -5633,13 +5633,15 @@ static void do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes,
invert_m4_m4(mat_inv, mat);
mul_v3_mat3_m4v3(plane_no, mat, area_no);
rotate_v3_v3v3fl(plane_no_rot, plane_no, y_axis, DEG2RADF(-angle * 0.5f));
rotate_v3_v3v3fl(
plane_no_rot, plane_no, y_axis, DEG2RADF(-ss->cache->multiplane_scrape_angle * 0.5f));
mul_v3_mat3_m4v3(plane_no, mat_inv, plane_no_rot);
normalize_v3(plane_no);
plane_from_point_normal_v3(data.multiplane_scrape_planes[1], area_co, plane_no);
mul_v3_mat3_m4v3(plane_no, mat, area_no);
rotate_v3_v3v3fl(plane_no_rot, plane_no, y_axis, DEG2RADF(angle * 0.5f));
rotate_v3_v3v3fl(
plane_no_rot, plane_no, y_axis, DEG2RADF(ss->cache->multiplane_scrape_angle * 0.5f));
mul_v3_mat3_m4v3(plane_no, mat_inv, plane_no_rot);
normalize_v3(plane_no);
plane_from_point_normal_v3(data.multiplane_scrape_planes[0], area_co, plane_no);

View File

@ -521,7 +521,7 @@ typedef struct StrokeCache {
float *automask;
float stroke_local_mat[4][4];
float multiplane_scrape_sampled_angle;
float multiplane_scrape_angle;
rcti previous_r; /* previous redraw rectangle */
rcti current_r; /* current redraw rectangle */