diff options
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc index 7463eb01471..a1d6695b33b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc @@ -2,6 +2,7 @@ #include "BLI_task.hh" +#include "DNA_mesh_types.h" #include "DNA_pointcloud_types.h" #include "BKE_attribute_math.hh" @@ -60,18 +61,18 @@ static void geometry_set_mesh_to_points(GeometrySet &geometry_set, Field<bool> &selection_field, const eAttrDomain domain) { - const MeshComponent *mesh_component = geometry_set.get_component_for_read<MeshComponent>(); - if (mesh_component == nullptr) { - geometry_set.keep_only({GEO_COMPONENT_TYPE_INSTANCES}); + const Mesh *mesh = geometry_set.get_mesh_for_read(); + if (mesh == nullptr) { + geometry_set.remove_geometry_during_modify(); return; } - GeometryComponentFieldContext field_context{*mesh_component, domain}; - const int domain_num = mesh_component->attribute_domain_num(domain); - if (domain_num == 0) { - geometry_set.keep_only({GEO_COMPONENT_TYPE_INSTANCES}); + const int domain_size = mesh->attributes().domain_size(domain); + if (domain_size == 0) { + geometry_set.remove_geometry_during_modify(); return; } - fn::FieldEvaluator evaluator{field_context, domain_num}; + bke::MeshFieldContext field_context{*mesh, domain}; + fn::FieldEvaluator evaluator{field_context, domain_size}; evaluator.set_selection(selection_field); /* Evaluating directly into the point cloud doesn't work because we are not using the full * "min_array_size" array but compressing the selected elements into the final array with no @@ -83,39 +84,40 @@ static void geometry_set_mesh_to_points(GeometrySet &geometry_set, PointCloud *pointcloud = BKE_pointcloud_new_nomain(selection.size()); geometry_set.replace_pointcloud(pointcloud); - PointCloudComponent &point_component = - geometry_set.get_component_for_write<PointCloudComponent>(); + MutableAttributeAccessor dst_attributes = pointcloud->attributes_for_write(); - OutputAttribute position = point_component.attribute_try_get_for_output_only( + GSpanAttributeWriter position = dst_attributes.lookup_or_add_for_write_only_span( "position", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3); materialize_compressed_to_uninitialized_threaded( - evaluator.get_evaluated(0), selection, position.as_span()); - position.save(); + evaluator.get_evaluated(0), selection, position.span); + position.finish(); - OutputAttribute radius = point_component.attribute_try_get_for_output_only( + GSpanAttributeWriter radius = dst_attributes.lookup_or_add_for_write_only_span( "radius", ATTR_DOMAIN_POINT, CD_PROP_FLOAT); materialize_compressed_to_uninitialized_threaded( - evaluator.get_evaluated(1), selection, radius.as_span()); - radius.save(); + evaluator.get_evaluated(1), selection, radius.span); + radius.finish(); Map<AttributeIDRef, AttributeKind> attributes; geometry_set.gather_attributes_for_propagation( {GEO_COMPONENT_TYPE_MESH}, GEO_COMPONENT_TYPE_POINT_CLOUD, false, attributes); attributes.remove("position"); + const AttributeAccessor src_attributes = mesh->attributes(); + for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) { const AttributeIDRef attribute_id = entry.key; const eCustomDataType data_type = entry.value.data_type; - GVArray src = mesh_component->attribute_get_for_read(attribute_id, domain, data_type); - OutputAttribute dst = point_component.attribute_try_get_for_output_only( + GVArray src = src_attributes.lookup_or_default(attribute_id, domain, data_type); + GSpanAttributeWriter dst = dst_attributes.lookup_or_add_for_write_only_span( attribute_id, ATTR_DOMAIN_POINT, data_type); if (dst && src) { - materialize_compressed_to_uninitialized_threaded(src, selection, dst.as_span()); - dst.save(); + materialize_compressed_to_uninitialized_threaded(src, selection, dst.span); + dst.finish(); } } - geometry_set.keep_only({GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_INSTANCES}); + geometry_set.keep_only_during_modify({GEO_COMPONENT_TYPE_POINT_CLOUD}); } static void node_geo_exec(GeoNodeExecParams params) |