Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-08-31 13:40:53 +0300
committerJacques Lucke <jacques@blender.org>2021-08-31 13:40:53 +0300
commit3c5681c2129b0bef2362cb32dc38dc93e1a20dff (patch)
tree82a1781bd1a615aaa24ffc7500ab09253579b3f4
parent28f1e71e2eb7b2ca6d3cbed43734e6f42261359c (diff)
support field conversion
-rw-r--r--source/blender/functions/FN_field.hh21
-rw-r--r--source/blender/modifiers/intern/MOD_nodes_evaluator.cc18
2 files changed, 21 insertions, 18 deletions
diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh
index 77c1dedb721..4b0dee88491 100644
--- a/source/blender/functions/FN_field.hh
+++ b/source/blender/functions/FN_field.hh
@@ -107,26 +107,13 @@ class GField {
}
};
-template<typename T> class Field {
- private:
- GField field_;
-
+template<typename T> class Field : public GField {
public:
Field() = default;
- Field(GField field) : field_(std::move(field))
- {
- BLI_assert(field_.cpp_type().is<T>());
- }
-
- const GField *operator->() const
- {
- return &field_;
- }
-
- const GField &operator*() const
+ Field(GField field) : GField(std::move(field))
{
- return field_;
+ BLI_assert(this->cpp_type().template is<T>());
}
};
@@ -222,7 +209,7 @@ template<typename T> T evaluate_constant_field(const Field<T> &field)
{
T value;
value.~T();
- evaluate_constant_field(*field, &value);
+ evaluate_constant_field(field, &value);
return value;
}
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 98006d1eaee..0251163d9a7 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -36,6 +36,7 @@ namespace blender::modifiers::geometry_nodes {
using fn::CPPType;
using fn::Field;
+using fn::FieldCPPType;
using fn::GField;
using fn::GValueMap;
using nodes::GeoNodeExecParams;
@@ -1381,6 +1382,21 @@ class GeometryNodesEvaluator {
return;
}
+ const FieldCPPType *from_field_type = dynamic_cast<const FieldCPPType *>(&from_type);
+ const FieldCPPType *to_field_type = dynamic_cast<const FieldCPPType *>(&to_type);
+
+ if (from_field_type != nullptr && to_field_type != nullptr) {
+ const CPPType &from_base_type = from_field_type->field_type();
+ const CPPType &to_base_type = to_field_type->field_type();
+ if (conversions_.is_convertible(from_base_type, to_base_type)) {
+ const MultiFunction &fn = *conversions_.get_conversion_multi_function(
+ MFDataType::ForSingle(from_base_type), MFDataType::ForSingle(to_base_type));
+ const GField &from_field = *(const GField *)from_value;
+ auto field_fn = std::make_shared<fn::FieldFunction>(fn, Vector<GField>{from_field});
+ new (to_value) GField(std::move(field_fn), 0);
+ return;
+ }
+ }
if (conversions_.is_convertible(from_type, to_type)) {
/* Do the conversion if possible. */
conversions_.convert_to_uninitialized(from_type, to_type, from_value, to_value);
@@ -1393,7 +1409,7 @@ class GeometryNodesEvaluator {
void construct_default_value(const CPPType &type, void *r_value)
{
- if (const fn::FieldCPPType *field_cpp_type = dynamic_cast<const fn::FieldCPPType *>(&type)) {
+ if (const FieldCPPType *field_cpp_type = dynamic_cast<const FieldCPPType *>(&type)) {
const CPPType &base_type = field_cpp_type->field_type();
auto constant_fn = std::make_unique<fn::CustomMF_GenericConstant>(base_type,
base_type.default_value());