Blender  V2.93
node_geo_mesh_primitive_cylinder.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #include "DNA_mesh_types.h"
18 #include "DNA_meshdata_types.h"
19 
20 #include "BKE_mesh.h"
21 
22 #include "UI_interface.h"
23 #include "UI_resources.h"
24 
25 #include "node_geometry_util.hh"
26 
28  {SOCK_INT, N_("Vertices"), 32, 0.0f, 0.0f, 0.0f, 3, 4096},
29  {SOCK_FLOAT, N_("Radius"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
30  {SOCK_FLOAT, N_("Depth"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
31  {-1, ""},
32 };
33 
35  {SOCK_GEOMETRY, N_("Geometry")},
36  {-1, ""},
37 };
38 
40  bContext *UNUSED(C),
41  PointerRNA *ptr)
42 {
43  uiLayoutSetPropSep(layout, true);
44  uiLayoutSetPropDecorate(layout, false);
45  uiItemR(layout, ptr, "fill_type", 0, nullptr, ICON_NONE);
46 }
47 
49 {
51  sizeof(NodeGeometryMeshCylinder), __func__);
52 
54 
55  node->storage = node_storage;
56 }
57 
58 namespace blender::nodes {
59 
61 {
62  const bNode &node = params.node();
63  const NodeGeometryMeshCylinder &storage = *(const NodeGeometryMeshCylinder *)node.storage;
64 
66  storage.fill_type;
67 
68  const float radius = params.extract_input<float>("Radius");
69  const float depth = params.extract_input<float>("Depth");
70  const int verts_num = params.extract_input<int>("Vertices");
71  if (verts_num < 3) {
72  params.set_output("Geometry", GeometrySet());
73  return;
74  }
75 
76  /* The cylinder is a special case of the cone mesh where the top and bottom radius are equal. */
77  Mesh *mesh = create_cylinder_or_cone_mesh(radius, radius, depth, verts_num, fill_type);
78 
79  params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
80 }
81 
82 } // namespace blender::nodes
83 
85 {
86  static bNodeType ntype;
87 
93  &ntype, "NodeGeometryMeshCylinder", node_free_standard_storage, node_copy_standard_storage);
96  nodeRegisterType(&ntype);
97 }
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4559
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
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:4599
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define UNUSED(x)
#define N_(msgid)
GeometryNodeMeshCircleFillType
@ GEO_NODE_MESH_CIRCLE_FILL_NGON
@ SOCK_INT
@ SOCK_FLOAT
@ SOCK_GEOMETRY
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Boolean Random Edge Subdivision Point Object Attribute Attribute Attribute Color Attribute Attribute Vector Point Attribute Sample Collection Attribute Attribute Combine Attribute GEO_NODE_MESH_PRIMITIVE_CYLINDER
@ PROP_DISTANCE
Definition: RNA_types.h:135
#define C
Definition: RandGen.cpp:39
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
OperationNode * node
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
Mesh * create_cylinder_or_cone_mesh(const float radius_top, const float radius_bottom, const float depth, const int verts_num, const GeometryNodeMeshCircleFillType fill_type)
static void geo_node_mesh_primitive_cylinder_exec(GeoNodeExecParams params)
static void geo_node_mesh_primitive_cylinder_init(bNodeTree *UNUSED(ntree), bNode *node)
static void geo_node_mesh_primitive_cylinder_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
void register_node_type_geo_mesh_primitive_cylinder()
static bNodeSocketTemplate geo_node_mesh_primitive_cylinder_out[]
static bNodeSocketTemplate geo_node_mesh_primitive_cylinder_in[]
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:67
void node_free_standard_storage(bNode *node)
Definition: node_util.c:55
static GeometrySet create_with_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:327
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:253
PointerRNA * ptr
Definition: wm_files.c:3157