Blender V5.3
node_geo_mesh_primitive_cone.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#include "BKE_mesh.hh"
7
8#include "NOD_rna_define.hh"
9
11#include "UI_resources.hh"
12
14
15#include "node_geometry_util.hh"
16
17#include "RNA_enum_types.hh"
18
20
22
24{
25 b.add_input<decl::Int>("Vertices"_ustr)
26 .default_value(32)
27 .min(3)
28 .max(512)
29 .description("Number of points on the circle at the top and bottom");
30 b.add_input<decl::Int>("Side Segments"_ustr)
32 .min(1)
33 .max(512)
34 .description("The number of edges running vertically along the side of the cone");
35 auto &fill = b.add_input<decl::Int>("Fill Segments"_ustr)
37 .min(1)
38 .max(512)
39 .description("Number of concentric rings used to fill the round face");
40 b.add_input<decl::Float>("Radius Top"_ustr)
41 .min(0.0f)
42 .subtype(PROP_DISTANCE)
43 .description("Radius of the top circle of the cone");
44 b.add_input<decl::Float>("Radius Bottom"_ustr)
45 .default_value(1.0f)
46 .min(0.0f)
47 .subtype(PROP_DISTANCE)
48 .description("Radius of the bottom circle of the cone");
49 b.add_input<decl::Float>("Depth"_ustr)
50 .default_value(2.0f)
51 .min(0.0f)
52 .subtype(PROP_DISTANCE)
53 .description("Height of the generated cone");
54 b.add_output<decl::Geometry>("Mesh"_ustr);
55 b.add_output<decl::Bool>("Top"_ustr)
56 .anonymous_attribute_output()
57 .translation_context(BLT_I18NCONTEXT_ID_NODETREE);
58 b.add_output<decl::Bool>("Bottom"_ustr)
59 .anonymous_attribute_output()
60 .translation_context(BLT_I18NCONTEXT_ID_NODETREE);
61 b.add_output<decl::Bool>("Side"_ustr).anonymous_attribute_output();
62 b.add_output<decl::Vector>("UV Map"_ustr).anonymous_attribute_output();
63
64 const bNode *node = b.node_or_null();
65 if (node != nullptr) {
66 const NodeGeometryMeshCone &storage = node_storage(*node);
68 storage.fill_type);
69 fill.available(fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE);
70 }
71}
72
73static void node_init(bNodeTree * /*tree*/, bNode *node)
74{
75 NodeGeometryMeshCone *node_storage = MEM_new<NodeGeometryMeshCone>(__func__);
76
78
79 node->storage = node_storage;
80}
81
82static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
83{
84 layout.use_property_split_set(true);
85 layout.use_property_decorate_set(false);
86 layout.prop(ptr, "fill_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
87}
88
90{
91 const NodeGeometryMeshCone &storage = node_storage(params.node());
93
94 const int circle_segments = params.extract_input<int>("Vertices"_ustr);
95 if (circle_segments < 3) {
96 params.error_message_add(NodeWarningType::Info, TIP_("Vertices must be at least 3"));
98 return;
99 }
100
101 const int side_segments = params.extract_input<int>("Side Segments"_ustr);
102 if (side_segments < 1) {
103 params.error_message_add(NodeWarningType::Info, TIP_("Side Segments must be at least 1"));
105 return;
106 }
107
108 const bool no_fill = fill == GEO_NODE_MESH_CIRCLE_FILL_NONE;
109 const int fill_segments = no_fill ? 1 : params.extract_input<int>("Fill Segments"_ustr);
110 if (fill_segments < 1) {
111 params.error_message_add(NodeWarningType::Info, TIP_("Fill Segments must be at least 1"));
113 return;
114 }
115
116 const float radius_top = params.extract_input<float>("Radius Top"_ustr);
117 const float radius_bottom = params.extract_input<float>("Radius Bottom"_ustr);
118 const float depth = params.extract_input<float>("Depth"_ustr);
119
120 geometry::ConeAttributeOutputs attribute_outputs;
121 attribute_outputs.top_id = params.get_output_anonymous_attribute_id_if_needed("Top"_ustr);
122 attribute_outputs.bottom_id = params.get_output_anonymous_attribute_id_if_needed("Bottom"_ustr);
123 attribute_outputs.side_id = params.get_output_anonymous_attribute_id_if_needed("Side"_ustr);
124 attribute_outputs.uv_map_id = params.get_output_anonymous_attribute_id_if_needed("UV Map"_ustr);
125
127 radius_bottom,
128 depth,
129 circle_segments,
130 side_segments,
131 fill_segments,
133 attribute_outputs);
135
136 /* Transform the mesh so that the base of the cone is at the origin. */
137 bke::mesh_translate(*mesh, float3(0.0f, 0.0f, depth * 0.5f), false);
138
139 params.set_output("Mesh"_ustr, GeometrySet::from_mesh(mesh));
140}
141
142static void node_rna(StructRNA *srna)
143{
145 "fill_type",
146 "Fill Type",
147 "",
151 nullptr,
152 true);
153}
154
155static void node_register()
156{
157 static bke::bNodeType ntype;
158
159 geo_node_type_base(&ntype, "GeometryNodeMeshCone"_ustr, GEO_NODE_MESH_PRIMITIVE_CONE);
160 ntype.ui_name = "Cone";
161 ntype.ui_description = "Generate a cone mesh";
162 ntype.enum_name_legacy = "MESH_PRIMITIVE_CONE";
164 ntype.initfunc = node_init;
166 ntype, "NodeGeometryMeshCone", node_free_standard_storage, node_copy_standard_storage);
169 ntype.declare = node_declare;
171
172 node_rna(ntype.rna_ext.srna);
173}
175
176} // namespace blender::nodes::node_geo_mesh_primitive_cone_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_CONE
#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 mesh_translate(Mesh &mesh, const float3 &translation, bool do_shape_keys)
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
VecBase< float, 3 > float3
@ 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)