[Bf-blender-cvs] [683b8ca60f3] temp-geometry-nodes-mix-attributes: Geometry Nodes: add Mix Attributes node

Jacques Lucke noreply at git.blender.org
Thu Dec 3 18:02:07 CET 2020


Commit: 683b8ca60f3b00a67c311362ba8814f27baab29c
Author: Jacques Lucke
Date:   Thu Dec 3 18:00:45 2020 +0100
Branches: temp-geometry-nodes-mix-attributes
https://developer.blender.org/rB683b8ca60f3b00a67c311362ba8814f27baab29c

Geometry Nodes: add Mix Attributes node

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

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/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/geometry/nodes/node_geo_mix_attributes.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index b1789776728..0437324a12c 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -488,6 +488,7 @@ geometry_node_categories = [
     GeometryNodeCategory("GEO_ATTRIBUTE", "Attribute", items=[
         NodeItem("GeometryNodeRandomAttribute"),
         NodeItem("GeometryNodeAttributeMath"),
+        NodeItem("GeometryNodeMixAttributes"),
     ]),
     GeometryNodeCategory("GEO_COLOR", "Color", items=[
         NodeItem("ShaderNodeValToRGB"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index a8a94958772..849cbb329f2 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1350,6 +1350,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_RANDOM_ATTRIBUTE 1008
 #define GEO_NODE_ATTRIBUTE_MATH 1009
 #define GEO_NODE_JOIN_GEOMETRY 1010
+#define GEO_NODE_MIX_ATTRIBUTES 1011
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index b564a4c468b..39750f61e68 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -4693,6 +4693,7 @@ static void registerGeometryNodes(void)
   register_node_type_geo_random_attribute();
   register_node_type_geo_attribute_math();
   register_node_type_geo_join_geometry();
+  register_node_type_geo_mix_attributes();
 }
 
 static void registerFunctionNodes(void)
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 84e7a74fab3..fc88a5a2b10 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3182,6 +3182,13 @@ static void node_geometry_buts_attribute_math(uiLayout *layout,
   uiItemR(layout, ptr, "input_type_b", DEFAULT_FLAGS, IFACE_("Type B"), ICON_NONE);
 }
 
+static void node_geometry_buts_mix_attributes(uiLayout *layout,
+                                              bContext *UNUSED(C),
+                                              PointerRNA *ptr)
+{
+  uiItemR(layout, ptr, "blend_type", DEFAULT_FLAGS, "", ICON_NONE);
+}
+
 static void node_geometry_set_butfunc(bNodeType *ntype)
 {
   switch (ntype->type) {
@@ -3200,6 +3207,9 @@ static void node_geometry_set_butfunc(bNodeType *ntype)
     case GEO_NODE_ATTRIBUTE_MATH:
       ntype->draw_buttons = node_geometry_buts_attribute_math;
       break;
+    case GEO_NODE_MIX_ATTRIBUTES:
+      ntype->draw_buttons = node_geometry_buts_mix_attributes;
+      break;
   }
 }
 
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 99ae1b85e0c..4f1ddebccb9 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -8368,6 +8368,18 @@ static void def_geo_attribute_math(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
 }
 
+static void def_geo_mix_attributes(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  prop = RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "custom1");
+  RNA_def_property_enum_items(prop, rna_enum_ramp_blend_items);
+  RNA_def_property_enum_default(prop, MA_RAMP_BLEND);
+  RNA_def_property_ui_text(prop, "Blending Mode", "");
+  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/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index a367f40dca7..6a8ec6624ce 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -143,6 +143,7 @@ set(SRC
   geometry/nodes/node_geo_boolean.cc
   geometry/nodes/node_geo_edge_split.cc
   geometry/nodes/node_geo_join_geometry.cc
+  geometry/nodes/node_geo_mix_attributes.cc
   geometry/nodes/node_geo_object_info.cc
   geometry/nodes/node_geo_subdivision_surface.cc
   geometry/nodes/node_geo_point_distribute.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 0532547375f..0491a7cea74 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -37,6 +37,7 @@ void register_node_type_geo_object_info(void);
 void register_node_type_geo_random_attribute(void);
 void register_node_type_geo_attribute_math(void);
 void register_node_type_geo_join_geometry(void);
+void register_node_type_geo_mix_attributes(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 09e0908140c..a314b85e249 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -277,6 +277,7 @@ DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, 0, "OBJECT_INFO", ObjectInfo, "Objec
 DefNode(GeometryNode, GEO_NODE_RANDOM_ATTRIBUTE, def_geo_random_attribute, "RANDOM_ATTRIBUTE", RandomAttribute, "Random Attribute", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_MATH, def_geo_attribute_math, "ATTRIBUTE_MATH", AttributeMath, "Attribute Math", "")
 DefNode(GeometryNode, GEO_NODE_JOIN_GEOMETRY, 0, "JOIN_GEOMETRY", JoinGeometry, "Join Geometry", "")
+DefNode(GeometryNode, GEO_NODE_MIX_ATTRIBUTES, def_geo_mix_attributes, "MIX_ATTRIBUTES", MixAttributes, "Mix Attributes", "")
 
 /* undefine macros */
 #undef DefNode
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mix_attributes.cc b/source/blender/nodes/geometry/nodes/node_geo_mix_attributes.cc
new file mode 100644
index 00000000000..d51fa618f4e
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mix_attributes.cc
@@ -0,0 +1,175 @@
+/*
+ * 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_material.h"
+
+#include "node_geometry_util.hh"
+
+static bNodeSocketTemplate geo_node_mix_attributes_in[] = {
+    {SOCK_GEOMETRY, N_("Geometry")},
+    {SOCK_STRING, N_("Factor")},
+    {SOCK_STRING, N_("Attribute A")},
+    {SOCK_STRING, N_("Attribute B")},
+    {SOCK_STRING, N_("Result")},
+    {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_mix_attribute_out[] = {
+    {SOCK_GEOMETRY, N_("Geometry")},
+    {-1, ""},
+};
+
+namespace blender::nodes {
+
+static void do_mix_operation_float(const int blend_mode,
+                                   const FloatReadAttribute &factors,
+                                   const FloatReadAttribute &inputs_a,
+                                   const FloatReadAttribute &inputs_b,
+                                   FloatWriteAttribute &results)
+{
+  const int size = results.size();
+  for (const int i : IndexRange(size)) {
+    const float factor = factors[i];
+    float3 a{inputs_a[i]};
+    const float3 b{inputs_b[i]};
+    ramp_blend(blend_mode, a, factor, b);
+    const float result = a.length();
+    results.set(i, result);
+  }
+}
+
+static void do_mix_operation_float3(const int blend_mode,
+                                    const FloatReadAttribute &factors,
+                                    const Float3ReadAttribute &inputs_a,
+                                    const Float3ReadAttribute &inputs_b,
+                                    Float3WriteAttribute &results)
+{
+  const int size = results.size();
+  for (const int i : IndexRange(size)) {
+    const float factor = factors[i];
+    float3 a = inputs_a[i];
+    const float3 b = inputs_b[i];
+    ramp_blend(blend_mode, a, factor, b);
+    results.set(i, a);
+  }
+}
+
+static void do_mix_operation_color4f(const int blend_mode,
+                                     const FloatReadAttribute &factors,
+                                     const Color4fReadAttribute &inputs_a,
+                                     const Color4fReadAttribute &inputs_b,
+                                     Color4fWriteAttribute &results)
+{
+  const int size = results.size();
+  for (const int i : IndexRange(size)) {
+    const float factor = factors[i];
+    Color4f a = inputs_a[i];
+    const Color4f b = inputs_b[i];
+    ramp_blend(blend_mode, a, factor, b);
+    results.set(i, a);
+  }
+}
+
+static void mix_attributes_calc(GeometryComponent &component, const GeoNodeExecParams &params)
+{
+  const bNode &node = params.node();
+  const int blend_mode = node.custom1;
+
+  const std::string factor_name = params.get_input<std::string>("Factor");
+  const std::string attribute_a_name = params.get_input<std::string>("Attribute A");
+  const std::string attribute_b_name = params.get_input<std::string>("Attribute B");
+  const std::string result_name = params.get_input<std::string>("Result");
+
+  CustomDataType result_type = CD_PROP_COLOR;
+  AttributeDomain result_domain = ATTR_DOMAIN_POINT;
+
+  /* Use type and domain from the result attribute, if it exists already. */
+  const ReadAttributePtr result_attribute_read = component.attribute_try_get_for_read(result_name);
+  if (result_attribute_read) {
+    result_type = result_attribute_read->custom_data_type();
+    result_domain = result_attribute_read->domain();
+  }
+
+  WriteAttributePtr attribute_result = component.attribute_try_ensure_for_write(
+      result_name, result_domain, result_type);
+  if (!attribute_result) {
+    return;
+  }
+
+  FloatReadAttribute attribute_factor = component.attribute_get_for_read<float>(
+      factor_name, result_domain, 0.5f);
+  ReadAttributePtr attribute_a =

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list