Blender V4.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.h"
6#include "BKE_mesh.hh"
7
8#include "NOD_rna_define.hh"
9
10#include "UI_interface.hh"
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")
31 .default_value(1)
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")
36 .default_value(1)
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)
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)
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)
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{
72 NodeGeometryMeshCone *node_storage = MEM_cnew<NodeGeometryMeshCone>(__func__);
73
75
76 node->storage = node_storage;
77}
78
79static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
80{
81 uiLayoutSetPropSep(layout, true);
82 uiLayoutSetPropDecorate(layout, false);
83 uiItemR(layout, ptr, "fill_type", UI_ITEM_NONE, nullptr, 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, GEO_NODE_MESH_PRIMITIVE_CONE, "Cone", NODE_CLASS_GEOMETRY);
157 ntype.initfunc = node_init;
159 &ntype, "NodeGeometryMeshCone", node_free_standard_storage, node_copy_standard_storage);
162 ntype.declare = node_declare;
164
165 node_rna(ntype.rna_ext.srna);
166}
168
169} // namespace blender::nodes::node_geo_mesh_primitive_cone_cc
General operations, lookup, etc. for materials.
void BKE_id_material_eval_ensure_default_slot(struct ID *id)
void BKE_mesh_translate(Mesh *mesh, const float offset[3], bool do_keys)
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#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:159
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
#define UI_ITEM_NONE
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
const EnumPropertyItem rna_enum_node_geometry_mesh_circle_fill_type_items[]
#define min(a, b)
Definition sort.c:32
StructRNA * srna
Definition RNA_types.hh:780
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126