Blender  V2.93
node_geo_triangulate.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 "UI_interface.h"
18 #include "UI_resources.h"
19 
20 #include "node_geometry_util.hh"
21 
22 extern "C" {
24  const int quad_method,
25  const int ngon_method,
26  const int min_vertices,
27  const int flag);
28 }
29 
31  {SOCK_GEOMETRY, N_("Geometry")},
32  {SOCK_INT, N_("Minimum Vertices"), 4, 0, 0, 0, 4, 10000},
33  {-1, ""},
34 };
35 
37  {SOCK_GEOMETRY, N_("Geometry")},
38  {-1, ""},
39 };
40 
42 {
43  uiItemR(layout, ptr, "quad_method", 0, "", ICON_NONE);
44  uiItemR(layout, ptr, "ngon_method", 0, "", ICON_NONE);
45 }
46 
48 {
51 }
52 
53 namespace blender::nodes {
55 {
56  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
57  const int min_vertices = std::max(params.extract_input<int>("Minimum Vertices"), 4);
58 
60  params.node().custom1);
62  params.node().custom2);
63 
64  geometry_set = geometry_set_realize_instances(geometry_set);
65 
66  /* #triangulate_mesh might modify the input mesh currently. */
67  Mesh *mesh_in = geometry_set.get_mesh_for_write();
68  if (mesh_in != nullptr) {
69  Mesh *mesh_out = triangulate_mesh(mesh_in, quad_method, ngon_method, min_vertices, 0);
70  geometry_set.replace_mesh(mesh_out);
71  }
72 
73  params.set_output("Geometry", std::move(geometry_set));
74 }
75 } // namespace blender::nodes
76 
78 {
79  static bNodeType ntype;
80 
86  nodeRegisterType(&ntype);
87 }
#define GEO_NODE_TRIANGULATE
Definition: BKE_node.h:1376
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 nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define UNUSED(x)
#define N_(msgid)
GeometryNodeTriangulateQuads
@ GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE
GeometryNodeTriangulateNGons
@ GEO_NODE_TRIANGULATE_NGON_BEAUTY
@ SOCK_INT
@ SOCK_GEOMETRY
#define C
Definition: RandGen.cpp:39
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
OperationNode * node
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
GeometrySet geometry_set_realize_instances(const GeometrySet &geometry_set)
static void geo_node_triangulate_exec(GeoNodeExecParams params)
static bNodeSocketTemplate geo_node_triangulate_out[]
static void geo_triangulate_init(bNodeTree *UNUSED(ntree), bNode *node)
static bNodeSocketTemplate geo_node_triangulate_in[]
void register_node_type_geo_triangulate()
Mesh * triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_method, const int min_vertices, const int flag)
static void geo_node_triangulate_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Mesh * get_mesh_for_write()
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
float max
PointerRNA * ptr
Definition: wm_files.c:3157