[Bf-blender-cvs] [1189582e399] builtin-simulation-nodes: add boolean math node ui

Jacques Lucke noreply at git.blender.org
Mon Mar 30 12:52:18 CEST 2020


Commit: 1189582e399e3a3c1e11e84024c254724e7f95cd
Author: Jacques Lucke
Date:   Mon Mar 30 12:51:46 2020 +0200
Branches: builtin-simulation-nodes
https://developer.blender.org/rB1189582e399e3a3c1e11e84024c254724e7f95cd

add boolean math node ui

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.c
M	source/blender/editors/space_node/drawnode.c
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_function.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/function/nodes/node_fn_boolean_math.cc
M	source/blender/nodes/intern/node_util.c
M	source/blender/nodes/intern/node_util.h

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index ef0e4864169..eaa2da8611f 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -525,6 +525,7 @@ simulation_node_categories = [
         NodeItem("FunctionNodeSeparateHSV"),
         NodeItem("FunctionNodeFloatMath"),
         NodeItem("FunctionNodeVectorMath"),
+        NodeItem("FunctionNodeBooleanMath"),
     ]),
     FunctionNodeCategory("SURFACE", "Surface", items=[
         NodeItem("FunctionNodeClosestSurface"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 6e102ca37c7..52f57d4f899 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1026,6 +1026,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree,
 #define FN_NODE_SURFACE_POSITION 1110
 #define FN_NODE_SURFACE_WEIGHT 1111
 #define FN_NODE_CLOSEST_SURFACE 1112
+#define FN_NODE_BOOLEAN_MATH 1113
 
 /* custom defines options for Material node */
 // #define SH_NODE_MAT_DIFF 1
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index e365294f828..a47461fe143 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -4238,6 +4238,7 @@ static void registerFunctionNodes(void)
   register_node_type_fn_surface_normal();
   register_node_type_fn_surface_position();
   register_node_type_fn_surface_weight();
+  register_node_type_fn_boolean_math();
 }
 
 void init_nodesystem(void)
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index f21386416c5..99afeac20f6 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3169,6 +3169,11 @@ static void node_function_buts_vector_math(uiLayout *layout, bContext *UNUSED(C)
   uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
 }
 
+static void node_function_buts_boolean_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+  uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
+}
+
 static void node_function_set_butfunc(bNodeType *ntype)
 {
   switch (ntype->type) {
@@ -3178,6 +3183,9 @@ static void node_function_set_butfunc(bNodeType *ntype)
     case FN_NODE_VECTOR_MATH:
       ntype->draw_buttons = node_function_buts_vector_math;
       break;
+    case FN_NODE_BOOLEAN_MATH:
+      ntype->draw_buttons = node_function_buts_boolean_math;
+      break;
   }
 }
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index a7c08269697..5dece86f8c9 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1309,6 +1309,12 @@ enum {
   NODE_VECTOR_MATH_TANGENT = 23,
 };
 
+enum {
+  NODE_BOOLEAN_MATH_AND = 0,
+  NODE_BOOLEAN_MATH_OR = 1,
+  NODE_BOOLEAN_MATH_NOT = 2,
+};
+
 /* Clamp node types. */
 enum {
   NODE_CLAMP_MINMAX = 0,
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index fef98f9da4b..b9f28731723 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -191,6 +191,7 @@ extern const EnumPropertyItem rna_enum_node_socket_in_out_items[];
 extern const EnumPropertyItem rna_enum_node_math_items[];
 extern const EnumPropertyItem rna_enum_mapping_type_items[];
 extern const EnumPropertyItem rna_enum_node_vec_math_items[];
+extern const EnumPropertyItem rna_enum_node_boolean_math_items[];
 extern const EnumPropertyItem rna_enum_node_filter_items[];
 extern const EnumPropertyItem rna_enum_node_map_range_items[];
 extern const EnumPropertyItem rna_enum_node_clamp_items[];
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 4c54cf8c7ad..f6758c171af 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -263,6 +263,13 @@ const EnumPropertyItem rna_enum_node_vec_math_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+const EnumPropertyItem rna_enum_node_boolean_math_items[] = {
+    {NODE_BOOLEAN_MATH_AND, "AND", 0, "And", "Outputs true only when both inputs are true"},
+    {NODE_BOOLEAN_MATH_OR, "OR", 0, "Or", "Outputs or when at least one of the inputs is true"},
+    {NODE_BOOLEAN_MATH_NOT, "NOT", 0, "Not", "Outputs the opposite of the input"},
+    {0, NULL, 0, NULL, NULL},
+};
+
 const EnumPropertyItem rna_enum_node_map_range_items[] = {
     {NODE_MAP_RANGE_LINEAR,
      "LINEAR",
@@ -3685,6 +3692,15 @@ static void rna_SimulationNode_socket_update(Main *bmain, Scene *scene, PointerR
   rna_Node_update(bmain, scene, ptr);
 }
 
+static void rna_FunctionNode_socket_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+  bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
+  bNode *node = (bNode *)ptr->data;
+
+  nodeUpdate(ntree, node);
+  rna_Node_update(bmain, scene, ptr);
+}
+
 static void rna_CompositorNodeScale_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
   bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
@@ -4128,7 +4144,18 @@ static void def_vector_math(StructRNA *srna)
   RNA_def_property_enum_sdna(prop, NULL, "custom1");
   RNA_def_property_enum_items(prop, rna_enum_node_vec_math_items);
   RNA_def_property_ui_text(prop, "Operation", "");
-  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_ShaderNode_socket_update");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_FunctionNode_socket_update");
+}
+
+static void def_boolean_math(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_enum_node_boolean_math_items);
+  RNA_def_property_ui_text(prop, "Operation", "");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_FunctionNode_socket_update");
 }
 
 static void def_rgb_curve(StructRNA *srna)
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 5311281d678..36a0a0d7fc2 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -129,6 +129,7 @@ set(SRC
   composite/node_composite_tree.c
   composite/node_composite_util.c
 
+  function/nodes/node_fn_boolean_math.cc
   function/nodes/node_fn_closest_surface.cc
   function/nodes/node_fn_combine_hsv.cc
   function/nodes/node_fn_combine_rgb.cc
diff --git a/source/blender/nodes/NOD_function.h b/source/blender/nodes/NOD_function.h
index 288f0cbe681..3b49b6afac1 100644
--- a/source/blender/nodes/NOD_function.h
+++ b/source/blender/nodes/NOD_function.h
@@ -18,6 +18,7 @@ void register_node_type_fn_surface_color(void);
 void register_node_type_fn_surface_normal(void);
 void register_node_type_fn_surface_position(void);
 void register_node_type_fn_surface_weight(void);
+void register_node_type_fn_boolean_math(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index e934d61671a..099b900eed5 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -284,8 +284,9 @@ DefNode(FunctionNode, FN_NODE_SURFACE_COLOR, 0, "SURFACE_COLOR", SurfaceColor, "
 DefNode(FunctionNode, FN_NODE_SURFACE_NORMAL, 0, "SURFACE_NORMAL", SurfaceNormal, "Surface Normal", "")
 DefNode(FunctionNode, FN_NODE_SURFACE_POSITION, 0, "SURFACE_POSITION", SurfacePosition, "Surface Position", "")
 DefNode(FunctionNode, FN_NODE_SURFACE_WEIGHT, 0, "SURFACE_WEIGHT", SurfaceWeight, "Surface Weight", "")
+DefNode(FunctionNode, FN_NODE_BOOLEAN_MATH, def_boolean_math, "BOOLEAN_MATH", BooleanMath, "Boolean Math", "");
 
 /* undefine macros */
 #undef DefNode
 
-    /* clang-format on */
+/* clang-format on */
diff --git a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc
new file mode 100644
index 00000000000..f63141b6164
--- /dev/null
+++ b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc
@@ -0,0 +1,23 @@
+#include "node_fn_util.h"
+
+static bNodeSocketTemplate fn_node_boolean_math_in[] = {
+    {SOCK_BOOLEAN, N_("Boolean")},
+    {SOCK_BOOLEAN, N_("Boolean")},
+    {-1, ""},
+};
+
+static bNodeSocketTemplate fn_node_boolean_math_out[] = {
+    {SOCK_BOOLEAN, N_("Boolean")},
+    {-1, ""},
+};
+
+void register_node_type_fn_boolean_math()
+{
+  static bNodeType ntype;
+
+  fn_node_type_base(&ntype, FN_NODE_BOOLEAN_MATH, "Boolean Math", 0, 0);
+  node_type_socket_templates(&ntype, fn_node_boolean_math_in, fn_node_boolean_math_out);
+  node_type_label(&ntype, node_boolean_math_label);
+  node_type_update(&ntype, node_boolean_math_update);
+  nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c
index 2fbe1cd3b5d..c66d61f8df6 100644
--- a/source/blender/nodes/intern/node_util.c
+++ b/source/blender/nodes/intern/node_util.c
@@ -225,6 +225,14 @@ void node_vector_math_update(bNodeTree *UNUSED(ntree), bNode *node)
   }
 }
 
+void node_boolean_math_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+  bNodeSocket *sockB = BLI_findlink(&node->inputs, 1);
+
+  nodeSetSocketAvailability(sockB,
+                            ELEM(node->custom1, NODE_BOOLEAN_MATH_AND, NODE_BOOLEAN_MATH_OR));
+}
+
 /**** Labels ****/
 
 void node_blend_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
@@ -274,6 +282,16 @@ void node_filter_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int m
   BLI_strncpy(label, IFACE_(name), maxlen);
 }
 
+void node_boolean_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
+{
+  const char *name;
+  bool enum_label = RNA_enum_name(rna_enum_node_boolean_math_items, node->custom1, &name);
+  if (!enum_label) {
+    name = "Unknown";
+  }
+  BLI_strncpy(label, IFACE_(name), maxlen);
+}
+
 /*** Link Insertion ***/
 
 /* test if two sockets are interchangeable */
diff --git a/source/blender/nodes/intern/node_util.h b/source/blender/nodes/intern/node_util.h
index 5432438849c..96578801530 100644
--- a/source/blender/n

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list