[Bf-blender-cvs] [c1e587bc46c] temp-attribute-processor: add initial attribute group

Jacques Lucke noreply at git.blender.org
Fri May 28 13:43:47 CEST 2021


Commit: c1e587bc46c453b911c59e2d9effd632dc6d69cf
Author: Jacques Lucke
Date:   Fri May 28 11:28:05 2021 +0200
Branches: temp-attribute-processor
https://developer.blender.org/rBc1e587bc46c453b911c59e2d9effd632dc6d69cf

add initial attribute group

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

M	source/blender/blenkernel/intern/node.cc
M	source/blender/editors/space_node/node_edit.c
M	source/blender/editors/space_node/node_group.c
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
A	source/blender/nodes/geometry/nodes/node_attribute_group.cc

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

diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index d6edf85f53e..ba1ee929a7b 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5059,6 +5059,7 @@ static void registerTextureNodes()
 static void registerGeometryNodes()
 {
   register_node_type_geo_group();
+  register_node_type_attribute_group();
 
   register_node_type_geo_align_rotation_to_vector();
   register_node_type_geo_attribute_clamp();
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index a3b8f2f0a28..e16b65c862d 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -468,6 +468,7 @@ bool ED_node_is_geometry(struct SpaceNode *snode)
 
 bool ED_node_is_attribute(struct SpaceNode *snode)
 {
+  /* TODO: Better support for different tree types in the group hierarchy. */
   return STREQ(snode->tree_idname, ntreeType_Attribute->idname);
 }
 
diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c
index 29c2ed8b8dc..39bc38fbf78 100644
--- a/source/blender/editors/space_node/node_group.c
+++ b/source/blender/editors/space_node/node_group.c
@@ -124,6 +124,9 @@ const char *node_group_idname(bContext *C)
   if (ED_node_is_geometry(snode)) {
     return "GeometryNodeGroup";
   }
+  if (ED_node_is_attribute(snode)) {
+    return "AttributeNodeGroup";
+  }
 
   return "";
 }
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 69efc43ae1a..a79c818fa39 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -871,6 +871,20 @@ static const EnumPropertyItem *rna_node_static_type_itemf(bContext *UNUSED(C),
 #  undef DefNode
   }
 
+  if (RNA_struct_is_a(ptr->type, &RNA_AttributeNode)) {
+#  define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
+    if (STREQ(#Category, "AttributeNode")) { \
+      tmp.value = ID; \
+      tmp.identifier = EnumName; \
+      tmp.name = UIName; \
+      tmp.description = UIDesc; \
+      tmp.icon = ICON_NONE; \
+      RNA_enum_item_add(&item, &totitem, &tmp); \
+    }
+#  include "../../nodes/NOD_static_types.h"
+#  undef DefNode
+  }
+
   if (RNA_struct_is_a(ptr->type, &RNA_FunctionNode)) {
 #  define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
     if (STREQ(#Category, "FunctionNode")) { \
@@ -2286,6 +2300,28 @@ static StructRNA *rna_GeometryNode_register(Main *bmain,
   return nt->rna_ext.srna;
 }
 
+static StructRNA *rna_AttributeNode_register(Main *bmain,
+                                             ReportList *reports,
+                                             void *data,
+                                             const char *identifier,
+                                             StructValidateFunc validate,
+                                             StructCallbackFunc call,
+                                             StructFreeFunc free)
+{
+  bNodeType *nt = rna_Node_register_base(
+      bmain, reports, &RNA_AttributeNode, data, identifier, validate, call, free);
+  if (!nt) {
+    return NULL;
+  }
+
+  nodeRegisterType(nt);
+
+  /* update while blender is running */
+  WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
+
+  return nt->rna_ext.srna;
+}
+
 static StructRNA *rna_FunctionNode_register(Main *bmain,
                                             ReportList *reports,
                                             void *data,
@@ -3418,7 +3454,32 @@ static StructRNA *rna_GeometryNodeCustomGroup_register(Main *bmain,
   return nt->rna_ext.srna;
 }
 
-void register_node_type_geo_custom_group(bNodeType *ntype);
+static StructRNA *rna_AttributeNodeCustomGroup_register(Main *bmain,
+                                                        ReportList *reports,
+                                                        void *data,
+                                                        const char *identifier,
+                                                        StructValidateFunc validate,
+                                                        StructCallbackFunc call,
+                                                        StructFreeFunc free)
+{
+  bNodeType *nt = rna_Node_register_base(
+      bmain, reports, &RNA_AttributeNodeCustomGroup, data, identifier, validate, call, free);
+
+  if (!nt) {
+    return NULL;
+  }
+
+  nt->group_update_func = node_group_update;
+  nt->type = NODE_CUSTOM_GROUP;
+
+  register_node_type_attribute_custom_group(nt);
+
+  nodeRegisterType(nt);
+
+  WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
+
+  return nt->rna_ext.srna;
+}
 
 static StructRNA *rna_ShaderNodeCustomGroup_register(Main *bmain,
                                                      ReportList *reports,
@@ -10047,6 +10108,16 @@ static void rna_def_geometry_node(BlenderRNA *brna)
   RNA_def_struct_register_funcs(srna, "rna_GeometryNode_register", "rna_Node_unregister", NULL);
 }
 
+static void rna_def_attribute_node(BlenderRNA *brna)
+{
+  StructRNA *srna;
+
+  srna = RNA_def_struct(brna, "AttributeNode", "NodeInternal");
+  RNA_def_struct_ui_text(srna, "Attribute Node", "");
+  RNA_def_struct_sdna(srna, "bNode");
+  RNA_def_struct_register_funcs(srna, "rna_AttributeNode_register", "rna_Node_unregister", NULL);
+}
+
 static void rna_def_function_node(BlenderRNA *brna)
 {
   StructRNA *srna;
@@ -11983,6 +12054,7 @@ void RNA_def_nodetree(BlenderRNA *brna)
   rna_def_compositor_node(brna);
   rna_def_texture_node(brna);
   rna_def_geometry_node(brna);
+  rna_def_attribute_node(brna);
   rna_def_function_node(brna);
 
   rna_def_nodetree(brna);
@@ -12020,6 +12092,7 @@ void RNA_def_nodetree(BlenderRNA *brna)
   define_specific_node(brna, "CompositorNodeGroup", "CompositorNode", "Group", "", def_group);
   define_specific_node(brna, "TextureNodeGroup", "TextureNode", "Group", "", def_group);
   define_specific_node(brna, "GeometryNodeGroup", "GeometryNode", "Group", "", def_group);
+  define_specific_node(brna, "AttributeNodeGroup", "AttributeNode", "Group", "", def_group);
   def_custom_group(brna,
                    "ShaderNodeCustomGroup",
                    "ShaderNode",
@@ -12044,6 +12117,12 @@ void RNA_def_nodetree(BlenderRNA *brna)
                    "Geometry Custom Group",
                    "Custom Geometry Group Node for Python nodes",
                    "rna_GeometryNodeCustomGroup_register");
+  def_custom_group(brna,
+                   "AttributeNodeCustomGroup",
+                   "AttributeNode",
+                   "Attribute Custom Group",
+                   "Custom Attribute Group for Python nodes",
+                   "rna_AttributeNodeCustomGroup_register");
 
   /* special socket types */
   rna_def_cmp_output_file_slot_file(brna);
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 1912e35ad1a..c5f384f869f 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -139,6 +139,7 @@ set(SRC
   function/nodes/node_fn_random_float.cc
   function/node_function_util.cc
 
+  geometry/nodes/node_attribute_group.cc
   geometry/nodes/node_geo_align_rotation_to_vector.cc
   geometry/nodes/node_geo_attribute_clamp.cc
   geometry/nodes/node_geo_attribute_color_ramp.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 7b72f25f470..6068e7ca9b5 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -31,6 +31,9 @@ void register_node_tree_type_attr(void);
 void register_node_type_geo_group(void);
 void register_node_type_geo_custom_group(bNodeType *ntype);
 
+void register_node_type_attribute_group(void);
+void register_node_type_attribute_custom_group(bNodeType *ntype);
+
 void register_node_type_geo_align_rotation_to_vector(void);
 void register_node_type_geo_attribute_clamp(void);
 void register_node_type_geo_attribute_color_ramp(void);
diff --git a/source/blender/nodes/geometry/nodes/node_attribute_group.cc b/source/blender/nodes/geometry/nodes/node_attribute_group.cc
new file mode 100644
index 00000000000..2893fe33cc7
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_attribute_group.cc
@@ -0,0 +1,59 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "BKE_node.h"
+
+#include "NOD_geometry.h"
+
+#include "NOD_common.h"
+#include "node_common.h"
+#include "node_geometry_util.hh"
+
+void register_node_type_attribute_group(void)
+{
+  static bNodeType ntype;
+
+  node_type_base_custom(&ntype, "AttributeNodeGroup", "Group", NODE_CLASS_GROUP, 0);
+  ntype.type = NODE_GROUP;
+  ntype.poll = geo_node_poll_default;
+  ntype.poll_instance = node_group_poll_instance;
+  ntype.insert_link = node_insert_link_default;
+  ntype.update_internal_links = node_update_internal_links_default;
+  ntype.rna_ext.srna = RNA_struct_find("AttributeNodeGroup");
+  BLI_assert(ntype.rna_ext.srna != nullptr);
+  RNA_struct_blender_type_set(ntype.rna_ext.srna, &ntype);
+
+  node_type_socket_templates(&ntype, nullptr, nullptr);
+  node_type_size(&ntype, 140, 60, 400);
+  node_type_label(&ntype, node_group_label);
+  node_type_group_update(&ntype, node_group_update);
+
+  nodeRegisterType(&ntype);
+}
+
+void register_node_type_attribute_custom_group(bNodeType *ntype)
+{
+  /* These methods can be overridden but need a default implementation otherwise. */
+  if (ntype->poll == n

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list