Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | public: | ||||
| } | } | ||||
| }; | }; | ||||
| /** | /** | ||||
| * Return true if the attribute should be copied/interpolated to the result curves. | * Return true if the attribute should be copied/interpolated to the result curves. | ||||
| * Don't output attributes that correspond to curve types that have no curves in the result. | * Don't output attributes that correspond to curve types that have no curves in the result. | ||||
| */ | */ | ||||
| static bool interpolate_attribute_to_curves(const AttributeIDRef &attribute_id, | static bool interpolate_attribute_to_curves(const AttributeIDRef &attribute_id, | ||||
| const std::array<int, CURVE_TYPES_NUM> &type_counts) | const Span<int> type_counts) | ||||
| { | { | ||||
| if (!attribute_id.is_named()) { | if (!attribute_id.is_named()) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (ELEM(attribute_id.name(), | if (ELEM(attribute_id.name(), | ||||
| "handle_type_left", | "handle_type_left", | ||||
| "handle_type_right", | "handle_type_right", | ||||
| "handle_left", | "handle_left", | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| * Gather a set of all generic attribute IDs to copy to the result curves. | * Gather a set of all generic attribute IDs to copy to the result curves. | ||||
| */ | */ | ||||
| static void gather_point_attributes_to_interpolate(const CurveComponent &src_component, | static void gather_point_attributes_to_interpolate(const CurveComponent &src_component, | ||||
| CurveComponent &dst_component, | CurveComponent &dst_component, | ||||
| AttributesForInterpolation &result) | AttributesForInterpolation &result) | ||||
| { | { | ||||
| const Curves &dst_curves_id = *dst_component.get_for_read(); | const Curves &dst_curves_id = *dst_component.get_for_read(); | ||||
| const bke::CurvesGeometry &dst_curves = bke::CurvesGeometry::wrap(dst_curves_id.geometry); | const bke::CurvesGeometry &dst_curves = bke::CurvesGeometry::wrap(dst_curves_id.geometry); | ||||
| const std::array<int, CURVE_TYPES_NUM> type_counts = dst_curves.count_curve_types(); | |||||
| VectorSet<AttributeIDRef> ids; | VectorSet<AttributeIDRef> ids; | ||||
| VectorSet<AttributeIDRef> ids_no_interpolation; | VectorSet<AttributeIDRef> ids_no_interpolation; | ||||
| src_component.attribute_foreach( | src_component.attribute_foreach( | ||||
| [&](const AttributeIDRef &id, const AttributeMetaData meta_data) { | [&](const AttributeIDRef &id, const AttributeMetaData meta_data) { | ||||
| if (meta_data.domain != ATTR_DOMAIN_POINT) { | if (meta_data.domain != ATTR_DOMAIN_POINT) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (!interpolate_attribute_to_curves(id, type_counts)) { | if (!interpolate_attribute_to_curves(id, dst_curves.curve_type_counts())) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (interpolate_attribute_to_poly_curve(id)) { | if (interpolate_attribute_to_poly_curve(id)) { | ||||
| ids.add_new(id); | ids.add_new(id); | ||||
| } | } | ||||
| else { | else { | ||||
| ids_no_interpolation.add_new(id); | ids_no_interpolation.add_new(id); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | const Vector<IndexRange> unselected_ranges = selection.extract_ranges_invert( | ||||
| src_curves.curves_range(), nullptr); | src_curves.curves_range(), nullptr); | ||||
| /* Fill the counts for the curves that aren't selected and accumulate the counts into offsets. */ | /* Fill the counts for the curves that aren't selected and accumulate the counts into offsets. */ | ||||
| fill_curve_counts(src_curves, unselected_ranges, dst_offsets); | fill_curve_counts(src_curves, unselected_ranges, dst_offsets); | ||||
| accumulate_counts_to_offsets(dst_offsets); | accumulate_counts_to_offsets(dst_offsets); | ||||
| dst_curves.resize(dst_offsets.last(), dst_curves.curves_num()); | dst_curves.resize(dst_offsets.last(), dst_curves.curves_num()); | ||||
| /* All resampled curves are poly curves. */ | /* All resampled curves are poly curves. */ | ||||
| dst_curves.curve_types_for_write().fill_indices(selection, CURVE_TYPE_POLY); | dst_curves.fill_curve_types(selection, CURVE_TYPE_POLY); | ||||
| VArray<bool> curves_cyclic = src_curves.cyclic(); | VArray<bool> curves_cyclic = src_curves.cyclic(); | ||||
| VArray<int8_t> curve_types = src_curves.curve_types(); | VArray<int8_t> curve_types = src_curves.curve_types(); | ||||
| Span<float3> evaluated_positions = src_curves.evaluated_positions(); | Span<float3> evaluated_positions = src_curves.evaluated_positions(); | ||||
| MutableSpan<float3> dst_positions = dst_curves.positions_for_write(); | MutableSpan<float3> dst_positions = dst_curves.positions_for_write(); | ||||
| AttributesForInterpolation attributes; | AttributesForInterpolation attributes; | ||||
| gather_point_attributes_to_interpolate(src_component, dst_component, attributes); | gather_point_attributes_to_interpolate(src_component, dst_component, attributes); | ||||
| ▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | static Curves *resample_to_evaluated(const CurveComponent &src_component, | ||||
| dst_component.replace(dst_curves_id, GeometryOwnershipType::Editable); | dst_component.replace(dst_curves_id, GeometryOwnershipType::Editable); | ||||
| /* Directly copy curve attributes, since they stay the same (except for curve types). */ | /* Directly copy curve attributes, since they stay the same (except for curve types). */ | ||||
| CustomData_copy(&src_curves.curve_data, | CustomData_copy(&src_curves.curve_data, | ||||
| &dst_curves.curve_data, | &dst_curves.curve_data, | ||||
| CD_MASK_ALL, | CD_MASK_ALL, | ||||
| CD_DUPLICATE, | CD_DUPLICATE, | ||||
| src_curves.curves_num()); | src_curves.curves_num()); | ||||
| /* All resampled curves are poly curves. */ | /* All resampled curves are poly curves. */ | ||||
| dst_curves.curve_types_for_write().fill_indices(selection, CURVE_TYPE_POLY); | dst_curves.fill_curve_types(selection, CURVE_TYPE_POLY); | ||||
| MutableSpan<int> dst_offsets = dst_curves.offsets_for_write(); | MutableSpan<int> dst_offsets = dst_curves.offsets_for_write(); | ||||
| src_curves.ensure_evaluated_offsets(); | src_curves.ensure_evaluated_offsets(); | ||||
| threading::parallel_for(selection.index_range(), 4096, [&](IndexRange range) { | threading::parallel_for(selection.index_range(), 4096, [&](IndexRange range) { | ||||
| for (const int i : selection.slice(range)) { | for (const int i : selection.slice(range)) { | ||||
| dst_offsets[i] = src_curves.evaluated_points_for_curve(i).size(); | dst_offsets[i] = src_curves.evaluated_points_for_curve(i).size(); | ||||
| } | } | ||||
| }); | }); | ||||
| ▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines | |||||