Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-07-21 18:20:05 +0300
committerJacques Lucke <jacques@blender.org>2020-07-21 18:35:09 +0300
commit8369adabc0ec7a1fce248b688bf20860ae0434bb (patch)
treeaf767efe8c6765c5876391a5eb96923fc8d6ac68 /source/blender/simulation/intern/simulation_solver.cc
parent6c7e62ef9be564fbee279c7467c9b6adaf51b6c8 (diff)
Particles: initial object socket and emitter node support
Object sockets work now, but only the new Object Transforms and the Particle Mesh Emitter node use it. The emitter does not actually use the mesh surface yet. Instead, new particles are just emitted around the origin of the object. Internally, handles to object data blocks are passed around in the network, instead of raw object pointers. Using handles has a couple of benefits: * The caller of the function has control over which handles can be resolved and therefore limit access to specific data. The set of data blocks that is accessed by a node tree should be known statically. This is necessary for a proper integration with the dependency graph. * When the pointer to an object changes (e.g. after restarting Blender), all handles are still valid. * When an object is deleted, the handle is invalidated without causing crashes. * The handle is just an integer that can be stored per particle and can be cached easily. The mapping between handles and their corresponding data blocks is stored in the Simulation data block.
Diffstat (limited to 'source/blender/simulation/intern/simulation_solver.cc')
-rw-r--r--source/blender/simulation/intern/simulation_solver.cc67
1 files changed, 62 insertions, 5 deletions
diff --git a/source/blender/simulation/intern/simulation_solver.cc b/source/blender/simulation/intern/simulation_solver.cc
index f542d6ab2c8..158c50957df 100644
--- a/source/blender/simulation/intern/simulation_solver.cc
+++ b/source/blender/simulation/intern/simulation_solver.cc
@@ -17,8 +17,11 @@
#include "simulation_solver.hh"
#include "BKE_customdata.h"
+#include "BKE_lib_id.h"
+#include "BKE_persistent_data_handle.hh"
#include "BLI_rand.hh"
+#include "BLI_set.hh"
namespace blender::sim {
@@ -243,6 +246,53 @@ BLI_NOINLINE static void remove_dead_and_add_new_particles(ParticleSimulationSta
state.next_particle_id += allocator.total_allocated();
}
+static void update_persistent_data_handles(Simulation &simulation,
+ const VectorSet<ID *> &used_data_blocks)
+{
+ Set<ID *> contained_ids;
+ Set<int> used_handles;
+
+ /* Remove handles that have been invalidated. */
+ LISTBASE_FOREACH_MUTABLE (
+ PersistentDataHandleItem *, handle_item, &simulation.persistent_data_handles) {
+ if (handle_item->id == nullptr) {
+ BLI_remlink(&simulation.persistent_data_handles, handle_item);
+ continue;
+ }
+ if (!used_data_blocks.contains(handle_item->id)) {
+ id_us_min(handle_item->id);
+ BLI_remlink(&simulation.persistent_data_handles, handle_item);
+ MEM_freeN(handle_item);
+ continue;
+ }
+ contained_ids.add_new(handle_item->id);
+ used_handles.add_new(handle_item->handle);
+ }
+
+ /* Add new handles that are not in the list yet. */
+ int next_handle = 0;
+ for (ID *id : used_data_blocks) {
+ if (contained_ids.contains(id)) {
+ continue;
+ }
+
+ /* Find the next available handle. */
+ while (used_handles.contains(next_handle)) {
+ next_handle++;
+ }
+ used_handles.add_new(next_handle);
+
+ PersistentDataHandleItem *handle_item = (PersistentDataHandleItem *)MEM_callocN(
+ sizeof(*handle_item), AT);
+ /* Cannot store const pointers in DNA. */
+ id_us_plus(id);
+ handle_item->id = id;
+ handle_item->handle = next_handle;
+
+ BLI_addtail(&simulation.persistent_data_handles, handle_item);
+ }
+}
+
void initialize_simulation_states(Simulation &simulation,
Depsgraph &UNUSED(depsgraph),
const SimulationInfluences &UNUSED(influences))
@@ -255,11 +305,18 @@ void solve_simulation_time_step(Simulation &simulation,
const SimulationInfluences &influences,
float time_step)
{
- SimulationSolveContext solve_context{
- simulation,
- depsgraph,
- influences,
- TimeInterval(simulation.current_simulation_time, time_step)};
+ update_persistent_data_handles(simulation, influences.used_data_blocks);
+
+ bke::PersistentDataHandleMap handle_map;
+ LISTBASE_FOREACH (PersistentDataHandleItem *, handle, &simulation.persistent_data_handles) {
+ handle_map.add(handle->handle, *handle->id);
+ }
+
+ SimulationSolveContext solve_context{simulation,
+ depsgraph,
+ influences,
+ TimeInterval(simulation.current_simulation_time, time_step),
+ handle_map};
TimeInterval simulation_time_interval{simulation.current_simulation_time, time_step};
Vector<SimulationState *> simulation_states{simulation.states};