Blender V4.3
node_geo_curve_primitive_spiral.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_curves.hh"
6
8
10
12{
13 b.add_input<decl::Int>("Resolution")
14 .default_value(32)
15 .min(1)
16 .max(1024)
18 .description("Number of points in one rotation of the spiral");
19 b.add_input<decl::Float>("Rotations")
20 .default_value(2.0f)
21 .min(0.0f)
22 .description("Number of times the spiral makes a full rotation")
23 .translation_context(BLT_I18NCONTEXT_ID_NODETREE);
24 b.add_input<decl::Float>("Start Radius")
25 .default_value(1.0f)
27 .description("Horizontal Distance from the Z axis at the start of the spiral");
28 b.add_input<decl::Float>("End Radius")
29 .default_value(2.0f)
31 .description("Horizontal Distance from the Z axis at the end of the spiral");
32 b.add_input<decl::Float>("Height")
33 .default_value(2.0f)
35 .description("The height perpendicular to the base of the spiral");
36 b.add_input<decl::Bool>("Reverse").description(
37 "Switch the direction from clockwise to counterclockwise");
38 b.add_output<decl::Geometry>("Curve");
39}
40
41static Curves *create_spiral_curve(const float rotations,
42 const int resolution,
43 const float start_radius,
44 const float end_radius,
45 const float height,
46 const bool direction)
47{
48 const int totalpoints = std::max(int(resolution * rotations), 1);
49 const float delta_radius = (end_radius - start_radius) / float(totalpoints);
50 const float delta_height = height / float(totalpoints);
51 const float delta_theta = (M_PI * 2 * rotations) / float(totalpoints) *
52 (direction ? 1.0f : -1.0f);
53
54 Curves *curves_id = bke::curves_new_nomain_single(totalpoints + 1, CURVE_TYPE_POLY);
55 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
56
57 MutableSpan<float3> positions = curves.positions_for_write();
58
59 for (const int i : IndexRange(totalpoints + 1)) {
60 const float theta = i * delta_theta;
61 const float radius = start_radius + i * delta_radius;
62 const float x = radius * cos(theta);
63 const float y = radius * sin(theta);
64 const float z = delta_height * i;
65
66 positions[i] = {x, y, z};
67 }
68
69 return curves_id;
70}
71
73{
74 const float rotations = std::max(params.extract_input<float>("Rotations"), 0.0f);
75 if (rotations == 0.0f) {
76 params.set_default_remaining_outputs();
77 return;
78 }
79
80 Curves *curves = create_spiral_curve(rotations,
81 std::max(params.extract_input<int>("Resolution"), 1),
82 params.extract_input<float>("Start Radius"),
83 params.extract_input<float>("End Radius"),
84 params.extract_input<float>("Height"),
85 params.extract_input<bool>("Reverse"));
86 params.set_output("Curve", GeometrySet::from_curves(curves));
87}
88
89static void node_register()
90{
91 static blender::bke::bNodeType ntype;
92
93 geo_node_type_base(&ntype, GEO_NODE_CURVE_PRIMITIVE_SPIRAL, "Spiral", NODE_CLASS_GEOMETRY);
94 ntype.declare = node_declare;
97}
99
100} // namespace blender::nodes::node_geo_curve_primitive_spiral_cc
Low-level operations for curves.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define M_PI
#define BLT_I18NCONTEXT_ID_NODETREE
@ CURVE_TYPE_POLY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DISTANCE
Definition RNA_types.hh:159
@ PROP_UNSIGNED
Definition RNA_types.hh:152
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float3 cos(float3 v)
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
Curves * curves_new_nomain_single(int points_num, CurveType type)
static Curves * create_spiral_curve(const float rotations, const int resolution, const float start_radius, const float end_radius, const float height, const bool direction)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
CurvesGeometry geometry
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
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