[Bf-blender-cvs] [32f101c6038] temp-geometry-nodes-fields: add initial Attribute Freeze node

Jacques Lucke noreply at git.blender.org
Fri Sep 3 11:59:04 CEST 2021


Commit: 32f101c6038b83256fc505b5f06018296f4fe446
Author: Jacques Lucke
Date:   Fri Sep 3 11:55:22 2021 +0200
Branches: temp-geometry-nodes-fields
https://developer.blender.org/rB32f101c6038b83256fc505b5f06018296f4fe446

add initial Attribute Freeze node

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_anonymous_attribute.hh
M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/node.cc
M	source/blender/functions/FN_field.hh
M	source/blender/makesdna/DNA_node_types.h
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_attribute_freeze.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 18e21e22102..4e952c7d0a9 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -482,6 +482,7 @@ geometry_node_categories = [
         NodeItem("GeometryNodeAttributeConvert"),
         NodeItem("GeometryNodeAttributeCurveMap"),
         NodeItem("GeometryNodeAttributeFill"),
+        NodeItem("GeometryNodeAttributeFreeze"),
         NodeItem("GeometryNodeAttributeMix"),
         NodeItem("GeometryNodeAttributeProximity"),
         NodeItem("GeometryNodeAttributeColorRamp"),
diff --git a/source/blender/blenkernel/BKE_anonymous_attribute.hh b/source/blender/blenkernel/BKE_anonymous_attribute.hh
index ee7aaa2d4d5..444ba9b0fbf 100644
--- a/source/blender/blenkernel/BKE_anonymous_attribute.hh
+++ b/source/blender/blenkernel/BKE_anonymous_attribute.hh
@@ -30,6 +30,8 @@ template<bool IsStrongReference> class OwnedAnonymousAttributeID {
  private:
   const AnonymousAttributeID *data_ = nullptr;
 
+  template<bool OtherIsStrongReference> friend class OwnedAnonymousAttributeID;
+
  public:
   OwnedAnonymousAttributeID() = default;
 
@@ -117,7 +119,7 @@ template<bool IsStrongReference> class OwnedAnonymousAttributeID {
     return extracted_data;
   }
 
-  const AnonymousAttributeID *get()
+  const AnonymousAttributeID *get() const
   {
     return data_;
   }
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index a7e04a814b1..c1ce0563769 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -626,4 +626,24 @@ class AttributeContextFieldSource : public fn::ContextFieldSource {
   bool is_equal_to(const fn::FieldSource &other) const override;
 };
 
+class AnonymousAttributeContextFieldSource : public fn::ContextFieldSource {
+ private:
+  StrongAnonymousAttributeID anonymous_id_;
+
+ public:
+  AnonymousAttributeContextFieldSource(StrongAnonymousAttributeID anonymous_id,
+                                       const CPPType &type)
+      : fn::ContextFieldSource(type, anonymous_id.debug_name()),
+        anonymous_id_(std::move(anonymous_id))
+  {
+  }
+
+  const GVArray *try_get_varray_for_context(const fn::FieldContext &context,
+                                            IndexMask mask,
+                                            ResourceScope &scope) const override;
+
+  uint64_t hash() const override;
+  bool is_equal_to(const fn::FieldSource &other) const override;
+};
+
 }  // namespace blender::bke
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 6b9a0134ce7..ce7e77805a9 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1487,6 +1487,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_SET_POSITION 1077
 #define GEO_NODE_INPUT_INDEX 1078
 #define GEO_NODE_INPUT_NORMAL 1079
+#define GEO_NODE_ATTRIBUTE_FREEZE 1080
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 9d07afc2e63..e6c50417153 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -1331,4 +1331,33 @@ bool AttributeContextFieldSource::is_equal_to(const fn::FieldSource &other) cons
   return false;
 }
 
+const GVArray *AnonymousAttributeContextFieldSource::try_get_varray_for_context(
+    const fn::FieldContext &context, IndexMask UNUSED(mask), ResourceScope &scope) const
+{
+  if (const GeometryComponentFieldContext *geometry_context =
+          dynamic_cast<const GeometryComponentFieldContext *>(&context)) {
+    const GeometryComponent &component = geometry_context->geometry_component();
+    const AttributeDomain domain = geometry_context->domain();
+    const CustomDataType data_type = cpp_type_to_custom_data_type(*type_);
+    GVArrayPtr attribute = component.attribute_try_get_for_read(
+        anonymous_id_.get(), domain, data_type);
+    return scope.add(std::move(attribute), __func__);
+  }
+  return nullptr;
+}
+
+uint64_t AnonymousAttributeContextFieldSource::hash() const
+{
+  return get_default_hash_2(anonymous_id_.get(), type_);
+}
+
+bool AnonymousAttributeContextFieldSource::is_equal_to(const fn::FieldSource &other) const
+{
+  if (const AnonymousAttributeContextFieldSource *other_typed =
+          dynamic_cast<const AnonymousAttributeContextFieldSource *>(&other)) {
+    return anonymous_id_.get() == other_typed->anonymous_id_.get() && type_ == other_typed->type_;
+  }
+  return false;
+}
+
 }  // namespace blender::bke
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 504cf0d71a1..0eddb14ea7d 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5139,6 +5139,7 @@ static void registerGeometryNodes()
   register_node_type_geo_attribute_convert();
   register_node_type_geo_attribute_curve_map();
   register_node_type_geo_attribute_fill();
+  register_node_type_geo_attribute_freeze();
   register_node_type_geo_attribute_map_range();
   register_node_type_geo_attribute_math();
   register_node_type_geo_attribute_mix();
diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh
index d639b355ab9..29bb2cc25ba 100644
--- a/source/blender/functions/FN_field.hh
+++ b/source/blender/functions/FN_field.hh
@@ -307,6 +307,17 @@ class FieldEvaluator : NonMovable, NonCopyable {
     return this->add_with_destination(GField(std::move(field)), generic_dst_hint);
   }
 
+  int add(GField field, const GVArray **varray_ptr)
+  {
+    const int field_index = fields_to_evaluate_.append_and_get_index(std::move(field));
+    dst_hints_.append(nullptr);
+    output_pointer_infos_.append(OutputPointerInfo{
+        varray_ptr, [](void *dst, const GVArray &varray, ResourceScope &UNUSED(scope)) {
+          *(const GVArray **)dst = &varray;
+        }});
+    return field_index;
+  }
+
   /**
    * \param field: Field to add to the evaluator.
    * \param varray_ptr: Once #evaluate is called, the resulting virtual array will be will be
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 43dd4b4270e..e97c6232ec9 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1441,6 +1441,13 @@ typedef struct NodeGeometryCurveFill {
   uint8_t mode;
 } NodeGeometryCurveFill;
 
+typedef struct NodeGeometryAttributeFreeze {
+  /* CustomDataType. */
+  int8_t data_type;
+  /* AttributeDomain. */
+  int8_t domain;
+} NodeGeometryAttributeFreeze;
+
 /* script node mode */
 #define NODE_SCRIPT_INTERNAL 0
 #define NODE_SCRIPT_EXTERNAL 1
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 9e24a36915e..26f214b83be 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -10279,6 +10279,26 @@ static void def_geo_curve_fill(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_geo_attribute_freeze(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  RNA_def_struct_sdna_from(srna, "NodeGeometryAttributeFreeze", "storage");
+
+  prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, rna_enum_attribute_type_items);
+  RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_GeometryNodeAttributeFill_type_itemf");
+  RNA_def_property_enum_default(prop, CD_PROP_FLOAT);
+  RNA_def_property_ui_text(prop, "Data Type", "Type of data stored in attribute");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_GeometryNode_socket_update");
+
+  prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, rna_enum_attribute_domain_items);
+  RNA_def_property_enum_default(prop, ATTR_DOMAIN_POINT);
+  RNA_def_property_ui_text(prop, "Domain", "");
+  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 4d52358687e..4af2476ab36 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -148,6 +148,7 @@ set(SRC
   geometry/nodes/node_geo_attribute_convert.cc
   geometry/nodes/node_geo_attribute_curve_map.cc
   geometry/nodes/node_geo_attribute_fill.cc
+  geometry/nodes/node_geo_attribute_freeze.cc
   geometry/nodes/node_geo_attribute_map_range.cc
   geometry/nodes/node_geo_attribute_math.cc
   geometry/nodes/node_geo_attribute_mix.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index c7705b4ef63..79354ad4134 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -37,6 +37,7 @@ void register_node_type_geo_attribute_compare(void);
 void register_node_type_geo_attribute_convert(void);
 void register_node_type_geo_attribute_curve_map(void);
 void register_node_type_geo_attribute_fill(void);
+void register_node_type_geo_attribute_freeze(void);
 void register_node_type_geo_attribute_map_range(void);
 void register_node_type_geo_attribute_math(void);
 void register_node_type_geo_attribute_mix(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 5601ff1d6ef..ec6cb0a9293 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -275,6 +275,7 @@ DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_COMBINE_XYZ, def_geo_attribute_combine_
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_COMPARE, def_geo_attribute_attribute_compare, "ATTRIBUTE_COMPARE", AttributeCompare, "Attribute Compare", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_CONVERT, def_geo_attribute_convert, "ATTRIBUTE_CONVERT", AttributeConvert, "Attribute Convert", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list