diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-18 11:51:38 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-18 11:51:38 +0300 |
commit | fe49e4139cd3f78f126b60ea4240a0294eac9483 (patch) | |
tree | 159bfd716161d18d93ec9eda01bf13d657257f9f /source/blender/simulation/intern | |
parent | 9eaa48f520a68d1042f67a64dadf1c1ab9ff4a67 (diff) |
Simulation: cleanup deduplicating attribute input nodes
Diffstat (limited to 'source/blender/simulation/intern')
-rw-r--r-- | source/blender/simulation/intern/simulation_collect_influences.cc | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/source/blender/simulation/intern/simulation_collect_influences.cc b/source/blender/simulation/intern/simulation_collect_influences.cc index 84188096081..3e35b040dbe 100644 --- a/source/blender/simulation/intern/simulation_collect_influences.cc +++ b/source/blender/simulation/intern/simulation_collect_influences.cc @@ -43,44 +43,61 @@ static std::string dnode_to_path(const nodes::DNode &dnode) return path; } -static Map<const fn::MFOutputSocket *, std::string> find_and_deduplicate_particle_attribute_nodes( - nodes::MFNetworkTreeMap &network_map, DummyDataSources &r_data_sources) +static std::optional<Array<std::string>> compute_global_string_inputs( + nodes::MFNetworkTreeMap &network_map, Span<const fn::MFInputSocket *> sockets) { - fn::MFNetwork &network = network_map.network(); - const nodes::DerivedNodeTree &tree = network_map.tree(); - - Span<const nodes::DNode *> attribute_dnodes = tree.nodes_by_type( - "SimulationNodeParticleAttribute"); - uint amount = attribute_dnodes.size(); + uint amount = sockets.size(); if (amount == 0) { - return {}; + return Array<std::string>(); } - Vector<fn::MFInputSocket *> name_sockets; - for (const nodes::DNode *dnode : attribute_dnodes) { - fn::MFInputSocket &name_socket = network_map.lookup_dummy(dnode->input(0)); - name_sockets.append(&name_socket); + if (network_map.network().have_dummy_or_unlinked_dependencies(sockets)) { + return {}; } - fn::MFNetworkEvaluator network_fn{{}, name_sockets.as_span()}; + fn::MFNetworkEvaluator network_fn{{}, sockets}; fn::MFParamsBuilder params{network_fn, 1}; - Array<std::string> attribute_names{amount, NoInitialization()}; + Array<std::string> strings(amount, NoInitialization()); for (uint i : IndexRange(amount)) { params.add_uninitialized_single_output( - fn::GMutableSpan(fn::CPPType::get<std::string>(), attribute_names.data() + i, 1)); + fn::GMutableSpan(fn::CPPType::get<std::string>(), strings.data() + i, 1)); } fn::MFContextBuilder context; - /* Todo: Check that the names don't depend on dummy nodes. */ network_fn.call({0}, params, context); + return strings; +} + +static void find_and_deduplicate_particle_attribute_nodes(nodes::MFNetworkTreeMap &network_map, + DummyDataSources &r_data_sources) +{ + fn::MFNetwork &network = network_map.network(); + const nodes::DerivedNodeTree &tree = network_map.tree(); + + Span<const nodes::DNode *> attribute_dnodes = tree.nodes_by_type( + "SimulationNodeParticleAttribute"); + + Vector<fn::MFInputSocket *> name_sockets; + for (const nodes::DNode *dnode : attribute_dnodes) { + fn::MFInputSocket &name_socket = network_map.lookup_dummy(dnode->input(0)); + name_sockets.append(&name_socket); + } + + std::optional<Array<std::string>> attribute_names = compute_global_string_inputs(network_map, + name_sockets); + if (!attribute_names.has_value()) { + return; + } + Map<std::pair<std::string, fn::MFDataType>, Vector<fn::MFNode *>> attribute_nodes_by_name_and_type; - for (uint i : IndexRange(amount)) { + for (uint i : attribute_names->index_range()) { attribute_nodes_by_name_and_type - .lookup_or_add_default({attribute_names[i], name_sockets[i]->node().output(0).data_type()}) + .lookup_or_add_default( + {(*attribute_names)[i], name_sockets[i]->node().output(0).data_type()}) .append(&name_sockets[i]->node()); } |