[Bf-blender-cvs] [c3b9a4e0010] master: Cleanup: Access attributes with new API instead of geometry components
Hans Goudey
noreply at git.blender.org
Wed Jul 20 05:34:53 CEST 2022
Commit: c3b9a4e001057f9f9ec9296b53dd9cca86dfc21c
Author: Hans Goudey
Date: Tue Jul 19 22:34:32 2022 -0500
Branches: master
https://developer.blender.org/rBc3b9a4e001057f9f9ec9296b53dd9cca86dfc21c
Cleanup: Access attributes with new API instead of geometry components
Remove the boilerplate of using a local geometry component just to use
the attribute API that was necessary before b876ce2a4a4638142439.
===================================================================
M source/blender/geometry/GEO_point_merge_by_distance.hh
M source/blender/geometry/intern/point_merge_by_distance.cc
M source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
M source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc
M source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
M source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
M source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc
===================================================================
diff --git a/source/blender/geometry/GEO_point_merge_by_distance.hh b/source/blender/geometry/GEO_point_merge_by_distance.hh
index 1e977cf3bdc..92d871c62ab 100644
--- a/source/blender/geometry/GEO_point_merge_by_distance.hh
+++ b/source/blender/geometry/GEO_point_merge_by_distance.hh
@@ -17,7 +17,7 @@ namespace blender::geometry {
* Merge selected points into other selected points within the \a merge_distance. The merged
* indices favor speed over accuracy, since the results will depend on the order of the points.
*/
-PointCloud *point_merge_by_distance(const PointCloudComponent &src_points,
+PointCloud *point_merge_by_distance(const PointCloud &src_points,
const float merge_distance,
const IndexMask selection);
diff --git a/source/blender/geometry/intern/point_merge_by_distance.cc b/source/blender/geometry/intern/point_merge_by_distance.cc
index ac10f4ef00c..42fac849667 100644
--- a/source/blender/geometry/intern/point_merge_by_distance.cc
+++ b/source/blender/geometry/intern/point_merge_by_distance.cc
@@ -13,13 +13,12 @@
namespace blender::geometry {
-PointCloud *point_merge_by_distance(const PointCloudComponent &src_points,
+PointCloud *point_merge_by_distance(const PointCloud &src_points,
const float merge_distance,
const IndexMask selection)
{
- const PointCloud &src_pointcloud = *src_points.get_for_read();
- bke::AttributeAccessor attributes = bke::pointcloud_attributes(src_pointcloud);
- VArraySpan<float3> positions = attributes.lookup_or_default<float3>(
+ const bke::AttributeAccessor src_attributes = bke::pointcloud_attributes(src_points);
+ VArraySpan<float3> positions = src_attributes.lookup_or_default<float3>(
"position", ATTR_DOMAIN_POINT, float3(0));
const int src_size = positions.size();
@@ -42,8 +41,8 @@ PointCloud *point_merge_by_distance(const PointCloudComponent &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);
- PointCloudComponent dst_points;
- dst_points.replace(dst_pointcloud, GeometryOwnershipType::Editable);
+ bke::MutableAttributeAccessor dst_attributes = bke::pointcloud_attributes_for_write(
+ *dst_pointcloud);
/* 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
@@ -106,8 +105,6 @@ PointCloud *point_merge_by_distance(const PointCloudComponent &src_points,
point_merge_counts[dst_index]++;
}
- const bke::AttributeAccessor src_attributes = *src_points.attributes();
- bke::MutableAttributeAccessor dst_attributes = *dst_points.attributes_for_write();
Set<bke::AttributeIDRef> attribute_ids = src_attributes.all_ids();
/* Transfer the ID attribute if it exists, using the ID of the first merged point. */
diff --git a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
index 408596b65aa..582bcbc3395 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
@@ -43,13 +43,13 @@ static void copy_data_based_on_map(Span<T> src, MutableSpan<T> dst, Span<int> in
* Copies the attributes with a domain in `domains` to `result_component`.
*/
static void copy_attributes(const Map<AttributeIDRef, AttributeKind> &attributes,
- const GeometryComponent &in_component,
- GeometryComponent &result_component,
+ const bke::AttributeAccessor src_attributes,
+ bke::MutableAttributeAccessor dst_attributes,
const Span<eAttrDomain> domains)
{
for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;
- GAttributeReader attribute = in_component.attributes()->lookup(attribute_id);
+ GAttributeReader attribute = src_attributes.lookup(attribute_id);
if (!attribute) {
continue;
}
@@ -60,9 +60,8 @@ static void copy_attributes(const Map<AttributeIDRef, AttributeKind> &attributes
}
const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(attribute.varray.type());
- GSpanAttributeWriter result_attribute =
- result_component.attributes_for_write()->lookup_or_add_for_write_only_span(
- attribute_id, attribute.domain, data_type);
+ GSpanAttributeWriter result_attribute = dst_attributes.lookup_or_add_for_write_only_span(
+ attribute_id, attribute.domain, data_type);
if (!result_attribute) {
continue;
@@ -83,14 +82,14 @@ static void copy_attributes(const Map<AttributeIDRef, AttributeKind> &attributes
* the mask to `result_component`.
*/
static void copy_attributes_based_on_mask(const Map<AttributeIDRef, AttributeKind> &attributes,
- const GeometryComponent &in_component,
- GeometryComponent &result_component,
+ const bke::AttributeAccessor src_attributes,
+ bke::MutableAttributeAccessor dst_attributes,
const eAttrDomain domain,
const IndexMask mask)
{
for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;
- GAttributeReader attribute = in_component.attributes()->lookup(attribute_id);
+ GAttributeReader attribute = src_attributes.lookup(attribute_id);
if (!attribute) {
continue;
}
@@ -101,9 +100,8 @@ static void copy_attributes_based_on_mask(const Map<AttributeIDRef, AttributeKin
}
const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(attribute.varray.type());
- GSpanAttributeWriter result_attribute =
- result_component.attributes_for_write()->lookup_or_add_for_write_only_span(
- attribute_id, attribute.domain, data_type);
+ GSpanAttributeWriter result_attribute = dst_attributes.lookup_or_add_for_write_only_span(
+ attribute_id, attribute.domain, data_type);
if (!result_attribute) {
continue;
@@ -120,14 +118,14 @@ static void copy_attributes_based_on_mask(const Map<AttributeIDRef, AttributeKin
}
static void copy_attributes_based_on_map(const Map<AttributeIDRef, AttributeKind> &attributes,
- const GeometryComponent &in_component,
- GeometryComponent &result_component,
+ const bke::AttributeAccessor src_attributes,
+ bke::MutableAttributeAccessor dst_attributes,
const eAttrDomain domain,
const Span<int> index_map)
{
for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;
- GAttributeReader attribute = in_component.attributes()->lookup(attribute_id);
+ GAttributeReader attribute = src_attributes.lookup(attribute_id);
if (!attribute) {
continue;
}
@@ -138,9 +136,8 @@ static void copy_attributes_based_on_map(const Map<AttributeIDRef, AttributeKind
}
const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(attribute.varray.type());
- GSpanAttributeWriter result_attribute =
- result_component.attributes_for_write()->lookup_or_add_for_write_only_span(
- attribute_id, attribute.domain, data_type);
+ GSpanAttributeWriter result_attribute = dst_attributes.lookup_or_add_for_write_only_span(
+ attribute_id, attribute.domain, data_type);
if (!result_attribute) {
continue;
@@ -157,8 +154,8 @@ static void copy_attributes_based_on_map(const Map<AttributeIDRef, AttributeKind
}
static void copy_face_corner_attributes(const Map<AttributeIDRef, AttributeKind> &attributes,
- const GeometryComponent &in_component,
- GeometryComponent &out_component,
+ const bke::AttributeAccessor src_attributes,
+ bke::MutableAttributeAccessor dst_attributes,
const int selected_loops_num,
const Span<int> selected_poly_indices,
const Mesh &mesh_in)
@@ -174,7 +171,7 @@ static void copy_face_corner_attributes(const Map<AttributeIDRef, AttributeKind>
}
}
copy_attributes_based_on_mask(
- attributes, in_component, out_component, ATTR_DOMAIN_CORNER, IndexMask(indices));
+ attributes, src_attributes, dst_attributes, ATTR_DOMAIN_CORNER, IndexMask(indices));
}
static void copy_masked_vertices_to_new_mesh(const Mesh &src_mesh,
@@ -365,14 +362,15 @@ static void separate_point_cloud_selection(GeometrySet &geometry_set,
PointCloud *pointcloud = BKE_pointcloud_new_nomain(selection.size());
- PointCloudComponent dst_points;
- dst_points.replace(pointcloud, GeometryOwnershipType::Editable);
-
Map<AttributeIDRef, AttributeKind> attributes;
geometry_set.gather_attributes_for_propagation(
{GEO_COMPONENT_TYPE_POINT_CLOUD}, GEO_COMPONENT_TYPE_POINT_CLOUD, false, attributes);
- copy_attributes_based_on_mask(attributes, src_points, dst_points, ATTR_DOMAIN_POINT, selection);
+ copy_attributes_based_on_mask(attributes,
+ bke::pointcloud_attributes(*src_points.get_for_read()),
+ bke::pointcloud_attributes_for_write(*pointcloud),
+ ATTR_DOMAIN_POINT,
+ selection);
geometry_se
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list