From 565b33c0ad31966b860123837d2c4b5a8cbedad2 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 7 Dec 2021 15:37:12 +0100 Subject: Geometry Nodes: new Geometry to Instance node This adds a new Geometry to Instance node that turns every connected input geometry into an instance. Those instances can for example be used in the Instance on Points node. Differential Revision: https://developer.blender.org/D13500 --- source/blender/blenkernel/BKE_node.h | 1 + source/blender/blenkernel/intern/node.cc | 1 + source/blender/nodes/NOD_geometry.h | 1 + source/blender/nodes/NOD_static_types.h | 1 + source/blender/nodes/geometry/CMakeLists.txt | 1 + .../nodes/node_geo_geometry_to_instance.cc | 55 ++++++++++++++++++++++ 6 files changed, 60 insertions(+) create mode 100644 source/blender/nodes/geometry/nodes/node_geo_geometry_to_instance.cc (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index f460aaf0d6a..4bfbffcbb1d 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1715,6 +1715,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree, #define GEO_NODE_INPUT_MESH_FACE_AREA 1139 #define GEO_NODE_INPUT_MESH_FACE_NEIGHBORS 1140 #define GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS 1141 +#define GEO_NODE_GEOMETRY_TO_INSTANCE 1142 /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 14ba87d51eb..1efa4a2cdd2 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -5799,6 +5799,7 @@ static void registerGeometryNodes() register_node_type_geo_distribute_points_on_faces(); register_node_type_geo_dual_mesh(); register_node_type_geo_edge_split(); + register_node_type_geo_geometry_to_instance(); register_node_type_geo_image_texture(); register_node_type_geo_input_curve_handles(); register_node_type_geo_input_curve_tilt(); diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h index a64c53c32e1..0081cec0c2d 100644 --- a/source/blender/nodes/NOD_geometry.h +++ b/source/blender/nodes/NOD_geometry.h @@ -97,6 +97,7 @@ void register_node_type_geo_delete_geometry(void); void register_node_type_geo_distribute_points_on_faces(void); void register_node_type_geo_dual_mesh(void); void register_node_type_geo_edge_split(void); +void register_node_type_geo_geometry_to_instance(void); void register_node_type_geo_image_texture(void); void register_node_type_geo_input_curve_handles(void); void register_node_type_geo_input_curve_tilt(void); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index 5ef0fc52877..6adc6a45c77 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -350,6 +350,7 @@ DefNode(GeometryNode, GEO_NODE_DISTRIBUTE_POINTS_ON_FACES, def_geo_distribute_po DefNode(GeometryNode, GEO_NODE_DUAL_MESH, 0, "DUAL_MESH", DualMesh, "Dual Mesh", "") DefNode(GeometryNode, GEO_NODE_FILL_CURVE, def_geo_curve_fill, "FILL_CURVE", FillCurve, "Fill Curve", "") DefNode(GeometryNode, GEO_NODE_FILLET_CURVE, def_geo_curve_fillet, "FILLET_CURVE", FilletCurve, "Fillet Curve", "") +DefNode(GeometryNode, GEO_NODE_GEOMETRY_TO_INSTANCE, 0, "GEOMETRY_TO_INSTANCE", GeometryToInstance, "Geometry to Instance", "") DefNode(GeometryNode, GEO_NODE_IMAGE_TEXTURE, def_geo_image_texture, "IMAGE_TEXTURE", ImageTexture, "Image Texture", "") DefNode(GeometryNode, GEO_NODE_INPUT_CURVE_HANDLES, 0, "INPUT_CURVE_HANDLES", InputCurveHandlePositions, "Curve Handle Positions", "") DefNode(GeometryNode, GEO_NODE_INPUT_CURVE_TILT, 0, "INPUT_CURVE_TILT", InputCurveTilt, "Curve Tilt", "") diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt index 2d7e0293b62..de3184ab198 100644 --- a/source/blender/nodes/geometry/CMakeLists.txt +++ b/source/blender/nodes/geometry/CMakeLists.txt @@ -115,6 +115,7 @@ set(SRC nodes/node_geo_distribute_points_on_faces.cc nodes/node_geo_dual_mesh.cc nodes/node_geo_edge_split.cc + nodes/node_geo_geometry_to_instance.cc nodes/node_geo_image_texture.cc nodes/node_geo_input_curve_handles.cc nodes/node_geo_input_curve_tilt.cc diff --git a/source/blender/nodes/geometry/nodes/node_geo_geometry_to_instance.cc b/source/blender/nodes/geometry/nodes/node_geo_geometry_to_instance.cc new file mode 100644 index 00000000000..7faf104737f --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_geometry_to_instance.cc @@ -0,0 +1,55 @@ +/* + * 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" + +namespace blender::nodes::node_geo_geometry_to_instance_cc { + +static void node_declare(NodeDeclarationBuilder &b) +{ + b.add_input(N_("Geometry")).multi_input(); + b.add_output(N_("Instances")); +} + +static void node_geo_exec(GeoNodeExecParams params) +{ + Vector geometries = params.extract_multi_input("Geometry"); + GeometrySet instances_geometry; + InstancesComponent &instances_component = + instances_geometry.get_component_for_write(); + for (GeometrySet &geometry : geometries) { + geometry.ensure_owns_direct_data(); + const int handle = instances_component.add_reference(std::move(geometry)); + instances_component.add_instance(handle, float4x4::identity()); + } + params.set_output("Instances", std::move(instances_geometry)); +} + +} // namespace blender::nodes::node_geo_geometry_to_instance_cc + +void register_node_type_geo_geometry_to_instance() +{ + namespace file_ns = blender::nodes::node_geo_geometry_to_instance_cc; + + static bNodeType ntype; + + geo_node_type_base( + &ntype, GEO_NODE_GEOMETRY_TO_INSTANCE, "Geometry to Instance", NODE_CLASS_GEOMETRY, 0); + node_type_size(&ntype, 160, 100, 300); + ntype.geometry_node_execute = file_ns::node_geo_exec; + ntype.declare = file_ns::node_declare; + nodeRegisterType(&ntype); +} -- cgit v1.2.3