From 658b32093ad4e42b82d4cf4378fff4ef0c4479b2 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 14 Aug 2024 10:25:52 -0400 Subject: [PATCH] Refactor: Sculpt: Replace sculpt attribute system for dynamic topology data Part of #118145. Use the BMesh functions instead of the sculpt attribute API which we intend to remove. --- source/blender/blenkernel/BKE_paint.hh | 4 --- source/blender/blenkernel/intern/paint.cc | 35 +++---------------- .../editors/sculpt_paint/sculpt_dyntopo.cc | 9 ++--- 3 files changed, 7 insertions(+), 41 deletions(-) diff --git a/source/blender/blenkernel/BKE_paint.hh b/source/blender/blenkernel/BKE_paint.hh index f8013dfae6f..0ec25c1aae8 100644 --- a/source/blender/blenkernel/BKE_paint.hh +++ b/source/blender/blenkernel/BKE_paint.hh @@ -390,10 +390,6 @@ struct SculptAttributePointers { SculptAttribute *automasking_occlusion = nullptr; /* CD_PROP_INT8. */ SculptAttribute *automasking_stroke_id = nullptr; SculptAttribute *automasking_cavity = nullptr; - - /* BMesh */ - SculptAttribute *dyntopo_node_id_vertex = nullptr; - SculptAttribute *dyntopo_node_id_face = nullptr; }; struct SculptTopologyIslandCache { diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc index 75287b7cfc0..6dbcaffb916 100644 --- a/source/blender/blenkernel/intern/paint.cc +++ b/source/blender/blenkernel/intern/paint.cc @@ -94,7 +94,6 @@ static SculptAttribute *sculpt_attribute_ensure_ex(Object *ob, const SculptAttributeParams *params, blender::bke::pbvh::Type pbvhtype, bool flat_array_for_bmesh); -static void sculptsession_bmesh_add_layers(Object *ob); static void palette_init_data(ID *id) { @@ -2354,9 +2353,11 @@ namespace blender::bke { static std::unique_ptr build_pbvh_for_dynamic_topology(Object *ob) { - sculptsession_bmesh_add_layers(ob); + BMesh &bm = *ob->sculpt->bm; + BM_data_layer_ensure_named(&bm, &bm.vdata, CD_PROP_INT32, ".sculpt_dyntopo_node_id_vertex"); + BM_data_layer_ensure_named(&bm, &bm.pdata, CD_PROP_INT32, ".sculpt_dyntopo_node_id_face"); - return pbvh::build_bmesh(ob->sculpt->bm); + return pbvh::build_bmesh(&bm); } static std::unique_ptr build_pbvh_from_regular_mesh(Object *ob, @@ -2870,30 +2871,6 @@ SculptAttribute *BKE_sculpt_attribute_ensure(Object *ob, ob, domain, proptype, name, &temp_params, ob->sculpt->pbvh->type(), true); } -static void sculptsession_bmesh_add_layers(Object *ob) -{ - SculptSession *ss = ob->sculpt; - SculptAttributeParams params = {0}; - - ss->attrs.dyntopo_node_id_vertex = sculpt_attribute_ensure_ex( - ob, - AttrDomain::Point, - CD_PROP_INT32, - SCULPT_ATTRIBUTE_NAME(dyntopo_node_id_vertex), - ¶ms, - blender::bke::pbvh::Type::BMesh, - false); - - ss->attrs.dyntopo_node_id_face = sculpt_attribute_ensure_ex( - ob, - AttrDomain::Face, - CD_PROP_INT32, - SCULPT_ATTRIBUTE_NAME(dyntopo_node_id_face), - ¶ms, - blender::bke::pbvh::Type::BMesh, - false); -} - void BKE_sculpt_attributes_destroy_temporary_stroke(Object *ob) { SculptSession *ss = ob->sculpt; @@ -2920,10 +2897,6 @@ static void sculpt_attribute_update_refs(Object *ob, blender::bke::pbvh::Type pb sculpt_attr_update(ob, attr, pbvhtype); } } - - if (ss->bm) { - sculptsession_bmesh_add_layers(ob); - } } } diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc b/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc index df63fbae606..83642e0b427 100644 --- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc @@ -126,12 +126,9 @@ static void disable( SculptSession &ss = *ob.sculpt; Mesh *mesh = static_cast(ob.data); - if (ss.attrs.dyntopo_node_id_vertex) { - BKE_sculpt_attribute_destroy(&ob, ss.attrs.dyntopo_node_id_vertex); - } - - if (ss.attrs.dyntopo_node_id_face) { - BKE_sculpt_attribute_destroy(&ob, ss.attrs.dyntopo_node_id_face); + if (BMesh *bm = ss.bm) { + BM_data_layer_free_named(bm, &bm->vdata, ".sculpt_dyntopo_node_id_vertex"); + BM_data_layer_free_named(bm, &bm->pdata, ".sculpt_dyntopo_node_id_face"); } SCULPT_pbvh_clear(ob);