Blender V5.0
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"
6
8
10
12
14{
15 b.add_input<decl::Int>("Count").default_value(1).min(0).description(
16 "The number of points to create");
17 b.add_input<decl::Vector>("Position")
18 .subtype(PROP_TRANSLATION)
19 .default_value(float3(0.0f))
20 .supports_field()
21 .description("The positions of the new points");
22 b.add_input<decl::Float>("Radius")
23 .min(0.0f)
24 .default_value(0.1f)
25 .subtype(PROP_DISTANCE)
26 .supports_field()
27 .description("The radii of the new points");
28 b.add_output<decl::Geometry>("Points", "Geometry");
29}
30
32 private:
33 int points_num_;
34
35 public:
36 PointsFieldContext(const int points_num) : points_num_(points_num) {}
37
39 {
40 return points_num_;
41 }
42
44 const IndexMask &mask,
45 ResourceScope & /*scope*/) const override
46 {
47 const bke::IDAttributeFieldInput *id_field_input =
48 dynamic_cast<const bke::IDAttributeFieldInput *>(&field_input);
49
50 const fn::IndexFieldInput *index_field_input = dynamic_cast<const fn::IndexFieldInput *>(
51 &field_input);
52
53 if (id_field_input == nullptr && index_field_input == nullptr) {
54 return {};
55 }
56
58 }
59};
60
62{
63 const int count = params.extract_input<int>("Count");
64 if (count <= 0) {
65 params.set_default_remaining_outputs();
66 return;
67 }
68
69 Field<float3> position_field = params.extract_input<Field<float3>>("Position");
70 Field<float> radius_field = params.extract_input<Field<float>>("Radius");
71
73 MutableAttributeAccessor attributes = points->attributes_for_write();
74 AttributeWriter<float> output_radii = attributes.lookup_or_add_for_write<float>(
75 "radius", AttrDomain::Point);
76
78 fn::FieldEvaluator evaluator{context, count};
79 evaluator.add_with_destination(position_field, points->positions_for_write());
80 evaluator.add_with_destination(radius_field, output_radii.varray);
81 evaluator.evaluate();
82
83 output_radii.finish();
84 params.set_output("Geometry", GeometrySet::from_pointcloud(points));
85}
86
87static void node_register()
88{
89 static blender::bke::bNodeType ntype;
90 geo_node_type_base(&ntype, "GeometryNodePoints", GEO_NODE_POINTS);
91 ntype.ui_name = "Points";
92 ntype.ui_description = "Generate a point cloud with positions and radii defined by fields";
93 ntype.enum_name_legacy = "POINTS";
96 ntype.declare = node_declare;
98}
100
101} // namespace blender::nodes::node_geo_points_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#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:256
@ PROP_TRANSLATION
Definition RNA_types.hh:261
long long int int64_t
GAttributeWriter lookup_or_add_for_write(StringRef attribute_id, AttrDomain domain, AttrType 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:2416
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: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_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)