Blender  V3.3
node_geo_curve_primitive_star.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_("Points"))
12  .default_value(8)
13  .min(3)
14  .max(256)
15  .subtype(PROP_UNSIGNED)
16  .description(N_("Number of points on each of the circles"));
17  b.add_input<decl::Float>(N_("Inner Radius"))
18  .default_value(1.0f)
19  .min(0.0f)
20  .subtype(PROP_DISTANCE)
21  .description(N_("Radius of the inner circle; can be larger than outer radius"));
22  b.add_input<decl::Float>(N_("Outer Radius"))
23  .default_value(2.0f)
24  .min(0.0f)
25  .subtype(PROP_DISTANCE)
26  .description(N_("Radius of the outer circle; can be smaller than inner radius"));
27  b.add_input<decl::Float>(N_("Twist"))
28  .subtype(PROP_ANGLE)
29  .description(N_("The counterclockwise rotation of the inner set of points"));
30  b.add_output<decl::Geometry>(N_("Curve"));
31  b.add_output<decl::Bool>(N_("Outer Points"))
32  .field_source()
33  .description(N_("An attribute field with a selection of the outer points"));
34 }
35 
36 static Curves *create_star_curve(const float inner_radius,
37  const float outer_radius,
38  const float twist,
39  const int points)
40 {
41  Curves *curves_id = bke::curves_new_nomain_single(points * 2, CURVE_TYPE_POLY);
43  curves.cyclic_for_write().first() = true;
44 
45  MutableSpan<float3> positions = curves.positions_for_write();
46 
47  const float theta_step = (2.0f * M_PI) / float(points);
48  for (const int i : IndexRange(points)) {
49  const float x = outer_radius * cos(theta_step * i);
50  const float y = outer_radius * sin(theta_step * i);
51  positions[i * 2] = {x, y, 0.0f};
52 
53  const float inner_x = inner_radius * cos(theta_step * i + theta_step * 0.5f + twist);
54  const float inner_y = inner_radius * sin(theta_step * i + theta_step * 0.5f + twist);
55  positions[i * 2 + 1] = {inner_x, inner_y, 0.0f};
56  }
57 
58  return curves_id;
59 }
60 
62  StrongAnonymousAttributeID &r_attribute)
63 {
64  SpanAttributeWriter<bool> selection =
65  component.attributes_for_write()->lookup_or_add_for_write_only_span<bool>(r_attribute.get(),
67  for (int i : selection.span.index_range()) {
68  selection.span[i] = i % 2 == 0;
69  }
70  selection.finish();
71 }
72 
74 {
75  Curves *curves = create_star_curve(std::max(params.extract_input<float>("Inner Radius"), 0.0f),
76  std::max(params.extract_input<float>("Outer Radius"), 0.0f),
77  params.extract_input<float>("Twist"),
78  std::max(params.extract_input<int>("Points"), 3));
80 
81  if (params.output_is_required("Outer Points")) {
82  StrongAnonymousAttributeID attribute_output("Outer Points");
83  create_selection_output(output.get_component_for_write<CurveComponent>(), attribute_output);
84  params.set_output("Outer Points",
85  AnonymousAttributeFieldInput::Create<bool>(
86  std::move(attribute_output), params.attribute_producer_name()));
87  }
88  params.set_output("Curve", std::move(output));
89 }
90 } // namespace blender::nodes::node_geo_curve_primitive_star_cc
91 
93 {
95 
96  static bNodeType ntype;
100  nodeRegisterType(&ntype);
101 }
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
Low-level operations for curves.
#define GEO_NODE_CURVE_PRIMITIVE_STAR
Definition: BKE_node.h:1408
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define M_PI
Definition: BLI_math_base.h:20
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
@ 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 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_ANGLE
Definition: RNA_types.h:145
@ PROP_UNSIGNED
Definition: RNA_types.h:142
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_global KernelShaderEvalInput ccl_global float * output
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
OwnedAnonymousAttributeID< true > StrongAnonymousAttributeID
static Curves * create_star_curve(const float inner_radius, const float outer_radius, const float twist, const int points)
static void create_selection_output(CurveComponent &component, StrongAnonymousAttributeID &r_attribute)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_curve_primitive_star()
MutableSpan< float3 > positions
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
CurvesGeometry geometry
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)