Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2022-07-08 17:16:56 +0300
committerJacques Lucke <jacques@blender.org>2022-07-08 17:16:56 +0300
commitb876ce2a4a4638142439a7cf265a0780491ae4cc (patch)
tree871d71eb6d1cf215869fc941c831c81bcacc6433 /source/blender/editors/sculpt_paint
parentf391e8f316bd29b700cef874a59cf3b64203d70c (diff)
Geometry Nodes: new geometry attribute API
Currently, there are two attribute API. The first, defined in `BKE_attribute.h` is accessible from RNA and C code. The second is implemented with `GeometryComponent` and is only accessible in C++ code. The second is widely used, but only being accessible through the `GeometrySet` API makes it awkward to use, and even impossible for types that don't correspond directly to a geometry component like `CurvesGeometry`. This patch adds a new attribute API, designed to replace the `GeometryComponent` attribute API now, and to eventually replace or be the basis of the other one. The basic idea is that there is an `AttributeAccessor` class that allows code to interact with a set of attributes owned by some geometry. The accessor itself has no ownership. `AttributeAccessor` is a simple type that can be passed around by value. That makes it easy to return it from functions and to store it in containers. For const-correctness, there is also a `MutableAttributeAccessor` that allows changing individual and can add or remove attributes. Currently, `AttributeAccessor` is composed of two pointers. The first is a pointer to the owner of the attribute data. The second is a pointer to a struct with function pointers, that is similar to a virtual function table. The functions know how to access attributes on the owner. The actual attribute access for geometries is still implemented with the `AttributeProvider` pattern, which makes it easy to support different sources of attributes on a geometry and simplifies dealing with built-in attributes. There are different ways to get an attribute accessor for a geometry: * `GeometryComponent.attributes()` * `CurvesGeometry.attributes()` * `bke::mesh_attributes(const Mesh &)` * `bke::pointcloud_attributes(const PointCloud &)` All of these also have a `_for_write` variant that returns a `MutabelAttributeAccessor`. Differential Revision: https://developer.blender.org/D15280
Diffstat (limited to 'source/blender/editors/sculpt_paint')
-rw-r--r--source/blender/editors/sculpt_paint/curves_sculpt_add.cc9
-rw-r--r--source/blender/editors/sculpt_paint/curves_sculpt_density.cc10
-rw-r--r--source/blender/editors/sculpt_paint/curves_sculpt_slide.cc9
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc48
4 files changed, 29 insertions, 47 deletions
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
index 401550b3b3a..26145a386f5 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
@@ -176,12 +176,9 @@ struct AddOperationExecutor {
/* Find UV map. */
VArraySpan<float2> surface_uv_map;
if (curves_id_->surface_uv_map != nullptr) {
- MeshComponent surface_component;
- surface_component.replace(surface_, GeometryOwnershipType::ReadOnly);
- surface_uv_map = surface_component
- .attribute_try_get_for_read(curves_id_->surface_uv_map,
- ATTR_DOMAIN_CORNER)
- .typed<float2>();
+ const bke::AttributeAccessor surface_attributes = bke::mesh_attributes(*surface_);
+ surface_uv_map = surface_attributes.lookup<float2>(curves_id_->surface_uv_map,
+ ATTR_DOMAIN_CORNER);
}
/* Find normals. */
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc
index 826b0611e81..e211a568705 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc
@@ -64,7 +64,6 @@ struct DensityAddOperationExecutor {
Mesh *surface_ = nullptr;
Span<MLoopTri> surface_looptris_;
Span<float3> corner_normals_su_;
- VArraySpan<float2> surface_uv_map_;
const CurvesSculpt *curves_sculpt_ = nullptr;
const Brush *brush_ = nullptr;
@@ -228,12 +227,9 @@ struct DensityAddOperationExecutor {
/* Find UV map. */
VArraySpan<float2> surface_uv_map;
if (curves_id_->surface_uv_map != nullptr) {
- MeshComponent surface_component;
- surface_component.replace(surface_, GeometryOwnershipType::ReadOnly);
- surface_uv_map = surface_component
- .attribute_try_get_for_read(curves_id_->surface_uv_map,
- ATTR_DOMAIN_CORNER)
- .typed<float2>();
+ bke::AttributeAccessor surface_attributes = bke::mesh_attributes(*surface_);
+ surface_uv_map = surface_attributes.lookup<float2>(curves_id_->surface_uv_map,
+ ATTR_DOMAIN_CORNER);
}
/* Find normals. */
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
index dedc880988d..aabe6fd93e4 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
@@ -148,12 +148,9 @@ struct SlideOperationExecutor {
BKE_mesh_runtime_looptri_len(surface_)};
if (curves_id_->surface_uv_map != nullptr) {
- MeshComponent surface_component;
- surface_component.replace(surface_, GeometryOwnershipType::ReadOnly);
- surface_uv_map_ = surface_component
- .attribute_try_get_for_read(curves_id_->surface_uv_map,
- ATTR_DOMAIN_CORNER)
- .typed<float2>();
+ const bke::AttributeAccessor surface_attributes = bke::mesh_attributes(*surface_);
+ surface_uv_map_ = surface_attributes.lookup<float2>(curves_id_->surface_uv_map,
+ ATTR_DOMAIN_CORNER);
}
if (stroke_extension.is_first) {
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 50f8854d90f..8b726c7b942 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc
+++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc
@@ -92,11 +92,9 @@ static bool vertex_paint_from_weight(Object *ob)
return false;
}
- MeshComponent component;
- component.replace(me, GeometryOwnershipType::Editable);
+ bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
- bke::WriteAttributeLookup color_attribute = component.attribute_try_get_for_write(
- active_color_layer->name);
+ bke::GAttributeWriter color_attribute = attributes.lookup_for_write(active_color_layer->name);
if (!color_attribute) {
BLI_assert_unreachable();
return false;
@@ -104,7 +102,7 @@ static bool vertex_paint_from_weight(Object *ob)
/* Retrieve the vertex group with the domain and type of the existing color
* attribute, in order to let the attribute API handle both conversions. */
- const GVArray vertex_group = component.attribute_get_for_read(
+ const GVArray vertex_group = attributes.lookup(
deform_group->name,
ATTR_DOMAIN_POINT,
bke::cpp_type_to_custom_data_type(color_attribute.varray.type()));
@@ -113,14 +111,11 @@ static bool vertex_paint_from_weight(Object *ob)
return false;
}
- GVArraySpan interpolated{component.attribute_try_adapt_domain(
- vertex_group, ATTR_DOMAIN_POINT, color_attribute.domain)};
+ GVArraySpan interpolated{
+ attributes.adapt_domain(vertex_group, ATTR_DOMAIN_POINT, color_attribute.domain)};
color_attribute.varray.set_all(interpolated.data());
-
- if (color_attribute.tag_modified_fn) {
- color_attribute.tag_modified_fn();
- }
+ color_attribute.finish();
tag_object_after_update(ob);
return true;
@@ -167,29 +162,28 @@ static IndexMask get_selected_indices(const Mesh &mesh,
Span<MVert> verts(mesh.mvert, mesh.totvert);
Span<MPoly> faces(mesh.mpoly, mesh.totpoly);
- MeshComponent component;
- component.replace(&const_cast<Mesh &>(mesh), GeometryOwnershipType::ReadOnly);
+ bke::AttributeAccessor attributes = bke::mesh_attributes(mesh);
if (mesh.editflag & ME_EDIT_PAINT_FACE_SEL) {
- const VArray<bool> selection = component.attribute_try_adapt_domain(
+ const VArray<bool> selection = attributes.adapt_domain(
VArray<bool>::ForFunc(faces.size(),
[&](const int i) { return faces[i].flag & ME_FACE_SEL; }),
ATTR_DOMAIN_FACE,
domain);
return index_mask_ops::find_indices_from_virtual_array(
- IndexMask(component.attribute_domain_num(domain)), selection, 4096, indices);
+ IndexMask(attributes.domain_size(domain)), selection, 4096, indices);
}
if (mesh.editflag & ME_EDIT_PAINT_VERT_SEL) {
- const VArray<bool> selection = component.attribute_try_adapt_domain(
+ const VArray<bool> selection = attributes.adapt_domain(
VArray<bool>::ForFunc(verts.size(), [&](const int i) { return verts[i].flag & SELECT; }),
ATTR_DOMAIN_POINT,
domain);
return index_mask_ops::find_indices_from_virtual_array(
- IndexMask(component.attribute_domain_num(domain)), selection, 4096, indices);
+ IndexMask(attributes.domain_size(domain)), selection, 4096, indices);
}
- return IndexMask(component.attribute_domain_num(domain));
+ return IndexMask(attributes.domain_size(domain));
}
static void face_corner_color_equalize_vertices(Mesh &mesh, const IndexMask selection)
@@ -202,17 +196,15 @@ static void face_corner_color_equalize_vertices(Mesh &mesh, const IndexMask sele
return;
}
- MeshComponent component;
- component.replace(&mesh, GeometryOwnershipType::Editable);
+ bke::AttributeAccessor attributes = bke::mesh_attributes(mesh);
- if (component.attribute_get_meta_data(active_color_layer->name)->domain == ATTR_DOMAIN_POINT) {
+ if (attributes.lookup_meta_data(active_color_layer->name)->domain == ATTR_DOMAIN_POINT) {
return;
}
- GVArray color_attribute_point = component.attribute_try_get_for_read(active_color_layer->name,
- ATTR_DOMAIN_POINT);
+ GVArray color_attribute_point = attributes.lookup(active_color_layer->name, ATTR_DOMAIN_POINT);
- GVArray color_attribute_corner = component.attribute_try_adapt_domain(
+ GVArray color_attribute_corner = attributes.adapt_domain(
color_attribute_point, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CORNER);
color_attribute_corner.materialize(selection, active_color_layer->data);
@@ -278,11 +270,9 @@ static bool transform_active_color(Mesh &mesh, const TransformFn &transform_fn)
return false;
}
- MeshComponent component;
- component.replace(&mesh, GeometryOwnershipType::Editable);
+ bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
- bke::WriteAttributeLookup color_attribute = component.attribute_try_get_for_write(
- active_color_layer->name);
+ bke::GAttributeWriter color_attribute = attributes.lookup_for_write(active_color_layer->name);
if (!color_attribute) {
BLI_assert_unreachable();
return false;
@@ -310,6 +300,8 @@ static bool transform_active_color(Mesh &mesh, const TransformFn &transform_fn)
});
});
+ color_attribute.finish();
+
DEG_id_tag_update(&mesh.id, 0);
return true;