[Bf-blender-cvs] [3ef59121a49] master: Simulation: move initial simulation code from bf_blenkernel to bf_simulation
Jacques Lucke
noreply at git.blender.org
Fri Jul 17 13:49:39 CEST 2020
Commit: 3ef59121a49b986700747469850e02f6420ee8aa
Author: Jacques Lucke
Date: Fri Jul 17 13:47:57 2020 +0200
Branches: master
https://developer.blender.org/rB3ef59121a49b986700747469850e02f6420ee8aa
Simulation: move initial simulation code from bf_blenkernel to bf_simulation
I removed bf_blenkernel from `nodes/CMakeLists.txt` again (added it yesterday),
because now this was causing me unresolved symbol errors... Without it, cmake
seems to link the libraries bf_simulation, bf_blenkernel and bf_nodes in the right
order. Not sure if that is just luck or if it is guaranteed.
It was possible to fix the issue by using cmakes `LINK_INTERFACE_MULTIPLICITY`,
but that is probably bad style.
===================================================================
M source/blender/blenkernel/intern/simulation.cc
M source/blender/nodes/CMakeLists.txt
M source/blender/simulation/CMakeLists.txt
A source/blender/simulation/SIM_simulation_update.hh
A source/blender/simulation/intern/simulation_update.cc
===================================================================
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index fdb0f0b235f..cec3547a3f3 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -61,9 +61,7 @@
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
-extern "C" {
-void WM_clipboard_text_set(const char *buf, bool selection);
-}
+#include "SIM_simulation_update.hh"
static void simulation_init_data(ID *id)
{
@@ -209,640 +207,7 @@ void *BKE_simulation_add(Main *bmain, const char *name)
return simulation;
}
-namespace blender::bke {
-
-static void ensure_attributes_exist(ParticleSimulationState *state)
-{
- if (CustomData_get_layer_named(&state->attributes, CD_PROP_FLOAT3, "Position") == nullptr) {
- CustomData_add_layer_named(
- &state->attributes, CD_PROP_FLOAT3, CD_CALLOC, nullptr, state->tot_particles, "Position");
- }
- if (CustomData_get_layer_named(&state->attributes, CD_PROP_FLOAT3, "Velocity") == nullptr) {
- CustomData_add_layer_named(
- &state->attributes, CD_PROP_FLOAT3, CD_CALLOC, nullptr, state->tot_particles, "Velocity");
- }
- if (CustomData_get_layer_named(&state->attributes, CD_PROP_INT32, "ID") == nullptr) {
- CustomData_add_layer_named(
- &state->attributes, CD_PROP_INT32, CD_CALLOC, nullptr, state->tot_particles, "ID");
- }
-}
-
-static void copy_states_to_cow(Simulation *simulation_orig, Simulation *simulation_cow)
-{
- BKE_simulation_state_remove_all(simulation_cow);
- simulation_cow->current_frame = simulation_orig->current_frame;
-
- LISTBASE_FOREACH (SimulationState *, state_orig, &simulation_orig->states) {
- switch ((eSimulationStateType)state_orig->type) {
- case SIM_STATE_TYPE_PARTICLES: {
- ParticleSimulationState *particle_state_orig = (ParticleSimulationState *)state_orig;
- ParticleSimulationState *particle_state_cow = (ParticleSimulationState *)
- BKE_simulation_state_add(simulation_cow, SIM_STATE_TYPE_PARTICLES, state_orig->name);
- particle_state_cow->tot_particles = particle_state_orig->tot_particles;
- CustomData_copy(&particle_state_orig->attributes,
- &particle_state_cow->attributes,
- CD_MASK_ALL,
- CD_DUPLICATE,
- particle_state_orig->tot_particles);
- break;
- }
- }
- }
-}
-
-static Map<const fn::MFOutputSocket *, std::string> deduplicate_attribute_nodes(
- fn::MFNetwork &network,
- nodes::MFNetworkTreeMap &network_map,
- const nodes::DerivedNodeTree &tree)
-{
- Span<const nodes::DNode *> attribute_dnodes = tree.nodes_by_type(
- "SimulationNodeParticleAttribute");
- uint amount = attribute_dnodes.size();
- if (amount == 0) {
- return {};
- }
-
- 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);
- }
-
- fn::MFNetworkEvaluator network_fn{{}, name_sockets.as_span()};
-
- fn::MFParamsBuilder params{network_fn, 1};
-
- Array<std::string> attribute_names{amount, NoInitialization()};
- for (uint i : IndexRange(amount)) {
- params.add_uninitialized_single_output(
- fn::GMutableSpan(fn::CPPType_string, attribute_names.data() + i, 1));
- }
-
- fn::MFContextBuilder context;
- /* Todo: Check that the names don't depend on dummy nodes. */
- network_fn.call({0}, params, context);
-
- Map<std::pair<std::string, fn::MFDataType>, Vector<fn::MFNode *>>
- attribute_nodes_by_name_and_type;
- for (uint i : IndexRange(amount)) {
- attribute_nodes_by_name_and_type
- .lookup_or_add_default({attribute_names[i], name_sockets[i]->node().output(0).data_type()})
- .append(&name_sockets[i]->node());
- }
-
- Map<const fn::MFOutputSocket *, std::string> attribute_inputs;
- for (auto item : attribute_nodes_by_name_and_type.items()) {
- StringRef attribute_name = item.key.first;
- fn::MFDataType data_type = item.key.second;
- Span<fn::MFNode *> nodes = item.value;
-
- fn::MFOutputSocket &new_attribute_socket = network.add_input(
- "Attribute '" + attribute_name + "'", data_type);
- for (fn::MFNode *node : nodes) {
- network.relink(node->output(0), new_attribute_socket);
- }
- network.remove(nodes);
-
- attribute_inputs.add_new(&new_attribute_socket, attribute_name);
- }
-
- return attribute_inputs;
-}
-
-class CustomDataAttributesRef {
- private:
- Vector<void *> buffers_;
- uint size_;
- std::unique_ptr<fn::AttributesInfo> info_;
-
- public:
- CustomDataAttributesRef(CustomData &custom_data, uint size)
- {
- fn::AttributesInfoBuilder builder;
- for (const CustomDataLayer &layer : Span(custom_data.layers, custom_data.totlayer)) {
- buffers_.append(layer.data);
- switch (layer.type) {
- case CD_PROP_INT32: {
- builder.add<int32_t>(layer.name, 0);
- break;
- }
- case CD_PROP_FLOAT3: {
- builder.add<float3>(layer.name, {0, 0, 0});
- break;
- }
- }
- }
- info_ = std::make_unique<fn::AttributesInfo>(builder);
- size_ = size;
- }
-
- operator fn::MutableAttributesRef()
- {
- return fn::MutableAttributesRef(*info_, buffers_, size_);
- }
-
- operator fn::AttributesRef() const
- {
- return fn::AttributesRef(*info_, buffers_, size_);
- }
-};
-
-static std::string dnode_to_path(const nodes::DNode &dnode)
-{
- std::string path;
- for (const nodes::DParentNode *parent = dnode.parent(); parent; parent = parent->parent()) {
- path = parent->node_ref().name() + "/" + path;
- }
- path = path + dnode.name();
- return path;
-}
-
-static void remove_unused_states(Simulation *simulation, const VectorSet<std::string> &state_names)
-{
- LISTBASE_FOREACH_MUTABLE (SimulationState *, state, &simulation->states) {
- if (!state_names.contains(state->name)) {
- BKE_simulation_state_remove(simulation, state);
- }
- }
-}
-
-static void reset_states(Simulation *simulation)
-{
- LISTBASE_FOREACH (SimulationState *, state, &simulation->states) {
- switch ((eSimulationStateType)state->type) {
- case SIM_STATE_TYPE_PARTICLES: {
- ParticleSimulationState *particle_state = (ParticleSimulationState *)state;
- CustomData_free(&particle_state->attributes, particle_state->tot_particles);
- particle_state->tot_particles = 0;
- break;
- }
- }
- }
-}
-
-static SimulationState *try_find_state_by_name(Simulation *simulation, StringRef name)
-{
- LISTBASE_FOREACH (SimulationState *, state, &simulation->states) {
- if (state->name == name) {
- return state;
- }
- }
- return nullptr;
-}
-
-static void add_missing_particle_states(Simulation *simulation, Span<std::string> state_names)
-{
- for (StringRefNull name : state_names) {
- SimulationState *state = try_find_state_by_name(simulation, name);
- if (state != nullptr) {
- BLI_assert(state->type == SIM_STATE_TYPE_PARTICLES);
- continue;
- }
-
- BKE_simulation_state_add(simulation, SIM_STATE_TYPE_PARTICLES, name.c_str());
- }
-}
-
-static void reinitialize_empty_simulation_states(Simulation *simulation,
- const nodes::DerivedNodeTree &tree)
-{
- VectorSet<std::string> state_names;
- for (const nodes::DNode *dnode : tree.nodes_by_type("SimulationNodeParticleSimulation")) {
- state_names.add(dnode_to_path(*dnode));
- }
-
- remove_unused_states(simulation, state_names);
- reset_states(simulation);
- add_missing_particle_states(simulation, state_names);
-}
-
-static void update_simulation_state_list(Simulation *simulation,
- const nodes::DerivedNodeTree &tree)
-{
- VectorSet<std::string> state_names;
- for (const nodes::DNode *dnode : tree.nodes_by_type("SimulationNodeParticleSimulation")) {
- state_names.add(dnode_to_path(*dnode));
- }
-
- remove_unused_states(simulation, state_names);
- add_missing_particle_states(simulation, state_names);
-}
-
-class ParticleFunctionInput {
- public:
- virtual ~ParticleFunctionInput() = default;
- virtual void add_input(fn::AttributesRef attributes,
- fn::MFParamsBuilder ¶ms,
- ResourceCollector &resources) const = 0;
-};
-
-class ParticleFunction {
- private:
- const fn::MultiFunction *global_fn_;
- const fn::MultiFunction *per_particle_fn_;
- Array<const ParticleFunctionInput *> global_inputs_;
- Array<const ParticleFunctionInput *> per_particle_inputs_;
- Array<bool> output_is_global_;
- Vector<uint> global_output_indices_;
- Vector<uint> per_particle_output_indices_;
- Vector<fn::MFDataType> output_types_;
- Vector<StringRefNull> output_names_;
-
- friend class ParticleFunctionEvaluator;
-
- public:
- ParticleFunction(const fn::MultiFunction *global_fn,
- const fn::MultiFunction *per_particle_fn,
- Span<const ParticleFunctionInput *> global_inputs,
- Span<const ParticleFunctionInput *> per_particle_inputs,
- Span<bool> output_is_global)
- : global_fn_(global_fn),
- per_particle_fn_(per_particle_fn),
- global_inputs_(global_inputs),
- per_particle_inputs_(per_particle_inputs),
- output_is_global_(output_is_global)
- {
- for (uint i : output_is_global_.index_range()) {
- if (output_is_global_[i]) {
- uint param_index = global_inputs_.size() + global_output_indices_.size();
- fn::MFParamType param_type = global_fn_->param_type(param_index);
- BLI_assert(param_type.is_output());
- output_types_.append(param_type.data_type());
- output_names_.append(global_fn_->param_name(param_index));
- global_output_indices_.append(i);
- }
- else {
- uint param_index = per_particle_inputs_.size() + per_particle_output_indices_.size();
- fn::MFParamType param_type = per_particle_fn_->param_type(param_index);
- BLI_assert(param_type.is_output());
- output_types_.append(param_type.data_type());
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list