diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-19 23:06:35 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-19 23:06:35 +0300 |
commit | 3884d78e491f73c5dc436630dd69a9ce66abb629 (patch) | |
tree | 69520597d29c177d18bdcdc14149d6588bbb3ac4 /source/blender/simulation/intern/simulation_collect_influences.cc | |
parent | 5063820c9b7fdc499c0aa16ca850541101ffda09 (diff) |
Particles: Make it easier to add attributes internally
Diffstat (limited to 'source/blender/simulation/intern/simulation_collect_influences.cc')
-rw-r--r-- | source/blender/simulation/intern/simulation_collect_influences.cc | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/source/blender/simulation/intern/simulation_collect_influences.cc b/source/blender/simulation/intern/simulation_collect_influences.cc index ec1e7db0f72..98b055802c9 100644 --- a/source/blender/simulation/intern/simulation_collect_influences.cc +++ b/source/blender/simulation/intern/simulation_collect_influences.cc @@ -45,6 +45,11 @@ static std::string dnode_to_path(const nodes::DNode &dnode) return path; } +static Span<const nodes::DNode *> get_particle_simulation_nodes(const nodes::DerivedNodeTree &tree) +{ + return tree.nodes_by_type("SimulationNodeParticleSimulation"); +} + static std::optional<Array<std::string>> compute_global_string_inputs( nodes::MFNetworkTreeMap &network_map, Span<const fn::MFInputSocket *> sockets) { @@ -243,8 +248,7 @@ static void collect_forces(nodes::MFNetworkTreeMap &network_map, DummyDataSources &data_sources, SimulationInfluences &r_influences) { - for (const nodes::DNode *dnode : - network_map.tree().nodes_by_type("SimulationNodeParticleSimulation")) { + for (const nodes::DNode *dnode : get_particle_simulation_nodes(network_map.tree())) { std::string name = dnode_to_path(*dnode); Vector<const ParticleForce *> forces = create_forces_for_particle_simulation( *dnode, network_map, resources, data_sources); @@ -286,14 +290,27 @@ static void collect_emitters(nodes::MFNetworkTreeMap &network_map, ResourceCollector &resources, SimulationInfluences &r_influences) { - for (const nodes::DNode *dnode : - network_map.tree().nodes_by_type("SimulationNodeParticleSimulation")) { + for (const nodes::DNode *dnode : get_particle_simulation_nodes(network_map.tree())) { std::string name = dnode_to_path(*dnode); ParticleEmitter &emitter = resources.construct<MyBasicEmitter>(AT, name); r_influences.particle_emitters.append(&emitter); } } +static void prepare_particle_attribute_builders(nodes::MFNetworkTreeMap &network_map, + ResourceCollector &resources, + SimulationInfluences &r_influences) +{ + for (const nodes::DNode *dnode : get_particle_simulation_nodes(network_map.tree())) { + std::string name = dnode_to_path(*dnode); + fn::AttributesInfoBuilder &builder = resources.construct<fn::AttributesInfoBuilder>(AT); + builder.add<float3>("Position", {0, 0, 0}); + builder.add<float3>("Velocity", {0, 0, 0}); + builder.add<int>("ID", 0); + r_influences.particle_attributes_builder.add_new(std::move(name), &builder); + } +} + void collect_simulation_influences(Simulation &simulation, ResourceCollector &resources, SimulationInfluences &r_influences, @@ -305,6 +322,8 @@ void collect_simulation_influences(Simulation &simulation, fn::MFNetwork &network = resources.construct<fn::MFNetwork>(AT); nodes::MFNetworkTreeMap network_map = insert_node_tree_into_mf_network(network, tree, resources); + prepare_particle_attribute_builders(network_map, resources, r_influences); + DummyDataSources data_sources; find_and_deduplicate_particle_attribute_nodes(network_map, data_sources); @@ -316,7 +335,7 @@ void collect_simulation_influences(Simulation &simulation, collect_forces(network_map, resources, data_sources, r_influences); collect_emitters(network_map, resources, r_influences); - for (const nodes::DNode *dnode : tree.nodes_by_type("SimulationNodeParticleSimulation")) { + for (const nodes::DNode *dnode : get_particle_simulation_nodes(tree)) { r_states_info.particle_simulation_names.add(dnode_to_path(*dnode)); } } |