Blender  V3.3
node_geo_curve_fillet.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "UI_interface.h"
4 #include "UI_resources.h"
5 
6 #include "GEO_fillet_curves.hh"
7 
8 #include "node_geometry_util.hh"
9 
11 
13 
15 {
16  b.add_input<decl::Geometry>(N_("Curve")).supported_type(GEO_COMPONENT_TYPE_CURVE);
17  b.add_input<decl::Int>(N_("Count"))
18  .default_value(1)
19  .min(1)
20  .max(1000)
21  .supports_field()
22  .make_available([](bNode &node) { node_storage(node).mode = GEO_NODE_CURVE_FILLET_POLY; });
23  b.add_input<decl::Float>(N_("Radius"))
24  .min(0.0f)
25  .max(FLT_MAX)
27  .default_value(0.25f)
28  .supports_field();
29  b.add_input<decl::Bool>(N_("Limit Radius"))
30  .description(
31  N_("Limit the maximum value of the radius in order to avoid overlapping fillets"));
32  b.add_output<decl::Geometry>(N_("Curve"));
33 }
34 
35 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
36 {
37  uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
38 }
39 
41 {
42  NodeGeometryCurveFillet *data = MEM_cnew<NodeGeometryCurveFillet>(__func__);
44  node->storage = data;
45 }
46 
48 {
49  const NodeGeometryCurveFillet &storage = node_storage(*node);
51  bNodeSocket *poly_socket = ((bNodeSocket *)node->inputs.first)->next;
53 }
54 
56 {
57  GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
58 
59  const NodeGeometryCurveFillet &storage = node_storage(params.node());
61 
62  Field<float> radius_field = params.extract_input<Field<float>>("Radius");
63  const bool limit_radius = params.extract_input<bool>("Limit Radius");
64 
65  std::optional<Field<int>> count_field;
66  if (mode == GEO_NODE_CURVE_FILLET_POLY) {
67  count_field.emplace(params.extract_input<Field<int>>("Count"));
68  }
69 
70  geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
71  if (!geometry_set.has_curves()) {
72  return;
73  }
74 
76  const Curves &curves_id = *component.get_for_read();
77  const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
79  fn::FieldEvaluator evaluator{context, curves.points_num()};
80  evaluator.add(radius_field);
81 
82  switch (mode) {
84  evaluator.evaluate();
86  curves, curves.curves_range(), evaluator.get_evaluated<float>(0), limit_radius);
87  Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
88  bke::curves_copy_parameters(curves_id, *dst_curves_id);
89  geometry_set.replace_curves(dst_curves_id);
90  break;
91  }
93  evaluator.add(*count_field);
94  evaluator.evaluate();
96  curves,
97  curves.curves_range(),
98  evaluator.get_evaluated<float>(0),
99  evaluator.get_evaluated<int>(1),
100  limit_radius);
101  Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
102  bke::curves_copy_parameters(curves_id, *dst_curves_id);
103  geometry_set.replace_curves(dst_curves_id);
104  break;
105  }
106  }
107  });
108 
109  params.set_output("Curve", std::move(geometry_set));
110 }
111 
112 } // namespace blender::nodes::node_geo_curve_fillet_cc
113 
115 {
116  namespace file_ns = blender::nodes::node_geo_curve_fillet_cc;
117 
118  static bNodeType ntype;
119 
123  &ntype, "NodeGeometryCurveFillet", node_free_standard_storage, node_copy_standard_storage);
128  nodeRegisterType(&ntype);
129 }
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
@ GEO_COMPONENT_TYPE_CURVE
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4443
#define NODE_STORAGE_FUNCS(StorageT)
Definition: BKE_node.h:1563
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3664
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
#define GEO_NODE_FILLET_CURVE
Definition: BKE_node.h:1431
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
GeometryNodeCurveFilletMode
@ GEO_NODE_CURVE_FILLET_BEZIER
@ GEO_NODE_CURVE_FILLET_POLY
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
@ UI_ITEM_R_EXPAND
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
OperationNode * node
void * tree
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static ulong * next
void curves_copy_parameters(const Curves &src, Curves &dst)
Definition: curves.cc:391
Curves * curves_new_nomain(int points_num, int curves_num)
Definition: curves.cc:367
static float limit_radius(const float3 &position_prev, const float3 &position, const float3 &position_next, const float angle_prev, const float angle, const float angle_next, const float radius_prev, const float radius, const float radius_next)
bke::CurvesGeometry fillet_curves_bezier(const bke::CurvesGeometry &src_curves, IndexMask curve_selection, const VArray< float > &radius, bool limit_radius)
bke::CurvesGeometry fillet_curves_poly(const bke::CurvesGeometry &src_curves, IndexMask curve_selection, const VArray< float > &radius, const VArray< int > &counts, bool limit_radius)
static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
static void node_geo_exec(GeoNodeExecParams params)
static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
Definition: node.cc:1082
void register_node_type_geo_curve_fillet()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
#define min(a, b)
Definition: sort.c:35
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const GeometryComponent * get_component_for_read(GeometryComponentType component_type) const
void modify_geometry_sets(ForeachSubGeometryCallback callback)
bool has_curves() const
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480