Blender
V4.5
source
blender
nodes
geometry
nodes
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
#include "
DNA_pointcloud_types.h
"
7
8
#include "
node_geometry_util.hh
"
9
10
namespace
blender::nodes::node_geo_points_cc
{
11
12
static
void
node_declare
(
NodeDeclarationBuilder
&
b
)
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
30
class
PointsFieldContext
:
public
FieldContext
{
31
private
:
32
int
points_num_;
33
34
public
:
35
PointsFieldContext
(
const
int
points_num
) : points_num_(
points_num
) {}
36
37
int64_t
points_num
()
const
38
{
39
return
points_num_;
40
}
41
42
GVArray
get_varray_for_input
(
const
FieldInput
&field_input,
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
56
return
fn::IndexFieldInput::get_index_varray
(
mask
);
57
}
58
};
59
60
static
void
node_geo_exec
(
GeoNodeExecParams
params
)
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
71
PointCloud
*points =
BKE_pointcloud_new_nomain
(
count
);
72
MutableAttributeAccessor
attributes = points->attributes_for_write();
73
AttributeWriter<float>
output_radii = attributes.
lookup_or_add_for_write
<
float
>(
74
"radius"
, AttrDomain::Point);
75
76
PointsFieldContext
context{
count
};
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
86
static
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"
;
93
ntype.
nclass
=
NODE_CLASS_GEOMETRY
;
94
ntype.
geometry_node_execute
=
node_geo_exec
;
95
ntype.
declare
=
node_declare
;
96
blender::bke::node_register_type
(ntype);
97
}
98
NOD_REGISTER_NODE
(
node_register
)
99
100
}
// namespace blender::nodes::node_geo_points_cc
NODE_CLASS_GEOMETRY
#define NODE_CLASS_GEOMETRY
Definition
BKE_node.hh:447
GEO_NODE_POINTS
#define GEO_NODE_POINTS
Definition
BKE_node_legacy_types.hh:424
BKE_pointcloud.hh
General operations for point clouds.
BKE_pointcloud_new_nomain
PointCloud * BKE_pointcloud_new_nomain(int totpoint)
Definition
pointcloud.cc:278
DNA_pointcloud_types.h
NOD_REGISTER_NODE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Definition
NOD_register.hh:34
PROP_DISTANCE
@ PROP_DISTANCE
Definition
RNA_types.hh:244
PROP_TRANSLATION
@ PROP_TRANSLATION
Definition
RNA_types.hh:249
blender::GVArray
Definition
BLI_generic_virtual_array.hh:174
blender::ResourceScope
Definition
BLI_resource_scope.hh:37
blender::bke::IDAttributeFieldInput
Definition
BKE_geometry_fields.hh:361
blender::bke::MutableAttributeAccessor
Definition
BKE_attribute.hh:730
blender::bke::MutableAttributeAccessor::lookup_or_add_for_write
GAttributeWriter lookup_or_add_for_write(StringRef attribute_id, AttrDomain domain, eCustomDataType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
Definition
attribute_access.cc:845
blender::fn::FieldContext
Definition
FN_field.hh:324
blender::fn::FieldEvaluator
Definition
FN_field.hh:336
blender::fn::FieldInput
Definition
FN_field.hh:259
blender::fn::Field
Definition
GEO_mesh_copy_selection.hh:16
blender::fn::IndexFieldInput
Definition
FN_field.hh:527
blender::fn::IndexFieldInput::get_index_varray
static GVArray get_index_varray(const IndexMask &mask)
Definition
field.cc:548
blender::index_mask::IndexMask
Definition
BLI_index_mask.hh:188
blender::nodes::GeoNodeExecParams
Definition
NOD_geometry_exec.hh:73
blender::nodes::NodeDeclarationBuilder
Definition
NOD_node_declaration.hh:629
blender::nodes::SocketDeclaration::description
std::string description
Definition
NOD_node_declaration.hh:202
blender::nodes::decl::Float
Definition
NOD_socket_declarations.hh:19
blender::nodes::decl::Float::default_value
float default_value
Definition
NOD_socket_declarations.hh:23
blender::nodes::decl::Geometry
Definition
NOD_socket_declarations_geometry.hh:15
blender::nodes::decl::Int
Definition
NOD_socket_declarations.hh:48
blender::nodes::decl::Vector
Definition
NOD_socket_declarations.hh:77
blender::nodes::decl::Vector::default_value
float4 default_value
Definition
NOD_socket_declarations.hh:81
blender::nodes::node_geo_points_cc::PointsFieldContext
Definition
node_geo_points.cc:30
blender::nodes::node_geo_points_cc::PointsFieldContext::PointsFieldContext
PointsFieldContext(const int points_num)
Definition
node_geo_points.cc:35
blender::nodes::node_geo_points_cc::PointsFieldContext::get_varray_for_input
GVArray get_varray_for_input(const FieldInput &field_input, const IndexMask &mask, ResourceScope &) const override
Definition
node_geo_points.cc:42
blender::nodes::node_geo_points_cc::PointsFieldContext::points_num
int64_t points_num() const
Definition
node_geo_points.cc:37
b
b
Definition
compositor_morphological_distance_info.hh:24
params
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Definition
interface_widgets.cc:1056
count
int count
Definition
interface_widgets.cc:1057
mask
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
Definition
math_float2.h:157
blender::bke::node_register_type
void node_register_type(bNodeType &ntype)
Definition
node.cc:2748
blender::nodes::node_geo_points_cc
Definition
node_geo_points.cc:10
blender::nodes::node_geo_points_cc::node_geo_exec
static void node_geo_exec(GeoNodeExecParams params)
Definition
node_geo_points.cc:60
blender::nodes::node_geo_points_cc::node_declare
static void node_declare(NodeDeclarationBuilder &b)
Definition
node_geo_points.cc:12
blender::nodes::node_geo_points_cc::node_register
static void node_register()
Definition
node_geo_points.cc:86
blender::float3
VecBase< float, 3 > float3
Definition
BLI_math_vector_types.hh:619
geo_node_type_base
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Definition
node_geometry_util.cc:124
node_geometry_util.hh
min
#define min(a, b)
Definition
sort.cc:36
int64_t
__int64 int64_t
Definition
stdint.h:89
PointCloud
Definition
DNA_pointcloud_types.h:40
blender::bke::AttributeWriter
Definition
BKE_attribute.hh:248
blender::bke::AttributeWriter::finish
void finish()
Definition
BKE_attribute.hh:272
blender::bke::AttributeWriter::varray
VMutableArray< T > varray
Definition
BKE_attribute.hh:253
blender::bke::GeometrySet::from_pointcloud
static GeometrySet from_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Definition
geometry_set.cc:454
blender::bke::bNodeType
Defines a node type.
Definition
BKE_node.hh:226
blender::bke::bNodeType::ui_description
std::string ui_description
Definition
BKE_node.hh:232
blender::bke::bNodeType::ui_name
std::string ui_name
Definition
BKE_node.hh:231
blender::bke::bNodeType::geometry_node_execute
NodeGeometryExecFunction geometry_node_execute
Definition
BKE_node.hh:347
blender::bke::bNodeType::nclass
short nclass
Definition
BKE_node.hh:239
blender::bke::bNodeType::enum_name_legacy
const char * enum_name_legacy
Definition
BKE_node.hh:235
blender::bke::bNodeType::declare
NodeDeclareFunction declare
Definition
BKE_node.hh:355
Generated on Fri Apr 3 2026 06:33:18 for Blender by
doxygen
1.11.0