Blender  V3.3
node_geo_curve_primitive_spiral.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "BKE_curves.hh"
4 
5 #include "node_geometry_util.hh"
6 
8 
10 {
11  b.add_input<decl::Int>(N_("Resolution"))
12  .default_value(32)
13  .min(1)
14  .max(1024)
15  .subtype(PROP_UNSIGNED)
16  .description(N_("Number of points in one rotation of the spiral"));
17  b.add_input<decl::Float>(N_("Rotations"))
18  .default_value(2.0f)
19  .min(0.0f)
20  .description(N_("Number of times the spiral makes a full rotation"));
21  b.add_input<decl::Float>(N_("Start Radius"))
22  .default_value(1.0f)
23  .subtype(PROP_DISTANCE)
24  .description(N_("Horizontal Distance from the Z axis at the start of the spiral"));
25  b.add_input<decl::Float>(N_("End Radius"))
26  .default_value(2.0f)
27  .subtype(PROP_DISTANCE)
28  .description(N_("Horizontal Distance from the Z axis at the end of the spiral"));
29  b.add_input<decl::Float>(N_("Height"))
30  .default_value(2.0f)
31  .subtype(PROP_DISTANCE)
32  .description(N_("The height perpendicular to the base of the spiral"));
33  b.add_input<decl::Bool>(N_("Reverse"))
34  .description(N_("Switch the direction from clockwise to counterclockwise"));
35  b.add_output<decl::Geometry>(N_("Curve"));
36 }
37 
38 static Curves *create_spiral_curve(const float rotations,
39  const int resolution,
40  const float start_radius,
41  const float end_radius,
42  const float height,
43  const bool direction)
44 {
45  const int totalpoints = std::max(int(resolution * rotations), 1);
46  const float delta_radius = (end_radius - start_radius) / (float)totalpoints;
47  const float delta_height = height / (float)totalpoints;
48  const float delta_theta = (M_PI * 2 * rotations) / (float)totalpoints *
49  (direction ? 1.0f : -1.0f);
50 
51  Curves *curves_id = bke::curves_new_nomain_single(totalpoints + 1, CURVE_TYPE_POLY);
53 
54  MutableSpan<float3> positions = curves.positions_for_write();
55 
56  for (const int i : IndexRange(totalpoints + 1)) {
57  const float theta = i * delta_theta;
58  const float radius = start_radius + i * delta_radius;
59  const float x = radius * cos(theta);
60  const float y = radius * sin(theta);
61  const float z = delta_height * i;
62 
63  positions[i] = {x, y, z};
64  }
65 
66  return curves_id;
67 }
68 
70 {
71  const float rotations = std::max(params.extract_input<float>("Rotations"), 0.0f);
72  if (rotations == 0.0f) {
73  params.set_default_remaining_outputs();
74  return;
75  }
76 
78  std::max(params.extract_input<int>("Resolution"), 1),
79  params.extract_input<float>("Start Radius"),
80  params.extract_input<float>("End Radius"),
81  params.extract_input<float>("Height"),
82  params.extract_input<bool>("Reverse"));
83  params.set_output("Curve", GeometrySet::create_with_curves(curves));
84 }
85 
86 } // namespace blender::nodes::node_geo_curve_primitive_spiral_cc
87 
89 {
91 
92  static bNodeType ntype;
93 
97  nodeRegisterType(&ntype);
98 }
typedef float(TangentPoint)[2]
Low-level operations for curves.
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
#define GEO_NODE_CURVE_PRIMITIVE_SPIRAL
Definition: BKE_node.h:1409
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define M_PI
Definition: BLI_math_base.h:20
@ CURVE_TYPE_POLY
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
@ PROP_DISTANCE
Definition: RNA_types.h:149
@ PROP_UNSIGNED
Definition: RNA_types.h:142
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311
Curves * curves_new_nomain_single(int points_num, CurveType type)
Definition: curves.cc:375
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)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_curve_primitive_spiral()
MutableSpan< float3 > positions
MutableSpan< float3 > rotations
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
static GeometrySet create_with_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeDeclareFunction declare
Definition: BKE_node.h:324
float max
#define N_(msgid)