Blender V5.0
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")
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")
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")
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")
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")
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")
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");
55 b.add_output<decl::Bool>("Top").field_on_all().translation_context(BLT_I18NCONTEXT_ID_NODETREE);
56 b.add_output<decl::Bool>("Bottom").field_on_all().translation_context(
58 b.add_output<decl::Bool>("Side").field_on_all();
59 b.add_output<decl::Vector>("UV Map").field_on_all();
60
61 const bNode *node = b.node_or_null();
62 if (node != nullptr) {
63 const NodeGeometryMeshCone &storage = node_storage(*node);
65 storage.fill_type);
66 fill.available(fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE);
67 }
68}
69
70static void node_init(bNodeTree * /*tree*/, bNode *node)
71{
73
75
76 node->storage = node_storage;
77}
78
79static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
80{
81 layout->use_property_split_set(true);
82 layout->use_property_decorate_set(false);
83 layout->prop(ptr, "fill_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
84}
85
87{
88 const NodeGeometryMeshCone &storage = node_storage(params.node());
90
91 const int circle_segments = params.extract_input<int>("Vertices");
92 if (circle_segments < 3) {
93 params.error_message_add(NodeWarningType::Info, TIP_("Vertices must be at least 3"));
94 params.set_default_remaining_outputs();
95 return;
96 }
97
98 const int side_segments = params.extract_input<int>("Side Segments");
99 if (side_segments < 1) {
100 params.error_message_add(NodeWarningType::Info, TIP_("Side Segments must be at least 1"));
101 params.set_default_remaining_outputs();
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");
107 if (fill_segments < 1) {
108 params.error_message_add(NodeWarningType::Info, TIP_("Fill Segments must be at least 1"));
109 params.set_default_remaining_outputs();
110 return;
111 }
112
113 const float radius_top = params.extract_input<float>("Radius Top");
114 const float radius_bottom = params.extract_input<float>("Radius Bottom");
115 const float depth = params.extract_input<float>("Depth");
116
117 geometry::ConeAttributeOutputs attribute_outputs;
118 attribute_outputs.top_id = params.get_output_anonymous_attribute_id_if_needed("Top");
119 attribute_outputs.bottom_id = params.get_output_anonymous_attribute_id_if_needed("Bottom");
120 attribute_outputs.side_id = params.get_output_anonymous_attribute_id_if_needed("Side");
121 attribute_outputs.uv_map_id = params.get_output_anonymous_attribute_id_if_needed("UV Map");
122
124 radius_bottom,
125 depth,
126 circle_segments,
127 side_segments,
128 fill_segments,
130 attribute_outputs);
132
133 /* Transform the mesh so that the base of the cone is at the origin. */
134 bke::mesh_translate(*mesh, float3(0.0f, 0.0f, depth * 0.5f), false);
135
136 params.set_output("Mesh", GeometrySet::from_mesh(mesh));
137}
138
139static void node_rna(StructRNA *srna)
140{
142 "fill_type",
143 "Fill Type",
144 "",
148 nullptr,
149 true);
150}
151
152static void node_register()
153{
154 static blender::bke::bNodeType ntype;
155
156 geo_node_type_base(&ntype, "GeometryNodeMeshCone", GEO_NODE_MESH_PRIMITIVE_CONE);
157 ntype.ui_name = "Cone";
158 ntype.ui_description = "Generate a cone mesh";
159 ntype.enum_name_legacy = "MESH_PRIMITIVE_CONE";
161 ntype.initfunc = node_init;
163 ntype, "NodeGeometryMeshCone", node_free_standard_storage, node_copy_standard_storage);
166 ntype.declare = node_declare;
168
169 node_rna(ntype.rna_ext.srna);
170}
172
173} // namespace blender::nodes::node_geo_mesh_primitive_cone_cc
General operations, lookup, etc. for materials.
void BKE_id_material_eval_ensure_default_slot(ID *id)
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1240
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_MESH_PRIMITIVE_CONE
#define BLT_I18NCONTEXT_ID_NODETREE
#define TIP_(msgid)
GeometryNodeMeshCircleFillType
@ GEO_NODE_MESH_CIRCLE_FILL_NGON
@ GEO_NODE_MESH_CIRCLE_FILL_NONE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
@ PROP_DISTANCE
Definition RNA_types.hh:256
#define UI_ITEM_NONE
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:5414
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(uiLayout *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)
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
const EnumPropertyItem rna_enum_node_geometry_mesh_circle_fill_type_items[]
#define min(a, b)
Definition sort.cc:36
StructRNA * srna
void * storage
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void use_property_decorate_set(bool is_sep)
void use_property_split_set(bool value)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
max
Definition text_draw.cc:251
PointerRNA * ptr
Definition wm_files.cc:4238