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/modifiers/intern/MOD_simulation.cc | |
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/modifiers/intern/MOD_simulation.cc')
-rw-r--r-- | source/blender/modifiers/intern/MOD_simulation.cc | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/source/blender/modifiers/intern/MOD_simulation.cc b/source/blender/modifiers/intern/MOD_simulation.cc index f126d1af959..5ccf945b5a6 100644 --- a/source/blender/modifiers/intern/MOD_simulation.cc +++ b/source/blender/modifiers/intern/MOD_simulation.cc @@ -21,11 +21,14 @@ * \ingroup modifiers */ +#include <cstring> #include <iostream> #include <string> #include "MEM_guardedalloc.h" +#include "BLI_float3.hh" +#include "BLI_listbase.h" #include "BLI_utildefines.h" #include "DNA_mesh_types.h" @@ -41,6 +44,8 @@ #include "BKE_lib_query.h" #include "BKE_mesh.h" #include "BKE_modifier.h" +#include "BKE_pointcloud.h" +#include "BKE_simulation.h" /* SpaceType struct has a member called 'new' which obviously conflicts with C++ * so temporarily redefining the new keyword to make it compile. */ @@ -59,6 +64,8 @@ #include "MOD_modifiertypes.h" #include "MOD_ui_common.h" +using BLI::float3; + static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) { SimulationModifierData *smd = (SimulationModifierData *)md; @@ -81,12 +88,42 @@ static bool isDisabled(const struct Scene *UNUSED(scene), return smd->simulation == nullptr; } +static const ParticleSimulationState *find_particle_state(SimulationModifierData *smd) +{ + if (smd->simulation == nullptr) { + return nullptr; + } + LISTBASE_FOREACH (const SimulationState *, state, &smd->simulation->states) { + if (state->type == SIM_STATE_TYPE_PARTICLES) { + return (ParticleSimulationState *)state; + } + } + return nullptr; +} + static PointCloud *modifyPointCloud(ModifierData *md, const ModifierEvalContext *UNUSED(ctx), - PointCloud *pointcloud) + PointCloud *input_pointcloud) { SimulationModifierData *smd = (SimulationModifierData *)md; - UNUSED_VARS(smd); + const ParticleSimulationState *state = find_particle_state(smd); + if (state == nullptr) { + return input_pointcloud; + } + + PointCloud *pointcloud = BKE_pointcloud_new_for_eval(input_pointcloud, state->tot_particles); + if (state->tot_particles == 0) { + return pointcloud; + } + + const float3 *positions = (const float3 *)CustomData_get_layer_named( + &state->attributes, CD_LOCATION, "Position"); + memcpy(pointcloud->co, positions, sizeof(float3) * state->tot_particles); + + for (int i = 0; i < state->tot_particles; i++) { + pointcloud->radius[i] = 0.05f; + } + return pointcloud; } |