[Bf-blender-cvs] [eacc1f1ff45] temp-geometry-nodes-fields-prototype: Fix raycast and geometry delete node for multi-spline curves

Hans Goudey noreply at git.blender.org
Tue Aug 3 18:51:22 CEST 2021


Commit: eacc1f1ff45a9c49be01a47aedd9b30006010d81
Author: Hans Goudey
Date:   Tue Aug 3 12:51:13 2021 -0400
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rBeacc1f1ff45a9c49be01a47aedd9b30006010d81

Fix raycast and geometry delete node for multi-spline curves

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

M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/curve_eval.cc
M	source/blender/blenkernel/intern/geometry_component_curve.cc
M	source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc
M	source/blender/nodes/geometry/nodes/node_geo_raycast.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 4c9af9f8a5a..97cac30129e 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -356,6 +356,12 @@ class CustomDataAttributes {
   bool create_by_move(const blender::StringRef name, const CustomDataType data_type, void *buffer);
   bool remove(const blender::StringRef name);
 
+  bool create_anonymous(const AnonymousCustomDataLayerID &id, const CustomDataType data_type);
+  std::optional<blender::fn::GSpan> get_anonymous_for_read(
+      const AnonymousCustomDataLayerID &id) const;
+  std::optional<blender::fn::GMutableSpan> get_anonymous_for_write(
+      const AnonymousCustomDataLayerID &id);
+
   bool foreach_attribute(const AttributeForeachCallback callback,
                          const AttributeDomain domain) const;
 };
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index 22bf4b34f98..4118a1013d4 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -136,6 +136,17 @@ class GeometryComponent {
   blender::bke::ReadAttributeLookup attribute_try_get_anonymous_for_read(
       const AnonymousCustomDataLayerID &layer_id) const;
 
+  blender::fn::GVArrayPtr attribute_try_get_anonymous_for_read(
+      const AnonymousCustomDataLayerID &id,
+      const AttributeDomain domain,
+      const CustomDataType data_type) const;
+
+  blender::fn::GVArrayPtr attribute_try_get_anonymous_for_read(
+      const AnonymousCustomDataLayerID &id,
+      const AttributeDomain domain,
+      const CustomDataType data_type,
+      const void *default_value) const;
+
   blender::bke::WriteAttributeLookup attribute_try_get_anonymous_for_write(
       const AnonymousCustomDataLayerID &layer_id);
 
@@ -150,8 +161,8 @@ class GeometryComponent {
   virtual bool is_empty() const;
 
   /* Get a virtual array to read the data of an attribute on the given domain and data type.
-   * Returns null when the attribute does not exist or cannot be converted to the requested domain
-   * and data type. */
+   * Returns null when the attribute does not exist or cannot be converted to the requested
+   * domain and data type. */
   std::unique_ptr<blender::fn::GVArray> attribute_try_get_for_read(
       const blender::StringRef attribute_name,
       const AttributeDomain domain,
@@ -192,14 +203,14 @@ class GeometryComponent {
   }
 
   /**
-   * Returns an "output attribute", which is essentially a mutable virtual array with some commonly
-   * used convince features. The returned output attribute might be empty if requested attribute
-   * cannot exist on the geometry.
+   * Returns an "output attribute", which is essentially a mutable virtual array with some
+   * commonly used convince features. The returned output attribute might be empty if requested
+   * attribute cannot exist on the geometry.
    *
    * The included convenience features are:
    * - Implicit type conversion when writing to builtin attributes.
-   * - If the attribute name exists already, but has a different type/domain, a temporary attribute
-   *   is created that will overwrite the existing attribute in the end.
+   * - If the attribute name exists already, but has a different type/domain, a temporary
+   * attribute is created that will overwrite the existing attribute in the end.
    */
   blender::bke::OutputAttribute attribute_try_get_for_output(
       const blender::StringRef attribute_name,
@@ -208,8 +219,8 @@ class GeometryComponent {
       const void *default_value = nullptr);
 
   /* Same as attribute_try_get_for_output, but should be used when the original values in the
-   * attributes are not read, i.e. the attribute is used only for output. Since values are not read
-   * from this attribute, no default value is necessary. */
+   * attributes are not read, i.e. the attribute is used only for output. Since values are not
+   * read from this attribute, no default value is necessary. */
   blender::bke::OutputAttribute attribute_try_get_for_output_only(
       const blender::StringRef attribute_name,
       const AttributeDomain domain,
@@ -235,6 +246,35 @@ class GeometryComponent {
     return this->attribute_try_get_for_output_only(attribute_name, domain, data_type);
   }
 
+  blender::bke::OutputAttribute attribute_try_get_anonymous_for_output(
+      const AnonymousCustomDataLayerID &id,
+      const AttributeDomain domain,
+      const CustomDataType data_type,
+      const void *default_value = nullptr);
+
+  blender::bke::OutputAttribute attribute_try_get_anonymous_for_output_only(
+      const AnonymousCustomDataLayerID &id,
+      const AttributeDomain domain,
+      const CustomDataType data_type);
+
+  template<typename T>
+  blender::bke::OutputAttribute_Typed<T> attribute_try_get_anonymous_for_output(
+      const AnonymousCustomDataLayerID &id, const AttributeDomain domain, const T default_value)
+  {
+    const blender::fn::CPPType &cpp_type = blender::fn::CPPType::get<T>();
+    const CustomDataType data_type = blender::bke::cpp_type_to_custom_data_type(cpp_type);
+    return this->attribute_try_get_anonymous_for_output(id, domain, data_type, &default_value);
+  }
+
+  template<typename T>
+  blender::bke::OutputAttribute_Typed<T> attribute_try_get_anonymous_for_output_only(
+      const AnonymousCustomDataLayerID &id, const AttributeDomain domain)
+  {
+    const blender::fn::CPPType &cpp_type = blender::fn::CPPType::get<T>();
+    const CustomDataType data_type = blender::bke::cpp_type_to_custom_data_type(cpp_type);
+    return this->attribute_try_get_anonymous_for_output_only(id, domain, data_type);
+  }
+
  private:
   virtual const blender::bke::ComponentAttributeProviders *get_attribute_providers() const;
 };
@@ -243,12 +283,12 @@ template<typename T>
 inline constexpr bool is_geometry_component_v = std::is_base_of_v<GeometryComponent, T>;
 
 /**
- * A geometry set contains zero or more geometry components. There is at most one component of each
- * type. Individual components might be shared between multiple geometries. Shared components are
- * copied automatically when write access is requested.
+ * A geometry set contains zero or more geometry components. There is at most one component of
+ * each type. Individual components might be shared between multiple geometries. Shared
+ * components are copied automatically when write access is requested.
  *
- * Copying a geometry set is a relatively cheap operation, because it does not copy the referenced
- * geometry components.
+ * Copying a geometry set is a relatively cheap operation, because it does not copy the
+ * referenced geometry components.
  */
 struct GeometrySet {
  private:
@@ -452,8 +492,8 @@ class InstanceReference {
   enum class Type {
     /**
      * An empty instance. This allows an `InstanceReference` to be default constructed without
-     * being in an invalid state. There might also be other use cases that we haven't explored much
-     * yet (such as changing the instance later on, and "disabling" some instances).
+     * being in an invalid state. There might also be other use cases that we haven't explored
+     * much yet (such as changing the instance later on, and "disabling" some instances).
      */
     None,
     Object,
@@ -524,8 +564,8 @@ class InstancesComponent : public GeometryComponent {
   blender::Vector<int> instance_ids_;
 
   /* These almost unique ids are generated based on `ids_`, which might not contain unique ids at
-   * all. They are *almost* unique, because under certain very unlikely circumstances, they are not
-   * unique. Code using these ids should not crash when they are not unique but can generally
+   * all. They are *almost* unique, because under certain very unlikely circumstances, they are
+   * not unique. Code using these ids should not crash when they are not unique but can generally
    * expect them to be unique. */
   mutable std::mutex almost_unique_ids_mutex_;
   mutable blender::Array<int> almost_unique_ids_;
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 051a257dc00..bb83d7bced4 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -788,6 +788,56 @@ bool CustomDataAttributes::create_by_move(const blender::StringRef name,
   return result != nullptr;
 }
 
+bool CustomDataAttributes::create_anonymous(const AnonymousCustomDataLayerID &id,
+                                            const CustomDataType data_type)
+{
+  for (const CustomDataLayer &layer : Span(data.layers, data.totlayer)) {
+    if (layer.anonymous_id == &id) {
+      /* Don't create two layers with the same id. */
+      return false;
+    }
+  }
+
+  const std::string name = get_anonymous_attribute_name();
+  if (!this->create(name, data_type)) {
+    return false;
+  }
+
+  const int layer_index = CustomData_get_named_layer_index(&data, data_type, name.c_str());
+  CustomDataLayer &layer = data.layers[layer_index];
+  layer.flag |= CD_FLAG_ANONYMOUS;
+  layer.anonymous_id = &id;
+  CustomData_anonymous_id_weak_increment(&id);
+
+  return true;
+}
+
+std::optional<GSpan> CustomDataAttributes::get_anonymous_for_read(
+    const AnonymousCustomDataLayerID &id) const
+{
+  for (const CustomDataLayer &layer : Span(data.layers, data.totlayer)) {
+    if (layer.anonymous_id == &id) {
+      const CPPType *cpp_type = custom_data_type_to_cpp_type((CustomDataType)layer.type);
+      BLI_assert(cpp_type != nullptr);
+      return GSpan(*cpp_type, layer.data, size_);
+    }
+  }
+  return {};
+}
+
+std::optional<GMutableSpan> CustomDataAttributes::get_anonymous_for_write(
+    const AnonymousCustomDataLayerID &id)
+{
+  for (CustomDataLayer &layer : MutableSpan(data.layers, data.totlayer)) {
+    if (layer.anonymous_id == &id) {
+      const CPPType *cpp_type = custom_data_type_to_cpp_type((CustomDataType)layer.type);
+      BLI_assert(cpp_type != nullptr);
+      return GMutableSpan(*cpp_type, layer.data, size_);
+    }
+  }
+  return {};

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list