Cleanup: Move sculpt undo system to C++ namespace

Similar commits:
- 466dca07d5
- 1863533eb6
- 785c49cf44
- ed7b914bd8
This commit is contained in:
Hans Goudey
2023-12-07 23:43:35 -05:00
parent d742f08cc6
commit 08d657c874
24 changed files with 270 additions and 232 deletions

View File

@@ -208,7 +208,7 @@ static void store_result_geometry(
Mesh &mesh = *static_cast<Mesh *>(object.data);
if (object.mode == OB_MODE_SCULPT) {
ED_sculpt_undo_geometry_begin(&object, &op);
sculpt_paint::undo::geometry_begin(&object, &op);
}
Mesh *new_mesh = geometry.get_component_for_write<bke::MeshComponent>().release();
@@ -228,7 +228,7 @@ static void store_result_geometry(
BKE_editmesh_looptri_and_normals_calc(mesh.edit_mesh);
}
else if (object.mode == OB_MODE_SCULPT) {
ED_sculpt_undo_geometry_end(&object);
sculpt_paint::undo::geometry_end(&object);
}
break;
}

View File

@@ -33,29 +33,34 @@ void ED_sculpt_end_transform(bContext *C, Object *ob);
/* sculpt_undo.cc */
/** Export for ED_undo_sys. */
void ED_sculpt_undosys_type(UndoType *ut);
namespace blender::ed::sculpt_paint {
namespace undo {
void register_type(UndoType *ut);
/**
* Pushes an undo step using the operator name. This is necessary for
* redo panels to work; operators that do not support that may use
* #ED_sculpt_undo_geometry_begin_ex instead if so desired.
* #geometry_begin_ex instead if so desired.
*/
void ED_sculpt_undo_geometry_begin(Object *ob, const wmOperator *op);
void ED_sculpt_undo_geometry_begin_ex(Object *ob, const char *name);
void ED_sculpt_undo_geometry_end(Object *ob);
void geometry_begin(Object *ob, const wmOperator *op);
void geometry_begin_ex(Object *ob, const char *name);
void geometry_end(Object *ob);
/* Face sets. */
/* Undo for changes happening on a base mesh for multires sculpting.
* if there is no multi-res sculpt active regular undo is used. */
void push_multires_mesh_begin(bContext *C, const char *str);
void push_multires_mesh_end(bContext *C, const char *str);
namespace blender::ed::sculpt_paint::face_set {
} // namespace undo
namespace face_set {
int find_next_available_id(Object &object);
void initialize_none_to_id(Mesh *mesh, int new_id);
int active_update_and_get(bContext *C, Object *ob, const float mval_fl[2]);
} // namespace blender::ed::sculpt_paint::face_set
} // namespace face_set
/* Undo for changes happening on a base mesh for multires sculpting.
* if there is no multi-res sculpt active regular undo is used. */
void ED_sculpt_undo_push_multires_mesh_begin(bContext *C, const char *str);
void ED_sculpt_undo_push_multires_mesh_end(bContext *C, const char *str);
} // namespace blender::ed::sculpt_paint

View File

@@ -471,7 +471,7 @@ static int paint_mask_slice_exec(bContext *C, wmOperator *op)
Mesh *new_mesh = (Mesh *)BKE_id_copy(bmain, &mesh->id);
if (ob->mode == OB_MODE_SCULPT) {
ED_sculpt_undo_geometry_begin(ob, op);
sculpt_paint::undo::geometry_begin(ob, op);
}
const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(new_mesh);
@@ -534,7 +534,7 @@ static int paint_mask_slice_exec(bContext *C, wmOperator *op)
const int next_face_set_id = sculpt_paint::face_set::find_next_available_id(*ob);
sculpt_paint::face_set::initialize_none_to_id(mesh, next_face_set_id);
}
ED_sculpt_undo_geometry_end(ob);
sculpt_paint::undo::geometry_end(ob);
}
BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL);

View File

@@ -2538,11 +2538,11 @@ static int multires_base_apply_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
ED_sculpt_undo_push_multires_mesh_begin(C, op->type->name);
blender::ed::sculpt_paint::undo::push_multires_mesh_begin(C, op->type->name);
multiresModifier_base_apply(depsgraph, object, mmd);
ED_sculpt_undo_push_multires_mesh_end(C, op->type->name);
blender::ed::sculpt_paint::undo::push_multires_mesh_end(C, op->type->name);
DEG_id_tag_update(&object->id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, object);

View File

@@ -121,6 +121,7 @@ static bool object_remesh_poll(bContext *C)
static int voxel_remesh_exec(bContext *C, wmOperator *op)
{
using namespace blender;
using namespace blender::ed;
Object *ob = CTX_data_active_object(C);
Mesh *mesh = static_cast<Mesh *>(ob->data);
@@ -148,7 +149,7 @@ static int voxel_remesh_exec(bContext *C, wmOperator *op)
}
if (ob->mode == OB_MODE_SCULPT) {
ED_sculpt_undo_geometry_begin(ob, op);
sculpt_paint::undo::geometry_begin(ob, op);
}
if (mesh->flag & ME_REMESH_FIX_POLES && mesh->remesh_voxel_adaptivity <= 0.0f) {
@@ -173,7 +174,7 @@ static int voxel_remesh_exec(bContext *C, wmOperator *op)
BKE_mesh_nomain_to_mesh(new_mesh, mesh, ob);
if (ob->mode == OB_MODE_SCULPT) {
ED_sculpt_undo_geometry_end(ob);
sculpt_paint::undo::geometry_end(ob);
}
BKE_mesh_batch_cache_dirty_tag(static_cast<Mesh *>(ob->data), BKE_MESH_BATCH_DIRTY_ALL);
@@ -830,6 +831,7 @@ static Mesh *remesh_symmetry_mirror(Object *ob, Mesh *mesh, eSymmetryAxes symmet
static void quadriflow_start_job(void *customdata, wmJobWorkerStatus *worker_status)
{
using namespace blender::ed;
QuadriFlowJob *qj = static_cast<QuadriFlowJob *>(customdata);
qj->stop = &worker_status->stop;
@@ -888,7 +890,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) {
ED_sculpt_undo_geometry_begin(ob, qj->op);
sculpt_paint::undo::geometry_begin(ob, qj->op);
}
if (qj->preserve_attributes) {
@@ -900,7 +902,7 @@ static void quadriflow_start_job(void *customdata, wmJobWorkerStatus *worker_sta
BKE_mesh_smooth_flag_set(static_cast<Mesh *>(ob->data), qj->smooth_normals);
if (ob->mode == OB_MODE_SCULPT) {
ED_sculpt_undo_geometry_end(ob);
sculpt_paint::undo::geometry_end(ob);
}
BKE_mesh_batch_cache_dirty_tag(static_cast<Mesh *>(ob->data), BKE_MESH_BATCH_DIRTY_ALL);

View File

@@ -164,7 +164,7 @@ void mesh_show_all(Object &object, const Span<PBVHNode *> nodes)
for (PBVHNode *node : nodes.slice(range)) {
const Span<int> verts = BKE_pbvh_node_get_vert_indices(node);
if (std::any_of(verts.begin(), verts.end(), [&](const int i) { return hide_vert[i]; })) {
SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert);
undo::push_node(&object, node, SculptUndoType::HideVert);
BKE_pbvh_node_mark_rebuild_draw(node);
}
}
@@ -201,7 +201,7 @@ static void vert_hide_update(Object &object,
}
any_changed = true;
SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert);
undo::push_node(&object, node, SculptUndoType::HideVert);
array_utils::scatter(new_hide.as_span(), verts, hide_vert.span);
BKE_pbvh_node_mark_update_visibility(node);
@@ -290,7 +290,7 @@ void grids_show_all(Depsgraph &depsgraph, Object &object, const Span<PBVHNode *>
}))
{
any_changed = true;
SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert);
undo::push_node(&object, node, SculptUndoType::HideVert);
BKE_pbvh_node_mark_rebuild_draw(node);
}
}
@@ -338,7 +338,7 @@ static void grid_hide_update(Depsgraph &depsgraph,
}
any_changed = true;
SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert);
undo::push_node(&object, node, SculptUndoType::HideVert);
for (const int i : grids.index_range()) {
grid_hidden[grids[i]].copy_from(new_hide[i].as_span());
@@ -483,7 +483,7 @@ static void partialvis_update_bmesh(Object *ob,
bool any_changed = false;
bool any_visible = false;
SCULPT_undo_push_node(ob, node, SculptUndoType::HideVert);
undo::push_node(ob, node, SculptUndoType::HideVert);
partialvis_update_bmesh_verts(bm,
BKE_pbvh_bmesh_node_unique_verts(node),
@@ -582,10 +582,10 @@ static int hide_show_exec(bContext *C, wmOperator *op)
/* Start undo. */
switch (action) {
case VisAction::Hide:
SCULPT_undo_push_begin_ex(ob, "Hide area");
undo::push_begin_ex(ob, "Hide area");
break;
case VisAction::Show:
SCULPT_undo_push_begin_ex(ob, "Show area");
undo::push_begin_ex(ob, "Show area");
break;
}
@@ -602,7 +602,7 @@ static int hide_show_exec(bContext *C, wmOperator *op)
}
/* End undo. */
SCULPT_undo_push_end(ob);
undo::push_end(ob);
SCULPT_topology_islands_invalidate(ob->sculpt);
tag_update_visibility(*C);
@@ -675,7 +675,7 @@ static void invert_visibility_mesh(Object &object, const Span<PBVHNode *> nodes)
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
for (PBVHNode *node : nodes.slice(range)) {
SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert);
undo::push_node(&object, node, SculptUndoType::HideVert);
for (const int vert : BKE_pbvh_node_get_unique_vert_indices(node)) {
hide_vert.span[vert] = !hide_vert.span[vert];
}
@@ -699,7 +699,7 @@ static void invert_visibility_grids(Depsgraph &depsgraph,
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
for (PBVHNode *node : nodes.slice(range)) {
SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert);
undo::push_node(&object, node, SculptUndoType::HideVert);
for (const int i : BKE_pbvh_node_get_grid_indices(*node)) {
bits::invert(grid_hidden[i]);
}
@@ -716,7 +716,7 @@ static void invert_visibility_bmesh(Object &object, const Span<PBVHNode *> nodes
{
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
for (PBVHNode *node : nodes.slice(range)) {
SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert);
undo::push_node(&object, node, SculptUndoType::HideVert);
bool fully_hidden = true;
for (BMVert *vert : BKE_pbvh_bmesh_node_unique_verts(node)) {
BM_elem_flag_toggle(vert, BM_ELEM_HIDDEN);
@@ -742,7 +742,7 @@ static int visibility_invert_exec(bContext *C, wmOperator *op)
BLI_assert(BKE_object_sculpt_pbvh_get(&object) == pbvh);
Vector<PBVHNode *> nodes = bke::pbvh::search_gather(pbvh, {});
SCULPT_undo_push_begin(&object, op);
undo::push_begin(&object, op);
switch (BKE_pbvh_type(pbvh)) {
case PBVH_FACES:
invert_visibility_mesh(object, nodes);
@@ -755,7 +755,7 @@ static int visibility_invert_exec(bContext *C, wmOperator *op)
break;
}
SCULPT_undo_push_end(&object);
undo::push_end(&object);
SCULPT_topology_islands_invalidate(object.sculpt);
tag_update_visibility(*C);

View File

@@ -188,7 +188,7 @@ static bool try_remove_mask_mesh(Object &object, const Span<PBVHNode *> nodes)
if (std::all_of(verts.begin(), verts.end(), [&](const int i) { return mask[i] == 0.0f; })) {
continue;
}
SCULPT_undo_push_node(&object, node, SculptUndoType::Mask);
undo::push_node(&object, node, SculptUndoType::Mask);
BKE_pbvh_node_mark_redraw(node);
}
});
@@ -219,7 +219,7 @@ static void fill_mask_mesh(Object &object, const float value, const Span<PBVHNod
if (std::all_of(verts.begin(), verts.end(), [&](int i) { return mask.span[i] == value; })) {
continue;
}
SCULPT_undo_push_node(&object, node, SculptUndoType::Mask);
undo::push_node(&object, node, SculptUndoType::Mask);
mask.span.fill_indices(verts, value);
BKE_pbvh_node_mark_redraw(node);
}
@@ -265,7 +265,7 @@ static void fill_mask_grids(Main &bmain,
{
continue;
}
SCULPT_undo_push_node(&object, node, SculptUndoType::Mask);
undo::push_node(&object, node, SculptUndoType::Mask);
if (grid_hidden.is_empty()) {
for (const int grid : grid_indices) {
@@ -306,7 +306,7 @@ static void fill_mask_bmesh(Object &object, const float value, const Span<PBVHNo
return;
}
SCULPT_undo_push_node(&object, nodes.first(), SculptUndoType::Mask);
undo::push_node(&object, nodes.first(), SculptUndoType::Mask);
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
for (PBVHNode *node : nodes.slice(range)) {
bool redraw = false;
@@ -361,7 +361,7 @@ static void invert_mask_mesh(Object &object, const Span<PBVHNode *> nodes)
".sculpt_mask", ATTR_DOMAIN_POINT);
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
for (PBVHNode *node : nodes.slice(range)) {
SCULPT_undo_push_node(&object, node, SculptUndoType::Mask);
undo::push_node(&object, node, SculptUndoType::Mask);
for (const int vert : BKE_pbvh_node_get_unique_vert_indices(node)) {
if (!hide_vert.is_empty() && hide_vert[vert]) {
continue;
@@ -392,7 +392,7 @@ static void invert_mask_grids(Main &bmain,
const Span<CCGElem *> grids = subdiv_ccg.grids;
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
for (PBVHNode *node : nodes.slice(range)) {
SCULPT_undo_push_node(&object, node, SculptUndoType::Mask);
undo::push_node(&object, node, SculptUndoType::Mask);
const Span<int> grid_indices = BKE_pbvh_node_get_grid_indices(*node);
if (grid_hidden.is_empty()) {
@@ -428,7 +428,7 @@ static void invert_mask_bmesh(Object &object, const Span<PBVHNode *> nodes)
return;
}
SCULPT_undo_push_node(&object, nodes.first(), SculptUndoType::Mask);
undo::push_node(&object, nodes.first(), SculptUndoType::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)) {
@@ -473,7 +473,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op)
BKE_sculpt_update_object_for_edit(&depsgraph, &object, false);
SCULPT_undo_push_begin(&object, op);
undo::push_begin(&object, op);
Vector<PBVHNode *> nodes = bke::pbvh::search_gather(object.sculpt->pbvh, {});
switch (mode) {
case PAINT_MASK_FLOOD_VALUE:
@@ -487,7 +487,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op)
break;
}
SCULPT_undo_push_end(&object);
undo::push_end(&object);
SCULPT_tag_update_overlays(C);
@@ -999,7 +999,7 @@ static bool sculpt_gesture_is_effected(SculptGestureContext *sgcontext,
static void sculpt_gesture_apply(bContext *C, SculptGestureContext *sgcontext, wmOperator *op)
{
SculptGestureOperation *operation = sgcontext->operation;
SCULPT_undo_push_begin(CTX_data_active_object(C), op);
undo::push_begin(CTX_data_active_object(C), op);
operation->sculpt_gesture_begin(C, sgcontext);
@@ -1015,7 +1015,7 @@ static void sculpt_gesture_apply(bContext *C, SculptGestureContext *sgcontext, w
operation->sculpt_gesture_end(C, sgcontext);
Object *ob = CTX_data_active_object(C);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
SCULPT_tag_update_overlays(C);
}
@@ -1052,7 +1052,7 @@ static void face_set_gesture_apply_mesh(SculptGestureContext *sgcontext,
threading::parallel_for(sgcontext->nodes.index_range(), 1, [&](const IndexRange range) {
for (PBVHNode *node : nodes.slice(range)) {
SCULPT_undo_push_node(sgcontext->vc.obact, node, SculptUndoType::FaceSet);
undo::push_node(sgcontext->vc.obact, node, SculptUndoType::FaceSet);
bool any_updated = false;
for (const int face : BKE_pbvh_node_calc_face_indices(pbvh, *node)) {
@@ -1089,7 +1089,7 @@ static void face_set_gesture_apply_bmesh(SculptGestureContext *sgcontext,
threading::parallel_for(sgcontext->nodes.index_range(), 1, [&](const IndexRange range) {
for (PBVHNode *node : nodes.slice(range)) {
SCULPT_undo_push_node(sgcontext->vc.obact, node, SculptUndoType::FaceSet);
undo::push_node(sgcontext->vc.obact, node, SculptUndoType::FaceSet);
bool any_updated = false;
for (BMFace *face : BKE_pbvh_bmesh_node_faces(node)) {
@@ -1186,7 +1186,7 @@ static void mask_gesture_apply_task(SculptGestureContext *sgcontext,
if (!any_masked) {
any_masked = true;
SCULPT_undo_push_node(ob, node, SculptUndoType::Mask);
undo::push_node(ob, node, SculptUndoType::Mask);
if (is_multires) {
BKE_pbvh_node_mark_normals_update(node);
@@ -1769,7 +1769,7 @@ static void sculpt_gesture_trim_begin(bContext *C, SculptGestureContext *sgconte
sculpt_gesture_trim_geometry_generate(sgcontext);
SCULPT_topology_islands_invalidate(ss);
BKE_sculpt_update_object_for_edit(depsgraph, sgcontext->vc.obact, false);
SCULPT_undo_push_node(sgcontext->vc.obact, nullptr, SculptUndoType::Geometry);
undo::push_node(sgcontext->vc.obact, nullptr, SculptUndoType::Geometry);
}
static void sculpt_gesture_trim_apply_for_symmetry_pass(bContext * /*C*/,
@@ -1798,7 +1798,7 @@ static void sculpt_gesture_trim_end(bContext * /*C*/, SculptGestureContext *sgco
sculpt_gesture_trim_geometry_free(sgcontext);
SCULPT_undo_push_node(sgcontext->vc.obact, nullptr, SculptUndoType::Geometry);
undo::push_node(sgcontext->vc.obact, nullptr, SculptUndoType::Geometry);
BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL);
DEG_id_tag_update(&sgcontext->vc.obact->id, ID_RECALC_GEOMETRY);
}
@@ -1873,7 +1873,7 @@ static void project_line_gesture_apply_task(SculptGestureContext *sgcontext, PBV
PBVHVertexIter vd;
bool any_updated = false;
SCULPT_undo_push_node(sgcontext->vc.obact, node, SculptUndoType::Position);
undo::push_node(sgcontext->vc.obact, node, SculptUndoType::Position);
BKE_pbvh_vertex_iter_begin (sgcontext->ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
float vertex_normal[3];

View File

@@ -1809,7 +1809,7 @@ static void vpaint_paint_leaves(bContext *C,
Span<PBVHNode *> nodes)
{
for (PBVHNode *node : nodes) {
SCULPT_undo_push_node(ob, node, SculptUndoType::Color);
undo::push_node(ob, node, SculptUndoType::Color);
}
const Brush *brush = ob->sculpt->cache->brush;
@@ -1994,7 +1994,7 @@ static void vpaint_stroke_done(const bContext *C, PaintStroke *stroke)
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
SCULPT_cache_free(ob->sculpt->cache);
ob->sculpt->cache = nullptr;
@@ -2019,7 +2019,7 @@ static int vpaint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
BKE_pbvh_ensure_node_loops(ob->sculpt->pbvh);
}
SCULPT_undo_push_begin_ex(ob, "Vertex Paint");
undo::push_begin_ex(ob, "Vertex Paint");
if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
paint_stroke_free(C, op, (PaintStroke *)op->customdata);
@@ -2240,6 +2240,7 @@ bool BKE_object_attributes_active_color_fill(Object *ob,
static int vertex_color_set_exec(bContext *C, wmOperator *op)
{
using namespace blender::ed::sculpt_paint;
Scene *scene = CTX_data_scene(C);
Object *obact = CTX_data_active_object(C);
@@ -2253,10 +2254,10 @@ static int vertex_color_set_exec(bContext *C, wmOperator *op)
/* Ensure valid sculpt state. */
BKE_sculpt_update_object_for_edit(CTX_data_ensure_evaluated_depsgraph(C), obact, true);
SCULPT_undo_push_begin(obact, op);
undo::push_begin(obact, op);
Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(obact->sculpt->pbvh, {});
for (PBVHNode *node : nodes) {
SCULPT_undo_push_node(obact, node, SculptUndoType::Color);
undo::push_node(obact, node, SculptUndoType::Color);
}
paint_object_attributes_active_color_fill_ex(obact, paintcol, true, affect_alpha);
@@ -2264,7 +2265,7 @@ static int vertex_color_set_exec(bContext *C, wmOperator *op)
for (PBVHNode *node : nodes) {
BKE_pbvh_node_mark_update_color(node);
}
SCULPT_undo_push_end(obact);
undo::push_end(obact);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obact);
return OPERATOR_FINISHED;

View File

@@ -301,16 +301,17 @@ static void transform_active_color(bContext *C,
wmOperator *op,
const FunctionRef<void(ColorGeometry4f &color)> transform_fn)
{
using namespace blender::ed::sculpt_paint;
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);
SCULPT_undo_push_begin(obact, op);
undo::push_begin(obact, op);
Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(obact->sculpt->pbvh, {});
for (PBVHNode *node : nodes) {
SCULPT_undo_push_node(obact, node, SculptUndoType::Color);
undo::push_node(obact, node, SculptUndoType::Color);
}
transform_active_color_data(*BKE_mesh_from_object(obact), transform_fn);
@@ -319,7 +320,7 @@ static void transform_active_color(bContext *C,
BKE_pbvh_node_mark_update_color(node);
}
SCULPT_undo_push_end(obact);
undo::push_end(obact);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obact);
}

View File

@@ -1223,8 +1223,9 @@ void SCULPT_orig_vert_data_init(SculptOrigVertData *data,
PBVHNode *node,
SculptUndoType type)
{
using namespace blender::ed::sculpt_paint;
SculptUndoNode *unode;
unode = SCULPT_undo_push_node(ob, node, type);
unode = undo::push_node(ob, node, type);
SCULPT_orig_vert_data_unode_init(data, ob, unode);
}
@@ -1293,10 +1294,10 @@ static void paint_mesh_restore_node(Object *ob, const SculptUndoType type, PBVHN
SculptUndoNode *unode;
if (ss->bm) {
unode = SCULPT_undo_push_node(ob, node, type);
unode = undo::push_node(ob, node, type);
}
else {
unode = SCULPT_undo_get_node(node, type);
unode = undo::get_node(node, type);
}
if (!unode) {
@@ -1416,7 +1417,7 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
if (ss->bm) {
/* Disable multi-threading when dynamic-topology is enabled. Otherwise,
* new entries might be inserted by #SCULPT_undo_push_node() into the #GHash
* new entries might be inserted by #undo::push_node() into the #GHash
* used internally by #BM_log_original_vert_co() by a different thread. See #33787. */
for (const int i : nodes.index_range()) {
paint_mesh_restore_node(ob, type, nodes[i]);
@@ -1791,6 +1792,7 @@ static void calc_area_normal_and_center_task(Object *ob,
AreaNormalCenterData *anctd,
bool &r_any_vertex_sampled)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
PBVHVertexIter vd;
@@ -1800,7 +1802,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 = SCULPT_undo_push_node(ob, node, SculptUndoType::Position);
unode = undo::push_node(ob, node, SculptUndoType::Position);
use_original = (!unode->co.is_empty() || unode->bm_entry);
}
@@ -3154,6 +3156,7 @@ static void sculpt_topology_update(Sculpt *sd,
UnifiedPaintSettings * /*ups*/,
PaintModeSettings * /*paint_mode_settings*/)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
/* Build a list of all nodes that are potentially within the brush's area of influence. */
@@ -3185,10 +3188,10 @@ static void sculpt_topology_update(Sculpt *sd,
}
for (PBVHNode *node : nodes) {
SCULPT_undo_push_node(ob,
node,
brush->sculpt_tool == SCULPT_TOOL_MASK ? SculptUndoType::Mask :
SculptUndoType::Position);
undo::push_node(ob,
node,
brush->sculpt_tool == SCULPT_TOOL_MASK ? SculptUndoType::Mask :
SculptUndoType::Position);
BKE_pbvh_node_mark_update(node);
if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
@@ -3214,6 +3217,7 @@ static void sculpt_topology_update(Sculpt *sd,
static void do_brush_action_task(Object *ob, const Brush *brush, PBVHNode *node)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
bool need_coords = ss->cache->supports_gravity;
@@ -3226,15 +3230,15 @@ static void do_brush_action_task(Object *ob, const Brush *brush, PBVHNode *node)
need_coords = true;
}
else {
SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet);
undo::push_node(ob, node, SculptUndoType::FaceSet);
}
}
else if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
SCULPT_undo_push_node(ob, node, SculptUndoType::Mask);
undo::push_node(ob, node, SculptUndoType::Mask);
BKE_pbvh_node_mark_update_mask(node);
}
else if (SCULPT_tool_is_paint(brush->sculpt_tool)) {
SCULPT_undo_push_node(ob, node, SculptUndoType::Color);
undo::push_node(ob, node, SculptUndoType::Color);
BKE_pbvh_node_mark_update_color(node);
}
else {
@@ -3242,7 +3246,7 @@ static void do_brush_action_task(Object *ob, const Brush *brush, PBVHNode *node)
}
if (need_coords) {
SCULPT_undo_push_node(ob, node, SculptUndoType::Position);
undo::push_node(ob, node, SculptUndoType::Position);
BKE_pbvh_node_mark_update(node);
}
}
@@ -3572,12 +3576,13 @@ static void sculpt_combine_proxies_node(Object &object,
const bool use_orco,
PBVHNode &node)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = object.sculpt;
float(*orco)[3] = nullptr;
if (use_orco && !ss->bm) {
orco = reinterpret_cast<float(*)[3]>(
(SCULPT_undo_push_node(&object, &node, SculptUndoType::Position)->co.data()));
(undo::push_node(&object, &node, SculptUndoType::Position)->co.data()));
}
MutableSpan<PBVHProxyNode> proxies = BKE_pbvh_node_get_proxies(&node);
@@ -4706,6 +4711,7 @@ void SCULPT_stroke_modifiers_check(const bContext *C, Object *ob, const Brush *b
static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin)
{
using namespace blender::ed::sculpt_paint;
if (BKE_pbvh_node_get_tmin(node) >= *tmin) {
return;
}
@@ -4719,7 +4725,7 @@ static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin)
}
else {
/* Intersect with coordinates from before we started stroke. */
SculptUndoNode *unode = SCULPT_undo_get_node(node, SculptUndoType::Position);
SculptUndoNode *unode = undo::get_node(node, SculptUndoType::Position);
origco = (unode) ? reinterpret_cast<float(*)[3]>(unode->co.data()) : nullptr;
use_origco = origco ? true : false;
}
@@ -4746,6 +4752,7 @@ static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin)
static void sculpt_find_nearest_to_ray_cb(PBVHNode *node, void *data_v, float *tmin)
{
using namespace blender::ed::sculpt_paint;
if (BKE_pbvh_node_get_tmin(node) >= *tmin) {
return;
}
@@ -4759,7 +4766,7 @@ static void sculpt_find_nearest_to_ray_cb(PBVHNode *node, void *data_v, float *t
}
else {
/* Intersect with coordinates from before we started stroke. */
SculptUndoNode *unode = SCULPT_undo_get_node(node, SculptUndoType::Position);
SculptUndoNode *unode = undo::get_node(node, SculptUndoType::Position);
origco = (unode) ? reinterpret_cast<float(*)[3]>(unode->co.data()) : nullptr;
use_origco = origco ? true : false;
}
@@ -5315,6 +5322,7 @@ static bool over_mesh(bContext *C, wmOperator * /*op*/, const float mval[2])
static void sculpt_stroke_undo_begin(const bContext *C, wmOperator *op)
{
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
Brush *brush = BKE_paint_brush(&sd->paint);
@@ -5328,12 +5336,13 @@ static void sculpt_stroke_undo_begin(const bContext *C, wmOperator *op)
ED_image_undo_push_begin(op->type->name, PAINT_MODE_SCULPT);
}
else {
SCULPT_undo_push_begin_ex(ob, sculpt_tool_name(sd));
undo::push_begin_ex(ob, sculpt_tool_name(sd));
}
}
static void sculpt_stroke_undo_end(const bContext *C, Brush *brush)
{
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
ToolSettings *tool_settings = CTX_data_tool_settings(C);
@@ -5343,7 +5352,7 @@ static void sculpt_stroke_undo_end(const bContext *C, Brush *brush)
ED_image_undo_push_end();
}
else {
SCULPT_undo_push_end(ob);
undo::push_end(ob);
}
}

View File

@@ -1448,6 +1448,7 @@ static void cloth_filter_apply_forces_task(Object *ob,
static int sculpt_cloth_filter_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
using namespace blender;
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
SculptSession *ss = ob->sculpt;
@@ -1457,7 +1458,7 @@ static int sculpt_cloth_filter_modal(bContext *C, wmOperator *op, const wmEvent
if (event->type == LEFTMOUSE && event->val == KM_RELEASE) {
SCULPT_filter_cache_free(ss);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COORDS);
return OPERATOR_FINISHED;
}
@@ -1507,6 +1508,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)
{
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
@@ -1526,7 +1528,7 @@ static int sculpt_cloth_filter_invoke(bContext *C, wmOperator *op, const wmEvent
SCULPT_stroke_id_next(ob);
SCULPT_undo_push_begin(ob, op);
undo::push_begin(ob, op);
SCULPT_filter_cache_init(C,
ob,
sd,

View File

@@ -87,6 +87,7 @@ static bool sculpt_and_dynamic_topology_poll(bContext *C)
static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op)
{
using namespace blender;
using namespace blender::ed::sculpt_paint;
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
@@ -111,8 +112,8 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op)
(sd->constant_detail * mat4_to_scale(ob->object_to_world));
BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail);
SCULPT_undo_push_begin(ob, op);
SCULPT_undo_push_node(ob, nullptr, SculptUndoType::Position);
undo::push_begin(ob, op);
undo::push_node(ob, nullptr, SculptUndoType::Position);
const double start_time = PIL_check_seconds_timer();
@@ -126,7 +127,7 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op)
CLOG_INFO(&LOG, 2, "Detail flood fill took %f seconds.", PIL_check_seconds_timer() - start_time);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
/* Force rebuild of PBVH for better BB placement. */
SCULPT_pbvh_clear(ob);

View File

@@ -207,34 +207,36 @@ void sculpt_dynamic_topology_disable_with_undo(Main *bmain,
Scene *scene,
Object *ob)
{
using namespace blender::ed::sculpt_paint;
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) {
SCULPT_undo_push_begin_ex(ob, "Dynamic topology disable");
SCULPT_undo_push_node(ob, nullptr, SculptUndoType::DyntopoEnd);
undo::push_begin_ex(ob, "Dynamic topology disable");
undo::push_node(ob, nullptr, SculptUndoType::DyntopoEnd);
}
SCULPT_dynamic_topology_disable_ex(bmain, depsgraph, scene, ob, nullptr);
if (use_undo) {
SCULPT_undo_push_end(ob);
undo::push_end(ob);
}
}
}
static void sculpt_dynamic_topology_enable_with_undo(Main *bmain, Depsgraph *depsgraph, Object *ob)
{
using namespace blender::ed::sculpt_paint;
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) {
SCULPT_undo_push_begin_ex(ob, "Dynamic topology enable");
undo::push_begin_ex(ob, "Dynamic topology enable");
}
SCULPT_dynamic_topology_enable_ex(bmain, depsgraph, ob);
if (use_undo) {
SCULPT_undo_push_node(ob, nullptr, SculptUndoType::DyntopoBegin);
SCULPT_undo_push_end(ob);
undo::push_node(ob, nullptr, SculptUndoType::DyntopoBegin);
undo::push_end(ob);
}
}
}

View File

@@ -1283,12 +1283,13 @@ static void sculpt_expand_restore_original_state(bContext *C,
*/
static void sculpt_expand_cancel(bContext *C, wmOperator * /*op*/)
{
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
sculpt_expand_restore_original_state(C, ob, ss->expand_cache);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
sculpt_expand_cache_free(ss);
}
@@ -1631,9 +1632,10 @@ static void sculpt_expand_reposition_pivot(bContext *C, Object *ob, ExpandCache
static void sculpt_expand_finish(bContext *C)
{
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
SCULPT_undo_push_end(ob);
undo::push_end(ob);
/* Tag all nodes to redraw to avoid artifacts after the fast partial updates. */
Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(ss->pbvh, {});
@@ -2116,23 +2118,24 @@ static void sculpt_expand_cache_initial_config_set(bContext *C,
*/
static void sculpt_expand_undo_push(Object *ob, ExpandCache *expand_cache)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
blender::Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(ss->pbvh, {});
switch (expand_cache->target) {
case SCULPT_EXPAND_TARGET_MASK:
for (PBVHNode *node : nodes) {
SCULPT_undo_push_node(ob, node, SculptUndoType::Mask);
undo::push_node(ob, node, SculptUndoType::Mask);
}
break;
case SCULPT_EXPAND_TARGET_FACE_SETS:
for (PBVHNode *node : nodes) {
SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet);
undo::push_node(ob, node, SculptUndoType::FaceSet);
}
break;
case SCULPT_EXPAND_TARGET_COLORS:
for (PBVHNode *node : nodes) {
SCULPT_undo_push_node(ob, node, SculptUndoType::Color);
undo::push_node(ob, node, SculptUndoType::Color);
}
break;
}
@@ -2140,6 +2143,7 @@ static void sculpt_expand_undo_push(Object *ob, ExpandCache *expand_cache)
static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
using namespace blender::ed::sculpt_paint;
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
@@ -2205,7 +2209,7 @@ static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *even
sculpt_expand_ensure_sculptsession_data(ob);
/* Initialize undo. */
SCULPT_undo_push_begin(ob, op);
undo::push_begin(ob, op);
sculpt_expand_undo_push(ob, ss->expand_cache);
/* Set the initial element for expand from the event position. */

View File

@@ -245,7 +245,7 @@ static void do_draw_face_sets_brush_faces(Object *ob,
BKE_pbvh_vertex_iter_end;
if (changed) {
SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet);
undo::push_node(ob, node, SculptUndoType::FaceSet);
}
}
});
@@ -302,7 +302,7 @@ static void do_draw_face_sets_brush_grids(Object *ob,
BKE_pbvh_vertex_iter_end;
if (changed) {
SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet);
undo::push_node(ob, node, SculptUndoType::FaceSet);
}
}
});
@@ -390,7 +390,7 @@ static void do_draw_face_sets_brush_bmesh(Object *ob,
}
if (changed) {
SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet);
undo::push_node(ob, node, SculptUndoType::FaceSet);
}
}
});
@@ -511,7 +511,7 @@ static void face_sets_update(Object &object,
continue;
}
SCULPT_undo_push_node(&object, node, SculptUndoType::FaceSet);
undo::push_node(&object, node, SculptUndoType::FaceSet);
array_utils::scatter(new_face_sets.as_span(), faces, face_sets.span);
BKE_pbvh_node_mark_update_face_sets(node);
}
@@ -547,7 +547,7 @@ static int sculpt_face_set_create_exec(bContext *C, wmOperator *op)
BKE_sculpt_update_object_for_edit(&depsgraph, &object, false);
SCULPT_undo_push_begin(&object, op);
undo::push_begin(&object, op);
const int next_face_set = find_next_available_id(object);
@@ -624,7 +624,7 @@ static int sculpt_face_set_create_exec(bContext *C, wmOperator *op)
}
}
SCULPT_undo_push_end(&object);
undo::push_end(&object);
SCULPT_tag_update_overlays(C);
@@ -772,9 +772,9 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
SCULPT_undo_push_begin(ob, op);
undo::push_begin(ob, op);
for (PBVHNode *node : nodes) {
SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet);
undo::push_node(ob, node, SculptUndoType::FaceSet);
}
const float threshold = RNA_float_get(op->ptr, "threshold");
@@ -856,7 +856,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op)
}
}
SCULPT_undo_push_end(ob);
undo::push_end(ob);
SCULPT_tag_update_overlays(C);
@@ -969,7 +969,7 @@ static void face_hide_update(Object &object,
}
any_changed = true;
SCULPT_undo_push_node(&object, node, SculptUndoType::HideFace);
undo::push_node(&object, node, SculptUndoType::HideFace);
array_utils::scatter(new_hide.as_span(), faces, hide_poly.span);
BKE_pbvh_node_mark_update_visibility(node);
}
@@ -1013,7 +1013,7 @@ static int sculpt_face_set_change_visibility_exec(bContext *C, wmOperator *op)
const VisibilityMode mode = VisibilityMode(RNA_enum_get(op->ptr, "mode"));
const int active_face_set = SCULPT_active_face_set_get(ss);
SCULPT_undo_push_begin(&object, op);
undo::push_begin(&object, op);
PBVH *pbvh = object.sculpt->pbvh;
Vector<PBVHNode *> nodes = bke::pbvh::search_gather(pbvh, {});
@@ -1080,7 +1080,7 @@ static int sculpt_face_set_change_visibility_exec(bContext *C, wmOperator *op)
ups->last_stroke_valid = true;
}
SCULPT_undo_push_end(&object);
undo::push_end(&object);
BKE_pbvh_update_visibility(ss->pbvh);
BKE_sculpt_hide_poly_pointer_update(object);
@@ -1214,7 +1214,7 @@ static void sculpt_face_set_grow_shrink(Object &object,
bke::SpanAttributeWriter face_sets = ensure_face_sets_mesh(object);
SCULPT_undo_push_begin(&object, op);
undo::push_begin(&object, op);
const Vector<PBVHNode *> nodes = bke::pbvh::search_gather(ss.pbvh, {});
face_sets_update(object, nodes, [&](const Span<int> indices, MutableSpan<int> face_sets) {
@@ -1252,7 +1252,7 @@ static void sculpt_face_set_grow_shrink(Object &object,
}
});
face_sets.finish();
SCULPT_undo_push_end(&object);
undo::push_end(&object);
}
static bool check_single_face_set(const Object &object, const bool check_visible_only)
@@ -1416,7 +1416,7 @@ static void sculpt_face_set_edit_modify_geometry(bContext *C,
wmOperator *op)
{
Mesh *mesh = static_cast<Mesh *>(ob->data);
ED_sculpt_undo_geometry_begin(ob, op);
undo::geometry_begin(ob, op);
switch (mode) {
case EditMode::DeleteGeometry:
sculpt_face_set_delete_geometry(ob, active_face_set, modify_hidden);
@@ -1424,7 +1424,7 @@ static void sculpt_face_set_edit_modify_geometry(bContext *C,
default:
BLI_assert_unreachable();
}
ED_sculpt_undo_geometry_end(ob);
undo::geometry_end(ob);
BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL);
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh);
@@ -1441,10 +1441,10 @@ static void sculpt_face_set_edit_modify_coordinates(
const float strength = RNA_float_get(op->ptr, "strength");
SCULPT_undo_push_begin(ob, op);
undo::push_begin(ob, op);
for (PBVHNode *node : nodes) {
BKE_pbvh_node_mark_update(node);
SCULPT_undo_push_node(ob, node, SculptUndoType::Position);
undo::push_node(ob, node, SculptUndoType::Position);
}
switch (mode) {
case EditMode::FairPositions:
@@ -1464,7 +1464,7 @@ static void sculpt_face_set_edit_modify_coordinates(
}
SCULPT_flush_update_step(C, SCULPT_UPDATE_COORDS);
SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COORDS);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
}
static bool sculpt_face_set_edit_init(bContext *C, wmOperator *op)

View File

@@ -292,9 +292,10 @@ static void sculpt_color_filter_apply(bContext *C, wmOperator *op, Object *ob)
static void sculpt_color_filter_end(bContext *C, Object *ob)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
SCULPT_undo_push_end(ob);
undo::push_end(ob);
SCULPT_filter_cache_free(ss);
SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COLOR);
}
@@ -324,6 +325,7 @@ static int sculpt_color_filter_modal(bContext *C, wmOperator *op, const wmEvent
static int sculpt_color_filter_init(bContext *C, wmOperator *op)
{
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
SculptSession *ss = ob->sculpt;
@@ -351,7 +353,7 @@ static int sculpt_color_filter_init(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
SCULPT_undo_push_begin(ob, op);
undo::push_begin(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

@@ -159,6 +159,7 @@ static void mask_filter_task(SculptSession *ss,
static int sculpt_mask_filter_exec(bContext *C, wmOperator *op)
{
using namespace blender;
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
const Scene *scene = CTX_data_scene(C);
@@ -177,10 +178,10 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op)
int num_verts = SCULPT_vertex_count_get(ss);
Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(pbvh, {});
SCULPT_undo_push_begin(ob, op);
undo::push_begin(ob, op);
for (PBVHNode *node : nodes) {
SCULPT_undo_push_node(ob, node, SculptUndoType::Mask);
undo::push_node(ob, node, SculptUndoType::Mask);
}
float *prev_mask = nullptr;
@@ -216,7 +217,7 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op)
}
}
SCULPT_undo_push_end(ob);
undo::push_end(ob);
SCULPT_tag_update_overlays(C);

View File

@@ -108,6 +108,7 @@ void SCULPT_filter_cache_init(bContext *C,
float start_strength)
{
using namespace blender;
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
PBVH *pbvh = ob->sculpt->pbvh;
@@ -140,7 +141,7 @@ void SCULPT_filter_cache_init(bContext *C,
}
for (const int i : ss->filter_cache->nodes.index_range()) {
SCULPT_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. */
@@ -870,6 +871,7 @@ static void sculpt_mesh_filter_cancel(bContext *C, wmOperator * /*op*/)
static int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
SculptSession *ss = ob->sculpt;
@@ -883,13 +885,13 @@ static int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *
switch (event->val) {
case FILTER_MESH_MODAL_CANCEL:
sculpt_mesh_filter_cancel(C, op);
SCULPT_undo_push_end_ex(ob, true);
undo::push_end_ex(ob, true);
ret = OPERATOR_CANCELLED;
break;
case FILTER_MESH_MODAL_CONFIRM:
ret = sculpt_mesh_filter_confirm(ss, op, filter_type);
SCULPT_undo_push_end_ex(ob, false);
undo::push_end_ex(ob, false);
break;
}
@@ -976,6 +978,7 @@ static void sculpt_filter_specific_init(const eSculptMeshFilterType filter_type,
/* Returns OPERATOR_PASS_THROUGH on success. */
static int sculpt_mesh_filter_start(bContext *C, wmOperator *op)
{
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
@@ -1013,7 +1016,7 @@ static int sculpt_mesh_filter_start(bContext *C, wmOperator *op)
SCULPT_boundary_info_ensure(ob);
}
SCULPT_undo_push_begin(ob, op);
undo::push_begin(ob, op);
SCULPT_filter_cache_init(C,
ob,

View File

@@ -1493,23 +1493,27 @@ void SCULPT_cache_free(StrokeCache *cache);
/** \name Sculpt Undo
* \{ */
SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType type);
SculptUndoNode *SCULPT_undo_get_node(PBVHNode *node, SculptUndoType type);
namespace blender::ed::sculpt_paint::undo {
SculptUndoNode *push_node(Object *ob, PBVHNode *node, SculptUndoType type);
SculptUndoNode *get_node(PBVHNode *node, SculptUndoType type);
/**
* Pushes an undo step using the operator name. This is necessary for
* redo panels to work; operators that do not support that may use
* #SCULPT_undo_push_begin_ex instead if so desired.
* #push_begin_ex instead if so desired.
*/
void SCULPT_undo_push_begin(Object *ob, const wmOperator *op);
void push_begin(Object *ob, const wmOperator *op);
/**
* NOTE: #SCULPT_undo_push_begin is preferred since `name`
* NOTE: #push_begin is preferred since `name`
* must match operator name for redo panels to work.
*/
void SCULPT_undo_push_begin_ex(Object *ob, const char *name);
void SCULPT_undo_push_end(Object *ob);
void SCULPT_undo_push_end_ex(Object *ob, const bool use_nested_undo);
void push_begin_ex(Object *ob, const char *name);
void push_end(Object *ob);
void push_end_ex(Object *ob, const bool use_nested_undo);
}
/** \} */

View File

@@ -54,9 +54,10 @@ static void mask_init_task(Object *ob,
const SculptMaskWriteInfo mask_write,
PBVHNode *node)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
PBVHVertexIter vd;
SCULPT_undo_push_node(ob, node, SculptUndoType::Mask);
undo::push_node(ob, node, SculptUndoType::Mask);
BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
float mask;
switch (mode) {
@@ -81,6 +82,7 @@ static void mask_init_task(Object *ob,
static int sculpt_mask_init_exec(bContext *C, wmOperator *op)
{
using namespace blender;
using namespace blender::ed::sculpt_paint;
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
@@ -99,7 +101,7 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
SCULPT_undo_push_begin(ob, op);
undo::push_begin(ob, op);
if (mode == SCULPT_MASK_INIT_RANDOM_PER_LOOSE_PART) {
SCULPT_topology_islands_ensure(ob);
@@ -116,7 +118,7 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op)
multires_stitch_grids(ob);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
BKE_pbvh_update_mask(ss->pbvh);
SCULPT_tag_update_overlays(C);

View File

@@ -170,6 +170,7 @@ static bool sculpt_no_multires_poll(bContext *C)
static int sculpt_symmetrize_exec(bContext *C, wmOperator *op)
{
using namespace blender::ed::sculpt_paint;
Main *bmain = CTX_data_main(C);
Object *ob = CTX_data_active_object(C);
const Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
@@ -189,8 +190,8 @@ static int sculpt_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). */
SCULPT_undo_push_begin(ob, op);
SCULPT_undo_push_node(ob, nullptr, SculptUndoType::DyntopoSymmetrize);
undo::push_begin(ob, op);
undo::push_node(ob, nullptr, SculptUndoType::DyntopoSymmetrize);
BM_log_before_all_removed(ss->bm, ss->bm_log);
BM_mesh_toolflags_set(ss->bm, true);
@@ -211,18 +212,18 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *op)
/* Finish undo. */
BM_log_all_added(ss->bm, ss->bm_log);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
break;
}
case PBVH_FACES: {
/* Mesh Symmetrize. */
ED_sculpt_undo_geometry_begin(ob, op);
undo::geometry_begin(ob, op);
Mesh *mesh = static_cast<Mesh *>(ob->data);
BKE_mesh_mirror_apply_mirror_on_axis(bmain, mesh, sd->symmetrize_direction, dist);
ED_sculpt_undo_geometry_end(ob);
undo::geometry_end(ob);
BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL);
break;
@@ -339,6 +340,7 @@ void ED_object_sculptmode_enter_ex(Main *bmain,
const bool force_dyntopo,
ReportList *reports)
{
using namespace blender::ed::sculpt_paint;
const int mode_flag = OB_MODE_SCULPT;
Mesh *me = BKE_mesh_from_object(ob);
@@ -401,12 +403,12 @@ void ED_object_sculptmode_enter_ex(Main *bmain,
bool has_undo = wm->undo_stack != nullptr;
/* Undo push is needed to prevent memory leak. */
if (has_undo) {
SCULPT_undo_push_begin_ex(ob, "Dynamic topology enable");
undo::push_begin_ex(ob, "Dynamic topology enable");
}
SCULPT_dynamic_topology_enable_ex(bmain, depsgraph, ob);
if (has_undo) {
SCULPT_undo_push_node(ob, nullptr, SculptUndoType::DyntopoBegin);
SCULPT_undo_push_end(ob);
undo::push_node(ob, nullptr, SculptUndoType::DyntopoBegin);
undo::push_end(ob);
}
}
else {
@@ -487,6 +489,7 @@ void ED_object_sculptmode_exit(bContext *C, Depsgraph *depsgraph)
static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
{
using namespace blender::ed::sculpt_paint;
wmMsgBus *mbus = CTX_wm_message_bus(C);
Main *bmain = CTX_data_main(C);
Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
@@ -522,8 +525,8 @@ 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) {
SCULPT_undo_push_begin(ob, op);
SCULPT_undo_push_end(ob);
undo::push_begin(ob, op);
undo::push_end(ob);
}
}
}
@@ -735,9 +738,10 @@ static void do_mask_by_color_contiguous_update_node(Object *ob,
const SculptMaskWriteInfo mask_write,
PBVHNode *node)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
SCULPT_undo_push_node(ob, node, SculptUndoType::Mask);
undo::push_node(ob, node, SculptUndoType::Mask);
bool update_node = false;
PBVHVertexIter vd;
@@ -841,9 +845,10 @@ static void do_mask_by_color_task(Object *ob,
const SculptMaskWriteInfo mask_write,
PBVHNode *node)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
SCULPT_undo_push_node(ob, node, SculptUndoType::Mask);
undo::push_node(ob, node, SculptUndoType::Mask);
bool update_node = false;
float active_color[4];
@@ -894,6 +899,7 @@ static void sculpt_mask_by_color_full_mesh(Object *object,
static int sculpt_mask_by_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
using namespace blender::ed::sculpt_paint;
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
@@ -922,7 +928,7 @@ static int sculpt_mask_by_color_invoke(bContext *C, wmOperator *op, const wmEven
const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false);
SCULPT_undo_push_begin(ob, op);
undo::push_begin(ob, op);
BKE_sculpt_color_layer_create_if_needed(ob);
const PBVHVertRef active_vertex = SCULPT_active_vertex_get(ss);
@@ -942,7 +948,7 @@ static int sculpt_mask_by_color_invoke(bContext *C, wmOperator *op, const wmEven
}
BKE_pbvh_update_mask(ss->pbvh);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK);
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
@@ -1006,10 +1012,11 @@ static void sculpt_bake_cavity_exec_task(Object *ob,
const SculptMaskWriteInfo mask_write,
PBVHNode *node)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
PBVHVertexIter vd;
SCULPT_undo_push_node(ob, node, SculptUndoType::Mask);
undo::push_node(ob, node, SculptUndoType::Mask);
AutomaskingNodeData automask_data;
SCULPT_automasking_node_begin(ob, automasking, &automask_data, node);
@@ -1053,6 +1060,7 @@ static void sculpt_bake_cavity_exec_task(Object *ob,
static int sculpt_bake_cavity_exec(bContext *C, wmOperator *op)
{
using namespace blender;
using namespace blender::ed::sculpt_paint;
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
@@ -1065,7 +1073,7 @@ static int sculpt_bake_cavity_exec(bContext *C, wmOperator *op)
BKE_sculpt_update_object_for_edit(depsgraph, ob, false);
SCULPT_vertex_random_access_ensure(ss);
SCULPT_undo_push_begin(ob, op);
undo::push_begin(ob, op);
CavityBakeMixMode mode = CavityBakeMixMode(RNA_enum_get(op->ptr, "mix_mode"));
float factor = RNA_float_get(op->ptr, "mix_factor");
@@ -1144,7 +1152,7 @@ static int sculpt_bake_cavity_exec(bContext *C, wmOperator *op)
SCULPT_automasking_cache_free(automasking);
BKE_pbvh_update_mask(ss->pbvh);
SCULPT_undo_push_end(ob);
undo::push_end(ob);
SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK);
SCULPT_tag_update_overlays(C);

View File

@@ -49,6 +49,7 @@ void ED_sculpt_init_transform(bContext *C,
const float mval_fl[2],
const char *undo_name)
{
using namespace blender::ed::sculpt_paint;
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
SculptSession *ss = ob->sculpt;
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
@@ -61,7 +62,7 @@ void ED_sculpt_init_transform(bContext *C,
copy_v4_v4(ss->prev_pivot_rot, ss->pivot_rot);
copy_v3_v3(ss->prev_pivot_scale, ss->pivot_scale);
SCULPT_undo_push_begin_ex(ob, undo_name);
undo::push_begin_ex(ob, undo_name);
BKE_sculpt_update_object_for_edit(depsgraph, ob, false);
ss->pivot_rot[3] = 1.0f;
@@ -144,6 +145,7 @@ static void sculpt_transform_matrices_init(SculptSession *ss,
static void sculpt_transform_task(Object *ob, const float transform_mats[8][4][4], PBVHNode *node)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
SculptOrigVertData orig_data;
@@ -151,7 +153,7 @@ static void sculpt_transform_task(Object *ob, const float transform_mats[8][4][4
PBVHVertexIter vd;
SCULPT_undo_push_node(ob, node, SculptUndoType::Position);
undo::push_node(ob, node, SculptUndoType::Position);
BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
SCULPT_orig_vert_data_update(&orig_data, &vd);
float *start_co;
@@ -209,7 +211,7 @@ static void sculpt_elastic_transform_task(Object *ob,
const float elastic_transform_pivot[3],
PBVHNode *node)
{
using namespace blender::ed::sculpt_paint;
SculptSession *ss = ob->sculpt;
const MutableSpan<float3> proxy = BKE_pbvh_node_add_proxy(*ss->pbvh, *node).co;
@@ -226,7 +228,7 @@ static void sculpt_elastic_transform_task(Object *ob,
const float poisson_ratio = 0.4f;
BKE_kelvinlet_init_params(&params, transform_radius, force, shear_modulus, poisson_ratio);
SCULPT_undo_push_node(ob, node, SculptUndoType::Position);
undo::push_node(ob, node, SculptUndoType::Position);
PBVHVertexIter vd;
BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {

View File

@@ -12,14 +12,14 @@
* The sculpt undo system is a delta-based system. Each undo step stores
* the difference with the prior one.
*
* To use the sculpt undo system, you must call SCULPT_undo_push_begin
* inside an operator exec or invoke callback (ED_sculpt_undo_geometry_begin
* To use the sculpt undo system, you must call undo::push_begin
* inside an operator exec or invoke callback (undo::geometry_begin
* may be called if you wish to save a non-delta copy of the entire mesh).
* This will initialize the sculpt undo stack and set up an undo step.
*
* At the end of the operator you should call SCULPT_undo_push_end.
* At the end of the operator you should call undo::push_end.
*
* SCULPT_undo_push_end and ED_sculpt_undo_geometry_begin both take a
* undo::push_end and undo::geometry_begin both take a
* #wmOperatorType as an argument. There are _ex versions that allow a custom
* name; try to avoid using them. These can break the redo panel since it requires
* the undo push have the same name as the calling operator.
@@ -81,9 +81,7 @@
#include "paint_intern.hh"
#include "sculpt_intern.hh"
using blender::MutableSpan;
using blender::Span;
using blender::Vector;
namespace blender::ed::sculpt_paint::undo {
/* Uncomment to print the undo stack in the console on push/undo/redo. */
//#define SCULPT_UNDO_DEBUG
@@ -160,7 +158,7 @@ struct SculptUndoStep {
#endif
};
static UndoSculpt *sculpt_undo_get_nodes(void);
static UndoSculpt *sculpt_undo_get_nodes();
static bool sculpt_attribute_ref_equals(SculptAttrRef *a, SculptAttrRef *b);
static void sculpt_save_active_attribute(Object *ob, SculptAttrRef *attr);
static UndoSculpt *sculpt_undosys_step_get_nodes(UndoStep *us_p);
@@ -299,7 +297,7 @@ static void update_modified_node_mesh(PBVHNode *node, void *userdata)
if (BKE_pbvh_node_has_vert_with_normal_update_tag(data->pbvh, node)) {
BKE_pbvh_node_mark_update(node);
}
const blender::Span<int> verts = BKE_pbvh_node_get_vert_indices(node);
const Span<int> verts = BKE_pbvh_node_get_vert_indices(node);
if (!data->modified_mask_verts.is_empty()) {
for (const int vert : verts) {
if (data->modified_mask_verts[vert]) {
@@ -419,7 +417,6 @@ static bool sculpt_undo_restore_coords(bContext *C,
Depsgraph *depsgraph,
SculptUndoNode *unode)
{
using namespace blender;
SculptSession *ss = ob->sculpt;
SubdivCCG *subdiv_ccg = ss->subdiv_ccg;
@@ -446,11 +443,11 @@ static bool sculpt_undo_restore_coords(bContext *C,
/* No need for float comparison here (memory is exactly equal or not). */
const Span<int> index = unode->index;
blender::MutableSpan<blender::float3> positions = ss->vert_positions;
MutableSpan<float3> positions = ss->vert_positions;
if (ss->shapekey_active) {
blender::MutableSpan<blender::float3> vertCos(
static_cast<blender::float3 *>(ss->shapekey_active->data), ss->shapekey_active->totelem);
MutableSpan<float3> vertCos(static_cast<float3 *>(ss->shapekey_active->data),
ss->shapekey_active->totelem);
if (!unode->orig_co.is_empty()) {
if (ss->deform_modifiers_active) {
@@ -505,7 +502,7 @@ static bool sculpt_undo_restore_coords(bContext *C,
const CCGKey key = BKE_subdiv_ccg_key_top_level(*subdiv_ccg);
const Span<int> grid_indices = unode->grids;
blender::MutableSpan<blender::float3> co = unode->co;
MutableSpan<float3> co = unode->co;
MutableSpan<CCGElem *> grids = subdiv_ccg->grids;
int index = 0;
@@ -525,7 +522,6 @@ static bool sculpt_undo_restore_hidden(Object *ob,
SculptUndoNode *unode,
MutableSpan<bool> modified_vertices)
{
using namespace blender;
SculptSession *ss = ob->sculpt;
SubdivCCG *subdiv_ccg = ss->subdiv_ccg;
@@ -550,7 +546,7 @@ static bool sculpt_undo_restore_hidden(Object *ob,
return true;
}
blender::BitGroupVector<> &grid_hidden = BKE_subdiv_ccg_grid_hidden_ensure(*subdiv_ccg);
BitGroupVector<> &grid_hidden = BKE_subdiv_ccg_grid_hidden_ensure(*subdiv_ccg);
const Span<int> grids = unode->grids;
for (const int i : grids.index_range()) {
/* Swap the two bit spans. */
@@ -572,7 +568,6 @@ static bool sculpt_undo_restore_hidden_face(Object &object,
SculptUndoNode &unode,
MutableSpan<bool> modified_faces)
{
using namespace blender;
Mesh &mesh = *static_cast<Mesh *>(object.data);
bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
bke::SpanAttributeWriter hide_poly = attributes.lookup_or_add_for_write_span<bool>(
@@ -631,7 +626,6 @@ static bool sculpt_undo_restore_mask(Object *ob,
SculptUndoNode *unode,
MutableSpan<bool> modified_vertices)
{
using namespace blender;
Mesh *mesh = BKE_object_get_original_mesh(ob);
SculptSession *ss = ob->sculpt;
SubdivCCG *subdiv_ccg = ss->subdiv_ccg;
@@ -657,7 +651,7 @@ static bool sculpt_undo_restore_mask(Object *ob,
const CCGKey key = BKE_subdiv_ccg_key_top_level(*subdiv_ccg);
const Span<int> grid_indices = unode->grids;
blender::MutableSpan<float> mask = unode->mask;
MutableSpan<float> mask = unode->mask;
MutableSpan<CCGElem *> grids = subdiv_ccg->grids;
int index = 0;
@@ -677,8 +671,6 @@ static bool sculpt_undo_restore_face_sets(Object *ob,
SculptUndoNode *unode,
MutableSpan<bool> modified_face_set_faces)
{
using namespace blender;
using namespace blender::ed::sculpt_paint;
bke::SpanAttributeWriter<int> face_sets = face_set::ensure_face_sets_mesh(*ob);
bool modified = false;
@@ -709,7 +701,7 @@ static void sculpt_undo_bmesh_restore_generic(SculptUndoNode *unode, Object *ob,
}
if (unode->type == SculptUndoType::Mask) {
Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(ss->pbvh, {});
Vector<PBVHNode *> nodes = bke::pbvh::search_gather(ss->pbvh, {});
for (PBVHNode *node : nodes) {
BKE_pbvh_node_mark_redraw(node);
}
@@ -790,10 +782,10 @@ static void sculpt_undo_geometry_store_data(SculptUndoNodeGeometry *geometry, Ob
CustomData_copy(&mesh->edge_data, &geometry->edge_data, CD_MASK_MESH.emask, mesh->totedge);
CustomData_copy(&mesh->loop_data, &geometry->loop_data, CD_MASK_MESH.lmask, mesh->totloop);
CustomData_copy(&mesh->face_data, &geometry->face_data, CD_MASK_MESH.pmask, mesh->faces_num);
blender::implicit_sharing::copy_shared_pointer(mesh->face_offset_indices,
mesh->runtime->face_offsets_sharing_info,
&geometry->face_offset_indices,
&geometry->face_offsets_sharing_info);
implicit_sharing::copy_shared_pointer(mesh->face_offset_indices,
mesh->runtime->face_offsets_sharing_info,
&geometry->face_offset_indices,
&geometry->face_offsets_sharing_info);
geometry->totvert = mesh->totvert;
geometry->totedge = mesh->totedge;
@@ -819,10 +811,10 @@ static void sculpt_undo_geometry_restore_data(SculptUndoNodeGeometry *geometry,
CustomData_copy(&geometry->edge_data, &mesh->edge_data, CD_MASK_MESH.emask, geometry->totedge);
CustomData_copy(&geometry->loop_data, &mesh->loop_data, CD_MASK_MESH.lmask, geometry->totloop);
CustomData_copy(&geometry->face_data, &mesh->face_data, CD_MASK_MESH.pmask, geometry->faces_num);
blender::implicit_sharing::copy_shared_pointer(geometry->face_offset_indices,
geometry->face_offsets_sharing_info,
&mesh->face_offset_indices,
&mesh->runtime->face_offsets_sharing_info);
implicit_sharing::copy_shared_pointer(geometry->face_offset_indices,
geometry->face_offsets_sharing_info,
&mesh->face_offset_indices,
&mesh->runtime->face_offsets_sharing_info);
}
static void sculpt_undo_geometry_free_data(SculptUndoNodeGeometry *geometry)
@@ -839,8 +831,8 @@ static void sculpt_undo_geometry_free_data(SculptUndoNodeGeometry *geometry)
if (geometry->faces_num) {
CustomData_free(&geometry->face_data, geometry->faces_num);
}
blender::implicit_sharing::free_shared_data(&geometry->face_offset_indices,
&geometry->face_offsets_sharing_info);
implicit_sharing::free_shared_data(&geometry->face_offset_indices,
&geometry->face_offsets_sharing_info);
}
static void sculpt_undo_geometry_restore(SculptUndoNode *unode, Object *object)
@@ -905,8 +897,8 @@ static void sculpt_undo_refine_subdiv(Depsgraph *depsgraph,
Object *object,
Subdiv *subdiv)
{
blender::Array<blender::float3> deformed_verts =
BKE_multires_create_deformed_base_mesh_vert_coords(depsgraph, object, ss->multires.modifier);
Array<float3> deformed_verts = BKE_multires_create_deformed_base_mesh_vert_coords(
depsgraph, object, ss->multires.modifier);
BKE_subdiv_eval_refine_from_mesh(subdiv,
static_cast<const Mesh *>(object->data),
@@ -915,7 +907,6 @@ static void sculpt_undo_refine_subdiv(Depsgraph *depsgraph,
static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase *lb)
{
using namespace blender::ed::sculpt_paint;
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
@@ -1146,7 +1137,7 @@ static void sculpt_undo_free_list(ListBase *lb)
}
}
SculptUndoNode *SCULPT_undo_get_node(PBVHNode *node, SculptUndoType type)
SculptUndoNode *get_node(PBVHNode *node, SculptUndoType type)
{
UndoSculpt *usculpt = sculpt_undo_get_nodes();
@@ -1169,18 +1160,18 @@ static size_t sculpt_undo_alloc_and_store_hidden(SculptSession *ss, SculptUndoNo
if (!ss->subdiv_ccg) {
return 0;
}
const blender::BitGroupVector<> grid_hidden = ss->subdiv_ccg->grid_hidden;
const BitGroupVector<> grid_hidden = ss->subdiv_ccg->grid_hidden;
if (grid_hidden.is_empty()) {
return 0;
}
const Span<int> grid_indices = BKE_pbvh_node_get_grid_indices(*node);
unode->grid_hidden = blender::BitGroupVector<>(grid_indices.size(), grid_hidden.group_size());
unode->grid_hidden = BitGroupVector<>(grid_indices.size(), grid_hidden.group_size());
for (const int i : grid_indices.index_range()) {
unode->grid_hidden[i].copy_from(grid_hidden[grid_indices[i]]);
}
return unode->grid_hidden.all_bits().full_ints_num() / blender::bits::BitsPerInt;
return unode->grid_hidden.all_bits().full_ints_num() / bits::BitsPerInt;
}
/* Allocate node and initialize its default fields specific for the given undo type.
@@ -1358,7 +1349,6 @@ static void sculpt_undo_store_coords(Object *ob, SculptUndoNode *unode)
static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode)
{
using namespace blender;
if (!unode->grids.is_empty()) {
/* Already stored during allocation. */
}
@@ -1371,14 +1361,13 @@ static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode)
}
PBVHNode *node = static_cast<PBVHNode *>(unode->node);
const blender::Span<int> verts = BKE_pbvh_node_get_vert_indices(node);
const Span<int> verts = BKE_pbvh_node_get_vert_indices(node);
for (const int i : verts.index_range())
unode->vert_hidden[i].set(hide_vert[verts[i]]);
}
static void sculpt_undo_store_face_hidden(Object &object, SculptUndoNode &unode)
{
using namespace blender;
const Mesh &mesh = *static_cast<const Mesh *>(object.data);
const bke::AttributeAccessor attributes = mesh.attributes();
const VArraySpan<bool> hide_poly = *attributes.lookup<bool>(".hide_poly", ATTR_DOMAIN_FACE);
@@ -1442,7 +1431,7 @@ static SculptUndoNode *sculpt_undo_geometry_push(Object *object, SculptUndoType
static void sculpt_undo_store_face_sets(const Mesh &mesh, SculptUndoNode &unode)
{
blender::array_utils::gather(
array_utils::gather(
*mesh.attributes().lookup_or_default<int>(".sculpt_face_set", ATTR_DOMAIN_FACE, 0),
unode.face_indices.as_span(),
unode.face_sets.as_mutable_span());
@@ -1524,7 +1513,7 @@ static SculptUndoNode *sculpt_undo_bmesh_push(Object *ob, PBVHNode *node, Sculpt
return unode;
}
SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType type)
SculptUndoNode *push_node(Object *ob, PBVHNode *node, SculptUndoType type)
{
SculptSession *ss = ob->sculpt;
SculptUndoNode *unode;
@@ -1546,7 +1535,7 @@ SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType
BLI_thread_unlock(LOCK_CUSTOM1);
return unode;
}
if ((unode = SCULPT_undo_get_node(node, type))) {
if ((unode = get_node(node, type))) {
BLI_thread_unlock(LOCK_CUSTOM1);
return unode;
}
@@ -1631,7 +1620,6 @@ static bool sculpt_attribute_ref_equals(SculptAttrRef *a, SculptAttrRef *b)
static void sculpt_save_active_attribute(Object *ob, SculptAttrRef *attr)
{
using namespace blender;
Mesh *mesh = BKE_object_get_original_mesh(ob);
attr->was_set = true;
attr->domain = NO_ACTIVE_LAYER;
@@ -1655,12 +1643,12 @@ static void sculpt_save_active_attribute(Object *ob, SculptAttrRef *attr)
attr->type = meta_data->data_type;
}
void SCULPT_undo_push_begin(Object *ob, const wmOperator *op)
void push_begin(Object *ob, const wmOperator *op)
{
SCULPT_undo_push_begin_ex(ob, op->type->name);
push_begin_ex(ob, op->type->name);
}
void SCULPT_undo_push_begin_ex(Object *ob, const char *name)
void push_begin_ex(Object *ob, const char *name)
{
UndoStack *ustack = ED_undo_stack_get();
@@ -1681,7 +1669,7 @@ void SCULPT_undo_push_begin_ex(Object *ob, const char *name)
sculpt_save_active_attribute(ob, &us->active_color_start);
}
/* Set end attribute in case SCULPT_undo_push_end is not called,
/* 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) {
@@ -1690,12 +1678,12 @@ void SCULPT_undo_push_begin_ex(Object *ob, const char *name)
}
}
void SCULPT_undo_push_end(Object *ob)
void push_end(Object *ob)
{
SCULPT_undo_push_end_ex(ob, false);
push_end_ex(ob, false);
}
void SCULPT_undo_push_end_ex(Object *ob, const bool use_nested_undo)
void push_end_ex(Object *ob, const bool use_nested_undo)
{
UndoSculpt *usculpt = sculpt_undo_get_nodes();
@@ -1765,7 +1753,7 @@ static void sculpt_undo_set_active_layer(bContext *C, SculptAttrRef *attr)
if (!layer) {
/* Memfile undo killed the layer; re-create it. */
me->attributes_for_write().add(
attr->name, attr->domain, attr->type, blender::bke::AttributeInitDefaultValue());
attr->name, attr->domain, attr->type, bke::AttributeInitDefaultValue());
layer = BKE_id_attribute_find(&me->id, attr->name, attr->type, attr->domain);
}
@@ -1945,25 +1933,25 @@ static void sculpt_undosys_step_free(UndoStep *us_p)
sculpt_undo_free_list(&us->data.nodes);
}
void ED_sculpt_undo_geometry_begin(Object *ob, const wmOperator *op)
void geometry_begin(Object *ob, const wmOperator *op)
{
SCULPT_undo_push_begin(ob, op);
SCULPT_undo_push_node(ob, nullptr, SculptUndoType::Geometry);
push_begin(ob, op);
push_node(ob, nullptr, SculptUndoType::Geometry);
}
void ED_sculpt_undo_geometry_begin_ex(Object *ob, const char *name)
void geometry_begin_ex(Object *ob, const char *name)
{
SCULPT_undo_push_begin_ex(ob, name);
SCULPT_undo_push_node(ob, nullptr, SculptUndoType::Geometry);
push_begin_ex(ob, name);
push_node(ob, nullptr, SculptUndoType::Geometry);
}
void ED_sculpt_undo_geometry_end(Object *ob)
void geometry_end(Object *ob)
{
SCULPT_undo_push_node(ob, nullptr, SculptUndoType::Geometry);
SCULPT_undo_push_end(ob);
push_node(ob, nullptr, SculptUndoType::Geometry);
push_end(ob);
}
void ED_sculpt_undosys_type(UndoType *ut)
void register_type(UndoType *ut)
{
ut->name = "Sculpt";
ut->poll = nullptr; /* No poll from context for now. */
@@ -2047,14 +2035,14 @@ static void sculpt_undo_push_all_grids(Object *object)
return;
}
Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(ss->pbvh, {});
Vector<PBVHNode *> nodes = bke::pbvh::search_gather(ss->pbvh, {});
for (PBVHNode *node : nodes) {
SculptUndoNode *unode = SCULPT_undo_push_node(object, node, SculptUndoType::Position);
SculptUndoNode *unode = push_node(object, node, SculptUndoType::Position);
unode->node = nullptr;
}
}
void ED_sculpt_undo_push_multires_mesh_begin(bContext *C, const char *str)
void push_multires_mesh_begin(bContext *C, const char *str)
{
if (!sculpt_undo_use_multires_mesh(C)) {
return;
@@ -2062,16 +2050,15 @@ void ED_sculpt_undo_push_multires_mesh_begin(bContext *C, const char *str)
Object *object = CTX_data_active_object(C);
SCULPT_undo_push_begin_ex(object, str);
push_begin_ex(object, str);
SculptUndoNode *geometry_unode = SCULPT_undo_push_node(
object, nullptr, SculptUndoType::Geometry);
SculptUndoNode *geometry_unode = push_node(object, nullptr, SculptUndoType::Geometry);
geometry_unode->geometry_clear_pbvh = false;
sculpt_undo_push_all_grids(object);
}
void ED_sculpt_undo_push_multires_mesh_end(bContext *C, const char *str)
void push_multires_mesh_end(bContext *C, const char *str)
{
if (!sculpt_undo_use_multires_mesh(C)) {
ED_undo_push(C, str);
@@ -2080,11 +2067,12 @@ void ED_sculpt_undo_push_multires_mesh_end(bContext *C, const char *str)
Object *object = CTX_data_active_object(C);
SculptUndoNode *geometry_unode = SCULPT_undo_push_node(
object, nullptr, SculptUndoType::Geometry);
SculptUndoNode *geometry_unode = push_node(object, nullptr, SculptUndoType::Geometry);
geometry_unode->geometry_clear_pbvh = false;
SCULPT_undo_push_end(object);
push_end(object);
}
/** \} */
} // namespace blender::ed::sculpt_paint::undo

View File

@@ -29,6 +29,7 @@
void ED_undosys_type_init()
{
/* Edit Modes */
using namespace blender;
BKE_undosys_type_append(ED_armature_undosys_type);
BKE_undosys_type_append(ED_curve_undosys_type);
BKE_undosys_type_append(ED_font_undosys_type);
@@ -40,7 +41,7 @@ void ED_undosys_type_init()
/* Paint Modes */
BKE_UNDOSYS_TYPE_IMAGE = BKE_undosys_type_append(ED_image_undosys_type);
BKE_UNDOSYS_TYPE_SCULPT = BKE_undosys_type_append(ED_sculpt_undosys_type);
BKE_UNDOSYS_TYPE_SCULPT = BKE_undosys_type_append(ed::sculpt_paint::undo::register_type);
BKE_UNDOSYS_TYPE_PARTICLE = BKE_undosys_type_append(ED_particle_undosys_type);