diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-23 16:19:40 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-23 16:19:40 +0300 |
commit | 060a5341419412fd7996cf99a56db1f581a4c30c (patch) | |
tree | 59413121aaf62bedc794822ea8d1c4d2c55e9088 /source/blender/blenkernel/intern/mesh_remesh_voxel.cc | |
parent | 35375380d73b93999b879164fd59266ee044472c (diff) |
Mesh: Move sculpt face sets to a generic attribute
Similar to the other refactors from T95965, this commit moves sculpt
face sets to use a generic integer attribute named `".sculpt_face_set"`.
This makes face sets accessible in the Python API.
The attribute is not visible in the attributes list or the spreadsheet
because it is meant for internal use, though that could be an option
in the future along with other similar attributes. Currently the change
is small, but in the future this could simplify code by allowing use
of more generic attribute APIs.
Differential Revision: https://developer.blender.org/D16045
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_remesh_voxel.cc')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_remesh_voxel.cc | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc index a77879fb573..12f42dbc4ec 100644 --- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc +++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc @@ -24,6 +24,7 @@ #include "DNA_meshdata_types.h" #include "BKE_attribute.h" +#include "BKE_attribute.hh" #include "BKE_bvhutils.h" #include "BKE_customdata.h" #include "BKE_editmesh.h" @@ -318,24 +319,28 @@ void BKE_mesh_remesh_reproject_paint_mask(Mesh *target, const Mesh *source) void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source) { + using namespace blender; + using namespace blender::bke; + const AttributeAccessor src_attributes = source->attributes(); + MutableAttributeAccessor dst_attributes = target->attributes_for_write(); const MPoly *target_polys = (const MPoly *)CustomData_get_layer(&target->pdata, CD_MPOLY); const MVert *target_verts = (const MVert *)CustomData_get_layer(&target->vdata, CD_MVERT); const MLoop *target_loops = (const MLoop *)CustomData_get_layer(&target->ldata, CD_MLOOP); - const int *source_face_sets = (const int *)CustomData_get_layer(&source->pdata, - CD_SCULPT_FACE_SETS); - if (source_face_sets == nullptr) { - return; - } - int *target_face_sets; - if (CustomData_has_layer(&target->pdata, CD_SCULPT_FACE_SETS)) { - target_face_sets = (int *)CustomData_get_layer(&target->pdata, CD_SCULPT_FACE_SETS); + const VArray<int> src_face_sets = src_attributes.lookup<int>(".sculpt_face_set", + ATTR_DOMAIN_FACE); + if (!src_face_sets) { + return; } - else { - target_face_sets = (int *)CustomData_add_layer( - &target->pdata, CD_SCULPT_FACE_SETS, CD_CONSTRUCT, nullptr, target->totpoly); + SpanAttributeWriter<int> dst_face_sets = dst_attributes.lookup_or_add_for_write_only_span<int>( + ".sculpt_face_set", ATTR_DOMAIN_FACE); + if (!dst_face_sets) { + return; } + const VArraySpan<int> src(src_face_sets); + MutableSpan<int> dst = dst_face_sets.span; + const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(source); BVHTreeFromMesh bvhtree = {nullptr}; BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_LOOPTRI, 2); @@ -349,13 +354,14 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source) BKE_mesh_calc_poly_center(mpoly, &target_loops[mpoly->loopstart], target_verts, from_co); BLI_bvhtree_find_nearest(bvhtree.tree, from_co, &nearest, bvhtree.nearest_callback, &bvhtree); if (nearest.index != -1) { - target_face_sets[i] = source_face_sets[looptri[nearest.index].poly]; + dst[i] = src[looptri[nearest.index].poly]; } else { - target_face_sets[i] = 1; + dst[i] = 1; } } free_bvhtree_from_mesh(&bvhtree); + dst_face_sets.finish(); } void BKE_remesh_reproject_vertex_paint(Mesh *target, const Mesh *source) |