Fix T79914: Grab active vertex using wrong coordinates

This was introduced in the first commit of the cloth brush. In order to
support the cloth brush deformations with subsurf modifiers, the sculpt
API was changed to return the deformed coordinates from the PBVH instead
of the mesh coordinates. When using grab active vertex and rendering the
original mesh wireframe it should render the undeformed mesh coordinates
when available.

Reviewed By: sergey

Maniphest Tasks: T79914

Differential Revision: https://developer.blender.org/D8630
This commit is contained in:
Pablo Dobarro 2020-09-07 17:24:52 +02:00 committed by Pablo Dobarro
parent bbbfd7130a
commit 1dc11d15a6
Notes: blender-bot 2023-02-14 06:00:44 +01:00
Referenced by issue #79914, Sculpt Mode uses wrong base mesh with Subdiv modifier
3 changed files with 24 additions and 4 deletions

View File

@ -1154,7 +1154,8 @@ static void sculpt_geometry_preview_lines_draw(const uint gpuattr,
if (ss->preview_vert_index_count > 0) {
immBegin(GPU_PRIM_LINES, ss->preview_vert_index_count);
for (int i = 0; i < ss->preview_vert_index_count; i++) {
immVertex3fv(gpuattr, SCULPT_vertex_co_get(ss, ss->preview_vert_index_list[i]));
immVertex3fv(gpuattr,
SCULPT_vertex_co_for_grab_active_get(ss, ss->preview_vert_index_list[i]));
}
immEnd();
}
@ -1572,7 +1573,14 @@ static void paint_cursor_draw_3d_view_brush_cursor_inactive(PaintCursorContext *
/* Cursor location symmetry points. */
const float *active_vertex_co = SCULPT_active_vertex_co_get(pcontext->ss);
const float *active_vertex_co;
if (brush->sculpt_tool == SCULPT_TOOL_GRAB && brush->flag & BRUSH_GRAB_ACTIVE_VERTEX) {
active_vertex_co = SCULPT_vertex_co_for_grab_active_get(
pcontext->ss, SCULPT_active_vertex_get(pcontext->ss));
}
else {
active_vertex_co = SCULPT_active_vertex_co_get(pcontext->ss);
}
if (len_v3v3(active_vertex_co, pcontext->location) < pcontext->radius) {
immUniformColor3fvAlpha(pcontext->outline_col, pcontext->outline_alpha);
cursor_draw_point_with_symmetry(pcontext->pos,

View File

@ -204,6 +204,14 @@ const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, int index)
return SCULPT_vertex_co_get(ss, index);
}
const float *SCULPT_vertex_co_for_grab_active_get(SculptSession *ss, int index)
{
if (ss->mvert) {
return ss->mvert[index].co;
}
return SCULPT_vertex_co_get(ss, index);
}
void SCULPT_vertex_limit_surface_get(SculptSession *ss, int index, float r_co[3])
{
switch (BKE_pbvh_type(ss->pbvh)) {
@ -6694,7 +6702,8 @@ static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Bru
if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache)) {
if (tool == SCULPT_TOOL_GRAB && brush->flag & BRUSH_GRAB_ACTIVE_VERTEX) {
copy_v3_v3(cache->orig_grab_location, SCULPT_active_vertex_co_get(ss));
copy_v3_v3(cache->orig_grab_location,
SCULPT_vertex_co_for_grab_active_get(ss, SCULPT_active_vertex_get(ss)));
}
else {
copy_v3_v3(cache->orig_grab_location, cache->true_location);
@ -8366,7 +8375,7 @@ void SCULPT_geometry_preview_lines_update(bContext *C, SculptSession *ss, float
totpoints++;
if (!BLI_BITMAP_TEST(visited_vertices, to_v)) {
BLI_BITMAP_ENABLE(visited_vertices, to_v);
const float *co = SCULPT_vertex_co_get(ss, to_v);
const float *co = SCULPT_vertex_co_for_grab_active_get(ss, to_v);
if (len_squared_v3v3(brush_co, co) < radius * radius) {
BLI_gsqueue_push(not_visited_vertices, &to_v);
}

View File

@ -100,6 +100,9 @@ const float *SCULPT_vertex_color_get(SculptSession *ss, int index);
const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, int index);
void SCULPT_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3]);
/* Coordinates used for manipulating the base mesh when Grab Active Vertex is enabled. */
const float *SCULPT_vertex_co_for_grab_active_get(SculptSession *ss, int index);
/* Returns the info of the limit surface when Multires is available, otherwise it returns the
* current coordinate of the vertex. */
void SCULPT_vertex_limit_surface_get(SculptSession *ss, int index, float r_co[3]);