Blender V5.0
node_geo_geometry_to_instance.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_instances.hh"
6
8
10
12{
13 b.add_input<decl::Geometry>("Geometry")
14 .multi_input()
15 .description("Each input geometry is turned into a separate instance");
16 b.add_output<decl::Geometry>("Instances").propagate_all();
17}
18
20{
22 params.extract_input<GeoNodesMultiInput<GeometrySet>>("Geometry");
23 std::unique_ptr<bke::Instances> instances = std::make_unique<bke::Instances>();
24
25 for (GeometrySet &geometry : geometries.values) {
26 geometry.ensure_owns_direct_data();
27 const int handle = instances->add_reference(std::move(geometry));
28 instances->add_instance(handle, float4x4::identity());
29 }
30
31 GeometrySet new_geometry = GeometrySet::from_instances(instances.release());
32 params.set_output("Instances", std::move(new_geometry));
33}
34
35static void node_register()
36{
37 static blender::bke::bNodeType ntype;
38
39 geo_node_type_base(&ntype, "GeometryNodeGeometryToInstance", GEO_NODE_GEOMETRY_TO_INSTANCE);
40 ntype.ui_name = "Geometry to Instance";
41 ntype.ui_description =
42 "Convert each input geometry into an instance, which can be much faster than the Join "
43 "Geometry node when the inputs are large";
44 ntype.enum_name_legacy = "GEOMETRY_TO_INSTANCE";
46 blender::bke::node_type_size(ntype, 160, 100, 300);
48 ntype.declare = node_declare;
50}
52
53} // namespace blender::nodes::node_geo_geometry_to_instance_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_GEOMETRY_TO_INSTANCE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_type_size(bNodeType &ntype, int width, int minwidth, int maxwidth)
Definition node.cc:5384
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362
static GeometrySet from_instances(Instances *instances, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)