Refactor: Sculpt: Add scene argument to undo step creation functions

This is necessary for using the 3D cursor instead of the sculpt pivot (#118250).
It's committed separately from #127863 to make that diff smaller.
This commit is contained in:
Hans Goudey
2024-09-19 11:28:33 -04:00
parent fe68190923
commit 9e920bc95b
24 changed files with 93 additions and 59 deletions

View File

@@ -246,7 +246,7 @@ static void store_result_geometry(
const bool has_shape_keys = mesh.key != nullptr;
if (object.mode == OB_MODE_SCULPT) {
sculpt_paint::undo::geometry_begin(object, &op);
sculpt_paint::undo::geometry_begin(scene, object, &op);
}
Mesh *new_mesh = geometry.get_component_for_write<bke::MeshComponent>().release();

View File

@@ -57,8 +57,8 @@ void register_type(UndoType *ut);
* redo panels to work; operators that do not support that may use
* #geometry_begin_ex instead if so desired.
*/
void geometry_begin(Object &ob, const wmOperator *op);
void geometry_begin_ex(Object &ob, const char *name);
void geometry_begin(const Scene &scene, Object &ob, const wmOperator *op);
void geometry_begin_ex(const Scene &scene, Object &ob, const char *name);
void geometry_end(Object &ob);
/**

View File

@@ -458,6 +458,7 @@ static int paint_mask_slice_exec(bContext *C, wmOperator *op)
{
using namespace blender;
using namespace blender::ed;
const Scene &scene = *CTX_data_scene(C);
Main &bmain = *CTX_data_main(C);
Object &ob = *CTX_data_active_object(C);
View3D *v3d = CTX_wm_view3d(C);
@@ -473,7 +474,7 @@ static int paint_mask_slice_exec(bContext *C, wmOperator *op)
/* Undo crashes when new object is created in the middle of a sculpt, see #87243. */
if (ob.mode == OB_MODE_SCULPT && !create_new_object) {
sculpt_paint::undo::geometry_begin(ob, op);
sculpt_paint::undo::geometry_begin(scene, ob, op);
}
const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(new_mesh);

View File

@@ -105,6 +105,7 @@ static bool object_remesh_poll(bContext *C)
static int voxel_remesh_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
Mesh *mesh = static_cast<Mesh *>(ob->data);
@@ -132,7 +133,7 @@ static int voxel_remesh_exec(bContext *C, wmOperator *op)
}
if (ob->mode == OB_MODE_SCULPT) {
sculpt_paint::undo::geometry_begin(*ob, op);
sculpt_paint::undo::geometry_begin(scene, *ob, op);
}
if (mesh->flag & ME_REMESH_FIX_POLES && mesh->remesh_voxel_adaptivity <= 0.0f) {
@@ -842,6 +843,7 @@ static void quadriflow_start_job(void *customdata, wmJobWorkerStatus *worker_sta
Object *ob = qj->owner;
Mesh *mesh = static_cast<Mesh *>(ob->data);
Scene &scene = *qj->scene;
Mesh *new_mesh;
Mesh *bisect_mesh;
@@ -887,7 +889,7 @@ static void quadriflow_start_job(void *customdata, wmJobWorkerStatus *worker_sta
new_mesh = remesh_symmetry_mirror(qj->owner, new_mesh, qj->symmetry_axes);
if (ob->mode == OB_MODE_SCULPT) {
sculpt_paint::undo::geometry_begin(*ob, qj->op);
sculpt_paint::undo::geometry_begin(scene, *ob, qj->op);
}
if (qj->preserve_attributes) {

View File

@@ -515,6 +515,7 @@ static void partialvis_all_update_bmesh(const Depsgraph &depsgraph,
static int hide_show_all_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
@@ -525,10 +526,10 @@ static int hide_show_all_exec(bContext *C, wmOperator *op)
/* Start undo. */
switch (action) {
case VisAction::Hide:
undo::push_begin_ex(ob, "Hide area");
undo::push_begin_ex(scene, ob, "Hide area");
break;
case VisAction::Show:
undo::push_begin_ex(ob, "Show area");
undo::push_begin_ex(scene, ob, "Show area");
break;
}
@@ -631,6 +632,7 @@ static void partialvis_masked_update_bmesh(const Depsgraph &depsgraph,
static int hide_show_masked_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
@@ -641,10 +643,10 @@ static int hide_show_masked_exec(bContext *C, wmOperator *op)
/* Start undo. */
switch (action) {
case VisAction::Hide:
undo::push_begin_ex(ob, "Hide area");
undo::push_begin_ex(scene, ob, "Hide area");
break;
case VisAction::Show:
undo::push_begin_ex(ob, "Show area");
undo::push_begin_ex(scene, ob, "Show area");
break;
}
@@ -791,6 +793,7 @@ static void invert_visibility_bmesh(const Depsgraph &depsgraph,
static int visibility_invert_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &object = *CTX_data_active_object(C);
Depsgraph &depsgraph = *CTX_data_ensure_evaluated_depsgraph(C);
@@ -798,7 +801,7 @@ static int visibility_invert_exec(bContext *C, wmOperator *op)
IndexMaskMemory memory;
const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
undo::push_begin(object, op);
undo::push_begin(scene, object, op);
switch (pbvh.type()) {
case bke::pbvh::Type::Mesh:
invert_visibility_mesh(depsgraph, object, node_mask);
@@ -1118,6 +1121,7 @@ static void grow_shrink_visibility_bmesh(const Depsgraph &depsgraph,
static int visibility_filter_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &object = *CTX_data_active_object(C);
Depsgraph &depsgraph = *CTX_data_ensure_evaluated_depsgraph(C);
@@ -1138,7 +1142,7 @@ static int visibility_filter_exec(bContext *C, wmOperator *op)
iterations = int(num_verts / VERTEX_ITERATION_THRESHOLD) + 1;
}
undo::push_begin(object, op);
undo::push_begin(scene, object, op);
switch (pbvh.type()) {
case bke::pbvh::Type::Mesh:
grow_shrink_visibility_mesh(depsgraph, object, node_mask, mode, iterations);
@@ -1285,10 +1289,11 @@ static void partialvis_gesture_update_bmesh(gesture::GestureData &gesture_data)
static void hide_show_begin(bContext &C, wmOperator &op, gesture::GestureData & /*gesture_data*/)
{
const Scene &scene = *CTX_data_scene(&C);
Object *ob = CTX_data_active_object(&C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(&C);
undo::push_begin(*ob, &op);
undo::push_begin(scene, *ob, &op);
bke::object::pbvh_ensure(*depsgraph, *ob);
}

View File

@@ -660,7 +660,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op)
BKE_sculpt_update_object_for_edit(&depsgraph, &object, false);
undo::push_begin(object, op);
undo::push_begin(scene, object, op);
switch (mode) {
case FloodFillMode::Value:
fill_mask(bmain, scene, depsgraph, object, value);
@@ -723,9 +723,10 @@ struct MaskOperation {
static void gesture_begin(bContext &C, wmOperator &op, gesture::GestureData &gesture_data)
{
const Scene &scene = *CTX_data_scene(&C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(&C);
BKE_sculpt_update_object_for_edit(depsgraph, gesture_data.vc.obact, false);
undo::push_begin(*gesture_data.vc.obact, &op);
undo::push_begin(scene, *gesture_data.vc.obact, &op);
}
static float mask_gesture_get_new_value(const float elem, FloodFillMode mode, float value)

View File

@@ -2073,9 +2073,10 @@ static int vpaint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
vpaint_stroke_done,
event->type);
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
undo::push_begin_ex(ob, "Vertex Paint");
undo::push_begin_ex(scene, ob, "Vertex Paint");
if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
paint_stroke_free(C, op, (PaintStroke *)op->customdata);
@@ -2310,7 +2311,7 @@ static int vertex_color_set_exec(bContext *C, wmOperator *op)
bke::pbvh::Tree &pbvh = *bke::object::pbvh_get(obact);
undo::push_begin(obact, op);
undo::push_begin(scene, obact, op);
IndexMaskMemory memory;
const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);

View File

@@ -308,13 +308,14 @@ static void transform_active_color(bContext *C,
{
using namespace blender;
using namespace blender::ed::sculpt_paint;
const Scene &scene = *CTX_data_scene(C);
const Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
Object &obact = *CTX_data_active_object(C);
/* Ensure valid sculpt state. */
BKE_sculpt_update_object_for_edit(CTX_data_ensure_evaluated_depsgraph(C), &obact, true);
undo::push_begin(obact, op);
undo::push_begin(scene, obact, op);
bke::pbvh::Tree &pbvh = *bke::object::pbvh_get(obact);

View File

@@ -5134,6 +5134,7 @@ static bool over_mesh(bContext *C, wmOperator * /*op*/, const float mval[2])
static void stroke_undo_begin(const bContext *C, wmOperator *op)
{
using namespace blender::ed::sculpt_paint;
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
const Brush *brush = BKE_paint_brush_for_read(&sd.paint);
@@ -5147,7 +5148,7 @@ static void stroke_undo_begin(const bContext *C, wmOperator *op)
ED_image_undo_push_begin(op->type->name, PaintMode::Sculpt);
}
else {
undo::push_begin_ex(ob, sculpt_brush_type_name(sd));
undo::push_begin_ex(scene, ob, sculpt_brush_type_name(sd));
}
}

View File

@@ -2403,6 +2403,7 @@ static int sculpt_cloth_filter_modal(bContext *C, wmOperator *op, const wmEvent
static int sculpt_cloth_filter_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
@@ -2428,7 +2429,7 @@ static int sculpt_cloth_filter_invoke(bContext *C, wmOperator *op, const wmEvent
return OPERATOR_CANCELLED;
}
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
filter::cache_init(C,
ob,
sd,

View File

@@ -97,6 +97,7 @@ static bool sculpt_and_dynamic_topology_poll(bContext *C)
static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
const Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
Object &ob = *CTX_data_active_object(C);
@@ -131,7 +132,7 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op)
(sd->constant_detail * mat4_to_scale(ob.object_to_world().ptr()));
const float min_edge_len = max_edge_len * detail_size::EDGE_LENGTH_MIN_FACTOR;
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
undo::push_node(depsgraph, ob, nullptr, undo::Type::Position);
const double start_time = BLI_time_now_seconds();

View File

@@ -173,7 +173,7 @@ void disable_with_undo(Main &bmain, Depsgraph &depsgraph, Scene &scene, Object &
/* May be false in background mode. */
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_begin_ex(scene, ob, "Dynamic topology disable");
undo::push_node(depsgraph, ob, nullptr, undo::Type::DyntopoEnd);
}
disable(bmain, depsgraph, scene, ob, nullptr);
@@ -183,14 +183,14 @@ void disable_with_undo(Main &bmain, Depsgraph &depsgraph, Scene &scene, Object &
}
}
static void enable_with_undo(Main &bmain, Depsgraph &depsgraph, Object &ob)
static void enable_with_undo(Main &bmain, Depsgraph &depsgraph, const Scene &scene, Object &ob)
{
SculptSession &ss = *ob.sculpt;
if (ss.bm == nullptr) {
/* May be false in background mode. */
const bool use_undo = G.background ? (ED_undo_stack_get() != nullptr) : true;
if (use_undo) {
undo::push_begin_ex(ob, "Dynamic topology enable");
undo::push_begin_ex(scene, ob, "Dynamic topology enable");
}
enable_ex(bmain, depsgraph, ob);
if (use_undo) {
@@ -214,7 +214,7 @@ static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator * /*op*/)
disable_with_undo(bmain, depsgraph, scene, ob);
}
else {
enable_with_undo(bmain, depsgraph, ob);
enable_with_undo(bmain, depsgraph, scene, ob);
}
WM_cursor_wait(false);

View File

@@ -2610,6 +2610,7 @@ static bool any_nonzero_mask(const Object &object)
static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
const Scene &scene = *CTX_data_scene(C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object &ob = *CTX_data_active_object(C);
SculptSession &ss = *ob.sculpt;
@@ -2677,7 +2678,7 @@ static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *even
}
/* Initialize undo. */
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
undo_push(*depsgraph, ob, *ss.expand_cache);
/* Cache bke::pbvh::Tree nodes. */

View File

@@ -407,6 +407,7 @@ static void clear_face_sets(const Depsgraph &depsgraph, Object &object, const In
static int create_op_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &object = *CTX_data_active_object(C);
Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
@@ -429,7 +430,7 @@ static int create_op_exec(bContext *C, wmOperator *op)
BKE_sculpt_update_object_for_edit(&depsgraph, &object, false);
undo::push_begin(object, op);
undo::push_begin(scene, object, op);
const int next_face_set = find_next_available_id(object);
@@ -670,6 +671,7 @@ Set<int> gather_hidden_face_sets(const Span<bool> hide_poly, const Span<int> fac
static int init_op_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
@@ -695,7 +697,7 @@ static int init_op_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
undo::push_nodes(*depsgraph, ob, node_mask, undo::Type::FaceSet);
const float threshold = RNA_float_get(op->ptr, "threshold");
@@ -957,6 +959,7 @@ static void show_all(Depsgraph &depsgraph, Object &object, const IndexMask &node
static int change_visibility_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &object = *CTX_data_active_object(C);
SculptSession &ss = *object.sculpt;
Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
@@ -974,7 +977,7 @@ static int change_visibility_exec(bContext *C, wmOperator *op)
const VisibilityMode mode = VisibilityMode(RNA_enum_get(op->ptr, "mode"));
const int active_face_set = active_face_set_get(object);
undo::push_begin(object, op);
undo::push_begin(scene, object, op);
IndexMaskMemory memory;
const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
@@ -1172,6 +1175,7 @@ enum class EditMode {
};
static void edit_grow_shrink(const Depsgraph &depsgraph,
const Scene &scene,
Object &object,
const EditMode mode,
const int active_face_set_id,
@@ -1190,7 +1194,7 @@ static void edit_grow_shrink(const Depsgraph &depsgraph,
const VArraySpan<bool> hide_poly = *attributes.lookup<bool>(".hide_poly", bke::AttrDomain::Face);
Array<int> prev_face_sets = duplicate_face_sets(mesh);
undo::push_begin(object, op);
undo::push_begin(scene, object, op);
IndexMaskMemory memory;
const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
@@ -1427,8 +1431,9 @@ static bool edit_is_operation_valid(const Object &object,
static void edit_modify_geometry(
bContext *C, Object &ob, const int active_face_set, const bool modify_hidden, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Mesh *mesh = static_cast<Mesh *>(ob.data);
undo::geometry_begin(ob, op);
undo::geometry_begin(scene, ob, op);
delete_geometry(ob, active_face_set, modify_hidden);
undo::geometry_end(ob);
BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL);
@@ -1439,6 +1444,7 @@ static void edit_modify_geometry(
static void edit_modify_coordinates(
bContext *C, Object &ob, const int active_face_set, const EditMode mode, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
const Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
bke::pbvh::Tree &pbvh = *bke::object::pbvh_get(ob);
@@ -1447,7 +1453,7 @@ static void edit_modify_coordinates(
const float strength = RNA_float_get(op->ptr, "strength");
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
undo::push_nodes(depsgraph, ob, node_mask, undo::Type::Position);
pbvh.tag_positions_changed(node_mask);
@@ -1491,6 +1497,7 @@ static int edit_op_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
const Scene &scene = *CTX_data_scene(C);
const Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
Object &ob = *CTX_data_active_object(C);
@@ -1504,7 +1511,7 @@ static int edit_op_exec(bContext *C, wmOperator *op)
break;
case EditMode::Grow:
case EditMode::Shrink:
edit_grow_shrink(depsgraph, ob, mode, active_face_set, modify_hidden, op);
edit_grow_shrink(depsgraph, scene, ob, mode, active_face_set, modify_hidden, op);
break;
case EditMode::FairPositions:
case EditMode::FairTangency:
@@ -1614,9 +1621,10 @@ struct FaceSetOperation {
static void gesture_begin(bContext &C, wmOperator &op, gesture::GestureData &gesture_data)
{
const Scene &scene = *CTX_data_scene(&C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(&C);
BKE_sculpt_update_object_for_edit(depsgraph, gesture_data.vc.obact, false);
undo::push_begin(*gesture_data.vc.obact, &op);
undo::push_begin(scene, *gesture_data.vc.obact, &op);
}
static void gesture_apply_mesh(gesture::GestureData &gesture_data, const IndexMask &node_mask)

View File

@@ -445,6 +445,7 @@ static int sculpt_color_filter_modal(bContext *C, wmOperator *op, const wmEvent
static int sculpt_color_filter_init(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
SculptSession &ss = *ob.sculpt;
@@ -474,7 +475,7 @@ static int sculpt_color_filter_init(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
BKE_sculpt_color_layer_create_if_needed(&ob);
/* CTX_data_ensure_evaluated_depsgraph should be used at the end to include the updates of

View File

@@ -661,9 +661,9 @@ static bool decrease_contrast_mask_bmesh(const Depsgraph &depsgraph,
static int sculpt_mask_filter_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
const Scene *scene = CTX_data_scene(C);
const FilterType filter_type = FilterType(RNA_enum_get(op->ptr, "filter_type"));
const View3D *v3d = CTX_wm_view3d(C);
@@ -672,7 +672,7 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, &ob);
MultiresModifierData *mmd = BKE_sculpt_multires_active(&scene, &ob);
BKE_sculpt_mask_layers_ensure(CTX_data_depsgraph_pointer(C), CTX_data_main(C), &ob, mmd);
BKE_sculpt_update_object_for_edit(depsgraph, &ob, false);
@@ -682,7 +682,7 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op)
IndexMaskMemory memory;
const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
int iterations = RNA_int_get(op->ptr, "iterations");

View File

@@ -2449,6 +2449,7 @@ static void sculpt_filter_specific_init(const Depsgraph &depsgraph,
/* Returns OPERATOR_PASS_THROUGH on success. */
static int sculpt_mesh_filter_start(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
@@ -2495,7 +2496,7 @@ static int sculpt_mesh_filter_start(bContext *C, wmOperator *op)
boundary::ensure_boundary_info(ob);
}
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
cache_init(C,
ob,

View File

@@ -116,6 +116,7 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op)
if (!BKE_base_is_visible(v3d, base)) {
return OPERATOR_CANCELLED;
}
const Scene &scene = *CTX_data_scene(C);
Object &ob = *CTX_data_active_object(C);
SculptSession &ss = *ob.sculpt;
Depsgraph &depsgraph = *CTX_data_ensure_evaluated_depsgraph(C);
@@ -129,7 +130,7 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
const InitMode mode = InitMode(RNA_enum_get(op->ptr, "mode"));
const int seed = BLI_time_now_seconds();

View File

@@ -206,6 +206,7 @@ static bool no_multires_poll(bContext *C)
static int symmetrize_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
const Scene &scene = *CTX_data_scene(C);
const Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
Object &ob = *CTX_data_active_object(C);
const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
@@ -231,7 +232,7 @@ static int symmetrize_exec(bContext *C, wmOperator *op)
* as deleted, then after symmetrize operation all BMesh elements
* are logged as added (as opposed to attempting to store just the
* parts that symmetrize modifies). */
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
undo::push_node(depsgraph, ob, nullptr, undo::Type::DyntopoSymmetrize);
BM_log_before_all_removed(ss.bm, ss.bm_log);
@@ -259,7 +260,7 @@ static int symmetrize_exec(bContext *C, wmOperator *op)
}
case bke::pbvh::Type::Mesh: {
/* Mesh Symmetrize. */
undo::geometry_begin(ob, op);
undo::geometry_begin(scene, ob, op);
Mesh *mesh = static_cast<Mesh *>(ob.data);
BKE_mesh_mirror_apply_mirror_on_axis(bmain, mesh, sd.symmetrize_direction, dist);
@@ -446,7 +447,7 @@ void object_sculpt_mode_enter(Main &bmain,
const bool has_undo = wm->undo_stack != nullptr;
/* Undo push is needed to prevent memory leak. */
if (has_undo) {
undo::push_begin_ex(ob, "Dynamic topology enable");
undo::push_begin_ex(scene, ob, "Dynamic topology enable");
}
dyntopo::enable_ex(bmain, depsgraph, ob);
if (has_undo) {
@@ -569,7 +570,7 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
* while it works it causes lag when undoing the first undo step, see #71564. */
wmWindowManager *wm = CTX_wm_manager(C);
if (wm->op_undo_depth <= 1) {
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
undo::push_end(ob);
}
}
@@ -796,6 +797,7 @@ static void mask_by_color_full_mesh(const Depsgraph &depsgraph,
static int mask_by_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
const Scene &scene = *CTX_data_scene(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
Object &ob = *CTX_data_active_object(C);
SculptSession &ss = *ob.sculpt;
@@ -825,7 +827,7 @@ static int mask_by_color_invoke(bContext *C, wmOperator *op, const wmEvent *even
const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false);
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
BKE_sculpt_color_layer_create_if_needed(&ob);
const float threshold = RNA_float_get(op->ptr, "threshold");
@@ -1034,6 +1036,7 @@ static void apply_mask_bmesh(const Depsgraph &depsgraph,
static int mask_from_cavity_exec(bContext *C, wmOperator *op)
{
const Scene &scene = *CTX_data_scene(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
Object &ob = *CTX_data_active_object(C);
const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
@@ -1051,7 +1054,7 @@ static int mask_from_cavity_exec(bContext *C, wmOperator *op)
BKE_sculpt_update_object_for_edit(depsgraph, &ob, false);
SCULPT_vertex_random_access_ensure(ob);
undo::push_begin(ob, op);
undo::push_begin(scene, ob, op);
const ApplyMaskMode mode = ApplyMaskMode(RNA_enum_get(op->ptr, "mix_mode"));
const float factor = RNA_float_get(op->ptr, "mix_factor");

View File

@@ -31,9 +31,10 @@ struct ProjectOperation {
static void gesture_begin(bContext &C, wmOperator &op, gesture::GestureData &gesture_data)
{
const Scene &scene = *CTX_data_scene(&C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(&C);
BKE_sculpt_update_object_for_edit(depsgraph, gesture_data.vc.obact, false);
undo::push_begin(*gesture_data.vc.obact, &op);
undo::push_begin(scene, *gesture_data.vc.obact, &op);
}
struct LocalData {

View File

@@ -53,6 +53,7 @@ namespace blender::ed::sculpt_paint {
void init_transform(bContext *C, Object &ob, const float mval_fl[2], const char *undo_name)
{
const Scene &scene = *CTX_data_scene(C);
const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
SculptSession &ss = *ob.sculpt;
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
@@ -65,7 +66,7 @@ void init_transform(bContext *C, Object &ob, const float mval_fl[2], const char
ss.prev_pivot_rot = ss.pivot_rot;
ss.prev_pivot_scale = ss.pivot_scale;
undo::push_begin_ex(ob, undo_name);
undo::push_begin_ex(scene, ob, undo_name);
BKE_sculpt_update_object_for_edit(depsgraph, &ob, false);
ss.pivot_rot[3] = 1.0f;

View File

@@ -508,6 +508,7 @@ static void generate_geometry(gesture::GestureData &gesture_data)
static void gesture_begin(bContext &C, wmOperator &op, gesture::GestureData &gesture_data)
{
const Scene &scene = *CTX_data_scene(&C);
Object *object = gesture_data.vc.obact;
SculptSession &ss = *object->sculpt;
const bke::pbvh::Tree &pbvh = *bke::object::pbvh_get(*object);
@@ -524,7 +525,7 @@ static void gesture_begin(bContext &C, wmOperator &op, gesture::GestureData &ges
generate_geometry(gesture_data);
islands::invalidate(ss);
BKE_sculpt_update_object_for_edit(depsgraph, gesture_data.vc.obact, false);
undo::geometry_begin(*gesture_data.vc.obact, &op);
undo::geometry_begin(scene, *gesture_data.vc.obact, &op);
}
static int bm_face_isect_pair(BMFace *f, void * /*user_data*/)

View File

@@ -1795,12 +1795,12 @@ static void save_active_attribute(Object &object, SculptAttrRef *attr)
attr->type = meta_data->data_type;
}
void push_begin(Object &ob, const wmOperator *op)
void push_begin(const Scene &scene, Object &ob, const wmOperator *op)
{
push_begin_ex(ob, op->type->name);
push_begin_ex(scene, ob, op->type->name);
}
void push_begin_ex(Object &ob, const char *name)
void push_begin_ex(const Scene & /*scene*/, Object &ob, const char *name)
{
UndoStack *ustack = ED_undo_stack_get();
@@ -2139,15 +2139,15 @@ static void step_free(UndoStep *us_p)
free_step_data(us->data);
}
void geometry_begin(Object &ob, const wmOperator *op)
void geometry_begin(const Scene &scene, Object &ob, const wmOperator *op)
{
push_begin(ob, op);
push_begin(scene, ob, op);
geometry_push(ob);
}
void geometry_begin_ex(Object &ob, const char *name)
void geometry_begin_ex(const Scene &scene, Object &ob, const char *name)
{
push_begin_ex(ob, name);
push_begin_ex(scene, ob, name);
geometry_push(ob);
}
@@ -2233,10 +2233,11 @@ void push_multires_mesh_begin(bContext *C, const char *str)
return;
}
const Scene &scene = *CTX_data_scene(C);
const Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
Object *object = CTX_data_active_object(C);
push_begin_ex(*object, str);
push_begin_ex(scene, *object, str);
geometry_push(*object);
get_step_data()->geometry_clear_pbvh = false;

View File

@@ -17,6 +17,7 @@ struct BMLogEntry;
struct Depsgraph;
struct Mesh;
struct Object;
struct Scene;
struct wmOperator;
namespace blender::bke::pbvh {
class Node;
@@ -60,13 +61,13 @@ void push_nodes(const Depsgraph &depsgraph,
* redo panels to work; operators that do not support that may use
* #push_begin_ex instead if so desired.
*/
void push_begin(Object &ob, const wmOperator *op);
void push_begin(const Scene &scene, Object &ob, const wmOperator *op);
/**
* NOTE: #push_begin is preferred since `name`
* must match operator name for redo panels to work.
*/
void push_begin_ex(Object &ob, const char *name);
void push_begin_ex(const Scene &scene, Object &ob, const char *name);
void push_end(Object &ob);
void push_end_ex(Object &ob, bool use_nested_undo);