[Bf-blender-cvs] [64a11ba6a2d] temp-geometry-nodes-fields-prototype: progress
Jacques Lucke
noreply at git.blender.org
Wed Jul 28 14:14:20 CEST 2021
Commit: 64a11ba6a2dea557baf5082e836b7c91ae7d673b
Author: Jacques Lucke
Date: Mon Jul 26 15:21:15 2021 +0200
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rB64a11ba6a2dea557baf5082e836b7c91ae7d673b
progress
===================================================================
M source/blender/blenkernel/BKE_field.hh
A source/blender/blenlib/BLI_optionally_owned_ptr.hh
M source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_field.hh b/source/blender/blenkernel/BKE_field.hh
index 867a3a1f541..5f1d23b47b3 100644
--- a/source/blender/blenkernel/BKE_field.hh
+++ b/source/blender/blenkernel/BKE_field.hh
@@ -24,6 +24,7 @@
#include "BLI_function_ref.hh"
#include "BLI_map.hh"
+#include "BLI_optionally_owned_ptr.hh"
#include "BLI_user_counter.hh"
#include "BLI_vector.hh"
#include "BLI_virtual_array.hh"
@@ -78,6 +79,16 @@ class AttributeFieldInputKey : public FieldInputKey {
return get_default_hash_2(name_, type_);
}
+ StringRefNull name() const
+ {
+ return name_;
+ }
+
+ const CPPType &type() const
+ {
+ return *type_;
+ }
+
private:
bool is_same_as(const FieldInputKey &other) const
{
@@ -89,6 +100,21 @@ class AttributeFieldInputKey : public FieldInputKey {
}
};
+class GVArrayFieldInputValue : public FieldInputValue {
+ private:
+ OptionallyOwnedPtr<GVArray> varray_;
+
+ public:
+ GVArrayFieldInputValue(OptionallyOwnedPtr<GVArray> varray) : varray_(std::move(varray))
+ {
+ }
+
+ const GVArray &varray() const
+ {
+ return *varray_;
+ }
+};
+
template<typename T> class VArrayFieldInputValue : public FieldInputValue {
private:
const VArray<T> *varray_;
diff --git a/source/blender/blenlib/BLI_optionally_owned_ptr.hh b/source/blender/blenlib/BLI_optionally_owned_ptr.hh
new file mode 100644
index 00000000000..cfb9cf5273f
--- /dev/null
+++ b/source/blender/blenlib/BLI_optionally_owned_ptr.hh
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bli
+ */
+
+#include <memory>
+
+#include "BLI_utildefines.h"
+
+namespace blender {
+
+template<typename T, typename OwnedTPtr = std::unique_ptr<T>> class OptionallyOwnedPtr {
+ private:
+ OwnedTPtr owned_ptr_;
+ T *ptr_ = nullptr;
+
+ public:
+ OptionallyOwnedPtr() = default;
+
+ OptionallyOwnedPtr(T &ptr) : ptr_(&ptr)
+ {
+ }
+
+ OptionallyOwnedPtr(OwnedTPtr owned_ptr) : owned_ptr_(std::move(owned_ptr)), ptr_(&*owned_ptr_)
+ {
+ }
+
+ T *operator->()
+ {
+ BLI_assert(ptr_ != nullptr);
+ return ptr_;
+ }
+
+ const T *operator->() const
+ {
+ BLI_assert(ptr_ != nullptr);
+ return ptr_;
+ }
+
+ T &operator*()
+ {
+ BLI_assert(ptr_ != nullptr);
+ return *ptr_;
+ }
+
+ const T &operator*() const
+ {
+ BLI_assert(ptr_ != nullptr);
+ return *ptr_;
+ }
+
+ operator bool() const
+ {
+ return ptr_ != nullptr;
+ }
+};
+
+} // namespace blender
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 ba5d1136348..5496e0d9bf1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
@@ -78,6 +78,25 @@ static AttributeDomain get_result_domain(const GeometryComponent &component, con
return ATTR_DOMAIN_POINT;
}
+static void prepare_field_inputs(bke::FieldInputs &field_inputs,
+ const GeometryComponent &component,
+ const AttributeDomain domain,
+ Vector<std::unique_ptr<bke::FieldInputValue>> &r_values)
+{
+ for (const bke::FieldInputKey &key : field_inputs) {
+ if (const bke::AttributeFieldInputKey *attribute_key =
+ dynamic_cast<const bke::AttributeFieldInputKey *>(&key)) {
+ const StringRef name = attribute_key->name();
+ const CPPType &cpp_type = attribute_key->type();
+ const CustomDataType type = bke::cpp_type_to_custom_data_type(cpp_type);
+ GVArrayPtr attribute = component.attribute_get_for_read(name, domain, type);
+ auto value = std::make_unique<bke::GVArrayFieldInputValue>(std::move(attribute));
+ field_inputs.set_input(key, *value);
+ r_values.append(std::move(value));
+ }
+ }
+}
+
static void fill_attribute(GeometryComponent &component, const GeoNodeExecParams ¶ms)
{
const std::string attribute_name = params.get_input<std::string>("Attribute");
@@ -104,6 +123,8 @@ static void fill_attribute(GeometryComponent &component, const GeoNodeExecParams
case CD_PROP_FLOAT: {
const FieldPtr<float> &value_field = params.get_input<FieldPtr<float>>("Value_001");
bke::FieldInputs field_inputs = value_field->prepare_inputs();
+ Vector<std::unique_ptr<bke::FieldInputValue>> input_values;
+ prepare_field_inputs(field_inputs, component, domain, input_values);
bke::FieldOutput<float> field_output = value_field->evaluate(IndexMask(domain_size),
field_inputs);
for (const int i : IndexRange(domain_size)) {
More information about the Bf-blender-cvs
mailing list