From 3c5681c2129b0bef2362cb32dc38dc93e1a20dff Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 31 Aug 2021 12:40:53 +0200 Subject: support field conversion --- source/blender/functions/FN_field.hh | 21 ++++----------------- .../blender/modifiers/intern/MOD_nodes_evaluator.cc | 18 +++++++++++++++++- 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 class Field { - private: - GField field_; - +template class Field : public GField { public: Field() = default; - Field(GField field) : field_(std::move(field)) - { - BLI_assert(field_.cpp_type().is()); - } - - 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()); } }; @@ -222,7 +209,7 @@ template T evaluate_constant_field(const Field &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(&from_type); + const FieldCPPType *to_field_type = dynamic_cast(&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, Vector{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(&type)) { + if (const FieldCPPType *field_cpp_type = dynamic_cast(&type)) { const CPPType &base_type = field_cpp_type->field_type(); auto constant_fn = std::make_unique(base_type, base_type.default_value()); -- cgit v1.2.3