[Bf-blender-cvs] [8ef8cb7e34d] geometry-nodes: Geometry Nodes: Add method enums to mesh triangulate node
Léo Depoix
noreply at git.blender.org
Thu Nov 12 21:50:27 CET 2020
Commit: 8ef8cb7e34d424a56ae9bfc4fb536756413dd288
Author: Léo Depoix
Date: Thu Nov 12 15:45:00 2020 -0500
Branches: geometry-nodes
https://developer.blender.org/rB8ef8cb7e34d424a56ae9bfc4fb536756413dd288
Geometry Nodes: Add method enums to mesh triangulate node
This commit adds the remaining "method" enums from the triangulate modifier.
Differential Revision: https://developer.blender.org/D9502
===================================================================
M source/blender/editors/space_node/drawnode.c
M source/blender/makesdna/DNA_node_types.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/NOD_static_types.h
M source/blender/nodes/geometry/nodes/node_geo_triangulate.cc
===================================================================
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 4aaa6eeae35..825b6274831 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3157,6 +3157,12 @@ static void node_geometry_buts_subdivision_surface(uiLayout *layout,
#endif
}
+static void node_geometry_buts_triangulate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "quad_method", DEFAULT_FLAGS, "", ICON_NONE);
+ uiItemR(layout, ptr, "ngon_method", DEFAULT_FLAGS, "", ICON_NONE);
+}
+
static void node_geometry_set_butfunc(bNodeType *ntype)
{
switch (ntype->type) {
@@ -3166,6 +3172,9 @@ static void node_geometry_set_butfunc(bNodeType *ntype)
case GEO_NODE_SUBDIVISION_SURFACE:
ntype->draw_buttons = node_geometry_buts_subdivision_surface;
break;
+ case GEO_NODE_TRIANGULATE:
+ ntype->draw_buttons = node_geometry_buts_triangulate;
+ break;
}
}
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 9a86de0556c..35fc1b81ecf 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1441,3 +1441,16 @@ typedef enum GeometryNodeBooleanOperation {
GEO_NODE_BOOLEAN_UNION = 1,
GEO_NODE_BOOLEAN_DIFFERENCE = 2,
} GeometryNodeBooleanOperation;
+
+/* Triangulate Node */
+typedef enum GeometryNodeTriangulateNGons {
+ GEO_NODE_TRIANGULATE_NGON_BEAUTY = 0,
+ GEO_NODE_TRIANGULATE_NGON_EARCLIP = 1,
+} GeometryNodeTriangulateNGons;
+
+typedef enum GeometryNodeTriangulateQuads {
+ GEO_NODE_TRIANGULATE_QUAD_BEAUTY = 0,
+ GEO_NODE_TRIANGULATE_QUAD_FIXED = 1,
+ GEO_NODE_TRIANGULATE_QUAD_ALTERNATE = 2,
+ GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE = 3,
+} GeometryNodeTriangulateQuads;
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 35e29722c0a..ec93fd0aac4 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -384,6 +384,44 @@ static const EnumPropertyItem rna_node_geometry_boolean_method_items[] = {
{0, NULL, 0, NULL, NULL},
};
+static const EnumPropertyItem rna_node_geometry_triangulate_quad_method_items[] = {
+ {GEO_NODE_TRIANGULATE_QUAD_BEAUTY,
+ "BEAUTY",
+ 0,
+ "Beauty",
+ "Split the quads in nice triangles, slower method"},
+ {GEO_NODE_TRIANGULATE_QUAD_FIXED,
+ "FIXED",
+ 0,
+ "Fixed",
+ "Split the quads on the first and third vertices"},
+ {GEO_NODE_TRIANGULATE_QUAD_ALTERNATE,
+ "FIXED_ALTERNATE",
+ 0,
+ "Fixed Alternate",
+ "Split the quads on the 2nd and 4th vertices"},
+ {GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE,
+ "SHORTEST_DIAGONAL",
+ 0,
+ "Shortest Diagonal",
+ "Split the quads based on the distance between the vertices"},
+ {0, NULL, 0, NULL, NULL},
+};
+
+static const EnumPropertyItem rna_node_geometry_triangulate_ngon_method_items[] = {
+ {GEO_NODE_TRIANGULATE_NGON_BEAUTY,
+ "BEAUTY",
+ 0,
+ "Beauty",
+ "Arrange the new triangles evenly (slow)"},
+ {GEO_NODE_TRIANGULATE_NGON_EARCLIP,
+ "CLIP",
+ 0,
+ "Clip",
+ "Split the polygons with an ear clipping algorithm"},
+ {0, NULL, 0, NULL, NULL},
+};
+
#endif
#ifdef RNA_RUNTIME
@@ -8200,6 +8238,26 @@ static void def_geo_boolean(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
+static void def_geo_triangulate(StructRNA *srna)
+{
+ PropertyRNA *prop;
+
+ prop = RNA_def_property(srna, "quad_method", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "custom1");
+ RNA_def_property_enum_items(prop, rna_node_geometry_triangulate_quad_method_items);
+ RNA_def_property_enum_default(prop, GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE);
+ RNA_def_property_ui_text(prop, "Quad Method", "Method for splitting the quads into triangles");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "ngon_method", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "custom2");
+ RNA_def_property_enum_items(prop, rna_node_geometry_triangulate_ngon_method_items);
+ RNA_def_property_enum_default(prop, GEO_NODE_TRIANGULATE_NGON_BEAUTY);
+ RNA_def_property_ui_text(
+ prop, "Polygon Method", "Method for splitting the polygons into triangles");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
/* -------------------------------------------------------------------------- */
static void rna_def_shader_node(BlenderRNA *brna)
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 984ba0ebd4e..af07ba87c84 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -266,7 +266,7 @@ DefNode(FunctionNode, FN_NODE_COMBINE_STRINGS, 0, "COMBINE_STRINGS
DefNode(FunctionNode, FN_NODE_OBJECT_TRANSFORMS, 0, "OBJECT_TRANSFORMS", ObjectTransforms, "Object Transforms", "")
DefNode(FunctionNode, FN_NODE_RANDOM_FLOAT, 0, "RANDOM_FLOAT", RandomFloat, "Random Float", "")
-DefNode(GeometryNode, GEO_NODE_TRIANGULATE, 0, "TRIANGULATE", Triangulate, "Triangulate", "")
+DefNode(GeometryNode, GEO_NODE_TRIANGULATE, def_geo_triangulate, "TRIANGULATE", Triangulate, "Triangulate", "")
DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Split", "")
DefNode(GeometryNode, GEO_NODE_TRANSFORM, 0, "TRANSFORM", Transform, "Transform", "")
DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE, 0, "SUBDIVISION_SURFACE", SubdivisionSurface, "Subdivision Surface", "")
diff --git a/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc b/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc
index be17d29ee73..5bbb7e564a1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc
@@ -14,6 +14,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include "DNA_node_types.h"
+
+#include "RNA_enum_types.h"
+
#include "node_geometry_util.hh"
extern "C" {
@@ -35,6 +39,12 @@ static bNodeSocketTemplate geo_node_triangulate_out[] = {
{-1, ""},
};
+static void geo_triangulate_init(bNodeTree *UNUSED(ntree), bNode *node)
+{
+ node->custom1 = GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE;
+ node->custom2 = GEO_NODE_TRIANGULATE_NGON_BEAUTY;
+}
+
namespace blender::nodes {
static void geo_triangulate_exec(GeoNodeExecParams params)
{
@@ -46,12 +56,17 @@ static void geo_triangulate_exec(GeoNodeExecParams params)
return;
}
+ GeometryNodeTriangulateQuads quad_method = static_cast<GeometryNodeTriangulateQuads>(
+ params.node().custom1);
+ GeometryNodeTriangulateNGons ngon_method = static_cast<GeometryNodeTriangulateNGons>(
+ params.node().custom2);
+
make_geometry_set_mutable(geometry_set);
/* #triangulate_mesh might modify the input mesh currently. */
Mesh *mesh_in = geometry_set->get_mesh_for_write();
if (mesh_in != nullptr) {
- Mesh *mesh_out = triangulate_mesh(mesh_in, 3, 0, min_vertices, 0);
+ Mesh *mesh_out = triangulate_mesh(mesh_in, quad_method, ngon_method, min_vertices, 0);
geometry_set->replace_mesh(mesh_out);
}
@@ -65,6 +80,7 @@ void register_node_type_geo_triangulate()
geo_node_type_base(&ntype, GEO_NODE_TRIANGULATE, "Triangulate", 0, 0);
node_type_socket_templates(&ntype, geo_node_triangulate_in, geo_node_triangulate_out);
+ node_type_init(&ntype, geo_triangulate_init);
ntype.geometry_node_execute = blender::nodes::geo_triangulate_exec;
nodeRegisterType(&ntype);
}
More information about the Bf-blender-cvs
mailing list