diff options
author | Jacques Lucke <jacques@blender.org> | 2021-10-17 16:56:37 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-10-17 16:56:37 +0300 |
commit | 19740b25c778ccd3fccd0ab33c7efd9f761dc001 (patch) | |
tree | 2ca1d70246e85edb713ffb33b94dfdf43fea38e7 /source/blender/nodes/geometry | |
parent | 6b0719c0f3ff43ecf92ef88cdcfb87bf1532f107 (diff) |
Geometry Nodes: bring back lazy evaluation for field types in Switch node
Differential Revision: https://developer.blender.org/D12878
Diffstat (limited to 'source/blender/nodes/geometry')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_switch.cc | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_switch.cc b/source/blender/nodes/geometry/nodes/node_geo_switch.cc index 05df927fb39..c01fcf5bb5f 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_switch.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_switch.cc @@ -157,23 +157,43 @@ template<typename T> void switch_fields(GeoNodeExecParams ¶ms, const StringR const std::string name_true = "True" + suffix; const std::string name_output = "Output" + suffix; - /* TODO: Allow for Laziness when the switch field is constant. */ - const bool require_false = params.lazy_require_input(name_false); - const bool require_true = params.lazy_require_input(name_true); - if (require_false | require_true) { - return; - } + Field<bool> switches_field = params.get_input<Field<bool>>("Switch"); + if (switches_field.node().depends_on_input()) { + /* The switch has to be incorporated into the field. Both inputs have to be evaluated. */ + const bool require_false = params.lazy_require_input(name_false); + const bool require_true = params.lazy_require_input(name_true); + if (require_false | require_true) { + return; + } - Field<bool> switches_field = params.extract_input<Field<bool>>("Switch"); - Field<T> falses_field = params.extract_input<Field<T>>(name_false); - Field<T> trues_field = params.extract_input<Field<T>>(name_true); + Field<T> falses_field = params.extract_input<Field<T>>(name_false); + Field<T> trues_field = params.extract_input<Field<T>>(name_true); - auto switch_fn = std::make_unique<SwitchFieldsFunction<T>>(); - auto switch_op = std::make_shared<FieldOperation>(FieldOperation( - std::move(switch_fn), - {std::move(switches_field), std::move(falses_field), std::move(trues_field)})); + auto switch_fn = std::make_unique<SwitchFieldsFunction<T>>(); + auto switch_op = std::make_shared<FieldOperation>(FieldOperation( + std::move(switch_fn), + {std::move(switches_field), std::move(falses_field), std::move(trues_field)})); - params.set_output(name_output, Field<T>(switch_op, 0)); + params.set_output(name_output, Field<T>(switch_op, 0)); + } + else { + /* The switch input is constant, so just evaluate and forward one of the inputs. */ + const bool switch_value = fn::evaluate_constant_field(switches_field); + if (switch_value) { + params.set_input_unused(name_false); + if (params.lazy_require_input(name_true)) { + return; + } + params.set_output(name_output, params.extract_input<Field<T>>(name_true)); + } + else { + params.set_input_unused(name_true); + if (params.lazy_require_input(name_false)) { + return; + } + params.set_output(name_output, params.extract_input<Field<T>>(name_false)); + } + } } template<typename T> void switch_no_fields(GeoNodeExecParams ¶ms, const StringRef suffix) |