From c7eada103c67021052f4c6a2340ca8f744cf17db Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sat, 11 Jul 2020 18:02:06 +0200 Subject: Nodes: support implicit conversions and incorrectly linked sockets --- .../blender/functions/FN_multi_function_builder.hh | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source/blender/functions/FN_multi_function_builder.hh') diff --git a/source/blender/functions/FN_multi_function_builder.hh b/source/blender/functions/FN_multi_function_builder.hh index 5905d1cc315..6e7efb21850 100644 --- a/source/blender/functions/FN_multi_function_builder.hh +++ b/source/blender/functions/FN_multi_function_builder.hh @@ -202,6 +202,30 @@ template class CustomMF_SM : public MultiFunction { } }; +/** + * Generates a multi-function that converts between two types. + */ +template class CustomMF_Convert : public MultiFunction { + public: + CustomMF_Convert() + { + std::string name = CPPType::get().name() + " to " + CPPType::get().name(); + MFSignatureBuilder signature = this->get_builder(std::move(name)); + signature.single_input("Input"); + signature.single_output("Output"); + } + + void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override + { + VSpan inputs = params.readonly_single_input(0); + MutableSpan outputs = params.uninitialized_single_output(1); + + for (uint i : mask) { + new ((void *)&outputs[i]) To(inputs[i]); + } + } +}; + /** * A multi-function that outputs the same value every time. The value is not owned by an instance * of this function. The caller is responsible for destructing and freeing the value. -- cgit v1.2.3