[Bf-blender-cvs] [4a7d8f378d6] geometry-nodes-boolean-node: Geometry Nodes: Add operation enum to boolean node

Hans Goudey noreply at git.blender.org
Mon Oct 26 19:57:01 CET 2020


Commit: 4a7d8f378d6aeb716ad6d200b2f31d52047b0c4f
Author: Hans Goudey
Date:   Mon Oct 26 13:56:54 2020 -0500
Branches: geometry-nodes-boolean-node
https://developer.blender.org/rB4a7d8f378d6aeb716ad6d200b2f31d52047b0c4f

Geometry Nodes: Add operation enum to boolean node

===================================================================

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_boolean.cc

===================================================================

diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index b9495519427..5b381bae5dc 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3140,8 +3140,18 @@ static void node_texture_set_butfunc(bNodeType *ntype)
 
 /* ****************** BUTTON CALLBACKS FOR GEOMETRY NODES ***************** */
 
-static void node_geometry_set_butfunc(bNodeType *UNUSED(ntype))
+static void node_geometry_buts_boolean_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
+  uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
+}
+
+static void node_geometry_set_butfunc(bNodeType *ntype)
+{
+  switch (ntype->type) {
+    case GEO_NODE_BOOLEAN:
+      ntype->draw_buttons = node_geometry_buts_boolean_math;
+      break;
+  }
 }
 
 /* ****************** BUTTON CALLBACKS FOR FUNCTION NODES ***************** */
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index c3dbd9f7d30..4a0902913db 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1423,3 +1423,12 @@ typedef enum NodeShaderOutputTarget {
   SHD_OUTPUT_EEVEE = 1,
   SHD_OUTPUT_CYCLES = 2,
 } NodeShaderOutputTarget;
+
+/* Geometry Nodes */
+
+/* Boolean Node */
+typedef enum GeometryNodeBooleanOperation {
+  GEO_NODE_BOOLEAN_INTERSECT = 0,
+  GEO_NODE_BOOLEAN_UNION = 1,
+  GEO_NODE_BOOLEAN_DIFFERENCE = 2,
+} GeometryNodeBooleanOperation;
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 3c69db0efcc..927a2805757 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -368,6 +368,22 @@ static const EnumPropertyItem prop_shader_output_target_items[] = {
     {SHD_OUTPUT_CYCLES, "CYCLES", 0, "Cycles", "Use shaders for Cycles renderer"},
     {0, NULL, 0, NULL, NULL},
 };
+
+static const EnumPropertyItem rna_node_geometry_boolean_method_items[] = {
+    {GEO_NODE_BOOLEAN_INTERSECT,
+     "INTERSECT",
+     0,
+     "Intersect",
+     "Keep the part of the mesh that is common between all operands"},
+    {GEO_NODE_BOOLEAN_UNION, "UNION", 0, "Union", "Combine meshes in an additive way"},
+    {GEO_NODE_BOOLEAN_DIFFERENCE,
+     "DIFFERENCE",
+     0,
+     "Difference",
+     "Combine meshes in a subtractive way"},
+    {0, NULL, 0, NULL, NULL},
+};
+
 #endif
 
 #ifdef RNA_RUNTIME
@@ -8141,6 +8157,20 @@ static void def_tex_bricks(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+/* -- Geometry Nodes --------------------------------------------------------- */
+
+static void def_geo_boolean(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  prop = RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "custom1");
+  RNA_def_property_enum_items(prop, rna_node_geometry_boolean_method_items);
+  RNA_def_property_enum_default(prop, GEO_NODE_BOOLEAN_INTERSECT);
+  RNA_def_property_ui_text(prop, "Operation", "");
+  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 6cff4d03d0c..731c9f99bf1 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -269,7 +269,7 @@ DefNode(FunctionNode, FN_NODE_RANDOM_FLOAT, 0,                  "RANDOM_FLOAT",
 DefNode(GeometryNode, GEO_NODE_TRIANGULATE, 0, "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_BOOLEAN, 0, "BOOLEAN", Boolean, "Boolean", "")
+DefNode(GeometryNode, GEO_NODE_BOOLEAN, def_geo_boolean, "BOOLEAN", Boolean, "Boolean", "")
 
 
 /* undefine macros */
diff --git a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
index 129794f8175..f37b2d6d611 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
@@ -16,13 +16,15 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_alloca.h"
+#include "BLI_math_matrix.h"
+
 #include "DNA_mesh_types.h"
 #include "DNA_modifier_types.h"
 
-#include "BKE_mesh.h"
+#include "RNA_enum_types.h"
 
-#include "BLI_alloca.h"
-#include "BLI_math_matrix.h"
+#include "BKE_mesh.h"
 
 #include "bmesh.h"
 #include "tools/bmesh_boolean.h"
@@ -45,7 +47,7 @@ static int bm_face_isect_pair(BMFace *f, void *UNUSED(user_data))
   return BM_elem_flag_test(f, BM_ELEM_DRAW) ? 1 : 0;
 }
 
-static Mesh *BM_mesh_boolean_calc(Mesh *mesh_a, Mesh *mesh_b, int boolean_mode)
+static Mesh *mesh_boolean_calc(Mesh *mesh_a, Mesh *mesh_b, int boolean_mode)
 {
   const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(mesh_a, mesh_b);
 
@@ -58,40 +60,31 @@ static Mesh *BM_mesh_boolean_calc(Mesh *mesh_a, Mesh *mesh_b, int boolean_mode)
   {
     struct BMeshFromMeshParams bmesh_from_mesh_params = {.calc_face_normal = true};
     BM_mesh_bm_from_me(bm, mesh_a, &bmesh_from_mesh_params);
-
     BM_mesh_bm_from_me(bm, mesh_b, &bmesh_from_mesh_params);
   }
 
   const int looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
   int tottri;
-  BMLoop *(*looptris)[3];
-  looptris = (BMLoop * (*)[3])(MEM_malloc_arrayN(looptris_tot, sizeof(*looptris), __func__));
+  BMLoop *(*looptris)[3] = (BMLoop *
+                            (*)[3])(MEM_malloc_arrayN(looptris_tot, sizeof(*looptris), __func__));
   BM_mesh_calc_tessellation_beauty(bm, looptris, &tottri);
 
-  BMIter iter;
-  int i;
   const int i_faces_end = mesh_a->totpoly;
 
   /* We need face normals because of 'BM_face_split_edgenet'
    * we could calculate on the fly too (before calling split). */
 
-  const short ob_src_totcol = mesh_a->totcol;
-  short *material_remap = BLI_array_alloca(material_remap, ob_src_totcol ? ob_src_totcol : 1);
-
+  int i = 0;
+  BMIter iter;
   BMFace *bm_face;
-  i = 0;
   BM_ITER_MESH (bm_face, &iter, bm, BM_FACES_OF_MESH) {
     normalize_v3(bm_face->no);
 
     /* Temp tag to test which side split faces are from. */
     BM_elem_flag_enable(bm_face, BM_ELEM_DRAW);
 
-    /* Remap material. */
-    if (bm_face->mat_nr < ob_src_totcol) {
-      bm_face->mat_nr = material_remap[bm_face->mat_nr];
-    }
-
-    if (++i == i_faces_end) {
+    i++;
+    if (i == i_faces_end) {
       break;
     }
   }
@@ -101,17 +94,13 @@ static Mesh *BM_mesh_boolean_calc(Mesh *mesh_a, Mesh *mesh_b, int boolean_mode)
   Mesh *result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, mesh_a);
   BM_mesh_free(bm);
   result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
+  MEM_freeN(looptris);
 
   return result;
 }
 
-// Mesh *mesh_boolean_calc(Mesh *mesh_a, Mesh *UNUSED(mesh_b), int UNUSED(boolean_mode))
-// {
-//   return mesh_a;
-// }
-
 namespace blender::nodes {
-static void geo_boolean_exec(bNode *UNUSED(node), GValueByName &inputs, GValueByName &outputs)
+static void geo_boolean_exec(bNode *node, GValueByName &inputs, GValueByName &outputs)
 {
   GeometryPtr geometry_in_a = inputs.extract<GeometryPtr>("Geometry A");
   GeometryPtr geometry_in_b = inputs.extract<GeometryPtr>("Geometry B");
@@ -129,9 +118,16 @@ static void geo_boolean_exec(bNode *UNUSED(node), GValueByName &inputs, GValueBy
     return;
   }
 
+  GeometryNodeBooleanOperation operation = (GeometryNodeBooleanOperation)node->custom1;
+  if (operation < 0 || operation > 2) {
+    BLI_assert(false);
+    outputs.move_in("Geometry", std::move(geometry_out));
+    return;
+  }
+
   geometry_out = GeometryPtr{new Geometry()};
 
-  Mesh *mesh_out = BM_mesh_boolean_calc(mesh_in_a, mesh_in_b, eBooleanModifierOp_Difference);
+  Mesh *mesh_out = mesh_boolean_calc(mesh_in_a, mesh_in_b, operation);
 
   geometry_out->mesh_set_and_transfer_ownership(mesh_out);



More information about the Bf-blender-cvs mailing list