[Bf-blender-cvs] [4e78bb3f0c8] temp-geometry-nodes-fields-prototype: Draw constant input sockets that don't support fields differently

Hans Goudey noreply at git.blender.org
Fri Aug 6 23:23:43 CEST 2021


Commit: 4e78bb3f0c8cec821f5e134565ac3518c080bce8
Author: Hans Goudey
Date:   Fri Aug 6 16:23:34 2021 -0500
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rB4e78bb3f0c8cec821f5e134565ac3518c080bce8

Draw constant input sockets that don't support fields differently

This is a really incomplete way to do this (it doesn't propogate to
linked nodes, and I haven't though about outputs), but it still provides
a very nice benefit to readability.

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

M	source/blender/editors/space_node/node_draw.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_store_anonymous.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_set_handles.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
M	source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
M	source/blender/nodes/geometry/nodes/node_geo_extrude.cc
M	source/blender/nodes/geometry/nodes/node_geo_material_assign.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc
M	source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
M	source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
M	source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
M	source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
M	source/blender/nodes/geometry/nodes/node_geo_raycast.cc
M	source/blender/nodes/geometry/nodes/node_geo_switch.cc

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

diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 1c14074840c..2850ffa2320 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -768,14 +768,14 @@ static void node_socket_draw(const bNodeSocket *sock,
   immVertex2f(pos_id, locx, locy);
 }
 
-static void node_socket_draw_multi_input(const float color[4],
-                                         const float color_outline[4],
-                                         const float width,
-                                         const float height,
-                                         const int locx,
-                                         const int locy)
+static void node_socket_draw_rounded_rectangle(const float color[4],
+                                               const float color_outline[4],
+                                               const float width,
+                                               const float height,
+                                               const float locx,
+                                               const float locy,
+                                               const float outline_width)
 {
-  const float outline_width = 1.0f;
   /* UI_draw_roundbox draws the outline on the outer side, so compensate for the outline width. */
   const rctf rect = {
       locx - width + outline_width * 0.5f,
@@ -789,6 +789,36 @@ static void node_socket_draw_multi_input(const float color[4],
       &rect, color, nullptr, 1.0f, color_outline, outline_width, width - outline_width * 0.5f);
 }
 
+static bool use_special_non_field_socket_drawing(const bNodeTree *node_tree,
+                                                 const bNode *node,
+                                                 const bNodeSocket *socket)
+{
+  if (node_tree->type != NTREE_GEOMETRY) {
+    return false;
+  }
+  if (ELEM(socket->type,
+           SOCK_MATERIAL,
+           SOCK_GEOMETRY,
+           SOCK_TEXTURE,
+           SOCK_COLLECTION,
+           SOCK_OBJECT,
+           SOCK_IMAGE,
+           SOCK_STRING)) {
+    return false;
+  }
+  if (socket->flag & SOCK_IS_FIELD) {
+    return false;
+  }
+  if (socket->in_out == SOCK_OUT) {
+    return false;
+  }
+  if (node->typeinfo->expand_in_mf_network) {
+    /* Wow, that's hacky. Don't use vertical bar for function nodes. */
+    return false;
+  }
+  return true;
+}
+
 static const float virtual_node_socket_outline_color[4] = {0.5, 0.5, 0.5, 1.0};
 
 static void node_socket_outline_color_get(const bool selected,
@@ -1026,24 +1056,27 @@ static void node_socket_draw_nested(const bContext *C,
   node_socket_color_get((bContext *)C, ntree, node_ptr, sock, color);
   node_socket_outline_color_get(selected, sock->type, outline_color);
 
-  node_socket_draw(sock,
-                   color,
-                   outline_color,
-                   size,
-                   sock->locx,
-                   sock->locy,
-                   pos_id,
-                   col_id,
-                   shape_id,
-                   size_id,
-                   outline_col_id);
+  bNode *node = (bNode *)node_ptr->data;
+
+  if (!use_special_non_field_socket_drawing(ntree, node, sock)) {
+    node_socket_draw(sock,
+                     color,
+                     outline_color,
+                     size,
+                     sock->locx,
+                     sock->locy,
+                     pos_id,
+                     col_id,
+                     shape_id,
+                     size_id,
+                     outline_col_id);
+  }
 
   if (ntree->type != NTREE_GEOMETRY) {
     /* Only geometry nodes has socket value tooltips currently. */
     return;
   }
 
-  bNode *node = (bNode *)node_ptr->data;
   uiBlock *block = node->block;
 
   /* Ideally sockets themselves should be buttons, but they aren't currently. So add an invisible
@@ -1403,20 +1436,28 @@ void node_draw_sockets(const View2D *v2d,
     if (nodeSocketIsHidden(socket)) {
       continue;
     }
-    if (!(socket->flag & SOCK_MULTI_INPUT)) {
-      continue;
-    }
-
-    const bool is_node_hidden = (node->flag & NODE_HIDDEN);
-    const float width = NODE_SOCKSIZE;
-    float height = is_node_hidden ? width : node_socket_calculate_height(socket) - width;
-
     float color[4];
     float outline_color[4];
     node_socket_color_get((bContext *)C, ntree, &node_ptr, socket, color);
     node_socket_outline_color_get(selected, socket->type, outline_color);
 
-    node_socket_draw_multi_input(color, outline_color, width, height, socket->locx, socket->locy);
+    if (socket->flag & SOCK_MULTI_INPUT) {
+      const bool is_node_hidden = (node->flag & NODE_HIDDEN);
+      const float width = NODE_SOCKSIZE;
+      float height = is_node_hidden ? width : node_socket_calculate_height(socket) - width;
+
+      node_socket_draw_rounded_rectangle(
+          color, outline_color, width, height, socket->locx, socket->locy, 1.0f);
+    }
+    else if (use_special_non_field_socket_drawing(ntree, node, socket)) {
+      node_socket_draw_rounded_rectangle(color,
+                                         outline_color,
+                                         NODE_SOCKSIZE * 0.6f,
+                                         NODE_SOCKSIZE * 1.3,
+                                         socket->locx - 0.8f,
+                                         socket->locy,
+                                         0.75f);
+    }
   }
 }
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index ad216f1e43f..0b2d6735cd1 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -178,6 +178,7 @@ typedef enum eNodeSocketDisplayShape {
   SOCK_DISPLAY_SHAPE_CIRCLE_DOT = 3,
   SOCK_DISPLAY_SHAPE_SQUARE_DOT = 4,
   SOCK_DISPLAY_SHAPE_DIAMOND_DOT = 5,
+  SOCK_DISPLAY_SHAPE_TALL_RECTANGLE = 6,
 } eNodeSocketDisplayShape;
 
 /* Socket side (input/output). */
@@ -214,6 +215,11 @@ typedef enum eNodeSocketFlag {
    * type is obvious and the name takes up too much space.
    */
   SOCK_HIDE_LABEL = (1 << 12),
+  /**
+   * For geometry nodes, the result is not a single value, but evaluated as a callback and
+   * potentially many different values.
+   */
+  SOCK_IS_FIELD = (1 << 13),
 } eNodeSocketFlag;
 
 /* TODO: Limit data in bNode to what we want to see saved. */
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
index 66b55fef8c6..b2893e9a237 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
@@ -22,10 +22,28 @@
 static bNodeSocketTemplate geo_node_attribute_fill_in[] = {
     {SOCK_GEOMETRY, N_("Geometry")},
     {SOCK_STRING, N_("Attribute")},
-    {SOCK_VECTOR, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
-    {SOCK_FLOAT, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
-    {SOCK_RGBA, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
-    {SOCK_BOOLEAN, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
+    {SOCK_VECTOR,
+     N_("Value"),
+     0.0f,
+     0.0f,
+     0.0f,
+     0.0f,
+     -FLT_MAX,
+     FLT_MAX,
+     PROP_NONE,
+     SOCK_IS_FIELD},
+    {SOCK_FLOAT, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_NONE, SOCK_IS_FIELD},
+    {SOCK_RGBA, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_NONE, SOCK_IS_FIELD},
+    {SOCK_BOOLEAN,
+     N_("Value"),
+     0.0f,
+     0.0f,
+     0.0f,
+     0.0f,
+     -FLT_MAX,
+     FLT_MAX,
+     PROP_NONE,
+     SOCK_IS_FIELD},
     {SOCK_INT, N_("Value"), 0, 0, 0, 0, -10000000.0f, 10000000.0f},
     {-1, ""},
 };
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_store_anonymous.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_store_anonymous.cc
index dd190c065c6..c8d76a6b79c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_store_anonymous.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_store_anonymous.cc
@@ -21,11 +21,29 @@
 
 static bNodeSocketTemplate geo_node_attribute_store_anonymous_in[] = {
     {SOCK_GEOMETRY, N_("Geometry")},
-    {SOCK_VECTOR, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
-    {SOCK_FLOAT, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
-    {SOCK_RGBA, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
-    {SOCK_BOOLEAN, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
-    {SOCK_INT, N_("Value"), 0, 0, 0, 0, -10000000.0f, 10000000.0f},
+    {SOCK_VECTOR,
+     N_("Value"),
+     0.0f,
+     0.0f,
+     0.0f,
+     0.0f,
+     -FLT_MAX,
+     FLT_MAX,
+     PROP_NONE,
+     SOCK_IS_FIELD},
+    {SOCK_FLOAT, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_NONE, SOCK_IS_FIELD},
+    {SOCK_RGBA, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_NONE, SOCK_IS_FIELD},
+    {SOCK_BOOLEAN,
+     N_("Value"),
+     0.0f,
+     0.0f,
+     0.0f,
+     0.0f,
+     -FLT_MAX,
+     FLT_MAX,
+     PROP_NONE,
+     SOCK_IS_FIELD},
+    {SOCK_INT, N_("Value"), 0, 0, 0, 0, -10000000.0f, 10000000.0f, PROP_NONE, SOCK_IS_FIELD},
     {-1, ""},
 };
 
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_set_handles.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_set_handles.cc
index d5171f99695..8cf9392f8af 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_set_handles.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_set_handles.cc
@@ -23,7 +23,7 @@
 
 static bNodeSocketTemplate geo_node_curve_set_handles_in[] = {
     {SOCK_GEOMETRY, N_("Curve")},
-    {SOCK_BOOLEAN, N_("Selection"), 1, 0, 0, 0, 0, 0, PROP_NONE, SOCK_HIDE_VALUE},
+    {SOCK_BOOLEAN, N_("Selection"), 1, 0, 0, 0, 0, 0, PROP_NONE, SOCK_HIDE_VALUE | SOCK_IS_FIELD},
     {-1, ""},
 };
 
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
index 7d432f5bb24..a38a3fa948e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
+++ b/source/blender/nodes/geometry/nodes/no

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list