diff options
author | Jacques Lucke <jacques@blender.org> | 2020-06-08 16:41:41 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-06-08 16:49:17 +0300 |
commit | 6f96dfabe5cbf6966282decd2307ade9aacdeaee (patch) | |
tree | 01529fbad8453faf81a62877d03373eaf0b77b57 /source/blender/blenloader | |
parent | bf4198cdaf7d4fa1a5f91526fb6bbe84d2fa2a37 (diff) |
Simulations: initial simulation state and cache
The current particle state is stored in a `CustomData` instance and
the cache is stored in `PointCache`.
The current state exists on the copy-on-write copies of the simulation,
while the cache only exists in the original data block.
This patch implements a temporary trivial particle simulation that does not
use the node system yet. It is used for testing and will be replaced soon.
`PointCache` still has some limitations that need to be overcome using
separate refactorings. For example, we need to be able to store the number
of particles in the point cache. Also we need to change which attributes
are stored for a particle system more dynamically than is currently possible afaik.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D7836
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 13 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 24 |
2 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index f7f18d98e73..1e09f01fa57 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -9105,6 +9105,19 @@ static void direct_link_simulation(BlendDataReader *reader, Simulation *simulati { BLO_read_data_address(reader, &simulation->adt); direct_link_animdata(reader, simulation->adt); + + BLO_read_list(reader, &simulation->states); + LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { + switch ((eSimulationStateType)state->type) { + case SIM_STATE_TYPE_PARTICLES: { + ParticleSimulationState *particle_state = (ParticleSimulationState *)state; + direct_link_customdata(reader, &particle_state->attributes, particle_state->tot_particles); + direct_link_pointcache_list( + reader, &particle_state->ptcaches, &particle_state->point_cache, 0); + break; + }; + } + } } /** \} */ diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 205184e6e7c..3fa36c6995e 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -3915,6 +3915,30 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const BLO_write_struct(writer, bNodeTree, simulation->nodetree); write_nodetree_nolib(writer, simulation->nodetree); } + + LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { + switch ((eSimulationStateType)state->type) { + case SIM_STATE_TYPE_PARTICLES: { + ParticleSimulationState *particle_state = (ParticleSimulationState *)state; + BLO_write_struct(writer, ParticleSimulationState, particle_state); + + CustomDataLayer *layers = NULL; + CustomDataLayer layers_buff[CD_TEMP_CHUNK_SIZE]; + CustomData_file_write_prepare( + &particle_state->attributes, &layers, layers_buff, ARRAY_SIZE(layers_buff)); + + write_customdata(writer, + &simulation->id, + particle_state->tot_particles, + &particle_state->attributes, + layers, + CD_MASK_ALL); + + write_pointcaches(writer, &particle_state->ptcaches); + break; + } + } + } } } |