diff options
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc b/source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc index 8b665376c01..d46ceac92ba 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ +#include "BKE_curves.hh" + #include "node_geometry_util.hh" namespace blender::nodes::node_geo_set_spline_resolution_cc { @@ -12,36 +14,36 @@ static void node_declare(NodeDeclarationBuilder &b) b.add_output<decl::Geometry>(N_("Geometry")); } -static void set_resolution_in_component(GeometryComponent &component, - const Field<bool> &selection_field, - const Field<int> &resolution_field) +static void set_resolution(bke::CurvesGeometry &curves, + const Field<bool> &selection_field, + const Field<int> &resolution_field) { - GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_CURVE}; - const int domain_num = component.attribute_domain_num(ATTR_DOMAIN_CURVE); - if (domain_num == 0) { + if (curves.curves_num() == 0) { return; } + MutableAttributeAccessor attributes = curves.attributes_for_write(); + AttributeWriter<int> resolutions = attributes.lookup_or_add_for_write<int>("resolution", + ATTR_DOMAIN_CURVE); - OutputAttribute_Typed<int> resolutions = component.attribute_try_get_for_output_only<int>( - "resolution", ATTR_DOMAIN_CURVE); - - fn::FieldEvaluator evaluator{field_context, domain_num}; + bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_CURVE}; + fn::FieldEvaluator evaluator{field_context, curves.curves_num()}; evaluator.set_selection(selection_field); - evaluator.add_with_destination(resolution_field, resolutions.varray()); + evaluator.add_with_destination(resolution_field, resolutions.varray); evaluator.evaluate(); - resolutions.save(); + resolutions.finish(); } static void node_geo_exec(GeoNodeExecParams params) { GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); - Field<bool> selection_field = params.extract_input<Field<bool>>("Selection"); - Field<int> resolution_field = params.extract_input<Field<int>>("Resolution"); + Field<bool> selection = params.extract_input<Field<bool>>("Selection"); + Field<int> resolution = params.extract_input<Field<int>>("Resolution"); geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { - set_resolution_in_component( - geometry_set.get_component_for_write<CurveComponent>(), selection_field, resolution_field); + if (Curves *curves_id = geometry_set.get_curves_for_write()) { + set_resolution(bke::CurvesGeometry::wrap(curves_id->geometry), selection, resolution); + } }); params.set_output("Geometry", std::move(geometry_set)); |