Page MenuHome

Separate Components Node
Confirmed, NormalPublicDESIGN

Description

This node will separate each kind of data from the input geometry set.
It is essential in cases where you pass two kinds of data to a different object with the object info node,
for example when you want to address points separately from instances in the same geometry set.

This node will only become more important as more data types are added to geometry sets.

Details

This node does not realize instances for efficiency, but it does create new geometry instances where necessary.

Implementation

An efficient implementation of this node requires direct instancing of geometry sets in the node tree.
Otherwise we would have to make all geometry sets real in order to pass the data to the next set,
because instances can only be objects or collections, which might contain two different types of data.
Instead, a new geometry set should be created for each data type when the original contains multiple.

Initial boilerplate code is here:

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index b573a7a75fb..b809afa7604 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -504,6 +504,7 @@ geometry_node_categories = [
         NodeItem("ShaderNodeCombineRGB"),
     ]),
     GeometryNodeCategory("GEO_GEOMETRY", "Geometry", items=[
+        NodeItem("GeometryNodeBoundBox"),
         NodeItem("GeometryNodeTransform"),
         NodeItem("GeometryNodeJoinGeometry"),
     ]),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 8dae1da69cb..e4655647ee3 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1398,6 +1398,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_MESH_PRIMITIVE_GRID 1039
 #define GEO_NODE_ATTRIBUTE_MAP_RANGE 1040
 #define GEO_NODE_ATTRIBUTE_CLAMP 1041
+#define GEO_NODE_SPLIT_COMPONENTS 1042
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 56f14dcc07d..9d18608471d 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -4950,6 +4950,7 @@ static void registerGeometryNodes()
   register_node_type_geo_point_translate();
   register_node_type_geo_points_to_volume();
   register_node_type_geo_sample_texture();
+  register_node_type_geo_split_components();
   register_node_type_geo_subdivide();
   register_node_type_geo_subdivision_surface();
   register_node_type_geo_transform();
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index aba3c3e041a..b982e232952 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -176,6 +176,7 @@ set(SRC
   geometry/nodes/node_geo_point_separate.cc
   geometry/nodes/node_geo_point_translate.cc
   geometry/nodes/node_geo_points_to_volume.cc
+  geometry/nodes/node_geo_split_components.cc
   geometry/nodes/node_geo_subdivide.cc
   geometry/nodes/node_geo_subdivision_surface.cc
   geometry/nodes/node_geo_transform.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 3a26f38d6ba..2b1cdbe04d5 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -63,6 +63,7 @@ void register_node_type_geo_point_separate(void);
 void register_node_type_geo_point_translate(void);
 void register_node_type_geo_points_to_volume(void);
 void register_node_type_geo_sample_texture(void);
+void register_node_type_geo_split_components(void);
 void register_node_type_geo_subdivide(void);
 void register_node_type_geo_subdivision_surface(void);
 void register_node_type_geo_transform(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index b3463f79a6e..0600e748d99 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -308,6 +308,7 @@ DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_LINE, def_geo_mesh_line, "MESH_PRI
 DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_GRID, 0, "MESH_PRIMITIVE_GRID", MeshGrid, "Grid", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_MAP_RANGE, def_geo_attribute_map_range, "ATTRIBUTE_MAP_RANGE", AttributeMapRange, "Attribute Map Range", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_CLAMP, def_geo_attribute_clamp, "ATTRIBUTE_CLAMP", AttributeClamp, "Attribute Clamp", "")
+DefNode(GeometryNode, GEO_NODE_SPLIT_COMPONENTS, 0, "SPLIT_COMPONENTS", SplitComponents, "Split Components", "")
 
 /* undefine macros */
 #undef DefNode
diff --git a/source/blender/nodes/geometry/nodes/node_geo_split_components.cc b/source/blender/nodes/geometry/nodes/node_geo_split_components.cc
new file mode 100644
index 00000000000..b7a2e41a0dd
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_split_components.cc
@@ -0,0 +1,71 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "node_geometry_util.hh"
+
+static bNodeSocketTemplate geo_node_split_components_in[] = {
+    {SOCK_GEOMETRY, N_("Geometry")},
+    {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_split_components_out[] = {
+    {SOCK_GEOMETRY, N_("Mesh")},
+    {SOCK_GEOMETRY, N_("Point Cloud")},
+    {SOCK_GEOMETRY, N_("Volume")},
+    {-1, ""},
+};
+
+namespace blender::nodes {
+
+static void geo_node_split_components_exec(GeoNodeExecParams params)
+{
+  const GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
+
+  GeometrySet meshes;
+  GeometrySet point_clouds;
+  GeometrySet volumes;
+
+  Vector<bke::GeometryInstanceGroup> set_groups;
+  bke::geometry_set_gather_instances(geometry_set, set_groups);
+  for (const bke::GeometryInstanceGroup &set_group : set_groups) {
+    const GeometrySet &set = set_group.geometry_set;
+    Span<float4x4> transforms = set_group.transforms;
+
+    if (set.has<PointCloudComponent>()) {
+    }
+    if (set.has<MeshComponent>()) {
+    }
+    if (set.has<VolumeComponent>()) {
+    }
+  }
+
+  params.set_output("Mesh", meshes);
+  params.set_output("Point Cloud", point_clouds);
+  params.set_output("Volume", volumes);
+}
+
+}  // namespace blender::nodes
+
+void register_node_type_geo_split_components()
+{
+  static bNodeType ntype;
+
+  geo_node_type_base(
+      &ntype, GEO_NODE_SPLIT_COMPONENTS, "Split Components", NODE_CLASS_GEOMETRY, 0);
+  node_type_socket_templates(&ntype, geo_node_split_components_in, geo_node_split_components_out);
+  ntype.geometry_node_execute = blender::nodes::geo_node_split_components_exec;
+  nodeRegisterType(&ntype);
+}

Event Timeline

Hans Goudey (HooglyBoogly) renamed this task from Split by Component Node to Split Components Node.Mar 26 2021, 9:28 PM
Hans Goudey (HooglyBoogly) changed the task status from Needs Triage to Confirmed.
Hans Goudey (HooglyBoogly) created this task.

This task can be moved to the "Community Tasks" column whenever direct geometry set instancing is completed.

I think it would make sence to make the input socket a multi input so you wouldnt have to separate each geometry by its type and join them together afterwards.

Hans Goudey (HooglyBoogly) renamed this task from Split Components Node to Separate Components Node.May 7 2021, 2:56 PM