diff options
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc index 30aa745ddff..536facbc2e5 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc @@ -14,9 +14,11 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "BKE_pointcloud.h" #include "DNA_pointcloud_types.h" +#include "BKE_attribute_math.hh" +#include "BKE_pointcloud.h" + #include "node_geometry_util.hh" namespace blender::nodes::node_geo_instances_to_points_cc { @@ -76,14 +78,31 @@ static void convert_instances_to_points(GeometrySet &geometry_set, const VArray<float> &radii = evaluator.get_evaluated<float>(1); copy_attribute_to_points(radii, selection, {pointcloud->radius, pointcloud->totpoint}); - if (!instances.instance_ids().is_empty()) { - OutputAttribute_Typed<int> id_attribute = points.attribute_try_get_for_output<int>( - "id", ATTR_DOMAIN_POINT, CD_PROP_INT32); - MutableSpan<int> ids = id_attribute.as_span(); - for (const int i : selection.index_range()) { - ids[i] = instances.instance_ids()[selection[i]]; - } - id_attribute.save(); + Map<AttributeIDRef, AttributeKind> attributes_to_propagate; + geometry_set.gather_attributes_for_propagation({GEO_COMPONENT_TYPE_INSTANCES}, + GEO_COMPONENT_TYPE_POINT_CLOUD, + false, + attributes_to_propagate); + /* These two attributes are added by the implicit inputs above. */ + attributes_to_propagate.remove("position"); + attributes_to_propagate.remove("radius"); + + for (const auto &item : attributes_to_propagate.items()) { + const AttributeIDRef &attribute_id = item.key; + const AttributeKind attribute_kind = item.value; + + const GVArray src = instances.attribute_get_for_read( + attribute_id, ATTR_DOMAIN_INSTANCE, attribute_kind.data_type); + BLI_assert(src); + OutputAttribute dst = points.attribute_try_get_for_output_only( + attribute_id, ATTR_DOMAIN_POINT, attribute_kind.data_type); + BLI_assert(dst); + + attribute_math::convert_to_static_type(attribute_kind.data_type, [&](auto dummy) { + using T = decltype(dummy); + copy_attribute_to_points(src.typed<T>(), selection, dst.as_span().typed<T>()); + }); + dst.save(); } } |