Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-12-01 07:30:35 +0300
committerHans Goudey <h.goudey@me.com>2021-12-01 07:30:35 +0300
commit386b112f7652f321f2fb8309dca0ab660b1b7021 (patch)
tree728b7cc5867084f5bf81188046ecfe59c4a90fce /source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc
parentd723e331f155871fa5c2771aaa634aea0193d2b1 (diff)
Geometry Nodes: Propagate attributes in Instances to Points node
This is part of T92926, and is very similar to 221b7b27fce3, except slightly similar, because it only transfers from one component, and it doesn't handle multi-threading at the moment.
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc37
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();
}
}