diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py index b7d09215676..01163dc9ce0 100644 --- a/release/scripts/startup/nodeitems_builtins.py +++ b/release/scripts/startup/nodeitems_builtins.py @@ -649,6 +649,7 @@ geometry_node_categories = [ NodeItem("GeometryNodeAttributeStatistic"), NodeItem("GeometryNodeAttributeTransfer"), NodeItem("GeometryNodeRemoveAttribute"), + NodeItem("GeometryNodeSmoothAttribute"), NodeItem("GeometryNodeStoreNamedAttribute"), ]), GeometryNodeCategory("GEO_COLOR", "Color", items=[ diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 55bf24f943e..c40c6ae5547 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1525,6 +1525,7 @@ struct TexResult; #define GEO_NODE_INPUT_SHORTEST_EDGE_PATHS 1168 #define GEO_NODE_EDGE_PATHS_TO_CURVES 1169 #define GEO_NODE_EDGE_PATHS_TO_SELECTION 1170 +#define GEO_NODE_SMOOTH_ATTRIBUTE 1171 /** \} */ diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index 06789e34ad4..8753d0ee6af 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -15,6 +15,9 @@ #include "BLI_math_rotation.hh" #include "BLI_task.hh" + +#include "BLI_packing_task.hh" + #include "DNA_curves_types.h" #include "BKE_attribute_math.hh" @@ -1466,7 +1469,25 @@ static void adapt_curve_domain_point_to_curve_impl(const CurvesGeometry &curves, MutableSpan r_values) { attribute_math::DefaultMixer mixer(r_values); - + + Array curves_points_num(curves.curves_num()); + + for (const int index : curves.curves_range()){ + curves_points_num[index] = curves.points_num_for_curve(index); + } + + packing_task::pack(curves_points_num, 1000, [&](const Span indices){ + Span mixer_mask; + for (const int i_curve : indices){ + for (const int i_point : curves.points_for_curve(i_curve)) { + mixer.mix_in(i_curve, old_values[i_point]); + } + const int64_t fff = i_curve; + mixer_mask = Span(&fff, 1); + mixer.finalize(mixer_mask); + } + }); +/* threading::parallel_for(curves.curves_range(), 128, [&](const IndexRange range) { for (const int i_curve : range) { for (const int i_point : curves.points_for_curve(i_curve)) { @@ -1474,7 +1495,7 @@ static void adapt_curve_domain_point_to_curve_impl(const CurvesGeometry &curves, } } mixer.finalize(range); - }); + });*/ } /** diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index c462d03e3da..fd1249a0eaa 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -4784,6 +4784,7 @@ static void registerGeometryNodes() register_node_type_geo_set_shade_smooth(); register_node_type_geo_set_spline_cyclic(); register_node_type_geo_set_spline_resolution(); + register_node_type_geo_smooth_attribute(); register_node_type_geo_store_named_attribute(); register_node_type_geo_string_join(); register_node_type_geo_string_to_curves(); diff --git a/source/blender/blenlib/BLI_task.hh b/source/blender/blenlib/BLI_task.hh index 33a781d3749..25d83f156fc 100644 --- a/source/blender/blenlib/BLI_task.hh +++ b/source/blender/blenlib/BLI_task.hh @@ -131,4 +131,27 @@ template void isolate_task(const Function &function) #endif } +/* + * The task granulation size must be a power of two. + * If the complexity is dynamic, the calculation may require a fast conversion to a power of two. + */ +inline int prepair_grain_size(const int crude_grain) { +#ifdef WITH_TBB + if (crude_grain <= 0) { + return 1; + } + int power = 0; + int grain = crude_grain; + while (grain != 1) { + grain >>= 1; + power++; + } + const int grain_size = 1 << power; + return grain_size != crude_grain ? grain_size << 1 : grain_size; +#else + /* Any processing of excess. If another addiction appears, the preparation for it should be individual. */ + return crude_grain; +#endif +} + } // namespace blender::threading diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 470ffebcad4..b6dbfdcfbf9 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -282,6 +282,7 @@ set(SRC BLI_multi_value_map.hh BLI_noise.h BLI_noise.hh + BLI_packing_task.hh BLI_parameter_pack_utils.hh BLI_path_util.h BLI_polyfill_2d.h diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index dbf5f434248..6e94c43278d 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -9555,6 +9555,20 @@ static void def_geo_accumulate_field(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); } +static void def_geo_smooth_attribute(StructRNA *srna) +{ + PropertyRNA *prop; + + prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "custom1"); + RNA_def_property_enum_items(prop, rna_enum_attribute_type_items); + RNA_def_property_enum_funcs( + prop, NULL, NULL, "rna_GeometryNodeAttributeType_type_with_socket_itemf"); + RNA_def_property_enum_default(prop, CD_PROP_FLOAT); + RNA_def_property_ui_text(prop, "Data Type", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_GeometryNode_socket_update"); +} + static void def_fn_random_value(StructRNA *srna) { PropertyRNA *prop; diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h index e16cd7a253f..3701694b14a 100644 --- a/source/blender/nodes/NOD_geometry.h +++ b/source/blender/nodes/NOD_geometry.h @@ -132,6 +132,7 @@ void register_node_type_geo_set_position(void); void register_node_type_geo_set_shade_smooth(void); void register_node_type_geo_set_spline_cyclic(void); void register_node_type_geo_set_spline_resolution(void); +void register_node_type_geo_smooth_attribute(void); void register_node_type_geo_store_named_attribute(void); void register_node_type_geo_string_join(void); void register_node_type_geo_string_to_curves(void); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index d587da823f1..151ef41669d 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -283,6 +283,7 @@ DefNode(FunctionNode, FN_NODE_VALUE_TO_STRING, 0, "VALUE_TO_STRING", ValueToStri DefNode(GeometryNode, GEO_NODE_ACCUMULATE_FIELD, def_geo_accumulate_field, "ACCUMULATE_FIELD", AccumulateField, "Accumulate Field", "Add the values of an evaluated field together and output the running total for each element") DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_DOMAIN_SIZE, def_geo_attribute_domain_size, "ATTRIBUTE_DOMAIN_SIZE", AttributeDomainSize, "Domain Size", "Retrieve the number of elements in a geometry for each attribute domain") DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_STATISTIC, def_geo_attribute_statistic, "ATTRIBUTE_STATISTIC",AttributeStatistic, "Attribute Statistic","Calculate statistics about a data set from a field evaluated on a geometry") +DefNode(GeometryNode, GEO_NODE_SMOOTH_ATTRIBUTE, def_geo_smooth_attribute, "SMOOTH_ATTRIBUTE", SmoothAttribute, "Smooth Attribute", "") DefNode(GeometryNode, GEO_NODE_BOUNDING_BOX, 0, "BOUNDING_BOX", BoundBox, "Bounding Box", "Calculate the limits of a geometry's positions and generate a box mesh with those dimensions") DefNode(GeometryNode, GEO_NODE_CAPTURE_ATTRIBUTE, def_geo_attribute_capture,"CAPTURE_ATTRIBUTE", CaptureAttribute, "Capture Attribute", "Store the result of a field on a geometry and output the data as a node socket. Allows remembering or interpolating data as the geometry changes, such as positions before deformation") DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_collection_info, "COLLECTION_INFO", CollectionInfo, "Collection Info", "Retrieve geometry from a collection") diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt index 31c00cc6b82..c4a4fa39c1d 100644 --- a/source/blender/nodes/geometry/CMakeLists.txt +++ b/source/blender/nodes/geometry/CMakeLists.txt @@ -141,6 +141,7 @@ set(SRC nodes/node_geo_set_shade_smooth.cc nodes/node_geo_set_spline_cyclic.cc nodes/node_geo_set_spline_resolution.cc + nodes/node_geo_smooth_attribute.cc nodes/node_geo_store_named_attribute.cc nodes/node_geo_string_join.cc nodes/node_geo_string_to_curves.cc