Separate Components Node #86970

Closed
opened 2021-03-26 21:28:26 +01:00 by Hans Goudey · 11 comments
Member

{F9911050 size=full}

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);
+}
{[F9911050](https://archive.blender.org/developer/F9911050/image.png) size=full} 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: ```lines=10 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); +} ```
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Member

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly
Hans Goudey changed title from Split by Component Node to Split Components Node 2021-03-26 21:28:56 +01:00
Author
Member

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

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

Added subscriber: @CreatorSiSo

Added subscriber: @CreatorSiSo

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.

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.

Added subscriber: @GregoryS

Added subscriber: @GregoryS

Added subscriber: @dodododorian

Added subscriber: @dodododorian

Added subscriber: @MiroHorvath

Added subscriber: @MiroHorvath
Hans Goudey changed title from Split Components Node to Separate Components Node 2021-05-07 14:56:06 +02:00

Added subscriber: @guitargeek

Added subscriber: @guitargeek
Implementation here https://developer.blender.org/D11577

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Dalai Felinto self-assigned this 2021-06-21 14:57:47 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
7 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#86970
No description provided.