Blender V4.3
node_geo_realize_instances.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
6
7#include "BKE_instances.hh"
8
10
11#include "UI_resources.hh"
12
14
16{
17 b.add_input<decl::Geometry>("Geometry");
18 b.add_input<decl::Bool>("Selection")
19 .default_value(true)
20 .hide_value()
21 .field_on_all()
22 .description("Which top-level instances to realize");
23 b.add_input<decl::Bool>("Realize All")
24 .default_value(true)
25 .field_on_all()
27 "Realize all levels of nested instances for a top-level instances. Overrides the value "
28 "of the Depth input");
29 b.add_input<decl::Int>("Depth").default_value(0).min(0).field_on_all().description(
30 "Number of levels of nested instances to realize for each top-level instance");
31 b.add_output<decl::Geometry>("Geometry").propagate_all();
32}
33
35{
36 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
37 if (!geometry_set.has_instances()) {
38 params.set_output("Geometry", std::move(geometry_set));
39 return;
40 }
41
43
44 Field<bool> realize_all_field = params.extract_input<Field<bool>>("Realize All");
45 Field<int> depth_field = params.extract_input<Field<int>>("Depth");
46
47 static auto depth_override = mf::build::SI2_SO<int, bool, int>(
48 "depth_override", [](int depth, bool realize_all_field) {
49 return realize_all_field ? geometry::VariedDepthOptions::MAX_DEPTH : std::max(depth, 0);
50 });
51
52 Field<int> depth_field_overridden(FieldOperation::Create(
53 depth_override, {std::move(depth_field), std::move(realize_all_field)}));
54
55 Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
56
57 static auto selection_override = mf::build::SI2_SO<int, bool, bool>(
58 "selection_override",
59 [](int depth_override, bool selection) { return depth_override == 0 ? false : selection; });
60
61 Field<bool> selection_field_overrided(FieldOperation::Create(
62 selection_override, {depth_field_overridden, std::move(selection_field)}));
63
64 const bke::Instances &instances = *geometry_set.get_instances();
65 const bke::InstancesFieldContext field_context(instances);
66 fn::FieldEvaluator evaluator(field_context, instances.instances_num());
67
68 const int evaluated_depth_index = evaluator.add(depth_field_overridden);
69 evaluator.set_selection(selection_field_overrided);
70 evaluator.evaluate();
71
72 geometry::VariedDepthOptions varied_depth_option;
73 varied_depth_option.depths = evaluator.get_evaluated<int>(evaluated_depth_index);
74 varied_depth_option.selection = evaluator.get_evaluated_selection_as_mask();
75
77 options.keep_original_ids = false;
78 options.realize_instance_attributes = true;
79 const NodeAttributeFilter attribute_filter = params.get_attribute_filter("Geometry");
80 options.attribute_filter = attribute_filter;
82 geometry_set, options, varied_depth_option);
83 new_geometry_set.name = geometry_set.name;
84 params.set_output("Geometry", std::move(new_geometry_set));
85}
86
87static void node_register()
88{
89 static blender::bke::bNodeType ntype;
90
91 geo_node_type_base(&ntype, GEO_NODE_REALIZE_INSTANCES, "Realize Instances", NODE_CLASS_GEOMETRY);
92 ntype.declare = node_declare;
95}
97
98} // namespace blender::nodes::node_geo_realize_instances_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static void remember_deformed_positions_if_necessary(GeometrySet &geometry)
void set_selection(Field< bool > selection)
Definition FN_field.hh:385
int add(GField field, GVArray *varray_ptr)
Definition field.cc:756
IndexMask get_evaluated_selection_as_mask() const
Definition field.cc:822
const GVArray & get_evaluated(const int field_index) const
Definition FN_field.hh:450
static std::shared_ptr< FieldOperation > Create(std::shared_ptr< const mf::MultiFunction > function, Vector< GField > inputs={})
Definition FN_field.hh:244
local_group_size(16, 16) .push_constant(Type b
CCL_NAMESPACE_BEGIN struct Options options
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
bke::GeometrySet realize_instances(bke::GeometrySet geometry_set, const RealizeInstancesOptions &options)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
GPU_SHADER_INTERFACE_INFO(overlay_edit_curve_handle_iface, "vert").flat(Type pos vertex_in(1, Type::UINT, "data") .vertex_out(overlay_edit_curve_handle_iface) .geometry_layout(PrimitiveIn Frequency::GEOMETRY storage_buf(1, Qualifier::READ, "uint", "data[]", Frequency::GEOMETRY) .push_constant(Type Frequency::GEOMETRY selection[]
const Instances * get_instances() const
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347