diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index 56b12ce6716..39ad6ea3d0e 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -17,6 +17,7 @@ #include "CLG_log.h" #include "BLI_array_utils.hh" +#include "BLI_bit_span_ops.hh" #include "BLI_blenlib.h" #include "BLI_dial_2d.h" #include "BLI_ghash.h" @@ -1334,12 +1335,20 @@ static void paint_mesh_restore_node(Object *ob, const undo::Type type, PBVHNode break; } case PBVH_GRIDS: { - PBVHVertexIter vd; - BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { - *CCG_elem_mask(&vd.key, vd.grid) = unode->mask[vd.i]; - break; + SubdivCCG &subdiv_ccg = *ss->subdiv_ccg; + const BitGroupVector<> grid_hidden = subdiv_ccg.grid_hidden; + const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg); + const Span grids = subdiv_ccg.grids; + int index = 0; + for (const int grid : unode->grids) { + CCGElem *elem = grids[grid]; + for (const int i : IndexRange(key.grid_area)) { + if (grid_hidden.is_empty() || !grid_hidden[grid][i]) { + *CCG_elem_offset_mask(&key, elem, i) = unode->mask[index]; + } + index++; + } } - BKE_pbvh_vertex_iter_end; break; } }