From 9f5878b62835da6cb83aa19127ac178c4e0fe3dc Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 6 Dec 2023 17:47:02 -0500 Subject: [PATCH] Cleanup: Use enum class for some sculpt enums Benefits are stronger type safety and prettier code. --- .../editors/sculpt_paint/paint_hide.cc | 16 +- .../editors/sculpt_paint/paint_mask.cc | 24 +- .../editors/sculpt_paint/paint_vertex.cc | 4 +- .../sculpt_paint/paint_vertex_color_ops.cc | 2 +- source/blender/editors/sculpt_paint/sculpt.cc | 48 +-- .../editors/sculpt_paint/sculpt_boundary.cc | 12 +- .../sculpt_paint/sculpt_brush_types.cc | 16 +- .../editors/sculpt_paint/sculpt_cloth.cc | 2 +- .../editors/sculpt_paint/sculpt_detail.cc | 2 +- .../editors/sculpt_paint/sculpt_dyntopo.cc | 4 +- .../editors/sculpt_paint/sculpt_expand.cc | 6 +- .../editors/sculpt_paint/sculpt_face_set.cc | 306 +++++++++--------- .../sculpt_paint/sculpt_filter_color.cc | 4 +- .../sculpt_paint/sculpt_filter_mask.cc | 2 +- .../sculpt_paint/sculpt_filter_mesh.cc | 12 +- .../editors/sculpt_paint/sculpt_intern.hh | 24 +- .../editors/sculpt_paint/sculpt_mask_init.cc | 2 +- .../editors/sculpt_paint/sculpt_ops.cc | 10 +- .../sculpt_paint/sculpt_paint_color.cc | 2 +- .../editors/sculpt_paint/sculpt_pose.cc | 2 +- .../editors/sculpt_paint/sculpt_smooth.cc | 2 +- .../editors/sculpt_paint/sculpt_transform.cc | 10 +- .../editors/sculpt_paint/sculpt_undo.cc | 140 ++++---- 23 files changed, 329 insertions(+), 323 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_hide.cc b/source/blender/editors/sculpt_paint/paint_hide.cc index 141484360e2..7dc074f549d 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.cc +++ b/source/blender/editors/sculpt_paint/paint_hide.cc @@ -112,7 +112,7 @@ void mesh_show_all(Object &object, const Span nodes) for (PBVHNode *node : nodes.slice(range)) { const Span verts = BKE_pbvh_node_get_vert_indices(node); if (std::any_of(verts.begin(), verts.end(), [&](const int i) { return hide_vert[i]; })) { - SCULPT_undo_push_node(&object, node, SCULPT_UNDO_HIDDEN); + SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert); BKE_pbvh_node_mark_rebuild_draw(node); } } @@ -159,7 +159,7 @@ static void vert_hide_update(Object &object, } any_changed = true; - SCULPT_undo_push_node(&object, node, SCULPT_UNDO_HIDDEN); + SCULPT_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); @@ -248,7 +248,7 @@ void grids_show_all(Depsgraph &depsgraph, Object &object, const Span })) { any_changed = true; - SCULPT_undo_push_node(&object, node, SCULPT_UNDO_HIDDEN); + SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert); BKE_pbvh_node_mark_rebuild_draw(node); } } @@ -296,7 +296,7 @@ static void grid_hide_update(Depsgraph &depsgraph, } any_changed = true; - SCULPT_undo_push_node(&object, node, SCULPT_UNDO_HIDDEN); + SCULPT_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()); @@ -441,7 +441,7 @@ static void partialvis_update_bmesh(Object *ob, bool any_changed = false; bool any_visible = false; - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_HIDDEN); + SCULPT_undo_push_node(ob, node, SculptUndoType::HideVert); partialvis_update_bmesh_verts(bm, BKE_pbvh_bmesh_node_unique_verts(node), @@ -633,7 +633,7 @@ static void invert_visibility_mesh(Object &object, const Span nodes) threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { - SCULPT_undo_push_node(&object, node, SCULPT_UNDO_HIDDEN); + SCULPT_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]; } @@ -657,7 +657,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, SCULPT_UNDO_HIDDEN); + SCULPT_undo_push_node(&object, node, SculptUndoType::HideVert); for (const int i : BKE_pbvh_node_get_grid_indices(*node)) { bits::invert(grid_hidden[i]); } @@ -674,7 +674,7 @@ static void invert_visibility_bmesh(Object &object, const Span nodes { threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { - SCULPT_undo_push_node(&object, node, SCULPT_UNDO_HIDDEN); + SCULPT_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); diff --git a/source/blender/editors/sculpt_paint/paint_mask.cc b/source/blender/editors/sculpt_paint/paint_mask.cc index 620d8da1e53..4cf942988d0 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.cc +++ b/source/blender/editors/sculpt_paint/paint_mask.cc @@ -188,7 +188,7 @@ static bool try_remove_mask_mesh(Object &object, const Span nodes) if (std::all_of(verts.begin(), verts.end(), [&](const int i) { return mask[i] == 0.0f; })) { continue; } - SCULPT_undo_push_node(&object, node, SCULPT_UNDO_MASK); + SCULPT_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 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, SCULPT_UNDO_MASK); + SCULPT_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 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, SCULPT_UNDO_MASK); + SCULPT_undo_push_node(&object, node, SculptUndoType::Mask); const Span 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 nodes) return; } - SCULPT_undo_push_node(&object, nodes.first(), SCULPT_UNDO_MASK); + SCULPT_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)) { @@ -1042,7 +1042,7 @@ static void face_set_gesture_apply_task(SculptGestureContext *sgcontext, PBVHNod SculptSession &ss = *sgcontext->ss; const PBVH &pbvh = *sgcontext->ss->pbvh; - SCULPT_undo_push_node(sgcontext->vc.obact, node, SCULPT_UNDO_FACE_SETS); + SCULPT_undo_push_node(sgcontext->vc.obact, node, SculptUndoType::FaceSet); const int new_face_set = face_set_operation->new_face_set_id; @@ -1171,7 +1171,7 @@ static void mask_gesture_apply_task(SculptGestureContext *sgcontext, if (!any_masked) { any_masked = true; - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_MASK); + SCULPT_undo_push_node(ob, node, SculptUndoType::Mask); if (is_multires) { BKE_pbvh_node_mark_normals_update(node); @@ -1755,7 +1755,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, SCULPT_UNDO_GEOMETRY); + SCULPT_undo_push_node(sgcontext->vc.obact, nullptr, SculptUndoType::Geometry); } static void sculpt_gesture_trim_apply_for_symmetry_pass(bContext * /*C*/, @@ -1788,7 +1788,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, SCULPT_UNDO_GEOMETRY); + SCULPT_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); } @@ -1863,7 +1863,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, SCULPT_UNDO_COORDS); + SCULPT_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]; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index 21472962cdc..c8954fa475d 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -1808,7 +1808,7 @@ static void vpaint_paint_leaves(bContext *C, Span nodes) { for (PBVHNode *node : nodes) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_COLOR); + SCULPT_undo_push_node(ob, node, SculptUndoType::Color); } const Brush *brush = ob->sculpt->cache->brush; @@ -2255,7 +2255,7 @@ static int vertex_color_set_exec(bContext *C, wmOperator *op) SCULPT_undo_push_begin(obact, op); Vector nodes = blender::bke::pbvh::search_gather(obact->sculpt->pbvh, {}); for (PBVHNode *node : nodes) { - SCULPT_undo_push_node(obact, node, SCULPT_UNDO_COLOR); + SCULPT_undo_push_node(obact, node, SculptUndoType::Color); } paint_object_attributes_active_color_fill_ex(obact, paintcol, true, affect_alpha); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc index 290ab1ef97c..edfa14b3611 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc @@ -310,7 +310,7 @@ static void transform_active_color(bContext *C, Vector nodes = blender::bke::pbvh::search_gather(obact->sculpt->pbvh, {}); for (PBVHNode *node : nodes) { - SCULPT_undo_push_node(obact, node, SCULPT_UNDO_COLOR); + SCULPT_undo_push_node(obact, node, SculptUndoType::Color); } transform_active_color_data(*BKE_mesh_from_object(obact), transform_fn); diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index 6ace76a0fcc..fde316b7450 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -1351,7 +1351,7 @@ void SCULPT_orig_vert_data_init(SculptOrigVertData *data, void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter *iter) { - if (orig_data->unode->type == SCULPT_UNDO_COORDS) { + if (orig_data->unode->type == SculptUndoType::Position) { if (orig_data->bm_log) { BM_log_original_vert_data(orig_data->bm_log, iter->bm_vert, &orig_data->co, &orig_data->no); } @@ -1360,10 +1360,10 @@ void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter orig_data->no = orig_data->normals[iter->i]; } } - else if (orig_data->unode->type == SCULPT_UNDO_COLOR) { + else if (orig_data->unode->type == SculptUndoType::Color) { orig_data->col = orig_data->colors[iter->i]; } - else if (orig_data->unode->type == SCULPT_UNDO_MASK) { + else if (orig_data->unode->type == SculptUndoType::Mask) { if (orig_data->bm_log) { orig_data->mask = BM_log_original_mask(orig_data->bm_log, iter->bm_vert); } @@ -1426,7 +1426,7 @@ static void paint_mesh_restore_node(Object *ob, } switch (type) { - case SCULPT_UNDO_MASK: { + case SculptUndoType::Mask: { switch (BKE_pbvh_type(ss->pbvh)) { case PBVH_FACES: { blender::array_utils::scatter(unode->mask.as_span(), @@ -1456,7 +1456,7 @@ static void paint_mesh_restore_node(Object *ob, BKE_pbvh_node_mark_update_mask(node); break; } - case SCULPT_UNDO_COLOR: { + case SculptUndoType::Color: { SculptOrigVertData orig_vert_data; SCULPT_orig_vert_data_unode_init(&orig_vert_data, ob, unode); PBVHVertexIter vd; @@ -1468,7 +1468,7 @@ static void paint_mesh_restore_node(Object *ob, BKE_pbvh_node_mark_update_color(node); break; } - case SCULPT_UNDO_FACE_SETS: { + case SculptUndoType::FaceSet: { const Span face_sets = unode->face_sets; ss->face_sets = BKE_sculpt_face_sets_ensure(ob); switch (BKE_pbvh_type(ss->pbvh)) { @@ -1493,7 +1493,7 @@ static void paint_mesh_restore_node(Object *ob, BKE_pbvh_node_mark_update_face_sets(node); break; } - case SCULPT_UNDO_COORDS: { + case SculptUndoType::Position: { SculptOrigVertData orig_vert_data; SCULPT_orig_vert_data_unode_init(&orig_vert_data, ob, unode); PBVHVertexIter vd; @@ -1524,22 +1524,22 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob) SculptUndoType type; switch (brush->sculpt_tool) { case SCULPT_TOOL_MASK: - type = SCULPT_UNDO_MASK; + type = SculptUndoType::Mask; break; case SCULPT_TOOL_PAINT: case SCULPT_TOOL_SMEAR: - type = SCULPT_UNDO_COLOR; + type = SculptUndoType::Color; break; case SCULPT_TOOL_DRAW_FACE_SETS: - type = ss->cache->alt_smooth ? SCULPT_UNDO_COORDS : SCULPT_UNDO_FACE_SETS; + type = ss->cache->alt_smooth ? SculptUndoType::Position : SculptUndoType::FaceSet; break; default: - type = SCULPT_UNDO_COORDS; + type = SculptUndoType::Position; break; } SculptMaskWriteInfo mask_write; - if (type == SCULPT_UNDO_MASK) { + if (type == SculptUndoType::Mask) { mask_write = SCULPT_mask_get_for_write(ss); } @@ -1929,7 +1929,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, SCULPT_UNDO_COORDS); + unode = SCULPT_undo_push_node(ob, node, SculptUndoType::Position); use_original = (!unode->co.is_empty() || unode->bm_entry); } @@ -3315,8 +3315,10 @@ static void sculpt_topology_update(Sculpt *sd, } for (PBVHNode *node : nodes) { - SCULPT_undo_push_node( - ob, node, brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK : SCULPT_UNDO_COORDS); + SCULPT_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) { @@ -3354,15 +3356,15 @@ static void do_brush_action_task(Object *ob, const Brush *brush, PBVHNode *node) need_coords = true; } else { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_FACE_SETS); + SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet); } } else if (brush->sculpt_tool == SCULPT_TOOL_MASK) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_MASK); + SCULPT_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, SCULPT_UNDO_COLOR); + SCULPT_undo_push_node(ob, node, SculptUndoType::Color); BKE_pbvh_node_mark_update_color(node); } else { @@ -3370,7 +3372,7 @@ static void do_brush_action_task(Object *ob, const Brush *brush, PBVHNode *node) } if (need_coords) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_COORDS); + SCULPT_undo_push_node(ob, node, SculptUndoType::Position); BKE_pbvh_node_mark_update(node); } } @@ -3705,7 +3707,7 @@ static void sculpt_combine_proxies_node(Object &object, float(*orco)[3] = nullptr; if (use_orco && !ss->bm) { orco = reinterpret_cast( - (SCULPT_undo_push_node(&object, &node, SCULPT_UNDO_COORDS)->co.data())); + (SCULPT_undo_push_node(&object, &node, SculptUndoType::Position)->co.data())); } MutableSpan proxies = BKE_pbvh_node_get_proxies(&node); @@ -4847,7 +4849,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, SCULPT_UNDO_COORDS); + SculptUndoNode *unode = SCULPT_undo_get_node(node, SculptUndoType::Position); origco = (unode) ? reinterpret_cast(unode->co.data()) : nullptr; use_origco = origco ? true : false; } @@ -4887,7 +4889,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, SCULPT_UNDO_COORDS); + SculptUndoNode *unode = SCULPT_undo_get_node(node, SculptUndoType::Position); origco = (unode) ? reinterpret_cast(unode->co.data()) : nullptr; use_origco = origco ? true : false; } @@ -6061,7 +6063,7 @@ void SCULPT_automasking_node_begin(Object *ob, (BRUSH_AUTOMASKING_BRUSH_NORMAL | BRUSH_AUTOMASKING_VIEW_NORMAL); if (automask_data->have_orig_data) { - SCULPT_orig_vert_data_init(&automask_data->orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&automask_data->orig_data, ob, node, SculptUndoType::Position); } else { memset(&automask_data->orig_data, 0, sizeof(automask_data->orig_data)); diff --git a/source/blender/editors/sculpt_paint/sculpt_boundary.cc b/source/blender/editors/sculpt_paint/sculpt_boundary.cc index ef904127713..49091a26642 100644 --- a/source/blender/editors/sculpt_paint/sculpt_boundary.cc +++ b/source/blender/editors/sculpt_paint/sculpt_boundary.cc @@ -660,7 +660,7 @@ static void do_boundary_brush_bend_task(Object *ob, const Brush *brush, PBVHNode PBVHVertexIter vd; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); const float disp = strength * sculpt_boundary_displacement_from_grab_delta_get(ss, boundary); float angle_factor = disp / ss->cache->radius; @@ -714,7 +714,7 @@ static void do_boundary_brush_slide_task(Object *ob, const Brush *brush, PBVHNod PBVHVertexIter vd; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); const float disp = sculpt_boundary_displacement_from_grab_delta_get(ss, boundary); AutomaskingNodeData automask_data; @@ -760,7 +760,7 @@ static void do_boundary_brush_inflate_task(Object *ob, const Brush *brush, PBVHN PBVHVertexIter vd; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); AutomaskingNodeData automask_data; SCULPT_automasking_node_begin(ob, ss->cache->automasking, &automask_data, node); @@ -806,7 +806,7 @@ static void do_boundary_brush_grab_task(Object *ob, const Brush *brush, PBVHNode PBVHVertexIter vd; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); AutomaskingNodeData automask_data; SCULPT_automasking_node_begin(ob, ss->cache->automasking, &automask_data, node); @@ -849,7 +849,7 @@ static void do_boundary_brush_twist_task(Object *ob, const Brush *brush, PBVHNod PBVHVertexIter vd; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); AutomaskingNodeData automask_data; SCULPT_automasking_node_begin(ob, ss->cache->automasking, &automask_data, node); @@ -903,7 +903,7 @@ static void do_boundary_brush_smooth_task(Object *ob, const Brush *brush, PBVHNo PBVHVertexIter vd; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { if (boundary->edit_info[vd.index].propagation_steps_num == -1) { diff --git a/source/blender/editors/sculpt_paint/sculpt_brush_types.cc b/source/blender/editors/sculpt_paint/sculpt_brush_types.cc index 74d9c816c0b..88f27c944b1 100644 --- a/source/blender/editors/sculpt_paint/sculpt_brush_types.cc +++ b/source/blender/editors/sculpt_paint/sculpt_brush_types.cc @@ -1235,7 +1235,7 @@ static void do_thumb_brush_task(Object *ob, const Brush *brush, const float *con const MutableSpan proxy = BKE_pbvh_node_add_proxy(*ss->pbvh, *node).co; const float bstrength = ss->cache->bstrength; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( @@ -1302,7 +1302,7 @@ static void do_rotate_brush_task(Object *ob, const Brush *brush, const float ang const MutableSpan proxy = BKE_pbvh_node_add_proxy(*ss->pbvh, *node).co; const float bstrength = ss->cache->bstrength; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( @@ -1372,7 +1372,7 @@ static void do_layer_brush_task(Object *ob, Sculpt *sd, const Brush *brush, PBVH PBVHVertexIter vd; SculptOrigVertData orig_data; const float bstrength = ss->cache->bstrength; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( @@ -1836,7 +1836,7 @@ static void do_grab_brush_task(Object *ob, const MutableSpan proxy = BKE_pbvh_node_add_proxy(*ss->pbvh, *node).co; const float bstrength = ss->cache->bstrength; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( @@ -1921,7 +1921,7 @@ static void do_elastic_deform_brush_task(Object *ob, const float bstrength = ss->cache->bstrength; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); AutomaskingNodeData automask_data; SCULPT_automasking_node_begin(ob, ss->cache->automasking, &automask_data, node); @@ -2027,7 +2027,7 @@ static void do_draw_sharp_brush_task(Object *ob, SculptOrigVertData orig_data; const MutableSpan proxy = BKE_pbvh_node_add_proxy(*ss->pbvh, *node).co; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( @@ -2105,7 +2105,7 @@ static void do_topology_slide_task(Object *ob, const Brush *brush, PBVHNode *nod SculptOrigVertData orig_data; const MutableSpan proxy = BKE_pbvh_node_add_proxy(*ss->pbvh, *node).co; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( @@ -2263,7 +2263,7 @@ static void do_topology_relax_task(Object *ob, const Brush *brush, PBVHNode *nod PBVHVertexIter vd; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); /* TODO(@sergey): This looks very suspicious: proxy is added but is never written. * Either this needs to be documented better why it is needed, or removed. The removal is likely diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.cc b/source/blender/editors/sculpt_paint/sculpt_cloth.cc index b0dbf3e811d..750659edf4b 100644 --- a/source/blender/editors/sculpt_paint/sculpt_cloth.cc +++ b/source/blender/editors/sculpt_paint/sculpt_cloth.cc @@ -1530,7 +1530,7 @@ static int sculpt_cloth_filter_invoke(bContext *C, wmOperator *op, const wmEvent SCULPT_filter_cache_init(C, ob, sd, - SCULPT_UNDO_COORDS, + SculptUndoType::Position, mval_fl, RNA_float_get(op->ptr, "area_normal_radius"), RNA_float_get(op->ptr, "strength")); diff --git a/source/blender/editors/sculpt_paint/sculpt_detail.cc b/source/blender/editors/sculpt_paint/sculpt_detail.cc index 1b8611f32de..59779a2930e 100644 --- a/source/blender/editors/sculpt_paint/sculpt_detail.cc +++ b/source/blender/editors/sculpt_paint/sculpt_detail.cc @@ -112,7 +112,7 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op) BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail); SCULPT_undo_push_begin(ob, op); - SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_COORDS); + SCULPT_undo_push_node(ob, nullptr, SculptUndoType::Position); const double start_time = PIL_check_seconds_timer(); diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc b/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc index a95bff21fbd..2507e74c8e0 100644 --- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc @@ -213,7 +213,7 @@ void sculpt_dynamic_topology_disable_with_undo(Main *bmain, 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, SCULPT_UNDO_DYNTOPO_END); + SCULPT_undo_push_node(ob, nullptr, SculptUndoType::DyntopoEnd); } SCULPT_dynamic_topology_disable_ex(bmain, depsgraph, scene, ob, nullptr); if (use_undo) { @@ -233,7 +233,7 @@ static void sculpt_dynamic_topology_enable_with_undo(Main *bmain, Depsgraph *dep } SCULPT_dynamic_topology_enable_ex(bmain, depsgraph, ob); if (use_undo) { - SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_DYNTOPO_BEGIN); + SCULPT_undo_push_node(ob, nullptr, SculptUndoType::DyntopoBegin); SCULPT_undo_push_end(ob); } } diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.cc b/source/blender/editors/sculpt_paint/sculpt_expand.cc index 53e5d7e9c85..2cf22a9494c 100644 --- a/source/blender/editors/sculpt_paint/sculpt_expand.cc +++ b/source/blender/editors/sculpt_paint/sculpt_expand.cc @@ -2121,17 +2121,17 @@ static void sculpt_expand_undo_push(Object *ob, ExpandCache *expand_cache) switch (expand_cache->target) { case SCULPT_EXPAND_TARGET_MASK: for (PBVHNode *node : nodes) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_MASK); + SCULPT_undo_push_node(ob, node, SculptUndoType::Mask); } break; case SCULPT_EXPAND_TARGET_FACE_SETS: for (PBVHNode *node : nodes) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_FACE_SETS); + SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet); } break; case SCULPT_EXPAND_TARGET_COLORS: for (PBVHNode *node : nodes) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_COLOR); + SCULPT_undo_push_node(ob, node, SculptUndoType::Color); } break; } diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc index 783e551c884..2a11d35b2dc 100644 --- a/source/blender/editors/sculpt_paint/sculpt_face_set.cc +++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc @@ -173,7 +173,7 @@ static void do_draw_face_sets_brush_faces(Object *ob, const Brush *brush, PBVHNo BKE_pbvh_vertex_iter_end; if (changed) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_FACE_SETS); + SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet); } } @@ -221,7 +221,7 @@ static void do_draw_face_sets_brush_grids(Object *ob, const Brush *brush, PBVHNo BKE_pbvh_vertex_iter_end; if (changed) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_FACE_SETS); + SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet); } } @@ -306,7 +306,7 @@ static void do_draw_face_sets_brush_bmesh(Object *ob, const Brush *brush, PBVHNo } if (changed) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_FACE_SETS); + SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet); } } @@ -412,11 +412,11 @@ void do_draw_face_sets_brush(Sculpt *sd, Object *ob, Span nodes) /* Face Sets Operators */ -enum eSculptFaceGroupsCreateModes { - SCULPT_FACE_SET_MASKED = 0, - SCULPT_FACE_SET_VISIBLE = 1, - SCULPT_FACE_SET_ALL = 2, - SCULPT_FACE_SET_SELECTION = 3, +enum class CreateMode { + Masked = 0, + Visible = 1, + All = 2, + Selection = 3, }; static int sculpt_face_set_create_exec(bContext *C, wmOperator *op) @@ -425,7 +425,7 @@ static int sculpt_face_set_create_exec(bContext *C, wmOperator *op) SculptSession *ss = ob->sculpt; Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); - const int mode = RNA_enum_get(op->ptr, "mode"); + const CreateMode mode = CreateMode(RNA_enum_get(op->ptr, "mode")); /* Dyntopo not supported. */ if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { @@ -449,69 +449,74 @@ static int sculpt_face_set_create_exec(bContext *C, wmOperator *op) SCULPT_undo_push_begin(ob, op); for (PBVHNode *node : nodes) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_FACE_SETS); + SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet); } const int next_face_set = SCULPT_face_set_next_available_get(ss); - if (mode == SCULPT_FACE_SET_MASKED) { - for (int i = 0; i < tot_vert; i++) { - PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); + switch (mode) { + case CreateMode::Masked: { + for (int i = 0; i < tot_vert; i++) { + PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); - if (SCULPT_vertex_mask_get(ss, vertex) >= threshold && SCULPT_vertex_visible_get(ss, vertex)) - { - SCULPT_vertex_face_set_set(ss, vertex, next_face_set); - } - } - } - - if (mode == SCULPT_FACE_SET_VISIBLE) { - - /* If all vertices in the sculpt are visible, create the new face set and update the default - * color. This way the new face set will be white, which is a quick way of disabling all face - * sets and the performance hit of rendering the overlay. */ - bool all_visible = true; - for (int i = 0; i < tot_vert; i++) { - PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); - - if (!SCULPT_vertex_visible_get(ss, vertex)) { - all_visible = false; - break; - } - } - - if (all_visible) { - mesh->face_sets_color_default = next_face_set; - } - - for (int i = 0; i < tot_vert; i++) { - PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); - - if (SCULPT_vertex_visible_get(ss, vertex)) { - SCULPT_vertex_face_set_set(ss, vertex, next_face_set); - } - } - } - - if (mode == SCULPT_FACE_SET_ALL) { - for (int i = 0; i < tot_vert; i++) { - PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); - - SCULPT_vertex_face_set_set(ss, vertex, next_face_set); - } - } - - if (mode == SCULPT_FACE_SET_SELECTION) { - const bke::AttributeAccessor attributes = mesh->attributes(); - const VArraySpan select_poly = *attributes.lookup_or_default( - ".select_poly", ATTR_DOMAIN_FACE, false); - threading::parallel_for(select_poly.index_range(), 4096, [&](const IndexRange range) { - for (const int i : range) { - if (select_poly[i]) { - ss->face_sets[i] = next_face_set; + if (SCULPT_vertex_mask_get(ss, vertex) >= threshold && + SCULPT_vertex_visible_get(ss, vertex)) { + SCULPT_vertex_face_set_set(ss, vertex, next_face_set); } } - }); + + break; + } + case CreateMode::Visible: { + /* If all vertices in the sculpt are visible, create the new face set and update the default + * color. This way the new face set will be white, which is a quick way of disabling all face + * sets and the performance hit of rendering the overlay. */ + bool all_visible = true; + for (int i = 0; i < tot_vert; i++) { + PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); + + if (!SCULPT_vertex_visible_get(ss, vertex)) { + all_visible = false; + break; + } + } + + if (all_visible) { + mesh->face_sets_color_default = next_face_set; + } + + for (int i = 0; i < tot_vert; i++) { + PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); + + if (SCULPT_vertex_visible_get(ss, vertex)) { + SCULPT_vertex_face_set_set(ss, vertex, next_face_set); + } + } + + break; + } + case CreateMode::All: { + for (int i = 0; i < tot_vert; i++) { + PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); + + SCULPT_vertex_face_set_set(ss, vertex, next_face_set); + } + + break; + } + case CreateMode::Selection: { + const bke::AttributeAccessor attributes = mesh->attributes(); + const VArraySpan select_poly = *attributes.lookup_or_default( + ".select_poly", ATTR_DOMAIN_FACE, false); + threading::parallel_for(select_poly.index_range(), 4096, [&](const IndexRange range) { + for (const int i : range) { + if (select_poly[i]) { + ss->face_sets[i] = next_face_set; + } + } + }); + break; + } } for (PBVHNode *node : nodes) { @@ -537,40 +542,40 @@ void SCULPT_OT_face_sets_create(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; static EnumPropertyItem modes[] = { - {SCULPT_FACE_SET_MASKED, + {int(CreateMode::Masked), "MASKED", 0, "Face Set from Masked", "Create a new Face Set from the masked faces"}, - {SCULPT_FACE_SET_VISIBLE, + {int(CreateMode::Visible), "VISIBLE", 0, "Face Set from Visible", "Create a new Face Set from the visible vertices"}, - {SCULPT_FACE_SET_ALL, + {int(CreateMode::All), "ALL", 0, "Face Set Full Mesh", "Create an unique Face Set with all faces in the sculpt"}, - {SCULPT_FACE_SET_SELECTION, + {int(CreateMode::Selection), "SELECTION", 0, "Face Set from Edit Mode Selection", "Create an Face Set corresponding to the Edit Mode face selection"}, {0, nullptr, 0, nullptr, nullptr}, }; - RNA_def_enum(ot->srna, "mode", modes, SCULPT_FACE_SET_MASKED, "Mode", ""); + RNA_def_enum(ot->srna, "mode", modes, int(CreateMode::Masked), "Mode", ""); } -enum eSculptFaceSetsInitMode { - SCULPT_FACE_SETS_FROM_LOOSE_PARTS = 0, - SCULPT_FACE_SETS_FROM_MATERIALS = 1, - SCULPT_FACE_SETS_FROM_NORMALS = 2, - SCULPT_FACE_SETS_FROM_UV_SEAMS = 3, - SCULPT_FACE_SETS_FROM_CREASES = 4, - SCULPT_FACE_SETS_FROM_SHARP_EDGES = 5, - SCULPT_FACE_SETS_FROM_BEVEL_WEIGHT = 6, - SCULPT_FACE_SETS_FROM_FACE_SET_BOUNDARIES = 8, +enum class InitMode { + LooseParts = 0, + Materials = 1, + Normals = 2, + UVSeams = 3, + Creases = 4, + SharpEdges = 5, + BevelWeight = 6, + FaceSetBoundaries = 8, }; using FaceSetsFloodFillFn = FunctionRef; @@ -632,12 +637,12 @@ static void sculpt_face_sets_init_flood_fill(Object *ob, const FaceSetsFloodFill } } -static void sculpt_face_sets_init_loop(Object *ob, const int mode) +static void sculpt_face_sets_init_loop(Object *ob, const InitMode mode) { Mesh *mesh = static_cast(ob->data); SculptSession *ss = ob->sculpt; - if (mode == SCULPT_FACE_SETS_FROM_MATERIALS) { + if (mode == InitMode::Materials) { const bke::AttributeAccessor attributes = mesh->attributes(); const VArraySpan material_indices = *attributes.lookup_or_default( "material_index", ATTR_DOMAIN_FACE, 0); @@ -653,7 +658,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) SculptSession *ss = ob->sculpt; Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); - const int mode = RNA_enum_get(op->ptr, "mode"); + const InitMode mode = InitMode(RNA_enum_get(op->ptr, "mode")); BKE_sculpt_update_object_for_edit(depsgraph, ob, false); @@ -671,7 +676,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) SCULPT_undo_push_begin(ob, op); for (PBVHNode *node : nodes) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_FACE_SETS); + SCULPT_undo_push_node(ob, node, SculptUndoType::FaceSet); } const float threshold = RNA_float_get(op->ptr, "threshold"); @@ -681,7 +686,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) const bke::AttributeAccessor attributes = mesh->attributes(); switch (mode) { - case SCULPT_FACE_SETS_FROM_LOOSE_PARTS: { + case InitMode::LooseParts: { const VArray hide_poly = *attributes.lookup_or_default( ".hide_poly", ATTR_DOMAIN_FACE, false); sculpt_face_sets_init_flood_fill( @@ -690,11 +695,11 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) }); break; } - case SCULPT_FACE_SETS_FROM_MATERIALS: { - sculpt_face_sets_init_loop(ob, SCULPT_FACE_SETS_FROM_MATERIALS); + case InitMode::Materials: { + sculpt_face_sets_init_loop(ob, InitMode::Materials); break; } - case SCULPT_FACE_SETS_FROM_NORMALS: { + case InitMode::Normals: { const Span face_normals = mesh->face_normals(); sculpt_face_sets_init_flood_fill( ob, [&](const int from_face, const int /*edge*/, const int to_face) -> bool { @@ -702,7 +707,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) }); break; } - case SCULPT_FACE_SETS_FROM_UV_SEAMS: { + case InitMode::UVSeams: { const VArraySpan uv_seams = *mesh->attributes().lookup_or_default( ".uv_seam", ATTR_DOMAIN_EDGE, false); sculpt_face_sets_init_flood_fill( @@ -711,7 +716,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) }); break; } - case SCULPT_FACE_SETS_FROM_CREASES: { + case InitMode::Creases: { const float *creases = static_cast( CustomData_get_layer_named(&mesh->edge_data, CD_PROP_FLOAT, "crease_edge")); sculpt_face_sets_init_flood_fill( @@ -720,7 +725,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) }); break; } - case SCULPT_FACE_SETS_FROM_SHARP_EDGES: { + case InitMode::SharpEdges: { const VArraySpan sharp_edges = *mesh->attributes().lookup_or_default( "sharp_edge", ATTR_DOMAIN_EDGE, false); sculpt_face_sets_init_flood_fill( @@ -729,7 +734,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) }); break; } - case SCULPT_FACE_SETS_FROM_BEVEL_WEIGHT: { + case InitMode::BevelWeight: { const float *bevel_weights = static_cast( CustomData_get_layer_named(&mesh->edge_data, CD_PROP_FLOAT, "bevel_weight_edge")); sculpt_face_sets_init_flood_fill( @@ -738,7 +743,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) }); break; } - case SCULPT_FACE_SETS_FROM_FACE_SET_BOUNDARIES: { + case InitMode::FaceSetBoundaries: { Array face_sets_copy(Span(ss->face_sets, mesh->faces_num)); sculpt_face_sets_init_flood_fill( ob, [&](const int from_face, const int /*edge*/, const int to_face) -> bool { @@ -767,49 +772,49 @@ void SCULPT_OT_face_sets_init(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; static EnumPropertyItem modes[] = { - {SCULPT_FACE_SETS_FROM_LOOSE_PARTS, + {int(InitMode::LooseParts), "LOOSE_PARTS", 0, "Face Sets from Loose Parts", "Create a Face Set per loose part in the mesh"}, - {SCULPT_FACE_SETS_FROM_MATERIALS, + {int(InitMode::Materials), "MATERIALS", 0, "Face Sets from Material Slots", "Create a Face Set per Material Slot"}, - {SCULPT_FACE_SETS_FROM_NORMALS, + {int(InitMode::Normals), "NORMALS", 0, "Face Sets from Mesh Normals", "Create Face Sets for Faces that have similar normal"}, - {SCULPT_FACE_SETS_FROM_UV_SEAMS, + {int(InitMode::UVSeams), "UV_SEAMS", 0, "Face Sets from UV Seams", "Create Face Sets using UV Seams as boundaries"}, - {SCULPT_FACE_SETS_FROM_CREASES, + {int(InitMode::Creases), "CREASES", 0, "Face Sets from Edge Creases", "Create Face Sets using Edge Creases as boundaries"}, - {SCULPT_FACE_SETS_FROM_BEVEL_WEIGHT, + {int(InitMode::BevelWeight), "BEVEL_WEIGHT", 0, "Face Sets from Bevel Weight", "Create Face Sets using Bevel Weights as boundaries"}, - {SCULPT_FACE_SETS_FROM_SHARP_EDGES, + {int(InitMode::SharpEdges), "SHARP_EDGES", 0, "Face Sets from Sharp Edges", "Create Face Sets using Sharp Edges as boundaries"}, - {SCULPT_FACE_SETS_FROM_FACE_SET_BOUNDARIES, + {int(InitMode::FaceSetBoundaries), "FACE_SET_BOUNDARIES", 0, "Face Sets from Face Set Boundaries", "Create a Face Set per isolated Face Set"}, {0, nullptr, 0, nullptr, nullptr}, }; - RNA_def_enum(ot->srna, "mode", modes, SCULPT_FACE_SET_MASKED, "Mode", ""); + RNA_def_enum(ot->srna, "mode", modes, int(InitMode::LooseParts), "Mode", ""); RNA_def_float( ot->srna, "threshold", @@ -822,10 +827,10 @@ void SCULPT_OT_face_sets_init(wmOperatorType *ot) 1.0f); } -enum eSculptFaceGroupVisibilityModes { - SCULPT_FACE_SET_VISIBILITY_TOGGLE = 0, - SCULPT_FACE_SET_VISIBILITY_SHOW_ACTIVE = 1, - SCULPT_FACE_SET_VISIBILITY_HIDE_ACTIVE = 2, +enum class VisibilityMode { + Toggle = 0, + ShowActive = 1, + HideActive = 2, }; static void face_hide_update(Object &object, @@ -861,7 +866,7 @@ static void face_hide_update(Object &object, } any_changed = true; - SCULPT_undo_push_node(&object, node, SCULPT_UNDO_FACE_HIDDEN); + SCULPT_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); } @@ -902,7 +907,7 @@ static int sculpt_face_set_change_visibility_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - const int mode = RNA_enum_get(op->ptr, "mode"); + 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); @@ -915,7 +920,7 @@ static int sculpt_face_set_change_visibility_exec(bContext *C, wmOperator *op) const VArraySpan face_sets = *attributes.lookup(".sculpt_face_set", ATTR_DOMAIN_FACE); switch (mode) { - case SCULPT_FACE_SET_VISIBILITY_TOGGLE: { + case VisibilityMode::Toggle: { if (hide_poly.contains(true) || face_sets.is_empty()) { show_all(depsgraph, object, nodes); } @@ -928,7 +933,7 @@ static int sculpt_face_set_change_visibility_exec(bContext *C, wmOperator *op) } break; } - case SCULPT_FACE_SET_VISIBILITY_SHOW_ACTIVE: + case VisibilityMode::ShowActive: if (face_sets.is_empty()) { show_all(depsgraph, object, nodes); } @@ -942,7 +947,7 @@ static int sculpt_face_set_change_visibility_exec(bContext *C, wmOperator *op) }); } break; - case SCULPT_FACE_SET_VISIBILITY_HIDE_ACTIVE: + case VisibilityMode::HideActive: if (face_sets.is_empty()) { face_hide_update(object, nodes, [&](const Span /*faces*/, MutableSpan hide) { hide.fill(true); @@ -962,7 +967,7 @@ static int sculpt_face_set_change_visibility_exec(bContext *C, wmOperator *op) /* For modes that use the cursor active vertex, update the rotation origin for viewport * navigation. */ - if (ELEM(mode, SCULPT_FACE_SET_VISIBILITY_TOGGLE, SCULPT_FACE_SET_VISIBILITY_SHOW_ACTIVE)) { + if (ELEM(mode, VisibilityMode::Toggle, VisibilityMode::ShowActive)) { UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; float location[3]; copy_v3_v3(location, SCULPT_active_vertex_co_get(ss)); @@ -1013,24 +1018,24 @@ void SCULPT_OT_face_set_change_visibility(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_DEPENDS_ON_CURSOR; static EnumPropertyItem modes[] = { - {SCULPT_FACE_SET_VISIBILITY_TOGGLE, + {int(VisibilityMode::Toggle), "TOGGLE", 0, "Toggle Visibility", "Hide all Face Sets except for the active one"}, - {SCULPT_FACE_SET_VISIBILITY_SHOW_ACTIVE, + {int(VisibilityMode::ShowActive), "SHOW_ACTIVE", 0, "Show Active Face Set", "Show Active Face Set"}, - {SCULPT_FACE_SET_VISIBILITY_HIDE_ACTIVE, + {int(VisibilityMode::HideActive), "HIDE_ACTIVE", 0, "Hide Active Face Sets", "Hide Active Face Sets"}, {0, nullptr, 0, nullptr, nullptr}, }; - RNA_def_enum(ot->srna, "mode", modes, SCULPT_FACE_SET_VISIBILITY_TOGGLE, "Mode", ""); + RNA_def_enum(ot->srna, "mode", modes, int(VisibilityMode::Toggle), "Mode", ""); } static int sculpt_face_sets_randomize_colors_exec(bContext *C, wmOperator * /*op*/) @@ -1081,12 +1086,12 @@ void SCULPT_OT_face_sets_randomize_colors(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -enum eSculptFaceSetEditMode { - SCULPT_FACE_SET_EDIT_GROW = 0, - SCULPT_FACE_SET_EDIT_SHRINK = 1, - SCULPT_FACE_SET_EDIT_DELETE_GEOMETRY = 2, - SCULPT_FACE_SET_EDIT_FAIR_POSITIONS = 3, - SCULPT_FACE_SET_EDIT_FAIR_TANGENCY = 4, +enum class EditMode { + Grow = 0, + Shrink = 1, + DeleteGeometry = 2, + FairPositions = 3, + FairTangency = 4, }; static void sculpt_face_set_grow(Object *ob, @@ -1257,33 +1262,33 @@ static void sculpt_face_set_edit_fair_face_set(Object *ob, static void sculpt_face_set_apply_edit(Object *ob, const int active_face_set_id, - const int mode, + const EditMode mode, const bool modify_hidden, const float strength = 0.0f) { SculptSession *ss = ob->sculpt; switch (mode) { - case SCULPT_FACE_SET_EDIT_GROW: { + case EditMode::Grow: { int *prev_face_sets = static_cast(MEM_dupallocN(ss->face_sets)); sculpt_face_set_grow(ob, ss, prev_face_sets, active_face_set_id, modify_hidden); MEM_SAFE_FREE(prev_face_sets); break; } - case SCULPT_FACE_SET_EDIT_SHRINK: { + case EditMode::Shrink: { int *prev_face_sets = static_cast(MEM_dupallocN(ss->face_sets)); sculpt_face_set_shrink(ob, ss, prev_face_sets, active_face_set_id, modify_hidden); MEM_SAFE_FREE(prev_face_sets); break; } - case SCULPT_FACE_SET_EDIT_DELETE_GEOMETRY: + case EditMode::DeleteGeometry: sculpt_face_set_delete_geometry(ob, ss, active_face_set_id, modify_hidden); break; - case SCULPT_FACE_SET_EDIT_FAIR_POSITIONS: + case EditMode::FairPositions: sculpt_face_set_edit_fair_face_set( ob, active_face_set_id, MESH_FAIRING_DEPTH_POSITION, strength); break; - case SCULPT_FACE_SET_EDIT_FAIR_TANGENCY: + case EditMode::FairTangency: sculpt_face_set_edit_fair_face_set( ob, active_face_set_id, MESH_FAIRING_DEPTH_TANGENCY, strength); break; @@ -1291,7 +1296,7 @@ static void sculpt_face_set_apply_edit(Object *ob, } static bool sculpt_face_set_edit_is_operation_valid(SculptSession *ss, - const eSculptFaceSetEditMode mode, + const EditMode mode, const bool modify_hidden) { if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { @@ -1299,7 +1304,7 @@ static bool sculpt_face_set_edit_is_operation_valid(SculptSession *ss, return false; } - if (mode == SCULPT_FACE_SET_EDIT_DELETE_GEOMETRY) { + if (mode == EditMode::DeleteGeometry) { if (BKE_pbvh_type(ss->pbvh) == PBVH_GRIDS) { /* Modification of base mesh geometry requires special remapping of multi-resolution * displacement, which does not happen here. @@ -1314,7 +1319,7 @@ static bool sculpt_face_set_edit_is_operation_valid(SculptSession *ss, } } - if (ELEM(mode, SCULPT_FACE_SET_EDIT_FAIR_POSITIONS, SCULPT_FACE_SET_EDIT_FAIR_TANGENCY)) { + if (ELEM(mode, EditMode::FairPositions, EditMode::FairTangency)) { if (BKE_pbvh_type(ss->pbvh) == PBVH_GRIDS) { /* TODO: Multi-resolution topology representation using grids and duplicates can't be used * directly by the fair algorithm. Multi-resolution topology needs to be exposed in a @@ -1329,7 +1334,7 @@ static bool sculpt_face_set_edit_is_operation_valid(SculptSession *ss, static void sculpt_face_set_edit_modify_geometry(bContext *C, Object *ob, const int active_face_set, - const eSculptFaceSetEditMode mode, + const EditMode mode, const bool modify_hidden, wmOperator *op) { @@ -1358,7 +1363,7 @@ static void face_set_edit_do_post_visibility_updates(Object *ob, Spansculpt; SculptSession *ss = ob->sculpt; @@ -1394,7 +1396,7 @@ static void sculpt_face_set_edit_modify_coordinates(bContext *C, SCULPT_undo_push_begin(ob, op); for (PBVHNode *node : nodes) { BKE_pbvh_node_mark_update(node); - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_COORDS); + SCULPT_undo_push_node(ob, node, SculptUndoType::Position); } sculpt_face_set_apply_edit(ob, active_face_set, mode, false, strength); @@ -1411,7 +1413,7 @@ static bool sculpt_face_set_edit_init(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - const eSculptFaceSetEditMode mode = eSculptFaceSetEditMode(RNA_enum_get(op->ptr, "mode")); + const EditMode mode = EditMode(RNA_enum_get(op->ptr, "mode")); const bool modify_hidden = RNA_boolean_get(op->ptr, "modify_hidden"); if (!sculpt_face_set_edit_is_operation_valid(ss, mode, modify_hidden)) { @@ -1433,19 +1435,19 @@ static int sculpt_face_set_edit_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); const int active_face_set = RNA_int_get(op->ptr, "active_face_set"); - const eSculptFaceSetEditMode mode = eSculptFaceSetEditMode(RNA_enum_get(op->ptr, "mode")); + const EditMode mode = EditMode(RNA_enum_get(op->ptr, "mode")); const bool modify_hidden = RNA_boolean_get(op->ptr, "modify_hidden"); switch (mode) { - case SCULPT_FACE_SET_EDIT_DELETE_GEOMETRY: + case EditMode::DeleteGeometry: sculpt_face_set_edit_modify_geometry(C, ob, active_face_set, mode, modify_hidden, op); break; - case SCULPT_FACE_SET_EDIT_GROW: - case SCULPT_FACE_SET_EDIT_SHRINK: + case EditMode::Grow: + case EditMode::Shrink: sculpt_face_set_edit_modify_face_sets(ob, active_face_set, mode, modify_hidden, op); break; - case SCULPT_FACE_SET_EDIT_FAIR_POSITIONS: - case SCULPT_FACE_SET_EDIT_FAIR_TANGENCY: + case EditMode::FairPositions: + case EditMode::FairTangency: sculpt_face_set_edit_modify_coordinates(C, ob, active_face_set, mode, op); break; } @@ -1493,28 +1495,28 @@ void SCULPT_OT_face_sets_edit(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_HIDDEN); static EnumPropertyItem modes[] = { - {SCULPT_FACE_SET_EDIT_GROW, + {int(EditMode::Grow), "GROW", 0, "Grow Face Set", "Grows the Face Sets boundary by one face based on mesh topology"}, - {SCULPT_FACE_SET_EDIT_SHRINK, + {int(EditMode::Shrink), "SHRINK", 0, "Shrink Face Set", "Shrinks the Face Sets boundary by one face based on mesh topology"}, - {SCULPT_FACE_SET_EDIT_DELETE_GEOMETRY, + {int(EditMode::DeleteGeometry), "DELETE_GEOMETRY", 0, "Delete Geometry", "Deletes the faces that are assigned to the Face Set"}, - {SCULPT_FACE_SET_EDIT_FAIR_POSITIONS, + {int(EditMode::FairPositions), "FAIR_POSITIONS", 0, "Fair Positions", "Creates a smooth as possible geometry patch from the Face Set minimizing changes in " "vertex positions"}, - {SCULPT_FACE_SET_EDIT_FAIR_TANGENCY, + {int(EditMode::FairTangency), "FAIR_TANGENCY", 0, "Fair Tangency", @@ -1522,7 +1524,7 @@ void SCULPT_OT_face_sets_edit(wmOperatorType *ot) "vertex tangents"}, {0, nullptr, 0, nullptr, nullptr}, }; - RNA_def_enum(ot->srna, "mode", modes, SCULPT_FACE_SET_EDIT_GROW, "Mode", ""); + RNA_def_enum(ot->srna, "mode", modes, int(EditMode::Grow), "Mode", ""); RNA_def_float(ot->srna, "strength", 1.0f, 0.0f, 1.0f, "Strength", "", 0.0f, 1.0f); ot->prop = RNA_def_boolean(ot->srna, diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_color.cc b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc index 943ed3728e4..b0544ad4b6c 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_color.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc @@ -81,7 +81,7 @@ static void color_filter_task(Object *ob, SculptSession *ss = ob->sculpt; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COLOR); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Color); AutomaskingNodeData automask_data; SCULPT_automasking_node_begin(ob, ss->filter_cache->automasking, &automask_data, node); @@ -362,7 +362,7 @@ static int sculpt_color_filter_init(bContext *C, wmOperator *op) SCULPT_filter_cache_init(C, ob, sd, - SCULPT_UNDO_COLOR, + SculptUndoType::Color, mval_fl, RNA_float_get(op->ptr, "area_normal_radius"), RNA_float_get(op->ptr, "strength")); diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc b/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc index 28203aad165..8828d692fea 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc @@ -180,7 +180,7 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op) SCULPT_undo_push_begin(ob, op); for (PBVHNode *node : nodes) { - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_MASK); + SCULPT_undo_push_node(ob, node, SculptUndoType::Mask); } float *prev_mask = nullptr; diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc index 6878d0e83b6..9ab119a12d5 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc @@ -102,7 +102,7 @@ void SCULPT_filter_zero_disabled_axis_components(float r_v[3], FilterCache *filt void SCULPT_filter_cache_init(bContext *C, Object *ob, Sculpt *sd, - const int undo_type, + const SculptUndoType undo_type, const float mval_fl[2], float area_normal_radius, float start_strength) @@ -115,7 +115,7 @@ void SCULPT_filter_cache_init(bContext *C, ss->filter_cache->start_filter_strength = start_strength; ss->filter_cache->random_seed = rand(); - if (undo_type == SCULPT_UNDO_COLOR) { + if (undo_type == SculptUndoType::Color) { BKE_pbvh_ensure_node_loops(ss->pbvh); } @@ -140,7 +140,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], SculptUndoType(undo_type)); + SCULPT_undo_push_node(ob, ss->filter_cache->nodes[i], undo_type); } /* Setup orientation matrices. */ @@ -355,7 +355,7 @@ static void mesh_filter_task(Object *ob, SculptSession *ss = ob->sculpt; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); /* When using the relax face sets meshes filter, * each 3 iterations, do a whole mesh relax to smooth the contents of the Face Set. */ @@ -857,7 +857,7 @@ static void sculpt_mesh_filter_cancel(bContext *C, wmOperator * /*op*/) PBVHVertexIter vd; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { SCULPT_orig_vert_data_update(&orig_data, &vd); @@ -1022,7 +1022,7 @@ static int sculpt_mesh_filter_start(bContext *C, wmOperator *op) SCULPT_filter_cache_init(C, ob, sd, - SCULPT_UNDO_COORDS, + SculptUndoType::Position, mval_fl, RNA_float_get(op->ptr, "area_normal_radius"), RNA_float_get(op->ptr, "strength")); diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.hh b/source/blender/editors/sculpt_paint/sculpt_intern.hh index 84653c6490b..13217395a96 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.hh +++ b/source/blender/editors/sculpt_paint/sculpt_intern.hh @@ -138,17 +138,17 @@ enum eBoundaryAutomaskMode { /* Undo */ -enum SculptUndoType { - SCULPT_UNDO_COORDS, - SCULPT_UNDO_HIDDEN, - SCULPT_UNDO_FACE_HIDDEN, - SCULPT_UNDO_MASK, - SCULPT_UNDO_DYNTOPO_BEGIN, - SCULPT_UNDO_DYNTOPO_END, - SCULPT_UNDO_DYNTOPO_SYMMETRIZE, - SCULPT_UNDO_GEOMETRY, - SCULPT_UNDO_FACE_SETS, - SCULPT_UNDO_COLOR, +enum class SculptUndoType : int8_t { + Position, + HideVert, + HideFace, + Mask, + DyntopoBegin, + DyntopoEnd, + DyntopoSymmetrize, + Geometry, + FaceSet, + Color, }; /* Storage of geometry for the undo node. @@ -1333,7 +1333,7 @@ float *SCULPT_geodesic_from_vertex_and_symm(Sculpt *sd, void SCULPT_filter_cache_init(bContext *C, Object *ob, Sculpt *sd, - int undo_type, + SculptUndoType undo_type, const float mval_fl[2], float area_normal_radius, float start_strength); diff --git a/source/blender/editors/sculpt_paint/sculpt_mask_init.cc b/source/blender/editors/sculpt_paint/sculpt_mask_init.cc index 69e462669b2..9963dd0adc4 100644 --- a/source/blender/editors/sculpt_paint/sculpt_mask_init.cc +++ b/source/blender/editors/sculpt_paint/sculpt_mask_init.cc @@ -56,7 +56,7 @@ static void mask_init_task(Object *ob, { SculptSession *ss = ob->sculpt; PBVHVertexIter vd; - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_MASK); + SCULPT_undo_push_node(ob, node, SculptUndoType::Mask); BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { float mask; switch (mode) { diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.cc b/source/blender/editors/sculpt_paint/sculpt_ops.cc index 2d59c4dbebd..c74baa05cf3 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/sculpt_ops.cc @@ -190,7 +190,7 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *op) * are logged as added (as opposed to attempting to store just the * parts that symmetrize modifies). */ SCULPT_undo_push_begin(ob, op); - SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_DYNTOPO_SYMMETRIZE); + SCULPT_undo_push_node(ob, nullptr, SculptUndoType::DyntopoSymmetrize); BM_log_before_all_removed(ss->bm, ss->bm_log); BM_mesh_toolflags_set(ss->bm, true); @@ -408,7 +408,7 @@ void ED_object_sculptmode_enter_ex(Main *bmain, } SCULPT_dynamic_topology_enable_ex(bmain, depsgraph, ob); if (has_undo) { - SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_DYNTOPO_BEGIN); + SCULPT_undo_push_node(ob, nullptr, SculptUndoType::DyntopoBegin); SCULPT_undo_push_end(ob); } } @@ -740,7 +740,7 @@ static void do_mask_by_color_contiguous_update_node(Object *ob, { SculptSession *ss = ob->sculpt; - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_MASK); + SCULPT_undo_push_node(ob, node, SculptUndoType::Mask); bool update_node = false; PBVHVertexIter vd; @@ -846,7 +846,7 @@ static void do_mask_by_color_task(Object *ob, { SculptSession *ss = ob->sculpt; - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_MASK); + SCULPT_undo_push_node(ob, node, SculptUndoType::Mask); bool update_node = false; float active_color[4]; @@ -1012,7 +1012,7 @@ static void sculpt_bake_cavity_exec_task(Object *ob, SculptSession *ss = ob->sculpt; PBVHVertexIter vd; - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_MASK); + SCULPT_undo_push_node(ob, node, SculptUndoType::Mask); AutomaskingNodeData automask_data; SCULPT_automasking_node_begin(ob, automasking, &automask_data, node); diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_color.cc b/source/blender/editors/sculpt_paint/sculpt_paint_color.cc index 4f46ada0bd5..549294698ed 100644 --- a/source/blender/editors/sculpt_paint/sculpt_paint_color.cc +++ b/source/blender/editors/sculpt_paint/sculpt_paint_color.cc @@ -92,7 +92,7 @@ static void do_paint_brush_task(Object *ob, PBVHColorBufferNode *color_buffer; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COLOR); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Color); color_buffer = BKE_pbvh_node_color_buffer_get(node); diff --git a/source/blender/editors/sculpt_paint/sculpt_pose.cc b/source/blender/editors/sculpt_paint/sculpt_pose.cc index 72d91eeb1e8..53be259165e 100644 --- a/source/blender/editors/sculpt_paint/sculpt_pose.cc +++ b/source/blender/editors/sculpt_paint/sculpt_pose.cc @@ -148,7 +148,7 @@ static void do_pose_brush_task(Object *ob, const Brush *brush, PBVHNode *node) float final_pos[3]; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); AutomaskingNodeData automask_data; SCULPT_automasking_node_begin(ob, ss->cache->automasking, &automask_data, node); diff --git a/source/blender/editors/sculpt_paint/sculpt_smooth.cc b/source/blender/editors/sculpt_paint/sculpt_smooth.cc index 42896de7684..9f3dc8b2c96 100644 --- a/source/blender/editors/sculpt_paint/sculpt_smooth.cc +++ b/source/blender/editors/sculpt_paint/sculpt_smooth.cc @@ -439,7 +439,7 @@ static void do_surface_smooth_brush_laplacian_task(Object *ob, const Brush *brus ss, &test, brush->falloff_shape); const int thread_id = BLI_task_parallel_thread_id(nullptr); - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); AutomaskingNodeData automask_data; SCULPT_automasking_node_begin(ob, ss->cache->automasking, &automask_data, node); diff --git a/source/blender/editors/sculpt_paint/sculpt_transform.cc b/source/blender/editors/sculpt_paint/sculpt_transform.cc index fced7afd063..85d4574b261 100644 --- a/source/blender/editors/sculpt_paint/sculpt_transform.cc +++ b/source/blender/editors/sculpt_paint/sculpt_transform.cc @@ -68,7 +68,7 @@ void ED_sculpt_init_transform(bContext *C, SCULPT_vertex_random_access_ensure(ss); - SCULPT_filter_cache_init(C, ob, sd, SCULPT_UNDO_COORDS, mval_fl, 5.0, 1.0f); + SCULPT_filter_cache_init(C, ob, sd, SculptUndoType::Position, mval_fl, 5.0, 1.0f); if (sd->transform_mode == SCULPT_TRANSFORM_MODE_RADIUS_ELASTIC) { ss->filter_cache->transform_displacement_mode = SCULPT_TRANSFORM_DISPLACEMENT_INCREMENTAL; @@ -147,11 +147,11 @@ static void sculpt_transform_task(Object *ob, const float transform_mats[8][4][4 SculptSession *ss = ob->sculpt; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); PBVHVertexIter vd; - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_COORDS); + SCULPT_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; @@ -215,7 +215,7 @@ static void sculpt_elastic_transform_task(Object *ob, const MutableSpan proxy = BKE_pbvh_node_add_proxy(*ss->pbvh, *node).co; SculptOrigVertData orig_data; - SCULPT_orig_vert_data_init(&orig_data, ob, node, SCULPT_UNDO_COORDS); + SCULPT_orig_vert_data_init(&orig_data, ob, node, SculptUndoType::Position); KelvinletParams params; /* TODO(pablodp606): These parameters can be exposed if needed as transform strength and volume @@ -226,7 +226,7 @@ static void sculpt_elastic_transform_task(Object *ob, const float poisson_ratio = 0.4f; BKE_kelvinlet_init_params(¶ms, transform_radius, force, shear_modulus, poisson_ratio); - SCULPT_undo_push_node(ob, node, SCULPT_UNDO_COORDS); + SCULPT_undo_push_node(ob, node, SculptUndoType::Position); PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.cc b/source/blender/editors/sculpt_paint/sculpt_undo.cc index 8b1ebbf3b4b..b1da08b7f40 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_undo.cc @@ -174,16 +174,16 @@ static UndoSculpt *sculpt_undosys_step_get_nodes(UndoStep *us_p); static char *undo_type_to_str(int type) { switch (type) { - _(SCULPT_UNDO_DYNTOPO_BEGIN) - _(SCULPT_UNDO_DYNTOPO_END) - _(SCULPT_UNDO_COORDS) - _(SCULPT_UNDO_GEOMETRY) - _(SCULPT_UNDO_DYNTOPO_SYMMETRIZE) - _(SCULPT_UNDO_FACE_SETS) - _(SCULPT_UNDO_HIDDEN) - _(SCULPT_UNDO_FACE_HIDDEN) - _(SCULPT_UNDO_MASK) - _(SCULPT_UNDO_COLOR) + _(SculptUndoType::DyntopoBegin) + _(SculptUndoType::DyntopoEnd) + _(SculptUndoType::Position) + _(SculptUndoType::Geometry) + _(SculptUndoType::DyntopoSymmetrize) + _(SculptUndoType::FaceSet) + _(SculptUndoType::HideVert) + _(SculptUndoType::HideFace) + _(SculptUndoType::Mask) + _(SculptUndoType::Color) default: return "unknown node type"; } @@ -707,7 +707,7 @@ static void sculpt_undo_bmesh_restore_generic(SculptUndoNode *unode, Object *ob, unode->applied = true; } - if (unode->type == SCULPT_UNDO_MASK) { + if (unode->type == SculptUndoType::Mask) { Vector nodes = blender::bke::pbvh::search_gather(ss->pbvh, {}); for (PBVHNode *node : nodes) { BKE_pbvh_node_mark_redraw(node); @@ -868,11 +868,11 @@ static int sculpt_undo_bmesh_restore(bContext *C, SculptSession *ss) { switch (unode->type) { - case SCULPT_UNDO_DYNTOPO_BEGIN: + case SculptUndoType::DyntopoBegin: sculpt_undo_bmesh_restore_begin(C, unode, ob, ss); return true; - case SCULPT_UNDO_DYNTOPO_END: + case SculptUndoType::DyntopoEnd: sculpt_undo_bmesh_restore_end(C, unode, ob, ss); return true; default: @@ -924,7 +924,7 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase bool clear_automask_cache = false; LISTBASE_FOREACH (SculptUndoNode *, unode, lb) { - if (!ELEM(unode->type, SCULPT_UNDO_COLOR, SCULPT_UNDO_MASK)) { + if (!ELEM(unode->type, SculptUndoType::Color, SculptUndoType::Mask)) { clear_automask_cache = true; } @@ -942,7 +942,7 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase * Undo steps like geometry does not need object to be updated before they run and will * ensure object is updated after the node is handled. */ const SculptUndoNode *first_unode = (const SculptUndoNode *)lb->first; - if (first_unode->type != SCULPT_UNDO_GEOMETRY) { + if (first_unode->type != SculptUndoType::Geometry) { BKE_sculpt_update_object_for_edit(depsgraph, ob, false); } @@ -991,50 +991,50 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase } switch (unode->type) { - case SCULPT_UNDO_COORDS: + case SculptUndoType::Position: if (sculpt_undo_restore_coords(C, ob, depsgraph, unode)) { changed_position = true; } break; - case SCULPT_UNDO_HIDDEN: + case SculptUndoType::HideVert: modified_verts_hide.resize(ss->totvert, false); if (sculpt_undo_restore_hidden(ob, unode, modified_verts_hide)) { changed_hide_vert = true; } break; - case SCULPT_UNDO_FACE_HIDDEN: + case SculptUndoType::HideFace: modified_faces_hide.resize(ss->totfaces, false); if (sculpt_undo_restore_hidden_face(*ob, *unode, modified_faces_hide)) { changed_hide_face = true; } break; - case SCULPT_UNDO_MASK: + case SculptUndoType::Mask: modified_verts_mask.resize(ss->totvert, false); if (sculpt_undo_restore_mask(ob, unode, modified_verts_mask)) { changed_mask = true; } break; - case SCULPT_UNDO_FACE_SETS: + case SculptUndoType::FaceSet: modified_faces_face_set.resize(ss->totfaces, false); if (sculpt_undo_restore_face_sets(ob, unode, modified_faces_face_set)) { changed_face_sets = true; } break; - case SCULPT_UNDO_COLOR: + case SculptUndoType::Color: modified_verts_color.resize(ss->totvert, false); if (sculpt_undo_restore_color(ob, unode, modified_verts_color)) { changed_color = true; } break; - case SCULPT_UNDO_GEOMETRY: + case SculptUndoType::Geometry: sculpt_undo_geometry_restore(unode, ob); changed_all_geometry = true; BKE_sculpt_update_object_for_edit(depsgraph, ob, false); break; - case SCULPT_UNDO_DYNTOPO_BEGIN: - case SCULPT_UNDO_DYNTOPO_END: - case SCULPT_UNDO_DYNTOPO_SYMMETRIZE: + case SculptUndoType::DyntopoBegin: + case SculptUndoType::DyntopoEnd: + case SculptUndoType::DyntopoSymmetrize: BLI_assert_msg(0, "Dynamic topology should've already been handled"); break; } @@ -1232,8 +1232,8 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt unode->totvert = totvert; - bool need_loops = type == SCULPT_UNDO_COLOR; - const bool need_faces = ELEM(type, SCULPT_UNDO_FACE_SETS, SCULPT_UNDO_FACE_HIDDEN); + bool need_loops = type == SculptUndoType::Color; + const bool need_faces = ELEM(type, SculptUndoType::FaceSet, SculptUndoType::HideFace); if (need_loops) { int totloop; @@ -1253,7 +1253,7 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt } switch (type) { - case SCULPT_UNDO_COORDS: { + case SculptUndoType::Position: { unode->co.reinitialize(allvert); usculpt->undo_size += unode->co.as_span().size_in_bytes(); @@ -1262,7 +1262,7 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt usculpt->undo_size += unode->no.as_span().size_in_bytes(); break; } - case SCULPT_UNDO_HIDDEN: { + case SculptUndoType::HideVert: { if (grids.is_empty()) { unode->vert_hidden.resize(allvert); usculpt->undo_size += BLI_BITMAP_SIZE(allvert); @@ -1273,17 +1273,17 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt break; } - case SCULPT_UNDO_FACE_HIDDEN: { + case SculptUndoType::HideFace: { unode->face_hidden.resize(unode->face_indices.size()); usculpt->undo_size += BLI_BITMAP_SIZE(unode->face_indices.size()); break; } - case SCULPT_UNDO_MASK: { + case SculptUndoType::Mask: { unode->mask.reinitialize(allvert); usculpt->undo_size += unode->mask.as_span().size_in_bytes(); break; } - case SCULPT_UNDO_COLOR: { + case SculptUndoType::Color: { /* Allocate vertex colors, even for loop colors we still * need this for original data lookup. */ unode->col.reinitialize(allvert); @@ -1296,14 +1296,14 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt } break; } - case SCULPT_UNDO_DYNTOPO_BEGIN: - case SCULPT_UNDO_DYNTOPO_END: - case SCULPT_UNDO_DYNTOPO_SYMMETRIZE: + case SculptUndoType::DyntopoBegin: + case SculptUndoType::DyntopoEnd: + case SculptUndoType::DyntopoSymmetrize: BLI_assert_msg(0, "Dynamic topology should've already been handled"); break; - case SCULPT_UNDO_GEOMETRY: + case SculptUndoType::Geometry: break; - case SCULPT_UNDO_FACE_SETS: { + case SculptUndoType::FaceSet: { unode->face_sets.reinitialize(unode->face_indices.size()); usculpt->undo_size += unode->face_sets.as_span().size_in_bytes(); break; @@ -1461,11 +1461,11 @@ static SculptUndoNode *sculpt_undo_bmesh_push(Object *ob, PBVHNode *node, Sculpt unode->type = type; unode->applied = true; - if (type == SCULPT_UNDO_DYNTOPO_END) { + if (type == SculptUndoType::DyntopoEnd) { unode->bm_entry = BM_log_entry_add(ss->bm_log); BM_log_before_all_removed(ss->bm, ss->bm_log); } - else if (type == SCULPT_UNDO_DYNTOPO_BEGIN) { + else if (type == SculptUndoType::DyntopoBegin) { /* Store a copy of the mesh's current vertices, loops, and * faces. A full copy like this is needed because entering * dynamic-topology immediately does topological edits @@ -1486,8 +1486,8 @@ static SculptUndoNode *sculpt_undo_bmesh_push(Object *ob, PBVHNode *node, Sculpt if (node) { switch (type) { - case SCULPT_UNDO_COORDS: - case SCULPT_UNDO_MASK: + case SculptUndoType::Position: + case SculptUndoType::Mask: /* Before any vertex values get modified, ensure their * original positions are logged. */ BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_ALL) { @@ -1496,8 +1496,8 @@ static SculptUndoNode *sculpt_undo_bmesh_push(Object *ob, PBVHNode *node, Sculpt BKE_pbvh_vertex_iter_end; break; - case SCULPT_UNDO_FACE_HIDDEN: - case SCULPT_UNDO_HIDDEN: { + case SculptUndoType::HideFace: + case SculptUndoType::HideVert: { BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_ALL) { BM_log_vert_before_modified(ss->bm_log, vd.bm_vert, vd.cd_vert_mask_offset); } @@ -1509,12 +1509,12 @@ static SculptUndoNode *sculpt_undo_bmesh_push(Object *ob, PBVHNode *node, Sculpt break; } - case SCULPT_UNDO_DYNTOPO_BEGIN: - case SCULPT_UNDO_DYNTOPO_END: - case SCULPT_UNDO_DYNTOPO_SYMMETRIZE: - case SCULPT_UNDO_GEOMETRY: - case SCULPT_UNDO_FACE_SETS: - case SCULPT_UNDO_COLOR: + case SculptUndoType::DyntopoBegin: + case SculptUndoType::DyntopoEnd: + case SculptUndoType::DyntopoSymmetrize: + case SculptUndoType::Geometry: + case SculptUndoType::FaceSet: + case SculptUndoType::Color: break; } } @@ -1532,14 +1532,14 @@ SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType ss->needs_flush_to_id = 1; - if (ss->bm || ELEM(type, SCULPT_UNDO_DYNTOPO_BEGIN, SCULPT_UNDO_DYNTOPO_END)) { + if (ss->bm || ELEM(type, SculptUndoType::DyntopoBegin, SculptUndoType::DyntopoEnd)) { /* Dynamic topology stores only one undo node per stroke, * regardless of the number of PBVH nodes modified. */ unode = sculpt_undo_bmesh_push(ob, node, type); BLI_thread_unlock(LOCK_CUSTOM1); return unode; } - if (type == SCULPT_UNDO_GEOMETRY) { + if (type == SculptUndoType::Geometry) { unode = sculpt_undo_geometry_push(ob, type); BLI_thread_unlock(LOCK_CUSTOM1); return unode; @@ -1577,30 +1577,30 @@ SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType } switch (type) { - case SCULPT_UNDO_COORDS: + case SculptUndoType::Position: sculpt_undo_store_coords(ob, unode); break; - case SCULPT_UNDO_HIDDEN: + case SculptUndoType::HideVert: sculpt_undo_store_hidden(ob, unode); break; - case SCULPT_UNDO_FACE_HIDDEN: + case SculptUndoType::HideFace: sculpt_undo_store_face_hidden(*ob, *unode); break; - case SCULPT_UNDO_MASK: + case SculptUndoType::Mask: if (pbvh_has_mask(ss->pbvh)) { sculpt_undo_store_mask(ob, unode); } break; - case SCULPT_UNDO_COLOR: + case SculptUndoType::Color: sculpt_undo_store_color(ob, unode); break; - case SCULPT_UNDO_DYNTOPO_BEGIN: - case SCULPT_UNDO_DYNTOPO_END: - case SCULPT_UNDO_DYNTOPO_SYMMETRIZE: + case SculptUndoType::DyntopoBegin: + case SculptUndoType::DyntopoEnd: + case SculptUndoType::DyntopoSymmetrize: BLI_assert_msg(0, "Dynamic topology should've already been handled"); - case SCULPT_UNDO_GEOMETRY: + case SculptUndoType::Geometry: break; - case SCULPT_UNDO_FACE_SETS: + case SculptUndoType::FaceSet: sculpt_undo_store_face_sets(*static_cast(ob->data), *unode); break; } @@ -1795,7 +1795,7 @@ static bool sculpt_undosys_step_encode(bContext * /*C*/, Main *bmain, UndoStep * us->step.data_size = us->data.undo_size; SculptUndoNode *unode = static_cast(us->data.nodes.last); - if (unode && unode->type == SCULPT_UNDO_DYNTOPO_END) { + if (unode && unode->type == SculptUndoType::DyntopoEnd) { us->step.use_memfile_step = true; } us->step.is_applied = true; @@ -1946,18 +1946,18 @@ static void sculpt_undosys_step_free(UndoStep *us_p) void ED_sculpt_undo_geometry_begin(Object *ob, const wmOperator *op) { SCULPT_undo_push_begin(ob, op); - SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_GEOMETRY); + SCULPT_undo_push_node(ob, nullptr, SculptUndoType::Geometry); } void ED_sculpt_undo_geometry_begin_ex(Object *ob, const char *name) { SCULPT_undo_push_begin_ex(ob, name); - SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_GEOMETRY); + SCULPT_undo_push_node(ob, nullptr, SculptUndoType::Geometry); } void ED_sculpt_undo_geometry_end(Object *ob) { - SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_GEOMETRY); + SCULPT_undo_push_node(ob, nullptr, SculptUndoType::Geometry); SCULPT_undo_push_end(ob); } @@ -2038,7 +2038,7 @@ static void sculpt_undo_push_all_grids(Object *object) * happens, for example, when an operation which tagged for geometry update was performed prior * to the current operation without making any stroke in between. * - * Skip pushing nodes based on the following logic: on redo SCULPT_UNDO_COORDS will ensure + * Skip pushing nodes based on the following logic: on redo SculptUndoType::Position will ensure * PBVH for the new base geometry, which will have same coordinates as if we create PBVH here. */ if (ss->pbvh == nullptr) { @@ -2047,7 +2047,7 @@ static void sculpt_undo_push_all_grids(Object *object) Vector nodes = blender::bke::pbvh::search_gather(ss->pbvh, {}); for (PBVHNode *node : nodes) { - SculptUndoNode *unode = SCULPT_undo_push_node(object, node, SCULPT_UNDO_COORDS); + SculptUndoNode *unode = SCULPT_undo_push_node(object, node, SculptUndoType::Position); unode->node = nullptr; } } @@ -2062,7 +2062,8 @@ void ED_sculpt_undo_push_multires_mesh_begin(bContext *C, const char *str) SCULPT_undo_push_begin_ex(object, str); - SculptUndoNode *geometry_unode = SCULPT_undo_push_node(object, nullptr, SCULPT_UNDO_GEOMETRY); + SculptUndoNode *geometry_unode = SCULPT_undo_push_node( + object, nullptr, SculptUndoType::Geometry); geometry_unode->geometry_clear_pbvh = false; sculpt_undo_push_all_grids(object); @@ -2077,7 +2078,8 @@ 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, SCULPT_UNDO_GEOMETRY); + SculptUndoNode *geometry_unode = SCULPT_undo_push_node( + object, nullptr, SculptUndoType::Geometry); geometry_unode->geometry_clear_pbvh = false; SCULPT_undo_push_end(object);