Blender V4.5
node_geo_points.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_pointcloud.hh"
7
9
11
13{
14 b.add_input<decl::Int>("Count").default_value(1).min(0).description(
15 "The number of points to create");
16 b.add_input<decl::Vector>("Position")
17 .subtype(PROP_TRANSLATION)
18 .default_value(float3(0.0f))
19 .supports_field()
20 .description("The positions of the new points");
21 b.add_input<decl::Float>("Radius")
22 .min(0.0f)
23 .default_value(0.1f)
24 .subtype(PROP_DISTANCE)
25 .supports_field()
26 .description("The radii of the new points");
27 b.add_output<decl::Geometry>("Points", "Geometry");
28}
29
31 private:
32 int points_num_;
33
34 public:
35 PointsFieldContext(const int points_num) : points_num_(points_num) {}
36
38 {
39 return points_num_;
40 }
41
43 const IndexMask &mask,
44 ResourceScope & /*scope*/) const override
45 {
46 const bke::IDAttributeFieldInput *id_field_input =
47 dynamic_cast<const bke::IDAttributeFieldInput *>(&field_input);
48
49 const fn::IndexFieldInput *index_field_input = dynamic_cast<const fn::IndexFieldInput *>(
50 &field_input);
51
52 if (id_field_input == nullptr && index_field_input == nullptr) {
53 return {};
54 }
55
57 }
58};
59
61{
62 const int count = params.extract_input<int>("Count");
63 if (count <= 0) {
64 params.set_default_remaining_outputs();
65 return;
66 }
67
68 Field<float3> position_field = params.extract_input<Field<float3>>("Position");
69 Field<float> radius_field = params.extract_input<Field<float>>("Radius");
70
72 MutableAttributeAccessor attributes = points->attributes_for_write();
73 AttributeWriter<float> output_radii = attributes.lookup_or_add_for_write<float>(
74 "radius", AttrDomain::Point);
75
77 fn::FieldEvaluator evaluator{context, count};
78 evaluator.add_with_destination(position_field, points->positions_for_write());
79 evaluator.add_with_destination(radius_field, output_radii.varray);
80 evaluator.evaluate();
81
82 output_radii.finish();
83 params.set_output("Geometry", GeometrySet::from_pointcloud(points));
84}
85
86static void node_register()
87{
88 static blender::bke::bNodeType ntype;
89 geo_node_type_base(&ntype, "GeometryNodePoints", GEO_NODE_POINTS);
90 ntype.ui_name = "Points";
91 ntype.ui_description = "Generate a point cloud with positions and radii defined by fields";
92 ntype.enum_name_legacy = "POINTS";
95 ntype.declare = node_declare;
97}
99
100} // namespace blender::nodes::node_geo_points_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#define GEO_NODE_POINTS
General operations for point clouds.
PointCloud * BKE_pointcloud_new_nomain(int totpoint)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DISTANCE
Definition RNA_types.hh:244
@ PROP_TRANSLATION
Definition RNA_types.hh:249
long long int int64_t
GAttributeWriter lookup_or_add_for_write(StringRef attribute_id, AttrDomain domain, eCustomDataType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
int add_with_destination(GField field, GVMutableArray dst)
Definition field.cc:738
static GVArray get_index_varray(const IndexMask &mask)
Definition field.cc:548
GVArray get_varray_for_input(const FieldInput &field_input, const IndexMask &mask, ResourceScope &) const override
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
int count
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:36
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355
static GeometrySet from_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)