diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/modifiers/intern/MOD_nodes_evaluator.cc | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc index 2157092d639..1391587fa7d 100644 --- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc +++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc @@ -1245,14 +1245,8 @@ class GeometryNodesEvaluator { void *buffer = allocator.allocate(to_type.size(), to_type.alignment()); GMutablePointer value{to_type, buffer}; - if (conversions_.is_convertible(from_type, to_type)) { - /* Do the conversion if possible. */ - conversions_.convert_to_uninitialized(from_type, to_type, value_to_forward.get(), buffer); - } - else { - /* Cannot convert, use default value instead. */ - to_type.copy_construct(to_type.default_value(), buffer); - } + this->convert_value(from_type, to_type, value_to_forward.get(), buffer); + /* Multi input socket values are logged once all values are available. */ if (!to_socket->is_multi_input_socket()) { this->log_socket_value({to_socket}, value); @@ -1380,17 +1374,29 @@ class GeometryNodesEvaluator { if (type == required_type) { return {type, buffer}; } - if (conversions_.is_convertible(type, required_type)) { - /* Convert the loaded value to the required type if possible. */ - void *converted_buffer = allocator.allocate(required_type.size(), required_type.alignment()); - conversions_.convert_to_uninitialized(type, required_type, buffer, converted_buffer); - type.destruct(buffer); - return {required_type, converted_buffer}; + void *converted_buffer = allocator.allocate(required_type.size(), required_type.alignment()); + this->convert_value(type, required_type, buffer, converted_buffer); + return {required_type, converted_buffer}; + } + + void convert_value(const CPPType &from_type, + const CPPType &to_type, + const void *from_value, + void *to_value) + { + if (from_type == to_type) { + from_type.copy_construct(from_value, to_value); + 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); + } + else { + /* Cannot convert, use default value instead. */ + to_type.copy_construct(to_type.default_value(), to_value); } - /* Use a default fallback value when the loaded type is not compatible. */ - void *default_buffer = allocator.allocate(required_type.size(), required_type.alignment()); - required_type.copy_construct(required_type.default_value(), default_buffer); - return {required_type, default_buffer}; } NodeState &get_node_state(const DNode node) |