[Bf-blender-cvs] [386b112f765] master: Geometry Nodes: Propagate attributes in Instances to Points node

Hans Goudey noreply at git.blender.org
Wed Dec 1 05:30:47 CET 2021


Commit: 386b112f7652f321f2fb8309dca0ab660b1b7021
Author: Hans Goudey
Date:   Tue Nov 30 23:30:35 2021 -0500
Branches: master
https://developer.blender.org/rB386b112f7652f321f2fb8309dca0ab660b1b7021

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.

===================================================================

M	source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc

===================================================================

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();
   }
 }



More information about the Bf-blender-cvs mailing list