Blender V5.3
node_geo_mesh_primitive_cylinder.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_material.hh"
6
7#include "NOD_rna_define.hh"
8
10
12#include "UI_resources.hh"
13
14#include "node_geometry_util.hh"
15
16#include "RNA_enum_types.hh"
17
19
21
23{
24 b.add_input<decl::Int>("Vertices"_ustr)
25 .default_value(32)
26 .min(3)
27 .max(512)
28 .description("The number of vertices on the top and bottom circles");
29 b.add_input<decl::Int>("Side Segments"_ustr)
31 .min(1)
32 .max(512)
33 .description("The number of rectangular segments along each side");
34 auto &fill = b.add_input<decl::Int>("Fill Segments"_ustr)
36 .min(1)
37 .max(512)
38 .description("The number of concentric rings used to fill the round faces");
39 b.add_input<decl::Float>("Radius"_ustr)
40 .default_value(1.0f)
41 .min(0.0f)
42 .subtype(PROP_DISTANCE)
43 .description("The radius of the cylinder");
44 b.add_input<decl::Float>("Depth"_ustr)
45 .default_value(2.0f)
46 .min(0.0f)
47 .subtype(PROP_DISTANCE)
48 .description("The height of the cylinder");
49 b.add_output<decl::Geometry>("Mesh"_ustr);
50 b.add_output<decl::Bool>("Top"_ustr)
51 .anonymous_attribute_output()
52 .translation_context(BLT_I18NCONTEXT_ID_NODETREE);
53 b.add_output<decl::Bool>("Side"_ustr).anonymous_attribute_output();
54 b.add_output<decl::Bool>("Bottom"_ustr)
55 .anonymous_attribute_output()
56 .translation_context(BLT_I18NCONTEXT_ID_NODETREE);
57 b.add_output<decl::Vector>("UV Map"_ustr).anonymous_attribute_output();
58
59 const bNode *node = b.node_or_null();
60 if (node != nullptr) {
61 const NodeGeometryMeshCylinder &storage = node_storage(*node);
63 storage.fill_type);
64 fill.available(fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE);
65 }
66}
67
68static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
69{
70 layout.use_property_split_set(true);
71 layout.use_property_decorate_set(false);
72 layout.prop(ptr, "fill_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
73}
74
75static void node_init(bNodeTree * /*tree*/, bNode *node)
76{
77 NodeGeometryMeshCylinder *node_storage = MEM_new<NodeGeometryMeshCylinder>(__func__);
78
80
81 node->storage = node_storage;
82}
83
85{
86 const NodeGeometryMeshCylinder &storage = node_storage(params.node());
88
89 const float radius = params.extract_input<float>("Radius"_ustr);
90 const float depth = params.extract_input<float>("Depth"_ustr);
91 const int circle_segments = params.extract_input<int>("Vertices"_ustr);
92 if (circle_segments < 3) {
93 params.error_message_add(NodeWarningType::Info, TIP_("Vertices must be at least 3"));
95 return;
96 }
97
98 const int side_segments = params.extract_input<int>("Side Segments"_ustr);
99 if (side_segments < 1) {
100 params.error_message_add(NodeWarningType::Info, TIP_("Side Segments must be at least 1"));
102 return;
103 }
104
105 const bool no_fill = fill == GEO_NODE_MESH_CIRCLE_FILL_NONE;
106 const int fill_segments = no_fill ? 1 : params.extract_input<int>("Fill Segments"_ustr);
107 if (fill_segments < 1) {
108 params.error_message_add(NodeWarningType::Info, TIP_("Fill Segments must be at least 1"));
110 return;
111 }
112
113 geometry::ConeAttributeOutputs attribute_outputs;
114 attribute_outputs.top_id = params.get_output_anonymous_attribute_id_if_needed("Top"_ustr);
115 attribute_outputs.bottom_id = params.get_output_anonymous_attribute_id_if_needed("Bottom"_ustr);
116 attribute_outputs.side_id = params.get_output_anonymous_attribute_id_if_needed("Side"_ustr);
117 attribute_outputs.uv_map_id = params.get_output_anonymous_attribute_id_if_needed("UV Map"_ustr);
118
119 /* The cylinder is a special case of the cone mesh where the top and bottom radius are equal. */
121 radius,
122 depth,
123 circle_segments,
124 side_segments,
125 fill_segments,
127 attribute_outputs);
129
130 params.set_output("Mesh"_ustr, GeometrySet::from_mesh(mesh));
131}
132
133static void node_rna(StructRNA *srna)
134{
136 "fill_type",
137 "Fill Type",
138 "",
142 nullptr,
143 true);
144}
145
146static void node_register()
147{
148 static bke::bNodeType ntype;
149 geo_node_type_base(&ntype, "GeometryNodeMeshCylinder"_ustr, GEO_NODE_MESH_PRIMITIVE_CYLINDER);
150 ntype.ui_name = "Cylinder";
151 ntype.ui_description = "Generate a cylinder mesh";
152 ntype.enum_name_legacy = "MESH_PRIMITIVE_CYLINDER";
154 ntype.initfunc = node_init;
156 ntype, "NodeGeometryMeshCylinder", node_free_standard_storage, node_copy_standard_storage);
157 ntype.declare = node_declare;
161
162 node_rna(ntype.rna_ext.srna);
163}
165
166} // namespace blender::nodes::node_geo_mesh_primitive_cylinder_cc
General operations, lookup, etc. for materials.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_MESH_PRIMITIVE_CYLINDER
#define BLT_I18NCONTEXT_ID_NODETREE
#define TIP_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
btScalar max
void error_message_add(const NodeWarningType type, StringRef message) const
std::optional< std::string > get_output_anonymous_attribute_id_if_needed(const UString output_identifier, const bool force_create=false)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
#define storage(slot, qualifiers)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
Mesh * create_cylinder_or_cone_mesh(float radius_top, float radius_bottom, float depth, int circle_segments, int side_segments, int fill_segments, ConeFillType fill_type, ConeAttributeOutputs &attribute_outputs)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
void BKE_id_material_eval_ensure_default_slot(ID *id)
const EnumPropertyItem rna_enum_node_geometry_mesh_circle_fill_type_items[]
GeometryNodeMeshCircleFillType
@ GEO_NODE_MESH_CIRCLE_FILL_NONE
@ GEO_NODE_MESH_CIRCLE_FILL_NGON
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
@ PROP_DISTANCE
Definition RNA_types.hh:313
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:38
GeometryNodeMeshCircleFillType fill_type
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)