Cleanup: Use C++ methods to retrieve attribute accessors

Replace `mesh_attributes`, `mesh_attributes_for_write` and the point
cloud versions with methods on the `Mesh` and `PointCloud` types.
This makes them friendlier to use and improves readability.

Differential Revision: https://developer.blender.org/D15907
This commit is contained in:
Hans Goudey 2022-09-07 21:41:39 -05:00
parent 17bc292530
commit d593497421
Notes: blender-bot 2023-02-14 01:07:44 +01:00
Referenced by issue #104358, Regression: Blender crash in weight paint mode and vertex select checked and then weights -> fix deforms
79 changed files with 244 additions and 259 deletions

View File

@ -755,12 +755,6 @@ class CustomDataAttributes {
bool foreach_attribute(const AttributeForeachCallback callback, eAttrDomain domain) const;
};
AttributeAccessor mesh_attributes(const Mesh &mesh);
MutableAttributeAccessor mesh_attributes_for_write(Mesh &mesh);
AttributeAccessor pointcloud_attributes(const PointCloud &pointcloud);
MutableAttributeAccessor pointcloud_attributes_for_write(PointCloud &pointcloud);
/* -------------------------------------------------------------------- */
/** \name #AttributeIDRef Inline Methods
* \{ */

View File

@ -826,7 +826,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
ASSERT_IS_VALID_MESH(mesh_final);
}
MutableAttributeAccessor attributes = mesh_attributes_for_write(*mesh_final);
MutableAttributeAccessor attributes = mesh_final->attributes_for_write();
SpanAttributeWriter<float3> rest_positions =
attributes.lookup_or_add_for_write_only_span<float3>("rest_position", ATTR_DOMAIN_POINT);
if (rest_positions) {

View File

@ -103,11 +103,11 @@ static std::optional<blender::bke::MutableAttributeAccessor> get_attribute_acces
Mesh &mesh = reinterpret_cast<Mesh &>(id);
/* The attribute API isn't implemented for BMesh, so edit mode meshes are not supported. */
BLI_assert(mesh.edit_mesh == nullptr);
return mesh_attributes_for_write(mesh);
return mesh.attributes_for_write();
}
case ID_PT: {
PointCloud &pointcloud = reinterpret_cast<PointCloud &>(id);
return pointcloud_attributes_for_write(pointcloud);
return pointcloud.attributes_for_write();
}
case ID_CV: {
Curves &curves_id = reinterpret_cast<Curves &>(id);

View File

@ -1294,7 +1294,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
break;
case BVHTREE_FROM_LOOPTRI_NO_HIDDEN: {
blender::bke::AttributeAccessor attributes = blender::bke::mesh_attributes(*mesh);
blender::bke::AttributeAccessor attributes = mesh->attributes();
mask = looptri_no_hidden_map_get(
mesh->polys().data(),
attributes.lookup_or_default(".hide_poly", ATTR_DOMAIN_FACE, false),
@ -1454,7 +1454,7 @@ BVHTree *BKE_bvhtree_from_pointcloud_get(BVHTreeFromPointCloud *data,
return nullptr;
}
blender::bke::AttributeAccessor attributes = blender::bke::pointcloud_attributes(*pointcloud);
blender::bke::AttributeAccessor attributes = pointcloud->attributes();
blender::VArraySpan<blender::float3> positions = attributes.lookup_or_default<blender::float3>(
"position", ATTR_DOMAIN_POINT, blender::float3(0));

View File

@ -711,7 +711,7 @@ Mesh *curve_to_mesh_sweep(const CurvesGeometry &main,
Set<AttributeIDRef> main_attributes_set;
MutableAttributeAccessor mesh_attributes = bke::mesh_attributes_for_write(*mesh);
MutableAttributeAccessor mesh_attributes = mesh->attributes_for_write();
main_attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
if (!should_add_attribute_to_mesh(main_attributes, mesh_attributes, id)) {

View File

@ -149,7 +149,7 @@ VArray<float3> mesh_normals_varray(const Mesh &mesh,
* array and copy the face normal for each of its corners. In this case using the mesh
* component's generic domain interpolation is fine, the data will still be normalized,
* since the face normal is just copied to every corner. */
return mesh_attributes(mesh).adapt_domain(
return mesh.attributes().adapt_domain(
VArray<float3>::ForSpan({(float3 *)BKE_mesh_poly_normals_ensure(&mesh), mesh.totpoly}),
ATTR_DOMAIN_FACE,
ATTR_DOMAIN_CORNER);
@ -1324,18 +1324,19 @@ static const AttributeAccessorFunctions &get_mesh_accessor_functions_ref()
return fn;
}
AttributeAccessor mesh_attributes(const Mesh &mesh)
{
return AttributeAccessor(&mesh, get_mesh_accessor_functions_ref());
}
MutableAttributeAccessor mesh_attributes_for_write(Mesh &mesh)
{
return MutableAttributeAccessor(&mesh, get_mesh_accessor_functions_ref());
}
} // namespace blender::bke
blender::bke::AttributeAccessor Mesh::attributes() const
{
return blender::bke::AttributeAccessor(this, blender::bke::get_mesh_accessor_functions_ref());
}
blender::bke::MutableAttributeAccessor Mesh::attributes_for_write()
{
return blender::bke::MutableAttributeAccessor(this,
blender::bke::get_mesh_accessor_functions_ref());
}
std::optional<blender::bke::AttributeAccessor> MeshComponent::attributes() const
{
return blender::bke::AttributeAccessor(mesh_, blender::bke::get_mesh_accessor_functions_ref());

View File

@ -201,18 +201,20 @@ static const AttributeAccessorFunctions &get_pointcloud_accessor_functions_ref()
return fn;
}
AttributeAccessor pointcloud_attributes(const PointCloud &pointcloud)
{
return AttributeAccessor(&pointcloud, get_pointcloud_accessor_functions_ref());
}
MutableAttributeAccessor pointcloud_attributes_for_write(PointCloud &pointcloud)
{
return MutableAttributeAccessor(&pointcloud, get_pointcloud_accessor_functions_ref());
}
} // namespace blender::bke
blender::bke::AttributeAccessor PointCloud::attributes() const
{
return blender::bke::AttributeAccessor(this,
blender::bke::get_pointcloud_accessor_functions_ref());
}
blender::bke::MutableAttributeAccessor PointCloud::attributes_for_write()
{
return blender::bke::MutableAttributeAccessor(
this, blender::bke::get_pointcloud_accessor_functions_ref());
}
std::optional<blender::bke::AttributeAccessor> PointCloudComponent::attributes() const
{
return blender::bke::AttributeAccessor(pointcloud_,

View File

@ -18,7 +18,7 @@ namespace blender::bke {
MeshFieldContext::MeshFieldContext(const Mesh &mesh, const eAttrDomain domain)
: mesh_(mesh), domain_(domain)
{
BLI_assert(mesh_attributes(mesh).domain_supported(domain_));
BLI_assert(mesh.attributes().domain_supported(domain_));
}
CurvesFieldContext::CurvesFieldContext(const CurvesGeometry &curves, const eAttrDomain domain)
@ -94,13 +94,13 @@ GeometryFieldContext::GeometryFieldContext(const InstancesComponent &instances)
std::optional<AttributeAccessor> GeometryFieldContext::attributes() const
{
if (const Mesh *mesh = this->mesh()) {
return mesh_attributes(*mesh);
return mesh->attributes();
}
if (const CurvesGeometry *curves = this->curves()) {
return curves->attributes();
}
if (const PointCloud *pointcloud = this->pointcloud()) {
return pointcloud_attributes(*pointcloud);
return pointcloud->attributes();
}
if (const InstancesComponent *instances = this->instances()) {
return instances->attributes();

View File

@ -2715,7 +2715,7 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
gpl_fill, scene->r.cfra + frame_offset, GP_GETFRAME_ADD_NEW);
int i;
const VArray<int> mesh_material_indices = mesh_attributes(*me_eval).lookup_or_default<int>(
const VArray<int> mesh_material_indices = me_eval->attributes().lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
for (i = 0; i < mpoly_len; i++) {
const MPoly *mp = &polys[i];

View File

@ -1343,7 +1343,7 @@ void BKE_mesh_material_index_remove(Mesh *me, short index)
{
using namespace blender;
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh_attributes_for_write(*me);
MutableAttributeAccessor attributes = me->attributes_for_write();
AttributeWriter<int> material_indices = attributes.lookup_for_write<int>("material_index");
if (!material_indices) {
return;
@ -1368,7 +1368,7 @@ bool BKE_mesh_material_index_used(Mesh *me, short index)
{
using namespace blender;
using namespace blender::bke;
const AttributeAccessor attributes = mesh_attributes(*me);
const AttributeAccessor attributes = me->attributes();
const VArray<int> material_indices = attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
if (material_indices.is_single()) {
@ -1382,7 +1382,7 @@ void BKE_mesh_material_index_clear(Mesh *me)
{
using namespace blender;
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh_attributes_for_write(*me);
MutableAttributeAccessor attributes = me->attributes_for_write();
attributes.remove("material_index");
BKE_mesh_tessface_clear(me);
@ -1411,7 +1411,7 @@ void BKE_mesh_material_remap(Mesh *me, const uint *remap, uint remap_len)
}
}
else {
MutableAttributeAccessor attributes = mesh_attributes_for_write(*me);
MutableAttributeAccessor attributes = me->attributes_for_write();
AttributeWriter<int> material_indices = attributes.lookup_for_write<int>("material_index");
if (!material_indices) {
return;
@ -1763,7 +1763,7 @@ void BKE_mesh_count_selected_items(const Mesh *mesh, int r_count[3])
void BKE_mesh_vert_coords_get(const Mesh *mesh, float (*vert_coords)[3])
{
blender::bke::AttributeAccessor attributes = blender::bke::mesh_attributes(*mesh);
blender::bke::AttributeAccessor attributes = mesh->attributes();
VArray<float3> positions = attributes.lookup_or_default(
"position", ATTR_DOMAIN_POINT, float3(0));
positions.materialize({(float3 *)vert_coords, mesh->totvert});

View File

@ -415,7 +415,7 @@ static void copy_poly_attributes(Mesh *dest_mesh,
Span<short> material_remap,
MutableSpan<int> dst_material_indices)
{
const VArray<int> src_material_indices = bke::mesh_attributes(*orig_me).lookup_or_default<int>(
const VArray<int> src_material_indices = orig_me->attributes().lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
const int src_index = src_material_indices[index_in_orig_me];
if (material_remap.size() > 0 && material_remap.index_range().contains(src_index)) {
@ -739,8 +739,8 @@ static Mesh *imesh_to_mesh(IMesh *im, MeshesToIMeshInfo &mim)
/* Set the loopstart and totloop for each output poly,
* and set the vertices in the appropriate loops. */
bke::SpanAttributeWriter<int> dst_material_indices =
bke::mesh_attributes_for_write(*result).lookup_or_add_for_write_only_span<int>(
"material_index", ATTR_DOMAIN_FACE);
result->attributes_for_write().lookup_or_add_for_write_only_span<int>("material_index",
ATTR_DOMAIN_FACE);
int cur_loop_index = 0;
MutableSpan<MLoop> dst_loops = result->loops_for_write();
MutableSpan<MPoly> dst_polys = result->polys_for_write();

View File

@ -193,7 +193,7 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
MEdge *medge = edges.data();
MPoly *mpoly = polys.data();
MLoop *mloop = loops.data();
MutableAttributeAccessor attributes = mesh_attributes_for_write(*mesh);
MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_only_span<int>(
"material_index", ATTR_DOMAIN_FACE);
MLoopUV *mloopuv = static_cast<MLoopUV *>(CustomData_add_layer_named(
@ -639,9 +639,8 @@ void BKE_pointcloud_from_mesh(Mesh *me, PointCloud *pointcloud)
/* Copy over all attributes. */
CustomData_merge(&me->vdata, &pointcloud->pdata, CD_MASK_PROP_ALL, CD_DUPLICATE, me->totvert);
bke::AttributeAccessor mesh_attributes = bke::mesh_attributes(*me);
bke::MutableAttributeAccessor point_attributes = bke::pointcloud_attributes_for_write(
*pointcloud);
bke::AttributeAccessor mesh_attributes = me->attributes();
bke::MutableAttributeAccessor point_attributes = pointcloud->attributes_for_write();
const VArray<float3> mesh_positions = mesh_attributes.lookup_or_default<float3>(
"position", ATTR_DOMAIN_POINT, float3(0));
@ -1085,7 +1084,7 @@ Mesh *BKE_mesh_new_from_object_to_bmain(Main *bmain,
BKE_mesh_nomain_to_mesh(mesh, mesh_in_bmain, nullptr, &CD_MASK_MESH, true);
/* Anonymous attributes shouldn't exist on original data. */
blender::bke::mesh_attributes_for_write(*mesh_in_bmain).remove_anonymous();
mesh_in_bmain->attributes_for_write().remove_anonymous();
/* User-count is required because so far mesh was in a limbo, where library management does
* not perform any user management (i.e. copy of a mesh will not increase users of materials). */

View File

@ -736,7 +736,7 @@ void BKE_mesh_flush_hidden_from_verts(Mesh *me)
{
using namespace blender;
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh_attributes_for_write(*me);
MutableAttributeAccessor attributes = me->attributes_for_write();
const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
".hide_vert", ATTR_DOMAIN_POINT, false);
@ -776,7 +776,7 @@ void BKE_mesh_flush_hidden_from_polys(Mesh *me)
{
using namespace blender;
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh_attributes_for_write(*me);
MutableAttributeAccessor attributes = me->attributes_for_write();
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
".hide_poly", ATTR_DOMAIN_FACE, false);
@ -907,7 +907,7 @@ static void mesh_flush_select_from_verts(const Span<MVert> verts,
void BKE_mesh_flush_select_from_verts(Mesh *me)
{
const blender::bke::AttributeAccessor attributes = blender::bke::mesh_attributes(*me);
const blender::bke::AttributeAccessor attributes = me->attributes();
mesh_flush_select_from_verts(
me->verts(),
me->loops(),

View File

@ -925,7 +925,7 @@ void BKE_mesh_legacy_convert_hide_layers_to_flags(Mesh *mesh)
{
using namespace blender;
using namespace blender::bke;
const AttributeAccessor attributes = mesh_attributes(*mesh);
const AttributeAccessor attributes = mesh->attributes();
MutableSpan<MVert> verts = mesh->verts_for_write();
const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
@ -959,7 +959,7 @@ void BKE_mesh_legacy_convert_flags_to_hide_layers(Mesh *mesh)
{
using namespace blender;
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh_attributes_for_write(*mesh);
MutableAttributeAccessor attributes = mesh->attributes_for_write();
const Span<MVert> verts = mesh->verts();
if (std::any_of(
@ -1010,7 +1010,7 @@ void BKE_mesh_legacy_convert_material_indices_to_mpoly(Mesh *mesh)
{
using namespace blender;
using namespace blender::bke;
const AttributeAccessor attributes = mesh_attributes(*mesh);
const AttributeAccessor attributes = mesh->attributes();
MutableSpan<MPoly> polys = mesh->polys_for_write();
const VArray<int> material_indices = attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
@ -1025,7 +1025,7 @@ void BKE_mesh_legacy_convert_mpoly_to_material_indices(Mesh *mesh)
{
using namespace blender;
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh_attributes_for_write(*mesh);
MutableAttributeAccessor attributes = mesh->attributes_for_write();
const Span<MPoly> polys = mesh->polys();
if (std::any_of(
polys.begin(), polys.end(), [](const MPoly &poly) { return poly.mat_nr != 0; })) {

View File

@ -243,7 +243,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
(void)0
blender::bke::AttributeWriter<int> material_indices =
blender::bke::mesh_attributes_for_write(*mesh).lookup_for_write<int>("material_index");
mesh->attributes_for_write().lookup_for_write<int>("material_index");
blender::MutableVArraySpan<int> material_indices_span(material_indices.varray);
MVert *mv = mverts;
@ -1152,7 +1152,7 @@ bool BKE_mesh_validate_material_indices(Mesh *me)
bool is_valid = true;
blender::bke::AttributeWriter<int> material_indices =
blender::bke::mesh_attributes_for_write(*me).lookup_for_write<int>("material_index");
me->attributes_for_write().lookup_for_write<int>("material_index");
blender::MutableVArraySpan<int> material_indices_span(material_indices.varray);
for (const int i : material_indices_span.index_range()) {
if (material_indices_span[i] < 0 || material_indices_span[i] > mat_nr_max) {

View File

@ -2134,7 +2134,7 @@ void BKE_sculpt_sync_face_sets_visibility_to_base_mesh(Mesh *mesh)
return;
}
MutableAttributeAccessor attributes = mesh_attributes_for_write(*mesh);
MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<bool> hide_poly = attributes.lookup_or_add_for_write_only_span<bool>(
".hide_poly", ATTR_DOMAIN_FACE);
if (!hide_poly) {

View File

@ -194,8 +194,7 @@ static void pointcloud_random(PointCloud *pointcloud)
RNG *rng = BLI_rng_new(0);
blender::bke::MutableAttributeAccessor attributes =
blender::bke::pointcloud_attributes_for_write(*pointcloud);
blender::bke::MutableAttributeAccessor attributes = pointcloud->attributes_for_write();
blender::bke::SpanAttributeWriter positions =
attributes.lookup_or_add_for_write_only_span<float3>(POINTCLOUD_ATTR_POSITION,
ATTR_DOMAIN_POINT);
@ -258,7 +257,7 @@ PointCloud *BKE_pointcloud_new_nomain(const int totpoint)
static std::optional<blender::bounds::MinMaxResult<float3>> point_cloud_bounds(
const PointCloud &pointcloud)
{
blender::bke::AttributeAccessor attributes = blender::bke::pointcloud_attributes(pointcloud);
blender::bke::AttributeAccessor attributes = pointcloud.attributes();
blender::VArraySpan<float3> positions = attributes.lookup_or_default<float3>(
POINTCLOUD_ATTR_POSITION, ATTR_DOMAIN_POINT, float3(0));
blender::VArray<float> radii = attributes.lookup_or_default<float>(

View File

@ -965,7 +965,7 @@ static void convert_bmesh_hide_flags_to_mesh_attributes(BMesh &bm,
return;
}
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
BM_mesh_elem_table_ensure(&bm, BM_VERT | BM_EDGE | BM_FACE);
write_fn_to_attribute<bool>(
@ -1154,11 +1154,9 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
if (need_material_index) {
BM_mesh_elem_table_ensure(bm, BM_FACE);
write_fn_to_attribute<int>(
blender::bke::mesh_attributes_for_write(*me),
"material_index",
ATTR_DOMAIN_FACE,
true,
[&](const int i) { return static_cast<int>(BM_face_at_index(bm, i)->mat_nr); });
me->attributes_for_write(), "material_index", ATTR_DOMAIN_FACE, true, [&](const int i) {
return static_cast<int>(BM_face_at_index(bm, i)->mat_nr);
});
}
/* Patch hook indices and vertex parents. */
@ -1423,11 +1421,9 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
if (need_material_index) {
BM_mesh_elem_table_ensure(bm, BM_FACE);
write_fn_to_attribute<int>(
blender::bke::mesh_attributes_for_write(*me),
"material_index",
ATTR_DOMAIN_FACE,
true,
[&](const int i) { return static_cast<int>(BM_face_at_index(bm, i)->mat_nr); });
me->attributes_for_write(), "material_index", ATTR_DOMAIN_FACE, true, [&](const int i) {
return static_cast<int>(BM_face_at_index(bm, i)->mat_nr);
});
}
convert_bmesh_hide_flags_to_mesh_attributes(

View File

@ -141,7 +141,7 @@ static void pointcloud_batch_cache_ensure_pos(const PointCloud &pointcloud,
return;
}
const bke::AttributeAccessor attributes = bke::pointcloud_attributes(pointcloud);
const bke::AttributeAccessor attributes = pointcloud.attributes();
const VArraySpan<float3> positions = attributes.lookup<float3>("position", ATTR_DOMAIN_POINT);
const VArray<float> radii = attributes.lookup<float>("radius", ATTR_DOMAIN_POINT);
/* From the opengl wiki:

View File

@ -1967,9 +1967,8 @@ static void draw_subdiv_cache_ensure_mat_offsets(DRWSubdivCache *cache,
return;
}
const blender::VArraySpan<int> material_indices = blender::bke::mesh_attributes(*mesh_eval)
.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
const blender::VArraySpan<int> material_indices = mesh_eval->attributes().lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
/* Count number of subdivided polygons for each material. */
int *mat_start = static_cast<int *>(MEM_callocN(sizeof(int) * mat_len, "subdiv mat_start"));

View File

@ -548,7 +548,7 @@ static void snap_curves_to_surface_exec_object(Object &curves_ob,
BKE_mesh_runtime_looptri_len(&surface_mesh)};
VArraySpan<float2> surface_uv_map;
if (curves_id.surface_uv_map != nullptr) {
const bke::AttributeAccessor surface_attributes = bke::mesh_attributes(surface_mesh);
const bke::AttributeAccessor surface_attributes = surface_mesh.attributes();
surface_uv_map = surface_attributes
.lookup(curves_id.surface_uv_map, ATTR_DOMAIN_CORNER, CD_PROP_FLOAT2)
.typed<float2>();

View File

@ -282,7 +282,7 @@ static int geometry_attribute_convert_exec(bContext *C, wmOperator *op)
RNA_enum_get(op->ptr, "mode"));
Mesh *mesh = reinterpret_cast<Mesh *>(ob_data);
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
/* General conversion steps are always the same:
* 1. Convert old data to right domain and data type.
@ -646,8 +646,7 @@ bool ED_geometry_attribute_convert(Mesh *mesh,
return false;
}
blender::bke::MutableAttributeAccessor attributes = blender::bke::mesh_attributes_for_write(
*mesh);
blender::bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
GVArray src_varray = attributes.lookup_or_default(name, new_domain, new_type);

View File

@ -67,11 +67,11 @@ void paintface_flush_flags(bContext *C,
return;
}
bke::AttributeAccessor attributes_me = bke::mesh_attributes(*me);
bke::AttributeAccessor attributes_me = me->attributes();
Mesh *me_orig = (Mesh *)ob_eval->runtime.data_orig;
bke::MutableAttributeAccessor attributes_orig = bke::mesh_attributes_for_write(*me_orig);
bke::MutableAttributeAccessor attributes_orig = me_orig->attributes_for_write();
Mesh *me_eval = (Mesh *)ob_eval->runtime.data_eval;
bke::MutableAttributeAccessor attributes_eval = bke::mesh_attributes_for_write(*me_eval);
bke::MutableAttributeAccessor attributes_eval = me_eval->attributes_for_write();
bool updated = false;
const Span<MPoly> me_polys = me->polys();
@ -142,7 +142,7 @@ void paintface_hide(bContext *C, Object *ob, const bool unselected)
}
MutableSpan<MPoly> polys = me->polys_for_write();
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::MutableAttributeAccessor attributes = me->attributes_for_write();
bke::SpanAttributeWriter<bool> hide_poly = attributes.lookup_or_add_for_write_span<bool>(
".hide_poly", ATTR_DOMAIN_FACE);
@ -175,7 +175,7 @@ void paintface_reveal(bContext *C, Object *ob, const bool select)
}
MutableSpan<MPoly> polys = me->polys_for_write();
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::MutableAttributeAccessor attributes = me->attributes_for_write();
if (select) {
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
@ -209,7 +209,7 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo
const Span<MEdge> edges = me->edges();
MutableSpan<MPoly> polys = me->polys_for_write();
const Span<MLoop> loops = me->loops();
bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
bke::AttributeAccessor attributes = me->attributes();
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
".hide_poly", ATTR_DOMAIN_FACE, false);
@ -306,7 +306,7 @@ bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool fl
}
MutableSpan<MPoly> polys = me->polys_for_write();
bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
bke::AttributeAccessor attributes = me->attributes();
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
".hide_poly", ATTR_DOMAIN_FACE, false);
@ -372,7 +372,7 @@ bool paintface_minmax(Object *ob, float r_min[3], float r_max[3])
const Span<MVert> verts = me->verts();
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
bke::AttributeAccessor attributes = me->attributes();
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
".hide_poly", ATTR_DOMAIN_FACE, false);
@ -410,7 +410,7 @@ bool paintface_mouse_select(bContext *C,
Mesh *me = BKE_mesh_from_object(ob);
MutableSpan<MPoly> polys = me->polys_for_write();
bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
bke::AttributeAccessor attributes = me->attributes();
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
".hide_poly", ATTR_DOMAIN_FACE, false);
@ -530,7 +530,7 @@ bool paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags)
}
MutableSpan<MVert> verts = me->verts_for_write();
bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
bke::AttributeAccessor attributes = me->attributes();
const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
".hide_vert", ATTR_DOMAIN_POINT, false);
@ -607,7 +607,7 @@ void paintvert_select_ungrouped(Object *ob, bool extend, bool flush_flags)
}
MutableSpan<MVert> verts = me->verts_for_write();
bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
bke::AttributeAccessor attributes = me->attributes();
const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
".hide_vert", ATTR_DOMAIN_POINT, false);
@ -636,7 +636,7 @@ void paintvert_hide(bContext *C, Object *ob, const bool unselected)
}
MutableSpan<MVert> verts = me->verts_for_write();
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::MutableAttributeAccessor attributes = me->attributes_for_write();
bke::SpanAttributeWriter<bool> hide_vert = attributes.lookup_or_add_for_write_span<bool>(
".hide_vert", ATTR_DOMAIN_POINT);
@ -669,7 +669,7 @@ void paintvert_reveal(bContext *C, Object *ob, const bool select)
}
MutableSpan<MVert> verts = me->verts_for_write();
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::MutableAttributeAccessor attributes = me->attributes_for_write();
const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
".hide_vert", ATTR_DOMAIN_POINT, false);

View File

@ -254,7 +254,7 @@ static void join_mesh_single(Depsgraph *depsgraph,
CustomData_copy_data_named(&me->pdata, pdata, 0, *polyofs, me->totpoly);
blender::bke::AttributeWriter<int> material_indices =
blender::bke::mesh_attributes_for_write(*me).lookup_for_write<int>("material_index");
me->attributes_for_write().lookup_for_write<int>("material_index");
if (material_indices) {
blender::MutableVArraySpan<int> material_indices_span(material_indices.varray);
for (const int i : material_indices_span.index_range()) {

View File

@ -3158,7 +3158,7 @@ static int object_convert_exec(bContext *C, wmOperator *op)
}
/* Anonymous attributes shouldn't be available on the applied geometry. */
blender::bke::mesh_attributes_for_write(*new_mesh).remove_anonymous();
new_mesh->attributes_for_write().remove_anonymous();
BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
}

View File

@ -766,7 +766,7 @@ static bool modifier_apply_obdata(
BKE_mesh_nomain_to_mesh(mesh_applied, me, ob, &CD_MASK_MESH, true);
/* Anonymous attributes shouldn't be available on the applied geometry. */
blender::bke::mesh_attributes_for_write(*me).remove_anonymous();
me->attributes_for_write().remove_anonymous();
if (md_eval->type == eModifierType_Multires) {
multires_customdata_delete(me);

View File

@ -167,11 +167,10 @@ struct AddOperationExecutor {
/* Find UV map. */
VArraySpan<float2> surface_uv_map;
if (curves_id_orig_->surface_uv_map != nullptr) {
surface_uv_map = bke::mesh_attributes(surface_orig)
.lookup<float2>(curves_id_orig_->surface_uv_map, ATTR_DOMAIN_CORNER);
surface_uv_map_eval_ = bke::mesh_attributes(*surface_eval_)
.lookup<float2>(curves_id_orig_->surface_uv_map,
ATTR_DOMAIN_CORNER);
surface_uv_map = surface_orig.attributes().lookup<float2>(curves_id_orig_->surface_uv_map,
ATTR_DOMAIN_CORNER);
surface_uv_map_eval_ = surface_eval_->attributes().lookup<float2>(
curves_id_orig_->surface_uv_map, ATTR_DOMAIN_CORNER);
}
if (surface_uv_map.is_empty()) {

View File

@ -137,9 +137,9 @@ struct DensityAddOperationExecutor {
/* Find UV map. */
VArraySpan<float2> surface_uv_map;
if (curves_id_orig_->surface_uv_map != nullptr) {
surface_uv_map = bke::mesh_attributes(*surface_orig_)
surface_uv_map = surface_orig_->attributes()
.lookup<float2>(curves_id_orig_->surface_uv_map, ATTR_DOMAIN_CORNER);
surface_uv_map_eval_ = bke::mesh_attributes(*surface_eval_)
surface_uv_map_eval_ = surface_eval_->attributes()
.lookup<float2>(curves_id_orig_->surface_uv_map,
ATTR_DOMAIN_CORNER);
}

View File

@ -180,8 +180,8 @@ struct SlideOperationExecutor {
}
surface_looptris_orig_ = {BKE_mesh_runtime_looptri_ensure(surface_orig_),
BKE_mesh_runtime_looptri_len(surface_orig_)};
surface_uv_map_orig_ =
bke::mesh_attributes(*surface_orig_).lookup<float2>(uv_map_name, ATTR_DOMAIN_CORNER);
surface_uv_map_orig_ = surface_orig_->attributes().lookup<float2>(uv_map_name,
ATTR_DOMAIN_CORNER);
if (surface_uv_map_orig_.is_empty()) {
report_missing_uv_map_on_original_surface(stroke_extension.reports);
return;
@ -209,8 +209,8 @@ struct SlideOperationExecutor {
BKE_mesh_runtime_looptri_len(surface_eval_)};
surface_verts_eval_ = surface_eval_->verts();
surface_loops_eval_ = surface_eval_->loops();
surface_uv_map_eval_ =
bke::mesh_attributes(*surface_eval_).lookup<float2>(uv_map_name, ATTR_DOMAIN_CORNER);
surface_uv_map_eval_ = surface_eval_->attributes().lookup<float2>(uv_map_name,
ATTR_DOMAIN_CORNER);
if (surface_uv_map_eval_.is_empty()) {
report_missing_uv_map_on_evaluated_surface(stroke_extension.reports);
return;

View File

@ -92,7 +92,7 @@ static bool vertex_paint_from_weight(Object *ob)
return false;
}
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::MutableAttributeAccessor attributes = me->attributes_for_write();
bke::GAttributeWriter color_attribute = attributes.lookup_for_write(active_color_layer->name);
if (!color_attribute) {
@ -162,7 +162,7 @@ static IndexMask get_selected_indices(const Mesh &mesh,
const Span<MVert> verts = mesh.verts();
const Span<MPoly> polys = mesh.polys();
bke::AttributeAccessor attributes = bke::mesh_attributes(mesh);
bke::AttributeAccessor attributes = mesh.attributes();
if (mesh.editflag & ME_EDIT_PAINT_FACE_SEL) {
const VArray<bool> selection = attributes.adapt_domain(
@ -196,7 +196,7 @@ static void face_corner_color_equalize_verts(Mesh &mesh, const IndexMask selecti
return;
}
bke::AttributeAccessor attributes = bke::mesh_attributes(mesh);
bke::AttributeAccessor attributes = mesh.attributes();
if (attributes.lookup_meta_data(active_color_layer->name)->domain == ATTR_DOMAIN_POINT) {
return;
@ -270,7 +270,7 @@ static bool transform_active_color(Mesh &mesh, const TransformFn &transform_fn)
return false;
}
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
bke::GAttributeWriter color_attribute = attributes.lookup_for_write(active_color_layer->name);
if (!color_attribute) {

View File

@ -276,7 +276,7 @@ IndexMask GeometryDataSource::apply_selection_filter(Vector<int64_t> &indices) c
BLI_assert(object_eval_->mode == OB_MODE_EDIT);
Object *object_orig = DEG_get_original_object(object_eval_);
const Mesh *mesh_eval = geometry_set_.get_mesh_for_read();
const bke::AttributeAccessor attributes_eval = bke::mesh_attributes(*mesh_eval);
const bke::AttributeAccessor attributes_eval = mesh_eval->attributes();
Mesh *mesh_orig = (Mesh *)object_orig->data;
BMesh *bm = mesh_orig->edit_mesh->bm;
BM_mesh_elem_table_ensure(bm, BM_VERT);

View File

@ -505,9 +505,8 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
FrsMaterial tmpMat;
const blender::VArray<int> material_indices =
blender::bke::mesh_attributes(*me).lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
const blender::VArray<int> material_indices = me->attributes().lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
// We parse the vlak nodes again and import meshes while applying the clipping
// by the near and far view planes.

View File

@ -321,7 +321,7 @@ static void calculate_polys(const CuboidConfig &config,
static void calculate_uvs(const CuboidConfig &config, Mesh *mesh, const bke::AttributeIDRef &uv_id)
{
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
bke::SpanAttributeWriter<float2> uv_attribute =
attributes.lookup_or_add_for_write_only_span<float2>(uv_id, ATTR_DOMAIN_CORNER);
MutableSpan<float2> uvs = uv_attribute.span;

View File

@ -44,7 +44,7 @@ bke::CurvesGeometry create_curve_from_vert_indices(const Mesh &mesh,
curves.cyclic_for_write().fill(false);
curves.cyclic_for_write().slice(cyclic_curves).fill(true);
const bke::AttributeAccessor mesh_attributes = bke::mesh_attributes(mesh);
const bke::AttributeAccessor mesh_attributes = mesh.attributes();
bke::MutableAttributeAccessor curves_attributes = curves.attributes_for_write();
Set<bke::AttributeIDRef> source_attribute_ids = mesh_attributes.all_ids();

View File

@ -17,7 +17,7 @@ PointCloud *point_merge_by_distance(const PointCloud &src_points,
const float merge_distance,
const IndexMask selection)
{
const bke::AttributeAccessor src_attributes = bke::pointcloud_attributes(src_points);
const bke::AttributeAccessor src_attributes = src_points.attributes();
VArraySpan<float3> positions = src_attributes.lookup_or_default<float3>(
"position", ATTR_DOMAIN_POINT, float3(0));
const int src_size = positions.size();
@ -41,8 +41,7 @@ PointCloud *point_merge_by_distance(const PointCloud &src_points,
/* Create the new point cloud and add it to a temporary component for the attribute API. */
const int dst_size = src_size - duplicate_count;
PointCloud *dst_pointcloud = BKE_pointcloud_new_nomain(dst_size);
bke::MutableAttributeAccessor dst_attributes = bke::pointcloud_attributes_for_write(
*dst_pointcloud);
bke::MutableAttributeAccessor dst_attributes = dst_pointcloud->attributes_for_write();
/* By default, every point is just "merged" with itself. Then fill in the results of the merge
* finding, converting from indices into the selection to indices into the full input point

View File

@ -668,7 +668,7 @@ static AllPointCloudsInfo preprocess_pointclouds(const GeometrySet &geometry_set
pointcloud_info.pointcloud = pointcloud;
/* Access attributes. */
bke::AttributeAccessor attributes = bke::pointcloud_attributes(*pointcloud);
bke::AttributeAccessor attributes = pointcloud->attributes();
pointcloud_info.attributes.reinitialize(info.attributes.size());
for (const int attribute_index : info.attributes.index_range()) {
const AttributeIDRef &attribute_id = info.attributes.ids[attribute_index];
@ -744,8 +744,7 @@ static void execute_realize_pointcloud_tasks(const RealizeInstancesOptions &opti
PointCloudComponent &dst_component =
r_realized_geometry.get_component_for_write<PointCloudComponent>();
dst_component.replace(dst_pointcloud);
bke::MutableAttributeAccessor dst_attributes = bke::pointcloud_attributes_for_write(
*dst_pointcloud);
bke::MutableAttributeAccessor dst_attributes = dst_pointcloud->attributes_for_write();
SpanAttributeWriter<float3> positions = dst_attributes.lookup_or_add_for_write_only_span<float3>(
"position", ATTR_DOMAIN_POINT);
@ -883,7 +882,7 @@ static AllMeshesInfo preprocess_meshes(const GeometrySet &geometry_set,
}
/* Access attributes. */
bke::AttributeAccessor attributes = bke::mesh_attributes(*mesh);
bke::AttributeAccessor attributes = mesh->attributes();
mesh_info.attributes.reinitialize(info.attributes.size());
for (const int attribute_index : info.attributes.index_range()) {
const AttributeIDRef &attribute_id = info.attributes.ids[attribute_index];
@ -1045,7 +1044,7 @@ static void execute_realize_mesh_tasks(const RealizeInstancesOptions &options,
Mesh *dst_mesh = BKE_mesh_new_nomain(tot_vertices, tot_edges, 0, tot_loops, tot_poly);
MeshComponent &dst_component = r_realized_geometry.get_component_for_write<MeshComponent>();
dst_component.replace(dst_mesh);
bke::MutableAttributeAccessor dst_attributes = bke::mesh_attributes_for_write(*dst_mesh);
bke::MutableAttributeAccessor dst_attributes = dst_mesh->attributes_for_write();
MutableSpan<MVert> dst_verts = dst_mesh->verts_for_write();
MutableSpan<MEdge> dst_edges = dst_mesh->edges_for_write();
MutableSpan<MPoly> dst_polys = dst_mesh->polys_for_write();

View File

@ -391,7 +391,7 @@ void ABCGenericMeshWriter::get_geo_groups(Object *object,
struct Mesh *mesh,
std::map<std::string, std::vector<int32_t>> &geo_groups)
{
const bke::AttributeAccessor attributes = bke::mesh_attributes(*mesh);
const bke::AttributeAccessor attributes = mesh->attributes();
const VArraySpan<int> material_indices = attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);

View File

@ -769,7 +769,7 @@ Mesh *AbcMeshReader::read_mesh(Mesh *existing_mesh,
size_t num_polys = new_mesh->totpoly;
if (num_polys > 0) {
std::map<std::string, int> mat_map;
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*new_mesh);
bke::MutableAttributeAccessor attributes = new_mesh->attributes_for_write();
bke::SpanAttributeWriter<int> material_indices =
attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE);
assign_facesets_to_material_indices(sample_sel, material_indices.span, mat_map);
@ -830,7 +830,7 @@ void AbcMeshReader::assign_facesets_to_material_indices(const ISampleSelector &s
void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const ISampleSelector &sample_sel)
{
std::map<std::string, int> mat_map;
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
bke::SpanAttributeWriter<int> material_indices =
attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE);
assign_facesets_to_material_indices(sample_sel, material_indices.span, mat_map);

View File

@ -288,7 +288,7 @@ static bool collect_vertex_counts_per_poly(Mesh *me,
std::vector<unsigned long> &vcount_list)
{
const Span<MPoly> polys = me->polys();
const blender::bke::AttributeAccessor attributes = blender::bke::mesh_attributes(*me);
const blender::bke::AttributeAccessor attributes = me->attributes();
const blender::VArray<int> material_indices = attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
bool is_triangulated = true;
@ -399,7 +399,7 @@ void GeometryExporter::create_mesh_primitive_list(short material_index,
/* performs the actual writing */
prepareToAppendValues(is_triangulated, *primitive_list, vcount_list);
const blender::bke::AttributeAccessor attributes = blender::bke::mesh_attributes(*me);
const blender::bke::AttributeAccessor attributes = me->attributes();
const blender::VArray<int> material_indices = attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);

View File

@ -807,7 +807,7 @@ void USDMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const double mot
std::map<pxr::SdfPath, int> mat_map;
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
bke::SpanAttributeWriter<int> material_indices =
attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE);
this->assign_facesets_to_material_indices(motionSampleTime, material_indices.span, &mat_map);
@ -916,7 +916,7 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh,
MutableSpan<MPoly> polys = active_mesh->polys_for_write();
if (!polys.is_empty() && import_params_.import_materials) {
std::map<pxr::SdfPath, int> mat_map;
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*active_mesh);
bke::MutableAttributeAccessor attributes = active_mesh->attributes_for_write();
bke::SpanAttributeWriter<int> material_indices =
attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE);
assign_facesets_to_material_indices(motionSampleTime, material_indices.span, &mat_map);

View File

@ -256,7 +256,7 @@ static void get_loops_polys(const Mesh *mesh, USDMeshData &usd_mesh_data)
{
/* Only construct face groups (a.k.a. geometry subsets) when we need them for material
* assignments. */
const bke::AttributeAccessor attributes = bke::mesh_attributes(*mesh);
const bke::AttributeAccessor attributes = mesh->attributes();
const VArray<int> material_indices = attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
if (!material_indices.is_single() && mesh->totcol > 1) {

View File

@ -255,7 +255,7 @@ void OBJWriter::write_vertex_coords(FormatHandler &fh,
colors_layer = BKE_id_attributes_active_color_get(&mesh->id);
}
if (write_colors && (colors_layer != nullptr)) {
const bke::AttributeAccessor attributes = bke::mesh_attributes(*mesh);
const bke::AttributeAccessor attributes = mesh->attributes();
const VArray<ColorGeometry4f> attribute = attributes.lookup_or_default<ColorGeometry4f>(
colors_layer->name, ATTR_DOMAIN_POINT, {0.0f, 0.0f, 0.0f, 0.0f});
@ -374,7 +374,7 @@ void OBJWriter::write_poly_elements(FormatHandler &fh,
}
}
const bke::AttributeAccessor attributes = bke::mesh_attributes(*obj_mesh_data.get_mesh());
const bke::AttributeAccessor attributes = obj_mesh_data.get_mesh()->attributes();
const VArray<int> material_indices = attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);

View File

@ -203,7 +203,7 @@ void OBJMesh::calc_smooth_groups(const bool use_bitflags)
void OBJMesh::calc_poly_order()
{
const bke::AttributeAccessor attributes = bke::mesh_attributes(*export_mesh_eval_);
const bke::AttributeAccessor attributes = export_mesh_eval_->attributes();
const VArray<int> material_indices = attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
if (material_indices.is_single() && material_indices.get_internal_single() == 0) {

View File

@ -188,8 +188,8 @@ void MeshFromGeometry::create_polys_loops(Mesh *mesh, bool use_vertex_groups)
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
bke::SpanAttributeWriter<int> material_indices =
bke::mesh_attributes_for_write(*mesh).lookup_or_add_for_write_only_span<int>(
"material_index", ATTR_DOMAIN_FACE);
mesh->attributes_for_write().lookup_or_add_for_write_only_span<int>("material_index",
ATTR_DOMAIN_FACE);
const int64_t tot_face_elems{mesh->totpoly};
int tot_loop_idx = 0;

View File

@ -18,6 +18,10 @@
namespace blender {
template<typename T> class Span;
template<typename T> class MutableSpan;
namespace bke {
class AttributeAccessor;
class MutableAttributeAccessor;
} // namespace bke
} // namespace blender
#endif
@ -346,6 +350,9 @@ typedef struct Mesh {
/** Write access to loop data. */
blender::MutableSpan<MLoop> loops_for_write();
blender::bke::AttributeAccessor attributes() const;
blender::bke::MutableAttributeAccessor attributes_for_write();
/**
* Vertex group data, encoded as an array of indices and weights for every vertex.
* \warning: May be empty.

View File

@ -9,6 +9,13 @@
#include "DNA_ID.h"
#include "DNA_customdata_types.h"
#ifdef __cplusplus
namespace blender::bke {
class AttributeAccessor;
class MutableAttributeAccessor;
} // namespace blender::bke
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -32,6 +39,11 @@ typedef struct PointCloud {
short totcol;
short _pad3[3];
#ifdef __cplusplus
blender::bke::AttributeAccessor attributes() const;
blender::bke::MutableAttributeAccessor attributes_for_write();
#endif
/* Draw Cache */
void *batch_cache;
} PointCloud;

View File

@ -154,7 +154,7 @@ static void node_geo_exec(GeoNodeExecParams params)
/* Store intersecting edges in attribute. */
if (attribute_outputs.intersecting_edges_id) {
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*result);
MutableAttributeAccessor attributes = result->attributes_for_write();
SpanAttributeWriter<bool> selection = attributes.lookup_or_add_for_write_only_span<bool>(
attribute_outputs.intersecting_edges_id.get(), ATTR_DOMAIN_EDGE);

View File

@ -270,8 +270,8 @@ static void node_geo_exec(GeoNodeExecParams params)
BKE_mesh_wrapper_ensure_mdata(surface_mesh_eval);
const AttributeAccessor mesh_attributes_eval = bke::mesh_attributes(*surface_mesh_eval);
const AttributeAccessor mesh_attributes_orig = bke::mesh_attributes(*surface_mesh_orig);
const AttributeAccessor mesh_attributes_eval = surface_mesh_eval->attributes();
const AttributeAccessor mesh_attributes_orig = surface_mesh_orig->attributes();
Curves &curves_id = *curves_geometry.get_curves_for_write();
CurvesGeometry &curves = CurvesGeometry::wrap(curves_id.geometry);

View File

@ -382,8 +382,8 @@ static void separate_point_cloud_selection(GeometrySet &geometry_set,
{GEO_COMPONENT_TYPE_POINT_CLOUD}, GEO_COMPONENT_TYPE_POINT_CLOUD, false, attributes);
copy_attributes_based_on_mask(attributes,
bke::pointcloud_attributes(src_pointcloud),
bke::pointcloud_attributes_for_write(*pointcloud),
src_pointcloud.attributes(),
pointcloud->attributes_for_write(),
ATTR_DOMAIN_POINT,
selection);
geometry_set.replace_pointcloud(pointcloud);
@ -921,23 +921,23 @@ static void do_mesh_separation(GeometrySet &geometry_set,
/* Copy attributes. */
copy_attributes_based_on_map(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
ATTR_DOMAIN_POINT,
vertex_map);
copy_attributes_based_on_map(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
ATTR_DOMAIN_EDGE,
edge_map);
copy_attributes_based_on_mask(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
ATTR_DOMAIN_FACE,
IndexMask(Vector<int64_t>(selected_poly_indices.as_span())));
copy_face_corner_attributes(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
selected_loops_num,
selected_poly_indices,
mesh_in);
@ -997,23 +997,21 @@ static void do_mesh_separation(GeometrySet &geometry_set,
mesh_in, *mesh_out, edge_map, selected_poly_indices, new_loop_starts);
/* Copy attributes. */
copy_attributes(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
{ATTR_DOMAIN_POINT});
copy_attributes(
attributes, mesh_in.attributes(), mesh_out->attributes_for_write(), {ATTR_DOMAIN_POINT});
copy_attributes_based_on_map(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
ATTR_DOMAIN_EDGE,
edge_map);
copy_attributes_based_on_mask(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
ATTR_DOMAIN_FACE,
IndexMask(Vector<int64_t>(selected_poly_indices.as_span())));
copy_face_corner_attributes(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
selected_loops_num,
selected_poly_indices,
mesh_in);
@ -1060,17 +1058,17 @@ static void do_mesh_separation(GeometrySet &geometry_set,
/* Copy attributes. */
copy_attributes(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
{ATTR_DOMAIN_POINT, ATTR_DOMAIN_EDGE});
copy_attributes_based_on_mask(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
ATTR_DOMAIN_FACE,
IndexMask(Vector<int64_t>(selected_poly_indices.as_span())));
copy_face_corner_attributes(attributes,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out),
mesh_in.attributes(),
mesh_out->attributes_for_write(),
selected_loops_num,
selected_poly_indices,
mesh_in);
@ -1089,8 +1087,7 @@ static void separate_mesh_selection(GeometrySet &geometry_set,
{
const Mesh &src_mesh = *geometry_set.get_mesh_for_read();
bke::MeshFieldContext field_context{src_mesh, selection_domain};
fn::FieldEvaluator evaluator{field_context,
bke::mesh_attributes(src_mesh).domain_size(selection_domain)};
fn::FieldEvaluator evaluator{field_context, src_mesh.attributes().domain_size(selection_domain)};
evaluator.add(selection_field);
evaluator.evaluate();
const VArray<bool> selection = evaluator.get_evaluated<bool>(0);

View File

@ -291,8 +291,8 @@ BLI_NOINLINE static void propagate_existing_attributes(
const Span<float3> bary_coords,
const Span<int> looptri_indices)
{
const AttributeAccessor mesh_attributes = bke::mesh_attributes(mesh);
MutableAttributeAccessor point_attributes = bke::pointcloud_attributes_for_write(points);
const AttributeAccessor mesh_attributes = mesh.attributes();
MutableAttributeAccessor point_attributes = points.attributes_for_write();
for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;
@ -333,7 +333,7 @@ BLI_NOINLINE static void compute_attribute_outputs(const Mesh &mesh,
const Span<int> looptri_indices,
const AttributeOutputs &attribute_outputs)
{
MutableAttributeAccessor point_attributes = bke::pointcloud_attributes_for_write(points);
MutableAttributeAccessor point_attributes = points.attributes_for_write();
SpanAttributeWriter<int> ids = point_attributes.lookup_or_add_for_write_only_span<int>(
"id", ATTR_DOMAIN_POINT);
@ -396,7 +396,7 @@ static Array<float> calc_full_density_factors_with_selection(const Mesh &mesh,
const Field<bool> &selection_field)
{
const eAttrDomain domain = ATTR_DOMAIN_CORNER;
const int domain_size = bke::mesh_attributes(mesh).domain_size(domain);
const int domain_size = mesh.attributes().domain_size(domain);
Array<float> densities(domain_size, 0.0f);
bke::MeshFieldContext field_context{mesh, domain};
@ -491,8 +491,7 @@ static void point_distribution_calculate(GeometrySet &geometry_set,
}
PointCloud *pointcloud = BKE_pointcloud_new_nomain(positions.size());
bke::MutableAttributeAccessor point_attributes = bke::pointcloud_attributes_for_write(
*pointcloud);
bke::MutableAttributeAccessor point_attributes = pointcloud->attributes_for_write();
bke::SpanAttributeWriter<float3> point_positions =
point_attributes.lookup_or_add_for_write_only_span<float3>("position", ATTR_DOMAIN_POINT);
bke::SpanAttributeWriter<float> point_radii =

View File

@ -918,8 +918,8 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
new_to_old_edges_map,
new_to_old_face_corners_map,
boundary_vertex_to_relevant_face_map,
bke::mesh_attributes(mesh_in),
bke::mesh_attributes_for_write(*mesh_out));
mesh_in.attributes(),
mesh_out->attributes_for_write());
MutableSpan<MVert> dst_verts = mesh_out->verts_for_write();
MutableSpan<MEdge> dst_edges = mesh_out->edges_for_write();

View File

@ -593,22 +593,15 @@ static void duplicate_faces(GeometrySet &geometry_set,
loop_mapping,
offsets,
selection,
bke::mesh_attributes(mesh),
bke::mesh_attributes_for_write(*new_mesh));
mesh.attributes(),
new_mesh->attributes_for_write());
copy_stable_id_faces(mesh,
selection,
offsets,
vert_mapping,
bke::mesh_attributes(mesh),
bke::mesh_attributes_for_write(*new_mesh));
copy_stable_id_faces(
mesh, selection, offsets, vert_mapping, mesh.attributes(), new_mesh->attributes_for_write());
if (attribute_outputs.duplicate_index) {
create_duplicate_index_attribute(bke::mesh_attributes_for_write(*new_mesh),
ATTR_DOMAIN_FACE,
selection,
attribute_outputs,
offsets);
create_duplicate_index_attribute(
new_mesh->attributes_for_write(), ATTR_DOMAIN_FACE, selection, attribute_outputs, offsets);
}
geometry_set.replace_mesh(new_mesh);
@ -769,17 +762,14 @@ static void duplicate_edges(GeometrySet &geometry_set,
vert_orig_indices,
edge_offsets,
selection,
bke::mesh_attributes(mesh),
bke::mesh_attributes_for_write(*new_mesh));
mesh.attributes(),
new_mesh->attributes_for_write());
copy_stable_id_edges(mesh,
selection,
edge_offsets,
bke::mesh_attributes(mesh),
bke::mesh_attributes_for_write(*new_mesh));
copy_stable_id_edges(
mesh, selection, edge_offsets, mesh.attributes(), new_mesh->attributes_for_write());
if (attribute_outputs.duplicate_index) {
create_duplicate_index_attribute(bke::mesh_attributes_for_write(*new_mesh),
create_duplicate_index_attribute(new_mesh->attributes_for_write(),
ATTR_DOMAIN_EDGE,
selection,
attribute_outputs,
@ -926,14 +916,13 @@ static void duplicate_points_mesh(GeometrySet &geometry_set,
ATTR_DOMAIN_POINT,
offsets,
selection,
bke::mesh_attributes(mesh),
bke::mesh_attributes_for_write(*new_mesh));
mesh.attributes(),
new_mesh->attributes_for_write());
copy_stable_id_point(
offsets, bke::mesh_attributes(mesh), bke::mesh_attributes_for_write(*new_mesh));
copy_stable_id_point(offsets, mesh.attributes(), new_mesh->attributes_for_write());
if (attribute_outputs.duplicate_index) {
create_duplicate_index_attribute(bke::mesh_attributes_for_write(*new_mesh),
create_duplicate_index_attribute(new_mesh->attributes_for_write(),
ATTR_DOMAIN_POINT,
selection,
attribute_outputs,
@ -973,15 +962,13 @@ static void duplicate_points_pointcloud(GeometrySet &geometry_set,
ATTR_DOMAIN_POINT,
offsets,
selection,
bke::pointcloud_attributes(src_points),
bke::pointcloud_attributes_for_write(*pointcloud));
src_points.attributes(),
pointcloud->attributes_for_write());
copy_stable_id_point(offsets,
bke::pointcloud_attributes(src_points),
bke::pointcloud_attributes_for_write(*pointcloud));
copy_stable_id_point(offsets, src_points.attributes(), pointcloud->attributes_for_write());
if (attribute_outputs.duplicate_index) {
create_duplicate_index_attribute(bke::pointcloud_attributes_for_write(*pointcloud),
create_duplicate_index_attribute(pointcloud->attributes_for_write(),
ATTR_DOMAIN_POINT,
selection,
attribute_outputs,

View File

@ -88,7 +88,7 @@ class PathToEdgeSelectionFieldInput final : public bke::MeshFieldInput {
edge_paths_to_selection(mesh, start_verts, next_vert, selection_span);
return bke::mesh_attributes(mesh).adapt_domain<bool>(
return mesh.attributes().adapt_domain<bool>(
VArray<bool>::ForContainer(std::move(selection)), ATTR_DOMAIN_EDGE, domain);
}

View File

@ -66,7 +66,7 @@ static void save_selection_as_attribute(Mesh &mesh,
const eAttrDomain domain,
const IndexMask selection)
{
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
MutableAttributeAccessor attributes = mesh.attributes_for_write();
BLI_assert(!attributes.contains(id));
SpanAttributeWriter<bool> attribute = attributes.lookup_or_add_for_write_span<bool>(id, domain);
@ -138,7 +138,7 @@ static CustomData &get_customdata(Mesh &mesh, const eAttrDomain domain)
static MutableSpan<int> get_orig_index_layer(Mesh &mesh, const eAttrDomain domain)
{
const bke::AttributeAccessor attributes = bke::mesh_attributes(mesh);
const bke::AttributeAccessor attributes = mesh.attributes();
CustomData &custom_data = get_customdata(mesh, domain);
if (int *orig_indices = static_cast<int *>(CustomData_get_layer(&custom_data, CD_ORIGINDEX))) {
return {orig_indices, attributes.domain_size(domain)};
@ -252,7 +252,7 @@ static void extrude_mesh_vertices(Mesh &mesh,
new_edges[i_selection] = new_loose_edge(selection[i_selection], new_vert_range[i_selection]);
}
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
if (!ELEM(meta_data.domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_EDGE)) {
@ -498,7 +498,7 @@ static void extrude_mesh_edges(Mesh &mesh,
const Array<Vector<int>> new_vert_to_duplicate_edge_map = create_vert_to_edge_map(
new_vert_range.size(), duplicate_edges, orig_vert_size);
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span(
@ -878,7 +878,7 @@ static void extrude_mesh_face_regions(Mesh &mesh,
const Array<Vector<int>> new_vert_to_duplicate_edge_map = create_vert_to_edge_map(
new_vert_range.size(), boundary_edges, orig_vert_size);
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span(
@ -1132,7 +1132,7 @@ static void extrude_individual_mesh_faces(Mesh &mesh,
}
});
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span(

View File

@ -44,7 +44,7 @@ static void mesh_flip_faces(Mesh &mesh, const Field<bool> &selection_field)
}
}
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all(
[&](const bke::AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
if (meta_data.domain == ATTR_DOMAIN_CORNER) {

View File

@ -82,8 +82,7 @@ class AngleFieldInput final : public bke::MeshFieldInput {
};
VArray<float> angles = VArray<float>::ForFunc(mesh.totedge, angle_fn);
return bke::mesh_attributes(mesh).adapt_domain<float>(
std::move(angles), ATTR_DOMAIN_EDGE, domain);
return mesh.attributes().adapt_domain<float>(std::move(angles), ATTR_DOMAIN_EDGE, domain);
}
uint64_t hash() const override
@ -150,8 +149,7 @@ class SignedAngleFieldInput final : public bke::MeshFieldInput {
};
VArray<float> angles = VArray<float>::ForFunc(mesh.totedge, angle_fn);
return bke::mesh_attributes(mesh).adapt_domain<float>(
std::move(angles), ATTR_DOMAIN_EDGE, domain);
return mesh.attributes().adapt_domain<float>(std::move(angles), ATTR_DOMAIN_EDGE, domain);
}
uint64_t hash() const override

View File

@ -34,7 +34,7 @@ class EdgeNeighborCountFieldInput final : public bke::MeshFieldInput {
face_count[loop.e]++;
}
return bke::mesh_attributes(mesh).adapt_domain<int>(
return mesh.attributes().adapt_domain<int>(
VArray<int>::ForContainer(std::move(face_count)), ATTR_DOMAIN_EDGE, domain);
}

View File

@ -83,13 +83,13 @@ static VArray<float3> construct_edge_positions_gvarray(const Mesh &mesh,
const Span<MEdge> edges = mesh.edges();
if (vertex == VERTEX_ONE) {
return bke::mesh_attributes(mesh).adapt_domain<float3>(
return mesh.attributes().adapt_domain<float3>(
VArray<float3>::ForFunc(edges.size(),
[verts, edges](const int i) { return verts[edges[i].v1].co; }),
ATTR_DOMAIN_EDGE,
domain);
}
return bke::mesh_attributes(mesh).adapt_domain<float3>(
return mesh.attributes().adapt_domain<float3>(
VArray<float3>::ForFunc(edges.size(),
[verts, edges](const int i) { return verts[edges[i].v2].co; }),
ATTR_DOMAIN_EDGE,

View File

@ -27,7 +27,7 @@ static VArray<float> construct_face_area_varray(const Mesh &mesh, const eAttrDom
return BKE_mesh_calc_poly_area(&poly, &loops[poly.loopstart], verts.data());
};
return bke::mesh_attributes(mesh).adapt_domain<float>(
return mesh.attributes().adapt_domain<float>(
VArray<float>::ForFunc(polys.size(), area_fn), ATTR_DOMAIN_FACE, domain);
}

View File

@ -72,7 +72,7 @@ class PlanarFieldInput final : public bke::MeshFieldInput {
return max - min < thresholds[i] / 2.0f;
};
return bke::mesh_attributes(mesh).adapt_domain<bool>(
return mesh.attributes().adapt_domain<bool>(
VArray<bool>::ForFunc(polys.size(), planar_fn), ATTR_DOMAIN_FACE, domain);
}

View File

@ -37,7 +37,7 @@ static VArray<int> construct_neighbor_count_varray(const Mesh &mesh, const eAttr
}
}
return bke::mesh_attributes(mesh).adapt_domain<int>(
return mesh.attributes().adapt_domain<int>(
VArray<int>::ForContainer(std::move(poly_count)), ATTR_DOMAIN_FACE, domain);
}
@ -71,7 +71,7 @@ class FaceNeighborCountFieldInput final : public bke::MeshFieldInput {
static VArray<int> construct_vertex_count_varray(const Mesh &mesh, const eAttrDomain domain)
{
const Span<MPoly> polys = mesh.polys();
return bke::mesh_attributes(mesh).adapt_domain<int>(
return mesh.attributes().adapt_domain<int>(
VArray<int>::ForFunc(polys.size(),
[polys](const int i) -> float { return polys[i].totloop; }),
ATTR_DOMAIN_FACE,

View File

@ -47,7 +47,7 @@ class IslandFieldInput final : public bke::MeshFieldInput {
output[i] = ordered_roots.index_of_or_add(root);
}
return bke::mesh_attributes(mesh).adapt_domain<int>(
return mesh.attributes().adapt_domain<int>(
VArray<int>::ForContainer(std::move(output)), ATTR_DOMAIN_POINT, domain);
}
@ -87,8 +87,7 @@ class IslandCountFieldInput final : public bke::MeshFieldInput {
island_list.add(root);
}
return VArray<int>::ForSingle(island_list.size(),
bke::mesh_attributes(mesh).domain_size(domain));
return VArray<int>::ForSingle(island_list.size(), mesh.attributes().domain_size(domain));
}
uint64_t hash() const override

View File

@ -125,7 +125,7 @@ class ShortestEdgePathsNextVertFieldInput final : public bke::MeshFieldInput {
}
}
});
return bke::mesh_attributes(mesh).adapt_domain<int>(
return mesh.attributes().adapt_domain<int>(
VArray<int>::ForContainer(std::move(next_index)), ATTR_DOMAIN_POINT, domain);
}
@ -189,7 +189,7 @@ class ShortestEdgePathsCostFieldInput final : public bke::MeshFieldInput {
}
}
});
return bke::mesh_attributes(mesh).adapt_domain<float>(
return mesh.attributes().adapt_domain<float>(
VArray<float>::ForContainer(std::move(cost)), ATTR_DOMAIN_POINT, domain);
}

View File

@ -45,8 +45,7 @@ static void convert_instances_to_points(GeometrySet &geometry_set,
PointCloud *pointcloud = BKE_pointcloud_new_nomain(selection.size());
geometry_set.replace_pointcloud(pointcloud);
bke::MutableAttributeAccessor point_attributes = bke::pointcloud_attributes_for_write(
*pointcloud);
bke::MutableAttributeAccessor point_attributes = pointcloud->attributes_for_write();
bke::SpanAttributeWriter<float3> point_positions =
point_attributes.lookup_or_add_for_write_only_span<float3>("position", ATTR_DOMAIN_POINT);

View File

@ -32,7 +32,7 @@ static void select_mesh_by_material(const Mesh &mesh,
slots.append(i);
}
}
const AttributeAccessor attributes = bke::mesh_attributes(mesh);
const AttributeAccessor attributes = mesh.attributes();
const VArray<int> material_indices = attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
if (material != nullptr && material_indices.is_single() &&
@ -81,7 +81,7 @@ class MaterialSelectionFieldInput final : public bke::GeometryFieldInput {
Array<bool> selection(mesh->totpoly);
select_mesh_by_material(*mesh, material_, IndexMask(mesh->totpoly), selection);
return bke::mesh_attributes(*mesh).adapt_domain<bool>(
return mesh->attributes().adapt_domain<bool>(
VArray<bool>::ForContainer(std::move(selection)), ATTR_DOMAIN_FACE, domain);
return nullptr;

View File

@ -480,7 +480,7 @@ static void calculate_selection_outputs(Mesh *mesh,
const ConeConfig &config,
ConeAttributeOutputs &attribute_outputs)
{
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
MutableAttributeAccessor attributes = mesh->attributes_for_write();
/* Populate "Top" selection output. */
if (attribute_outputs.top_id) {
@ -536,7 +536,7 @@ static void calculate_selection_outputs(Mesh *mesh,
*/
static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config)
{
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<float2> uv_attribute = attributes.lookup_or_add_for_write_only_span<float2>(
"uv_map", ATTR_DOMAIN_CORNER);

View File

@ -18,7 +18,7 @@ namespace blender::nodes {
static void calculate_uvs(
Mesh *mesh, Span<MVert> verts, Span<MLoop> loops, const float size_x, const float size_y)
{
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<float2> uv_attribute = attributes.lookup_or_add_for_write_only_span<float2>(
"uv_map", ATTR_DOMAIN_CORNER);

View File

@ -254,7 +254,7 @@ BLI_NOINLINE static void calculate_sphere_corners(MutableSpan<MLoop> loops,
BLI_NOINLINE static void calculate_sphere_uvs(Mesh *mesh, const float segments, const float rings)
{
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<float2> uv_attribute = attributes.lookup_or_add_for_write_only_span<float2>(
"uv_map", ATTR_DOMAIN_CORNER);

View File

@ -2,6 +2,7 @@
#include "BLI_task.hh"
#include "DNA_mesh_types.h"
#include "DNA_pointcloud_types.h"
#include "BKE_attribute_math.hh"
@ -65,7 +66,7 @@ static void geometry_set_mesh_to_points(GeometrySet &geometry_set,
geometry_set.remove_geometry_during_modify();
return;
}
const int domain_size = bke::mesh_attributes(*mesh).domain_size(domain);
const int domain_size = mesh->attributes().domain_size(domain);
if (domain_size == 0) {
geometry_set.remove_geometry_during_modify();
return;
@ -83,7 +84,7 @@ static void geometry_set_mesh_to_points(GeometrySet &geometry_set,
PointCloud *pointcloud = BKE_pointcloud_new_nomain(selection.size());
geometry_set.replace_pointcloud(pointcloud);
MutableAttributeAccessor dst_attributes = bke::pointcloud_attributes_for_write(*pointcloud);
MutableAttributeAccessor dst_attributes = pointcloud->attributes_for_write();
GSpanAttributeWriter position = dst_attributes.lookup_or_add_for_write_only_span(
"position", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
@ -102,7 +103,7 @@ static void geometry_set_mesh_to_points(GeometrySet &geometry_set,
{GEO_COMPONENT_TYPE_MESH}, GEO_COMPONENT_TYPE_POINT_CLOUD, false, attributes);
attributes.remove("position");
const AttributeAccessor src_attributes = bke::mesh_attributes(*mesh);
const AttributeAccessor src_attributes = mesh->attributes();
for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_pointcloud.h"
#include "DNA_pointcloud_types.h"
#include "BLI_task.hh"
@ -70,7 +71,7 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<float> radius_field = params.extract_input<Field<float>>("Radius");
PointCloud *points = BKE_pointcloud_new_nomain(count);
MutableAttributeAccessor attributes = bke::pointcloud_attributes_for_write(*points);
MutableAttributeAccessor attributes = points->attributes_for_write();
AttributeWriter<float3> output_position = attributes.lookup_or_add_for_write<float3>(
"position", ATTR_DOMAIN_POINT);
AttributeWriter<float> output_radii = attributes.lookup_or_add_for_write<float>(

View File

@ -47,8 +47,8 @@ static void geometry_set_points_to_vertices(GeometrySet &geometry_set,
Mesh *mesh = BKE_mesh_new_nomain(selection.size(), 0, 0, 0, 0);
geometry_set.replace_mesh(mesh);
const AttributeAccessor src_attributes = bke::pointcloud_attributes(*points);
MutableAttributeAccessor dst_attributes = bke::mesh_attributes_for_write(*mesh);
const AttributeAccessor src_attributes = points->attributes();
MutableAttributeAccessor dst_attributes = mesh->attributes_for_write();
for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;

View File

@ -312,7 +312,7 @@ class RaycastFunction : public fn::MultiFunction {
}
const Mesh &mesh = *target_.get_mesh_for_read();
target_context_.emplace(bke::MeshFieldContext{mesh, domain_});
const int domain_size = bke::mesh_attributes(mesh).domain_size(domain_);
const int domain_size = mesh.attributes().domain_size(domain_);
target_evaluator_ = std::make_unique<FieldEvaluator>(*target_context_, domain_size);
target_evaluator_->add(std::move(src_field));
target_evaluator_->evaluate();

View File

@ -50,7 +50,7 @@ static void assign_material_to_faces(Mesh &mesh, const IndexMask selection, Mate
BKE_id_material_eval_assign(&mesh.id, new_material_index + 1, material);
}
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
MutableAttributeAccessor attributes = mesh.attributes_for_write();
SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>(
"material_index", ATTR_DOMAIN_FACE);
material_indices.span.fill_indices(selection, new_material_index);

View File

@ -25,7 +25,7 @@ static void set_radius_in_component(PointCloud &pointcloud,
if (pointcloud.totpoint == 0) {
return;
}
MutableAttributeAccessor attributes = bke::pointcloud_attributes_for_write(pointcloud);
MutableAttributeAccessor attributes = pointcloud.attributes_for_write();
AttributeWriter<float> radii = attributes.lookup_or_add_for_write<float>("radius",
ATTR_DOMAIN_POINT);

View File

@ -22,7 +22,7 @@ static void set_smooth(Mesh &mesh,
return;
}
MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
MutableAttributeAccessor attributes = mesh.attributes_for_write();
AttributeWriter<bool> smooth = attributes.lookup_or_add_for_write<bool>("shade_smooth",
ATTR_DOMAIN_FACE);

View File

@ -438,7 +438,7 @@ class NearestInterpolatedTransferFunction : public fn::MultiFunction {
{
const Mesh &mesh = *source_.get_mesh_for_read();
source_context_.emplace(bke::MeshFieldContext{mesh, domain_});
const int domain_size = bke::mesh_attributes(mesh).domain_size(domain_);
const int domain_size = mesh.attributes().domain_size(domain_);
source_evaluator_ = std::make_unique<FieldEvaluator>(*source_context_, domain_size);
source_evaluator_->add(src_field_);
source_evaluator_->evaluate();
@ -583,7 +583,7 @@ class NearestTransferFunction : public fn::MultiFunction {
{
if (use_mesh_) {
const Mesh &mesh = *source_.get_mesh_for_read();
const int domain_size = bke::mesh_attributes(mesh).domain_size(domain_);
const int domain_size = mesh.attributes().domain_size(domain_);
mesh_context_.emplace(bke::MeshFieldContext(mesh, domain_));
mesh_evaluator_ = std::make_unique<FieldEvaluator>(*mesh_context_, domain_size);
mesh_evaluator_->add(src_field_);

View File

@ -47,7 +47,7 @@ static void transform_mesh(Mesh &mesh, const float4x4 &transform)
static void translate_pointcloud(PointCloud &pointcloud, const float3 translation)
{
MutableAttributeAccessor attributes = bke::pointcloud_attributes_for_write(pointcloud);
MutableAttributeAccessor attributes = pointcloud.attributes_for_write();
SpanAttributeWriter position = attributes.lookup_or_add_for_write_span<float3>(
"position", ATTR_DOMAIN_POINT);
for (const int i : position.span.index_range()) {
@ -58,7 +58,7 @@ static void translate_pointcloud(PointCloud &pointcloud, const float3 translatio
static void transform_pointcloud(PointCloud &pointcloud, const float4x4 &transform)
{
MutableAttributeAccessor attributes = bke::pointcloud_attributes_for_write(pointcloud);
MutableAttributeAccessor attributes = pointcloud.attributes_for_write();
SpanAttributeWriter position = attributes.lookup_or_add_for_write_span<float3>(
"position", ATTR_DOMAIN_POINT);
for (const int i : position.span.index_range()) {

View File

@ -87,7 +87,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
GEO_uv_parametrizer_flush(handle);
GEO_uv_parametrizer_delete(handle);
return bke::mesh_attributes(mesh).adapt_domain<float3>(
return mesh.attributes().adapt_domain<float3>(
VArray<float3>::ForContainer(std::move(uv)), ATTR_DOMAIN_CORNER, domain);
}

View File

@ -126,7 +126,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
GEO_uv_parametrizer_flush(handle);
GEO_uv_parametrizer_delete(handle);
return bke::mesh_attributes(mesh).adapt_domain<float3>(
return mesh.attributes().adapt_domain<float3>(
VArray<float3>::ForContainer(std::move(uv)), ATTR_DOMAIN_CORNER, domain);
}