From a4073563c8efb7349dfd9ddb65660f6a6b5dc4d6 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 23 Apr 2024 22:26:55 -0400 Subject: [PATCH] Cleanup: Use references for sculpt undo and restore functions --- .../editors/sculpt_paint/paint_hide.cc | 16 +- .../editors/sculpt_paint/paint_mask.cc | 16 +- .../editors/sculpt_paint/paint_vertex.cc | 4 +- .../sculpt_paint/paint_vertex_color_ops.cc | 2 +- source/blender/editors/sculpt_paint/sculpt.cc | 64 ++--- .../editors/sculpt_paint/sculpt_detail.cc | 2 +- .../editors/sculpt_paint/sculpt_dyntopo.cc | 4 +- .../editors/sculpt_paint/sculpt_expand.cc | 6 +- .../editors/sculpt_paint/sculpt_face_set.cc | 20 +- .../sculpt_paint/sculpt_filter_mask.cc | 2 +- .../sculpt_paint/sculpt_filter_mesh.cc | 2 +- .../editors/sculpt_paint/sculpt_intern.hh | 2 +- .../editors/sculpt_paint/sculpt_mask_init.cc | 2 +- .../editors/sculpt_paint/sculpt_ops.cc | 10 +- .../editors/sculpt_paint/sculpt_project.cc | 2 +- .../editors/sculpt_paint/sculpt_transform.cc | 4 +- .../editors/sculpt_paint/sculpt_trim.cc | 4 +- .../editors/sculpt_paint/sculpt_undo.cc | 233 +++++++++--------- 18 files changed, 200 insertions(+), 195 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_hide.cc b/source/blender/editors/sculpt_paint/paint_hide.cc index b0adb9fb85c..ddfdb79162f 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.cc +++ b/source/blender/editors/sculpt_paint/paint_hide.cc @@ -134,7 +134,7 @@ void mesh_show_all(Object &object, const Span nodes) for (PBVHNode *node : nodes.slice(range)) { const Span verts = BKE_pbvh_node_get_vert_indices(node); if (std::any_of(verts.begin(), verts.end(), [&](const int i) { return hide_vert[i]; })) { - undo::push_node(&object, node, undo::Type::HideVert); + undo::push_node(object, node, undo::Type::HideVert); BKE_pbvh_node_mark_rebuild_draw(node); } } @@ -163,7 +163,7 @@ void grids_show_all(Depsgraph &depsgraph, Object &object, const Span })) { any_changed = true; - undo::push_node(&object, node, undo::Type::HideVert); + undo::push_node(object, node, undo::Type::HideVert); BKE_pbvh_node_mark_rebuild_draw(node); } } @@ -221,7 +221,7 @@ static void vert_hide_update(Object &object, } any_changed = true; - undo::push_node(&object, node, undo::Type::HideVert); + undo::push_node(object, node, undo::Type::HideVert); array_utils::scatter(new_hide.as_span(), verts, hide_vert.span); BKE_pbvh_node_mark_update_visibility(node); @@ -266,7 +266,7 @@ static void grid_hide_update(Depsgraph &depsgraph, } any_changed = true; - undo::push_node(&object, node, undo::Type::HideVert); + undo::push_node(object, node, undo::Type::HideVert); for (const int i : grids.index_range()) { grid_hidden[grids[i]].copy_from(new_hide[i].as_span()); @@ -327,7 +327,7 @@ static void partialvis_update_bmesh_nodes(Object *ob, bool any_changed = false; bool any_visible = false; - undo::push_node(ob, node, undo::Type::HideVert); + undo::push_node(*ob, node, undo::Type::HideVert); partialvis_update_bmesh_verts( BKE_pbvh_bmesh_node_unique_verts(node), action, vert_test_fn, &any_changed, &any_visible); @@ -619,7 +619,7 @@ static void invert_visibility_mesh(Object &object, const Span nodes) threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { Vector &faces = all_index_data.local(); for (PBVHNode *node : nodes.slice(range)) { - undo::push_node(&object, node, undo::Type::HideFace); + undo::push_node(object, node, undo::Type::HideFace); bke::pbvh::node_face_indices_calc_mesh(pbvh, *node, faces); for (const int face : faces) { hide_poly.span[face] = !hide_poly.span[face]; @@ -643,7 +643,7 @@ static void invert_visibility_grids(Depsgraph &depsgraph, threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { - undo::push_node(&object, node, undo::Type::HideVert); + undo::push_node(object, node, undo::Type::HideVert); for (const int i : BKE_pbvh_node_get_grid_indices(*node)) { bits::invert(grid_hidden[i]); } @@ -660,7 +660,7 @@ static void invert_visibility_bmesh(Object &object, const Span nodes { threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { - undo::push_node(&object, node, undo::Type::HideVert); + undo::push_node(object, node, undo::Type::HideVert); bool fully_hidden = true; for (BMVert *vert : BKE_pbvh_bmesh_node_unique_verts(node)) { BM_elem_flag_toggle(vert, BM_ELEM_HIDDEN); diff --git a/source/blender/editors/sculpt_paint/paint_mask.cc b/source/blender/editors/sculpt_paint/paint_mask.cc index fcd873a4c33..d9c2443ebfd 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.cc +++ b/source/blender/editors/sculpt_paint/paint_mask.cc @@ -219,7 +219,7 @@ static bool try_remove_mask_mesh(Object &object, const Span nodes) if (std::all_of(verts.begin(), verts.end(), [&](const int i) { return mask[i] == 0.0f; })) { continue; } - undo::push_node(&object, node, undo::Type::Mask); + undo::push_node(object, node, undo::Type::Mask); BKE_pbvh_node_mark_redraw(node); } }); @@ -250,7 +250,7 @@ static void fill_mask_mesh(Object &object, const float value, const Span nodes) ".sculpt_mask", bke::AttrDomain::Point); threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { - undo::push_node(&object, node, undo::Type::Mask); + undo::push_node(object, node, undo::Type::Mask); for (const int vert : BKE_pbvh_node_get_unique_vert_indices(node)) { if (!hide_vert.is_empty() && hide_vert[vert]) { continue; @@ -420,7 +420,7 @@ static void invert_mask_grids(Main &bmain, const Span grids = subdiv_ccg.grids; threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { - undo::push_node(&object, node, undo::Type::Mask); + undo::push_node(object, node, undo::Type::Mask); const Span grid_indices = BKE_pbvh_node_get_grid_indices(*node); if (grid_hidden.is_empty()) { @@ -456,7 +456,7 @@ static void invert_mask_bmesh(Object &object, const Span nodes) return; } - undo::push_node(&object, nodes.first(), undo::Type::Mask); + undo::push_node(object, nodes.first(), undo::Type::Mask); threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { for (BMVert *vert : BKE_pbvh_bmesh_node_unique_verts(node)) { @@ -584,7 +584,7 @@ static void mask_gesture_apply_task(gesture::GestureData &gesture_data, if (!any_masked) { any_masked = true; - undo::push_node(ob, node, undo::Type::Mask); + undo::push_node(*ob, node, undo::Type::Mask); if (is_multires) { BKE_pbvh_node_mark_positions_update(node); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index 9c5c303fe52..0ce82373dea 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -1787,7 +1787,7 @@ static void vpaint_paint_leaves(bContext *C, Span nodes) { for (PBVHNode *node : nodes) { - undo::push_node(ob, node, undo::Type::Color); + undo::push_node(*ob, node, undo::Type::Color); } const Brush *brush = ob->sculpt->cache->brush; @@ -2235,7 +2235,7 @@ static int vertex_color_set_exec(bContext *C, wmOperator *op) undo::push_begin(obact, op); Vector nodes = blender::bke::pbvh::search_gather(obact->sculpt->pbvh, {}); for (PBVHNode *node : nodes) { - undo::push_node(obact, node, undo::Type::Color); + undo::push_node(*obact, node, undo::Type::Color); } paint_object_attributes_active_color_fill_ex(obact, paintcol, true, affect_alpha); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc index d84e1532436..85fbf038e51 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc @@ -314,7 +314,7 @@ static void transform_active_color(bContext *C, Vector nodes = blender::bke::pbvh::search_gather(obact->sculpt->pbvh, {}); for (PBVHNode *node : nodes) { - undo::push_node(obact, node, undo::Type::Color); + undo::push_node(*obact, node, undo::Type::Color); } transform_active_color_data(*BKE_mesh_from_object(obact), transform_fn); diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index 791572e2e64..9880ccc1977 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -1229,7 +1229,7 @@ void SCULPT_orig_vert_data_init(SculptOrigVertData *data, blender::ed::sculpt_paint::undo::Type type) { using namespace blender::ed::sculpt_paint; - undo::Node *unode = undo::push_node(ob, node, type); + undo::Node *unode = undo::push_node(*ob, node, type); SCULPT_orig_vert_data_unode_init(data, ob, unode); } @@ -1297,12 +1297,12 @@ bool stroke_is_dyntopo(const SculptSession *ss, const Brush *brush) /** \name Sculpt Paint Mesh * \{ */ -static void restore_mask(Object *ob, const Span nodes) +static void restore_mask(Object &object, const Span nodes) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; switch (BKE_pbvh_type(ss->pbvh)) { case PBVH_FACES: { - Mesh &mesh = *static_cast(ob->data); + Mesh &mesh = *static_cast(object.data); bke::MutableAttributeAccessor attributes = mesh.attributes_for_write(); bke::SpanAttributeWriter mask = attributes.lookup_or_add_for_write_span( ".sculpt_mask", bke::AttrDomain::Point); @@ -1323,7 +1323,7 @@ static void restore_mask(Object *ob, const Span nodes) &ss->bm->vdata, CD_PROP_FLOAT, ".sculpt_mask"); if (offset != -1) { for (PBVHNode *node : nodes) { - if (undo::push_node(ob, node, undo::Type::Mask)) { + if (undo::push_node(object, node, undo::Type::Mask)) { for (BMVert *vert : BKE_pbvh_bmesh_node_unique_verts(node)) { const float orig_mask = BM_log_original_mask(ss->bm_log, vert); BM_ELEM_CD_SET_FLOAT(vert, offset, orig_mask); @@ -1361,12 +1361,12 @@ static void restore_mask(Object *ob, const Span nodes) } } -static void restore_color(Object *ob, const Span nodes) +static void restore_color(Object &object, const Span nodes) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; const auto restore_generic = [&](PBVHNode *node, undo::Node *unode) { SculptOrigVertData orig_vert_data; - SCULPT_orig_vert_data_unode_init(&orig_vert_data, ob, unode); + SCULPT_orig_vert_data_unode_init(&orig_vert_data, &object, unode); PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { SCULPT_orig_vert_data_update(&orig_vert_data, &vd); @@ -1388,7 +1388,7 @@ static void restore_color(Object *ob, const Span nodes) } case PBVH_BMESH: { for (PBVHNode *node : nodes) { - if (undo::Node *unode = undo::push_node(ob, node, undo::Type::Color)) { + if (undo::Node *unode = undo::push_node(object, node, undo::Type::Color)) { restore_generic(node, unode); } } @@ -1407,13 +1407,13 @@ static void restore_color(Object *ob, const Span nodes) } } -static void restore_face_set(Object *ob, const Span nodes) +static void restore_face_set(Object &object, const Span nodes) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; switch (BKE_pbvh_type(ss->pbvh)) { case PBVH_FACES: case PBVH_GRIDS: { - bke::SpanAttributeWriter attribute = face_set::ensure_face_sets_mesh(*ob); + bke::SpanAttributeWriter attribute = face_set::ensure_face_sets_mesh(object); threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { if (undo::Node *unode = undo::get_node(node, undo::Type::FaceSet)) { @@ -1432,9 +1432,9 @@ static void restore_face_set(Object *ob, const Span nodes) } } -static void restore_position(Object *ob, const Span nodes) +static void restore_position(Object &object, const Span nodes) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; switch (BKE_pbvh_type(ss->pbvh)) { case PBVH_FACES: { MutableSpan positions = BKE_pbvh_get_vert_positions(ss->pbvh); @@ -1451,7 +1451,7 @@ static void restore_position(Object *ob, const Span nodes) } case PBVH_BMESH: { for (PBVHNode *node : nodes) { - if (undo::push_node(ob, node, undo::Type::Position)) { + if (undo::push_node(object, node, undo::Type::Position)) { for (BMVert *vert : BKE_pbvh_bmesh_node_unique_verts(node)) { copy_v3_v3(vert->co, BM_log_original_vert_co(ss->bm_log, vert)); } @@ -1492,31 +1492,31 @@ static void restore_position(Object *ob, const Span nodes) bke::pbvh::update_normals(*ss->pbvh, ss->subdiv_ccg); } -static void restore_from_undo_step(Sculpt *sd, Object *ob) +static void restore_from_undo_step(const Sculpt &sd, Object &object) { - SculptSession *ss = ob->sculpt; - Brush *brush = BKE_paint_brush(&sd->paint); + SculptSession *ss = object.sculpt; + const Brush *brush = BKE_paint_brush_for_read(&sd.paint); Vector nodes = bke::pbvh::search_gather(ss->pbvh, {}); switch (brush->sculpt_tool) { case SCULPT_TOOL_MASK: - restore_mask(ob, nodes); + restore_mask(object, nodes); break; case SCULPT_TOOL_PAINT: case SCULPT_TOOL_SMEAR: - restore_color(ob, nodes); + restore_color(object, nodes); break; case SCULPT_TOOL_DRAW_FACE_SETS: if (ss->cache->alt_smooth) { - restore_position(ob, nodes); + restore_position(object, nodes); } else { - restore_face_set(ob, nodes); + restore_face_set(object, nodes); } break; default: - restore_position(ob, nodes); + restore_position(object, nodes); break; } /* Disable multi-threading when dynamic-topology is enabled. Otherwise, @@ -1882,7 +1882,7 @@ static void calc_area_normal_and_center_task(Object *ob, bool normal_test_r, area_test_r; if (ss->cache && !ss->cache->accum) { - unode = undo::push_node(ob, node, undo::Type::Position); + unode = undo::push_node(*ob, node, undo::Type::Position); use_original = (!unode->position.is_empty() || unode->bm_entry); } @@ -3299,7 +3299,7 @@ static void sculpt_topology_update(Sculpt *sd, } for (PBVHNode *node : nodes) { - undo::push_node(ob, + undo::push_node(*ob, node, brush->sculpt_tool == SCULPT_TOOL_MASK ? undo::Type::Mask : undo::Type::Position); @@ -3340,15 +3340,15 @@ static void do_brush_action_task(Object *ob, const Brush *brush, PBVHNode *node) need_coords = true; } else { - undo::push_node(ob, node, undo::Type::FaceSet); + undo::push_node(*ob, node, undo::Type::FaceSet); } } else if (brush->sculpt_tool == SCULPT_TOOL_MASK) { - undo::push_node(ob, node, undo::Type::Mask); + undo::push_node(*ob, node, undo::Type::Mask); BKE_pbvh_node_mark_update_mask(node); } else if (SCULPT_tool_is_paint(brush->sculpt_tool)) { - undo::push_node(ob, node, undo::Type::Color); + undo::push_node(*ob, node, undo::Type::Color); BKE_pbvh_node_mark_update_color(node); } else { @@ -3356,7 +3356,7 @@ static void do_brush_action_task(Object *ob, const Brush *brush, PBVHNode *node) } if (need_coords) { - undo::push_node(ob, node, undo::Type::Position); + undo::push_node(*ob, node, undo::Type::Position); BKE_pbvh_node_mark_update(node); } } @@ -3689,7 +3689,7 @@ static void sculpt_combine_proxies_node(Object &object, float(*orco)[3] = nullptr; if (use_orco && !ss->bm) { orco = reinterpret_cast( - (undo::push_node(&object, &node, undo::Type::Position)->position.data())); + (undo::push_node(object, &node, undo::Type::Position)->position.data())); } MutableSpan proxies = BKE_pbvh_node_get_proxies(&node); @@ -5277,7 +5277,7 @@ static void sculpt_restore_mesh(Sculpt *sd, Object *ob) (brush->flag & BRUSH_DRAG_DOT)) { - restore_from_undo_step(sd, ob); + restore_from_undo_step(*sd, *ob); if (ss->cache) { MEM_SAFE_FREE(ss->cache->layer_displacement_factor); @@ -5816,7 +5816,7 @@ static void sculpt_brush_stroke_cancel(bContext *C, wmOperator *op) /* XXX Canceling strokes that way does not work with dynamic topology, * user will have to do real undo for now. See #46456. */ if (ss->cache && !dyntopo::stroke_is_dyntopo(ss, brush)) { - restore_from_undo_step(sd, ob); + restore_from_undo_step(*sd, *ob); } paint_stroke_cancel(C, op, static_cast(op->customdata)); diff --git a/source/blender/editors/sculpt_paint/sculpt_detail.cc b/source/blender/editors/sculpt_paint/sculpt_detail.cc index 5742cf8f4e5..1a7498fc5d5 100644 --- a/source/blender/editors/sculpt_paint/sculpt_detail.cc +++ b/source/blender/editors/sculpt_paint/sculpt_detail.cc @@ -124,7 +124,7 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op) BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail); undo::push_begin(ob, op); - undo::push_node(ob, nullptr, undo::Type::Position); + undo::push_node(*ob, nullptr, undo::Type::Position); const double start_time = BLI_time_now_seconds(); diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc b/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc index 6fea1b50c30..be9521bdf03 100644 --- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc @@ -210,7 +210,7 @@ void disable_with_undo(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object * const bool use_undo = G.background ? (ED_undo_stack_get() != nullptr) : true; if (use_undo) { undo::push_begin_ex(ob, "Dynamic topology disable"); - undo::push_node(ob, nullptr, undo::Type::DyntopoEnd); + undo::push_node(*ob, nullptr, undo::Type::DyntopoEnd); } SCULPT_dynamic_topology_disable_ex(bmain, depsgraph, scene, ob, nullptr); if (use_undo) { @@ -230,7 +230,7 @@ static void sculpt_dynamic_topology_enable_with_undo(Main *bmain, Depsgraph *dep } enable_ex(bmain, depsgraph, ob); if (use_undo) { - undo::push_node(ob, nullptr, undo::Type::DyntopoBegin); + undo::push_node(*ob, nullptr, undo::Type::DyntopoBegin); undo::push_end(ob); } } diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.cc b/source/blender/editors/sculpt_paint/sculpt_expand.cc index 136aec35539..3a2b175d0b8 100644 --- a/source/blender/editors/sculpt_paint/sculpt_expand.cc +++ b/source/blender/editors/sculpt_paint/sculpt_expand.cc @@ -2037,17 +2037,17 @@ static void sculpt_expand_undo_push(Object *ob, Cache *expand_cache) switch (expand_cache->target) { case SCULPT_EXPAND_TARGET_MASK: for (PBVHNode *node : nodes) { - undo::push_node(ob, node, undo::Type::Mask); + undo::push_node(*ob, node, undo::Type::Mask); } break; case SCULPT_EXPAND_TARGET_FACE_SETS: for (PBVHNode *node : nodes) { - undo::push_node(ob, node, undo::Type::FaceSet); + undo::push_node(*ob, node, undo::Type::FaceSet); } break; case SCULPT_EXPAND_TARGET_COLORS: for (PBVHNode *node : nodes) { - undo::push_node(ob, node, undo::Type::Color); + undo::push_node(*ob, node, undo::Type::Color); } break; } diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc index b132413848c..a498886e21e 100644 --- a/source/blender/editors/sculpt_paint/sculpt_face_set.cc +++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc @@ -252,7 +252,7 @@ static void do_draw_face_sets_brush_faces(Object *ob, BKE_pbvh_vertex_iter_end; if (changed) { - undo::push_node(ob, node, undo::Type::FaceSet); + undo::push_node(*ob, node, undo::Type::FaceSet); } } }); @@ -310,7 +310,7 @@ static void do_draw_face_sets_brush_grids(Object *ob, BKE_pbvh_vertex_iter_end; if (changed) { - undo::push_node(ob, node, undo::Type::FaceSet); + undo::push_node(*ob, node, undo::Type::FaceSet); } } }); @@ -397,7 +397,7 @@ static void do_draw_face_sets_brush_bmesh(Object *ob, } if (changed) { - undo::push_node(ob, node, undo::Type::FaceSet); + undo::push_node(*ob, node, undo::Type::FaceSet); } } }); @@ -521,7 +521,7 @@ static void face_sets_update(Object &object, continue; } - undo::push_node(&object, node, undo::Type::FaceSet); + undo::push_node(object, node, undo::Type::FaceSet); array_utils::scatter(new_face_sets.as_span(), faces, face_sets.span); BKE_pbvh_node_mark_update_face_sets(node); } @@ -559,7 +559,7 @@ static void clear_face_sets(Object &object, const Span nodes) return face_sets[face] != default_face_set; })) { - undo::push_node(&object, node, undo::Type::FaceSet); + undo::push_node(object, node, undo::Type::FaceSet); BKE_pbvh_node_mark_update_face_sets(node); } } @@ -826,7 +826,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) undo::push_begin(ob, op); for (PBVHNode *node : nodes) { - undo::push_node(ob, node, undo::Type::FaceSet); + undo::push_node(*ob, node, undo::Type::FaceSet); } const float threshold = RNA_float_get(op->ptr, "threshold"); @@ -1026,7 +1026,7 @@ static void face_hide_update(Object &object, } any_changed = true; - undo::push_node(&object, node, undo::Type::HideFace); + undo::push_node(object, node, undo::Type::HideFace); array_utils::scatter(new_hide.as_span(), faces, hide_poly.span); BKE_pbvh_node_mark_update_visibility(node); } @@ -1512,7 +1512,7 @@ static void sculpt_face_set_edit_modify_coordinates( undo::push_begin(ob, op); for (PBVHNode *node : nodes) { BKE_pbvh_node_mark_update(node); - undo::push_node(ob, node, undo::Type::Position); + undo::push_node(*ob, node, undo::Type::Position); } switch (mode) { case EditMode::FairPositions: @@ -1710,7 +1710,7 @@ static void face_set_gesture_apply_mesh(gesture::GestureData &gesture_data, threading::parallel_for(gesture_data.nodes.index_range(), 1, [&](const IndexRange range) { TLS &tls = all_tls.local(); for (PBVHNode *node : nodes.slice(range)) { - undo::push_node(gesture_data.vc.obact, node, undo::Type::FaceSet); + undo::push_node(*gesture_data.vc.obact, node, undo::Type::FaceSet); const Span node_faces = BKE_pbvh_type(&pbvh) == PBVH_FACES ? bke::pbvh::node_face_indices_calc_mesh(pbvh, *node, tls.face_indices) : @@ -1751,7 +1751,7 @@ static void face_set_gesture_apply_bmesh(gesture::GestureData &gesture_data, threading::parallel_for(gesture_data.nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { - undo::push_node(gesture_data.vc.obact, node, undo::Type::FaceSet); + undo::push_node(*gesture_data.vc.obact, node, undo::Type::FaceSet); bool any_updated = false; for (BMFace *face : BKE_pbvh_bmesh_node_faces(node)) { diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc b/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc index a868f3ef92b..e90ab514a6a 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc @@ -171,7 +171,7 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op) undo::push_begin(ob, op); for (PBVHNode *node : nodes) { - undo::push_node(ob, node, undo::Type::Mask); + undo::push_node(*ob, node, undo::Type::Mask); } Array prev_mask; diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc index a4d5e7308fc..cd0b87f13e4 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc @@ -130,7 +130,7 @@ void cache_init(bContext *C, } for (const int i : ss->filter_cache->nodes.index_range()) { - undo::push_node(ob, ss->filter_cache->nodes[i], undo_type); + undo::push_node(*ob, ss->filter_cache->nodes[i], undo_type); } /* Setup orientation matrices. */ diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.hh b/source/blender/editors/sculpt_paint/sculpt_intern.hh index 03128ff300f..a78984a05fc 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.hh +++ b/source/blender/editors/sculpt_paint/sculpt_intern.hh @@ -1612,7 +1612,7 @@ void SCULPT_cache_free(blender::ed::sculpt_paint::StrokeCache *cache); namespace blender::ed::sculpt_paint::undo { -undo::Node *push_node(const Object *ob, const PBVHNode *node, undo::Type type); +undo::Node *push_node(const Object &object, const PBVHNode *node, undo::Type type); undo::Node *get_node(const PBVHNode *node, undo::Type type); /** diff --git a/source/blender/editors/sculpt_paint/sculpt_mask_init.cc b/source/blender/editors/sculpt_paint/sculpt_mask_init.cc index 0efd49e3877..3efa14decc4 100644 --- a/source/blender/editors/sculpt_paint/sculpt_mask_init.cc +++ b/source/blender/editors/sculpt_paint/sculpt_mask_init.cc @@ -53,7 +53,7 @@ static void mask_init_task(Object *ob, { SculptSession *ss = ob->sculpt; PBVHVertexIter vd; - undo::push_node(ob, node, undo::Type::Mask); + undo::push_node(*ob, node, undo::Type::Mask); BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { float mask; switch (mode) { diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.cc b/source/blender/editors/sculpt_paint/sculpt_ops.cc index 6c1c9fff2f8..729ca2cb9a2 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/sculpt_ops.cc @@ -199,7 +199,7 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *op) * are logged as added (as opposed to attempting to store just the * parts that symmetrize modifies). */ undo::push_begin(ob, op); - undo::push_node(ob, nullptr, undo::Type::DyntopoSymmetrize); + undo::push_node(*ob, nullptr, undo::Type::DyntopoSymmetrize); BM_log_before_all_removed(ss->bm, ss->bm_log); BM_mesh_toolflags_set(ss->bm, true); @@ -417,7 +417,7 @@ void ED_object_sculptmode_enter_ex(Main *bmain, } dyntopo::enable_ex(bmain, depsgraph, ob); if (has_undo) { - undo::push_node(ob, nullptr, undo::Type::DyntopoBegin); + undo::push_node(*ob, nullptr, undo::Type::DyntopoBegin); undo::push_end(ob); } } @@ -758,7 +758,7 @@ static void do_mask_by_color_contiguous_update_node(Object *ob, using namespace blender::ed::sculpt_paint; SculptSession *ss = ob->sculpt; - undo::push_node(ob, node, undo::Type::Mask); + undo::push_node(*ob, node, undo::Type::Mask); bool update_node = false; PBVHVertexIter vd; @@ -869,7 +869,7 @@ static void do_mask_by_color_task(Object *ob, using namespace blender::ed::sculpt_paint; SculptSession *ss = ob->sculpt; - undo::push_node(ob, node, undo::Type::Mask); + undo::push_node(*ob, node, undo::Type::Mask); bool update_node = false; float active_color[4]; @@ -1044,7 +1044,7 @@ static void sculpt_bake_cavity_exec_task(Object *ob, SculptSession *ss = ob->sculpt; PBVHVertexIter vd; - undo::push_node(ob, node, undo::Type::Mask); + undo::push_node(*ob, node, undo::Type::Mask); auto_mask::NodeData automask_data = auto_mask::node_begin(*ob, &automasking, *node); diff --git a/source/blender/editors/sculpt_paint/sculpt_project.cc b/source/blender/editors/sculpt_paint/sculpt_project.cc index 2c7a3d3b2dd..a611dbdd699 100644 --- a/source/blender/editors/sculpt_paint/sculpt_project.cc +++ b/source/blender/editors/sculpt_paint/sculpt_project.cc @@ -35,7 +35,7 @@ static void apply_projection(gesture::GestureData &gesture_data, PBVHNode *node) PBVHVertexIter vd; bool any_updated = false; - undo::push_node(gesture_data.vc.obact, node, undo::Type::Position); + undo::push_node(*gesture_data.vc.obact, node, undo::Type::Position); BKE_pbvh_vertex_iter_begin (gesture_data.ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { float vertex_normal[3]; diff --git a/source/blender/editors/sculpt_paint/sculpt_transform.cc b/source/blender/editors/sculpt_paint/sculpt_transform.cc index 4eff3bd42ca..faefda0e3c5 100644 --- a/source/blender/editors/sculpt_paint/sculpt_transform.cc +++ b/source/blender/editors/sculpt_paint/sculpt_transform.cc @@ -149,7 +149,7 @@ static void sculpt_transform_task(Object *ob, const float transform_mats[8][4][4 PBVHVertexIter vd; - undo::push_node(ob, node, undo::Type::Position); + undo::push_node(*ob, node, undo::Type::Position); BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { SCULPT_orig_vert_data_update(&orig_data, &vd); float *start_co; @@ -220,7 +220,7 @@ static void sculpt_elastic_transform_task(Object *ob, const float poisson_ratio = 0.4f; BKE_kelvinlet_init_params(¶ms, transform_radius, force, shear_modulus, poisson_ratio); - undo::push_node(ob, node, undo::Type::Position); + undo::push_node(*ob, node, undo::Type::Position); PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { diff --git a/source/blender/editors/sculpt_paint/sculpt_trim.cc b/source/blender/editors/sculpt_paint/sculpt_trim.cc index e960a432b13..9295e87f478 100644 --- a/source/blender/editors/sculpt_paint/sculpt_trim.cc +++ b/source/blender/editors/sculpt_paint/sculpt_trim.cc @@ -454,7 +454,7 @@ static void gesture_begin(bContext &C, gesture::GestureData &gesture_data) generate_geometry(gesture_data); SCULPT_topology_islands_invalidate(ss); BKE_sculpt_update_object_for_edit(depsgraph, gesture_data.vc.obact, false); - undo::push_node(gesture_data.vc.obact, nullptr, undo::Type::Geometry); + undo::push_node(*gesture_data.vc.obact, nullptr, undo::Type::Geometry); } static int bm_face_isect_pair(BMFace *f, void * /*user_data*/) @@ -591,7 +591,7 @@ static void gesture_end(bContext & /*C*/, gesture::GestureData &gesture_data) free_geometry(gesture_data); - undo::push_node(gesture_data.vc.obact, nullptr, undo::Type::Geometry); + undo::push_node(*gesture_data.vc.obact, nullptr, undo::Type::Geometry); BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL); DEG_id_tag_update(&gesture_data.vc.obact->id, ID_RECALC_GEOMETRY); } diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.cc b/source/blender/editors/sculpt_paint/sculpt_undo.cc index ff0b83a687a..4704fe98d89 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_undo.cc @@ -157,7 +157,7 @@ struct SculptUndoStep { }; static UndoSculpt *get_nodes(); -static void sculpt_save_active_attribute(Object *ob, SculptAttrRef *attr); +static void sculpt_save_active_attribute(Object &object, SculptAttrRef *attr); static UndoSculpt *sculpt_undosys_step_get_nodes(UndoStep *us_p); #ifdef SCULPT_UNDO_DEBUG @@ -193,7 +193,7 @@ static void print_sculpt_node(Object *ob, Node *node) printf(" %s:%s {applied=%d}\n", undo_type_to_str(node->type), node->idname, node->applied); if (node->bm_entry) { - BM_log_print_entry(ob->sculpt ? ob->sculpt->bm : nullptr, node->bm_entry); + BM_log_print_entry(object.sculpt ? object.sculpt->bm : nullptr, node->bm_entry); } } @@ -413,10 +413,13 @@ static bool restore_deformed( return false; } -static bool restore_coords( - bContext *C, Object *ob, Depsgraph *depsgraph, Node &unode, MutableSpan modified_verts) +static bool restore_coords(bContext *C, + Object &object, + Depsgraph *depsgraph, + Node &unode, + MutableSpan modified_verts) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; SubdivCCG *subdiv_ccg = ss->subdiv_ccg; if (unode.mesh_verts_num) { @@ -425,14 +428,14 @@ static bool restore_coords( if (ss->shapekey_active && !STREQ(ss->shapekey_active->name, unode.shapeName)) { /* Shape key has been changed before calling undo operator. */ - Key *key = BKE_key_from_object(ob); + Key *key = BKE_key_from_object(&object); KeyBlock *kb = key ? BKE_keyblock_find_name(key, unode.shapeName) : nullptr; if (kb) { - ob->shapenr = BLI_findindex(&key->block, kb) + 1; + object.shapenr = BLI_findindex(&key->block, kb) + 1; - BKE_sculpt_update_object_for_edit(depsgraph, ob, false); - WM_event_add_notifier(C, NC_OBJECT | ND_DATA, ob); + BKE_sculpt_update_object_for_edit(depsgraph, &object, false); + WM_event_add_notifier(C, NC_OBJECT | ND_DATA, &object); } else { /* Key has been removed -- skip this undo node. */ @@ -445,7 +448,7 @@ static bool restore_coords( MutableSpan positions = ss->vert_positions; if (ss->shapekey_active) { - float(*vertCos)[3] = BKE_keyblock_convert_to_vertcos(ob, ss->shapekey_active); + float(*vertCos)[3] = BKE_keyblock_convert_to_vertcos(&object, ss->shapekey_active); MutableSpan key_positions(reinterpret_cast(vertCos), ss->shapekey_active->totelem); if (!unode.orig_position.is_empty()) { @@ -467,7 +470,7 @@ static bool restore_coords( } /* Propagate new coords to keyblock. */ - SCULPT_vertcos_to_key(ob, ss->shapekey_active, key_positions); + SCULPT_vertcos_to_key(&object, ss->shapekey_active, key_positions); /* PBVH uses its own vertex array, so coords should be */ /* propagated to PBVH here. */ @@ -518,13 +521,13 @@ static bool restore_coords( return true; } -static bool restore_hidden(Object *ob, Node &unode, MutableSpan modified_vertices) +static bool restore_hidden(Object &object, Node &unode, MutableSpan modified_vertices) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; SubdivCCG *subdiv_ccg = ss->subdiv_ccg; if (unode.mesh_verts_num) { - Mesh &mesh = *static_cast(ob->data); + Mesh &mesh = *static_cast(object.data); bke::MutableAttributeAccessor attributes = mesh.attributes_for_write(); bke::SpanAttributeWriter hide_vert = attributes.lookup_or_add_for_write_span( ".hide_vert", bke::AttrDomain::Point); @@ -586,9 +589,9 @@ static bool restore_hidden_face(Object &object, Node &unode, MutableSpan m return modified; } -static bool restore_color(Object *ob, Node &unode, MutableSpan modified_vertices) +static bool restore_color(Object &object, Node &unode, MutableSpan modified_vertices) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; bool modified = false; @@ -600,7 +603,7 @@ static bool restore_color(Object *ob, Node &unode, MutableSpan modified_ve modified = true; } - Mesh *mesh = BKE_object_get_original_mesh(ob); + Mesh *mesh = BKE_object_get_original_mesh(&object); if (!unode.loop_col.is_empty() && unode.mesh_corners_num == mesh->corners_num) { BKE_pbvh_swap_colors(ss->pbvh, unode.corner_indices, unode.loop_col); @@ -614,10 +617,10 @@ static bool restore_color(Object *ob, Node &unode, MutableSpan modified_ve return modified; } -static bool restore_mask(Object *ob, Node &unode, MutableSpan modified_vertices) +static bool restore_mask(Object &object, Node &unode, MutableSpan modified_vertices) { - Mesh *mesh = BKE_object_get_original_mesh(ob); - SculptSession *ss = ob->sculpt; + Mesh *mesh = BKE_object_get_original_mesh(&object); + SculptSession *ss = object.sculpt; SubdivCCG *subdiv_ccg = ss->subdiv_ccg; if (unode.mesh_verts_num) { @@ -656,11 +659,13 @@ static bool restore_mask(Object *ob, Node &unode, MutableSpan modified_ver return true; } -static bool restore_face_sets(Object *ob, Node &unode, MutableSpan modified_face_set_faces) +static bool restore_face_sets(Object &object, + Node &unode, + MutableSpan modified_face_set_faces) { const Span face_indices = unode.face_indices; - bke::SpanAttributeWriter face_sets = face_set::ensure_face_sets_mesh(*ob); + bke::SpanAttributeWriter face_sets = face_set::ensure_face_sets_mesh(object); bool modified = false; for (const int i : face_indices.index_range()) { const int face = face_indices[i]; @@ -675,7 +680,7 @@ static bool restore_face_sets(Object *ob, Node &unode, MutableSpan modifie return modified; } -static void bmesh_restore_generic(Node &unode, Object *ob, SculptSession *ss) +static void bmesh_restore_generic(Node &unode, Object &object, SculptSession *ss) { if (unode.applied) { BM_log_undo(ss->bm, ss->bm_log); @@ -693,17 +698,17 @@ static void bmesh_restore_generic(Node &unode, Object *ob, SculptSession *ss) } } else { - SCULPT_pbvh_clear(ob); + SCULPT_pbvh_clear(&object); } } /* Create empty sculpt BMesh and enable logging. */ -static void bmesh_enable(Object *ob, Node &unode) +static void bmesh_enable(Object &object, Node &unode) { - SculptSession *ss = ob->sculpt; - Mesh *mesh = static_cast(ob->data); + SculptSession *ss = object.sculpt; + Mesh *mesh = static_cast(object.data); - SCULPT_pbvh_clear(ob); + SCULPT_pbvh_clear(&object); /* Create empty BMesh and enable logging. */ BMeshCreateParams bmesh_create_params{}; @@ -718,14 +723,14 @@ static void bmesh_enable(Object *ob, Node &unode) ss->bm_log = BM_log_from_existing_entries_create(ss->bm, unode.bm_entry); } -static void bmesh_restore_begin(bContext *C, Node &unode, Object *ob, SculptSession *ss) +static void bmesh_restore_begin(bContext *C, Node &unode, Object &object, SculptSession *ss) { if (unode.applied) { dyntopo::disable(C, &unode); unode.applied = false; } else { - bmesh_enable(ob, unode); + bmesh_enable(object, unode); /* Restore the mesh from the first log entry. */ BM_log_redo(ss->bm, ss->bm_log); @@ -734,10 +739,10 @@ static void bmesh_restore_begin(bContext *C, Node &unode, Object *ob, SculptSess } } -static void bmesh_restore_end(bContext *C, Node &unode, Object *ob, SculptSession *ss) +static void bmesh_restore_end(bContext *C, Node &unode, Object &object, SculptSession *ss) { if (unode.applied) { - bmesh_enable(ob, unode); + bmesh_enable(object, unode); /* Restore the mesh from the last log entry. */ BM_log_undo(ss->bm, ss->bm_log); @@ -751,9 +756,9 @@ static void bmesh_restore_end(bContext *C, Node &unode, Object *ob, SculptSessio } } -static void store_geometry_data(NodeGeometry *geometry, const Object *object) +static void store_geometry_data(NodeGeometry *geometry, const Object &object) { - const Mesh *mesh = static_cast(object->data); + const Mesh *mesh = static_cast(object.data); BLI_assert(!geometry->is_initialized); geometry->is_initialized = true; @@ -774,9 +779,9 @@ static void store_geometry_data(NodeGeometry *geometry, const Object *object) geometry->faces_num = mesh->faces_num; } -static void restore_geometry_data(NodeGeometry *geometry, Object *object) +static void restore_geometry_data(NodeGeometry *geometry, Object &object) { - Mesh *mesh = static_cast(object->data); + Mesh *mesh = static_cast(object.data); BLI_assert(geometry->is_initialized); @@ -809,10 +814,10 @@ static void geometry_free_data(NodeGeometry *geometry) &geometry->face_offsets_sharing_info); } -static void restore_geometry(Node &unode, Object *object) +static void restore_geometry(Node &unode, Object &object) { if (unode.geometry_clear_pbvh) { - SCULPT_pbvh_clear(object); + SCULPT_pbvh_clear(&object); } if (unode.applied) { @@ -829,19 +834,19 @@ static void restore_geometry(Node &unode, Object *object) * * Returns true if this was a dynamic-topology undo step, otherwise * returns false to indicate the non-dyntopo code should run. */ -static int bmesh_restore(bContext *C, Node &unode, Object *ob, SculptSession *ss) +static int bmesh_restore(bContext *C, Node &unode, Object &object, SculptSession *ss) { switch (unode.type) { case Type::DyntopoBegin: - bmesh_restore_begin(C, unode, ob, ss); + bmesh_restore_begin(C, unode, object, ss); return true; case Type::DyntopoEnd: - bmesh_restore_end(C, unode, ob, ss); + bmesh_restore_end(C, unode, object, ss); return true; default: if (ss->bm_log) { - bmesh_restore_generic(unode, ob, ss); + bmesh_restore_generic(unode, object, ss); return true; } break; @@ -865,14 +870,14 @@ static int bmesh_restore(bContext *C, Node &unode, Object *ob, SculptSession *ss * so if the object's modifier stack references other object it is all fine. */ static void refine_subdiv(Depsgraph *depsgraph, SculptSession *ss, - Object *object, + Object &object, bke::subdiv::Subdiv *subdiv) { Array deformed_verts = BKE_multires_create_deformed_base_mesh_vert_coords( - depsgraph, object, ss->multires.modifier); + depsgraph, &object, ss->multires.modifier); bke::subdiv::eval_refine_from_mesh(subdiv, - static_cast(object->data), + static_cast(object.data), reinterpret_cast(deformed_verts.data())); } @@ -882,8 +887,8 @@ static void restore_list(bContext *C, Depsgraph *depsgraph, UndoSculpt &usculpt) ViewLayer *view_layer = CTX_data_view_layer(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); BKE_view_layer_synced_ensure(scene, view_layer); - Object *ob = BKE_view_layer_active_object_get(view_layer); - SculptSession *ss = ob->sculpt; + Object &object = *BKE_view_layer_active_object_get(view_layer); + SculptSession *ss = object.sculpt; SubdivCCG *subdiv_ccg = ss->subdiv_ccg; bool clear_automask_cache = false; @@ -907,10 +912,10 @@ static void restore_list(bContext *C, Depsgraph *depsgraph, UndoSculpt &usculpt) * ensure object is updated after the node is handled. */ const Node *first_unode = usculpt.nodes.first().get(); if (first_unode->type != Type::Geometry) { - BKE_sculpt_update_object_for_edit(depsgraph, ob, false); + BKE_sculpt_update_object_for_edit(depsgraph, &object, false); } - if (bmesh_restore(C, *usculpt.nodes.first(), ob, ss)) { + if (bmesh_restore(C, *usculpt.nodes.first(), object, ss)) { return; } } @@ -936,7 +941,7 @@ static void restore_list(bContext *C, Depsgraph *depsgraph, UndoSculpt &usculpt) Vector modified_faces_face_set; Vector modified_grids; for (std::unique_ptr &unode : usculpt.nodes) { - if (!STREQ(unode->idname, ob->id.name)) { + if (!STREQ(unode->idname, object.id.name)) { continue; } @@ -959,44 +964,44 @@ static void restore_list(bContext *C, Depsgraph *depsgraph, UndoSculpt &usculpt) switch (unode->type) { case Type::Position: modified_verts_position.resize(ss->totvert, false); - if (restore_coords(C, ob, depsgraph, *unode, modified_verts_position)) { + if (restore_coords(C, object, depsgraph, *unode, modified_verts_position)) { changed_position = true; } break; case Type::HideVert: modified_verts_hide.resize(ss->totvert, false); - if (restore_hidden(ob, *unode, modified_verts_hide)) { + if (restore_hidden(object, *unode, modified_verts_hide)) { changed_hide_vert = true; } break; case Type::HideFace: modified_faces_hide.resize(ss->totfaces, false); - if (restore_hidden_face(*ob, *unode, modified_faces_hide)) { + if (restore_hidden_face(object, *unode, modified_faces_hide)) { changed_hide_face = true; } break; case Type::Mask: modified_verts_mask.resize(ss->totvert, false); - if (restore_mask(ob, *unode, modified_verts_mask)) { + if (restore_mask(object, *unode, modified_verts_mask)) { changed_mask = true; } break; case Type::FaceSet: modified_faces_face_set.resize(ss->totfaces, false); - if (restore_face_sets(ob, *unode, modified_faces_face_set)) { + if (restore_face_sets(object, *unode, modified_faces_face_set)) { changed_face_sets = true; } break; case Type::Color: modified_verts_color.resize(ss->totvert, false); - if (restore_color(ob, *unode, modified_verts_color)) { + if (restore_color(object, *unode, modified_verts_color)) { changed_color = true; } break; case Type::Geometry: - restore_geometry(*unode, ob); + restore_geometry(*unode, object); changed_all_geometry = true; - BKE_sculpt_update_object_for_edit(depsgraph, ob, false); + BKE_sculpt_update_object_for_edit(depsgraph, &object, false); break; case Type::DyntopoBegin: @@ -1009,7 +1014,7 @@ static void restore_list(bContext *C, Depsgraph *depsgraph, UndoSculpt &usculpt) if (use_multires_undo) { for (std::unique_ptr &unode : usculpt.nodes) { - if (!STREQ(unode->idname, ob->id.name)) { + if (!STREQ(unode->idname, object.id.name)) { continue; } modified_grids.resize(unode->mesh_grids_num, false); @@ -1018,10 +1023,10 @@ static void restore_list(bContext *C, Depsgraph *depsgraph, UndoSculpt &usculpt) } if (subdiv_ccg != nullptr && changed_all_geometry) { - refine_subdiv(depsgraph, ss, ob, subdiv_ccg->subdiv); + refine_subdiv(depsgraph, ss, object, subdiv_ccg->subdiv); } - DEG_id_tag_update(&ob->id, ID_RECALC_SHADING); + DEG_id_tag_update(&object.id, ID_RECALC_SHADING); if (!changed_position && !changed_hide_vert && !changed_hide_face && !changed_mask && !changed_face_sets && !changed_color) @@ -1060,37 +1065,37 @@ static void restore_list(bContext *C, Depsgraph *depsgraph, UndoSculpt &usculpt) bke::pbvh::update_mask(*ss->pbvh); } if (changed_hide_face) { - hide::sync_all_from_faces(*ob); + hide::sync_all_from_faces(object); bke::pbvh::update_visibility(*ss->pbvh); } if (changed_hide_vert) { if (ELEM(BKE_pbvh_type(ss->pbvh), PBVH_FACES, PBVH_GRIDS)) { - Mesh &mesh = *static_cast(ob->data); + Mesh &mesh = *static_cast(object.data); BKE_pbvh_sync_visibility_from_verts(ss->pbvh, &mesh); } bke::pbvh::update_visibility(*ss->pbvh); } - if (BKE_sculpt_multires_active(scene, ob)) { + if (BKE_sculpt_multires_active(scene, &object)) { if (changed_hide_vert) { - multires_mark_as_modified(depsgraph, ob, MULTIRES_HIDDEN_MODIFIED); + multires_mark_as_modified(depsgraph, &object, MULTIRES_HIDDEN_MODIFIED); } else if (changed_position) { - multires_mark_as_modified(depsgraph, ob, MULTIRES_COORDS_MODIFIED); + multires_mark_as_modified(depsgraph, &object, MULTIRES_COORDS_MODIFIED); } } - const bool tag_update = ID_REAL_USERS(ob->data) > 1 || - !BKE_sculptsession_use_pbvh_draw(ob, rv3d) || ss->shapekey_active || + const bool tag_update = ID_REAL_USERS(object.data) > 1 || + !BKE_sculptsession_use_pbvh_draw(&object, rv3d) || ss->shapekey_active || ss->deform_modifiers_active; if (tag_update) { - Mesh *mesh = static_cast(ob->data); + Mesh *mesh = static_cast(object.data); if (changed_position) { mesh->tag_positions_changed(); BKE_sculptsession_free_deformMats(ss); } - DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + DEG_id_tag_update(&object.id, ID_RECALC_GEOMETRY); } } @@ -1146,7 +1151,7 @@ static size_t alloc_and_store_hidden(const SculptSession *ss, Node *unode) /* Allocate node and initialize its default fields specific for the given undo type. * Will also add the node to the list in the undo step. */ -static Node *alloc_node_type(const Object *object, const Type type) +static Node *alloc_node_type(const Object &object, const Type type) { UndoSculpt *usculpt = get_nodes(); std::unique_ptr unode = std::make_unique(); @@ -1154,7 +1159,7 @@ static Node *alloc_node_type(const Object *object, const Type type) usculpt->undo_size += sizeof(Node); Node *node_ptr = usculpt->nodes.last().get(); - STRNCPY(node_ptr->idname, object->id.name); + STRNCPY(node_ptr->idname, object.id.name); node_ptr->type = type; return node_ptr; @@ -1163,7 +1168,7 @@ static Node *alloc_node_type(const Object *object, const Type type) /* Will return first existing undo node of the given type. * If such node does not exist will allocate node of this type, register it in the undo step and * return it. */ -static Node *find_or_alloc_node_type(const Object *object, const Type type) +static Node *find_or_alloc_node_type(const Object &object, const Type type) { UndoSculpt *usculpt = get_nodes(); @@ -1176,12 +1181,12 @@ static Node *find_or_alloc_node_type(const Object *object, const Type type) return alloc_node_type(object, type); } -static Node *alloc_node(const Object *ob, const PBVHNode *node, const Type type) +static Node *alloc_node(const Object &object, const PBVHNode *node, const Type type) { UndoSculpt *usculpt = get_nodes(); - const SculptSession *ss = ob->sculpt; + const SculptSession *ss = object.sculpt; - Node *unode = alloc_node_type(ob, type); + Node *unode = alloc_node_type(object, type); unode->node = node; int verts_num; @@ -1211,7 +1216,7 @@ static Node *alloc_node(const Object *ob, const PBVHNode *node, const Type type) if (need_loops) { unode->corner_indices = BKE_pbvh_node_get_corner_indices(node); - unode->mesh_corners_num = static_cast(ob->data)->corners_num; + unode->mesh_corners_num = static_cast(object.data)->corners_num; usculpt->undo_size += unode->corner_indices.as_span().size_in_bytes(); } @@ -1292,9 +1297,9 @@ static Node *alloc_node(const Object *ob, const PBVHNode *node, const Type type) return unode; } -static void store_coords(const Object *ob, Node *unode) +static void store_coords(const Object &object, Node *unode) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; if (!unode->grids.is_empty()) { const SubdivCCG &subdiv_ccg = *ss->subdiv_ccg; @@ -1336,13 +1341,13 @@ static void store_coords(const Object *ob, Node *unode) } } -static void store_hidden(const Object *ob, Node *unode) +static void store_hidden(const Object &object, Node *unode) { if (!unode->grids.is_empty()) { /* Already stored during allocation. */ } - const Mesh &mesh = *static_cast(ob->data); + const Mesh &mesh = *static_cast(object.data); const bke::AttributeAccessor attributes = mesh.attributes(); const VArraySpan hide_vert = *attributes.lookup(".hide_vert", bke::AttrDomain::Point); @@ -1372,9 +1377,9 @@ static void store_face_hidden(const Object &object, Node &unode) } } -static void store_mask(const Object *ob, Node *unode) +static void store_mask(const Object &object, Node *unode) { - const SculptSession *ss = ob->sculpt; + const SculptSession *ss = object.sculpt; if (!unode->grids.is_empty()) { const SubdivCCG &subdiv_ccg = *ss->subdiv_ccg; @@ -1395,7 +1400,7 @@ static void store_mask(const Object *ob, Node *unode) } } else { - const Mesh &mesh = *static_cast(ob->data); + const Mesh &mesh = *static_cast(object.data); const bke::AttributeAccessor attributes = mesh.attributes(); if (const VArray mask = *attributes.lookup(".sculpt_mask", bke::AttrDomain::Point)) { array_utils::gather(mask, unode->vert_indices.as_span(), unode->mask.as_mutable_span()); @@ -1406,9 +1411,9 @@ static void store_mask(const Object *ob, Node *unode) } } -static void store_color(const Object *ob, Node *unode) +static void store_color(const Object &object, Node *unode) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; BLI_assert(BKE_pbvh_type(ss->pbvh) == PBVH_FACES); @@ -1433,7 +1438,7 @@ static NodeGeometry *geometry_get(Node *unode) return &unode->geometry_modified; } -static Node *geometry_push(const Object *object, const Type type) +static Node *geometry_push(const Object &object, const Type type) { Node *unode = find_or_alloc_node_type(object, type); unode->applied = false; @@ -1453,10 +1458,10 @@ static void store_face_sets(const Mesh &mesh, Node &unode) unode.face_sets.as_mutable_span()); } -static Node *bmesh_push(const Object *ob, const PBVHNode *node, Type type) +static Node *bmesh_push(const Object &object, const PBVHNode *node, Type type) { UndoSculpt *usculpt = get_nodes(); - const SculptSession *ss = ob->sculpt; + const SculptSession *ss = object.sculpt; Node *unode = usculpt->nodes.is_empty() ? nullptr : usculpt->nodes.first().get(); @@ -1464,7 +1469,7 @@ static Node *bmesh_push(const Object *ob, const PBVHNode *node, Type type) usculpt->nodes.append(std::make_unique()); unode = usculpt->nodes.last().get(); - STRNCPY(unode->idname, ob->id.name); + STRNCPY(unode->idname, object.id.name); unode->type = type; unode->applied = true; @@ -1479,7 +1484,7 @@ static Node *bmesh_push(const Object *ob, const PBVHNode *node, Type type) * (converting faces to triangles) that the BMLog can't * fully restore from. */ NodeGeometry *geometry = &unode->geometry_bmesh_enter; - store_geometry_data(geometry, ob); + store_geometry_data(geometry, object); unode->bm_entry = BM_log_entry_add(ss->bm_log); BM_log_all_added(ss->bm, ss->bm_log); @@ -1537,9 +1542,9 @@ static Node *bmesh_push(const Object *ob, const PBVHNode *node, Type type) return unode; } -Node *push_node(const Object *ob, const PBVHNode *node, Type type) +Node *push_node(const Object &object, const PBVHNode *node, Type type) { - SculptSession *ss = ob->sculpt; + SculptSession *ss = object.sculpt; Node *unode; @@ -1552,13 +1557,13 @@ Node *push_node(const Object *ob, const PBVHNode *node, Type type) if (ss->bm || ELEM(type, Type::DyntopoBegin, Type::DyntopoEnd)) { /* Dynamic topology stores only one undo node per stroke, * regardless of the number of PBVH nodes modified. */ - unode = bmesh_push(ob, node, type); + unode = bmesh_push(object, node, type); BLI_thread_unlock(LOCK_CUSTOM1); // return unode; return; } if (type == Type::Geometry) { - unode = geometry_push(ob, type); + unode = geometry_push(object, type); BLI_thread_unlock(LOCK_CUSTOM1); // return unode; return; @@ -1569,26 +1574,26 @@ Node *push_node(const Object *ob, const PBVHNode *node, Type type) return; } - unode = alloc_node(ob, node, type); + unode = alloc_node(object, node, type); /* NOTE: If this ever becomes a bottleneck, make a lock inside of the node. * so we release global lock sooner, but keep data locked for until it is * fully initialized. */ switch (type) { case Type::Position: - store_coords(ob, unode); + store_coords(object, unode); break; case Type::HideVert: - store_hidden(ob, unode); + store_hidden(object, unode); break; case Type::HideFace: - store_face_hidden(*ob, *unode); + store_face_hidden(object, *unode); break; case Type::Mask: - store_mask(ob, unode); + store_mask(object, unode); break; case Type::Color: - store_color(ob, unode); + store_color(object, unode); break; case Type::DyntopoBegin: case Type::DyntopoEnd: @@ -1597,7 +1602,7 @@ Node *push_node(const Object *ob, const PBVHNode *node, Type type) case Type::Geometry: break; case Type::FaceSet: - store_face_sets(*static_cast(ob->data), *unode); + store_face_sets(*static_cast(object.data), *unode); break; } @@ -1619,9 +1624,9 @@ Node *push_node(const Object *ob, const PBVHNode *node, Type type) return unode; } -static void sculpt_save_active_attribute(Object *ob, SculptAttrRef *attr) +static void sculpt_save_active_attribute(Object &object, SculptAttrRef *attr) { - Mesh *mesh = BKE_object_get_original_mesh(ob); + Mesh *mesh = BKE_object_get_original_mesh(&object); attr->was_set = true; attr->domain = NO_ACTIVE_LAYER; attr->name[0] = 0; @@ -1667,14 +1672,14 @@ void push_begin_ex(Object *ob, const char *name) ustack, C, name, BKE_UNDOSYS_TYPE_SCULPT); if (!us->active_color_start.was_set) { - sculpt_save_active_attribute(ob, &us->active_color_start); + sculpt_save_active_attribute(*ob, &us->active_color_start); } /* Set end attribute in case push_end is not called, * so we don't end up with corrupted state. */ if (!us->active_color_end.was_set) { - sculpt_save_active_attribute(ob, &us->active_color_end); + sculpt_save_active_attribute(*ob, &us->active_color_end); us->active_color_end.was_set = false; } } @@ -1709,7 +1714,7 @@ void push_end_ex(Object *ob, const bool use_nested_undo) SculptUndoStep *us = (SculptUndoStep *)BKE_undosys_stack_init_or_active_with_type( ustack, BKE_UNDOSYS_TYPE_SCULPT); - sculpt_save_active_attribute(ob, &us->active_color_end); + sculpt_save_active_attribute(*ob, &us->active_color_end); print_nodes(ob, nullptr); } @@ -1727,7 +1732,7 @@ static void set_active_layer(bContext *C, SculptAttrRef *attr) Mesh *mesh = BKE_object_get_original_mesh(ob); SculptAttrRef existing; - sculpt_save_active_attribute(ob, &existing); + sculpt_save_active_attribute(*ob, &existing); CustomDataLayer *layer = BKE_id_attribute_find(&mesh->id, attr->name, attr->type, attr->domain); @@ -1933,18 +1938,18 @@ static void sculpt_undosys_step_free(UndoStep *us_p) void geometry_begin(Object *ob, const wmOperator *op) { push_begin(ob, op); - push_node(ob, nullptr, Type::Geometry); + push_node(*ob, nullptr, Type::Geometry); } void geometry_begin_ex(Object *ob, const char *name) { push_begin_ex(ob, name); - push_node(ob, nullptr, Type::Geometry); + push_node(*ob, nullptr, Type::Geometry); } void geometry_end(Object *ob) { - push_node(ob, nullptr, Type::Geometry); + push_node(*ob, nullptr, Type::Geometry); push_end(ob); } @@ -2035,7 +2040,7 @@ static void push_all_grids(Object *object) Vector nodes = bke::pbvh::search_gather(ss->pbvh, {}); for (PBVHNode *node : nodes) { - Node *unode = push_node(object, node, Type::Position); + Node *unode = push_node(*object, node, Type::Position); unode->node = nullptr; } } @@ -2050,7 +2055,7 @@ void push_multires_mesh_begin(bContext *C, const char *str) push_begin_ex(object, str); - Node *geometry_unode = push_node(object, nullptr, Type::Geometry); + Node *geometry_unode = push_node(*object, nullptr, Type::Geometry); geometry_unode->geometry_clear_pbvh = false; push_all_grids(object); @@ -2065,7 +2070,7 @@ void push_multires_mesh_end(bContext *C, const char *str) Object *object = CTX_data_active_object(C); - Node *geometry_unode = push_node(object, nullptr, Type::Geometry); + Node *geometry_unode = push_node(*object, nullptr, Type::Geometry); geometry_unode->geometry_clear_pbvh = false; push_end(object);