Commit: c8bf758a9a7a0189498481a317c80dd5a40beeab Author: Jacques Lucke Date: Thu Jun 20 11:04:45 2019 +0200 Branches: functions https://developer.blender.org/rBc8bf758a9a7a0189498481a317c80dd5a40beeab
restructure solver api Now I have to bring back all the functionality that was there already. =================================================================== M source/blender/modifiers/intern/MOD_nodeparticles.c M source/blender/simulations/BParticles.h M source/blender/simulations/CMakeLists.txt M source/blender/simulations/bparticles/c_wrapper.cpp M source/blender/simulations/bparticles/core.cpp M source/blender/simulations/bparticles/core.hpp M source/blender/simulations/bparticles/particles_container.hpp D source/blender/simulations/bparticles/playground_solver.hpp A source/blender/simulations/bparticles/simulate.cpp A source/blender/simulations/bparticles/simulate.hpp =================================================================== diff --git a/source/blender/modifiers/intern/MOD_nodeparticles.c b/source/blender/modifiers/intern/MOD_nodeparticles.c index 0589297b140..422a742c8ff 100644 --- a/source/blender/modifiers/intern/MOD_nodeparticles.c +++ b/source/blender/modifiers/intern/MOD_nodeparticles.c @@ -49,104 +49,44 @@ #include "BParticles.h" typedef struct RuntimeData { - BParticlesDescription description; - BParticlesSolver solver; BParticlesState state; float last_simulated_frame; } RuntimeData; -static RuntimeData *get_runtime_data(NodeParticlesModifierData *npmd) +static RuntimeData *get_runtime_struct(NodeParticlesModifierData *npmd) { - RuntimeData *data = npmd->modifier.runtime; - BLI_assert(data); - return data; -} - -static BParticlesDescription create_current_description(Object *UNUSED(self), - NodeParticlesModifierData *npmd, - Depsgraph *UNUSED(depsgraph)) -{ - return BParticles_playground_description(npmd->control1, npmd->control2, npmd->emitter_object); -} - -static void ensure_runtime_data(Object *self, - NodeParticlesModifierData *npmd, - Depsgraph *depsgraph) -{ - if (npmd->modifier.runtime != NULL) { - return; + if (npmd->modifier.runtime == NULL) { + RuntimeData *runtime = MEM_callocN(sizeof(RuntimeData), __func__); + runtime->state = NULL; + runtime->last_simulated_frame = 0.0f; + npmd->modifier.runtime = runtime; } - RuntimeData *runtime = MEM_callocN(sizeof(RuntimeData), __func__); - - runtime->description = create_current_description(self, npmd, depsgraph); - runtime->solver = BParticles_solver_build(runtime->description); - runtime->state = BParticles_state_init(runtime->solver); - runtime->last_simulated_frame = 0.0f; - - npmd->modifier.runtime = runtime; + return npmd->modifier.runtime; } static void free_runtime_data(RuntimeData *runtime) { BParticles_state_free(runtime->state); - BParticles_solver_free(runtime->solver); - BParticles_description_free(runtime->description); MEM_freeN(runtime); } -static void clear_runtime_data(NodeParticlesModifierData *npmd) +static void free_modifier_runtime_data(NodeParticlesModifierData *npmd) { - if (npmd->modifier.runtime != NULL) { - free_runtime_data(npmd->modifier.runtime); + RuntimeData *runtime = (RuntimeData *)npmd->modifier.runtime; + if (runtime != NULL) { + free_runtime_data(runtime); npmd->modifier.runtime = NULL; } } -static Mesh *applyModifier(ModifierData *md, - const struct ModifierEvalContext *ctx, - Mesh *UNUSED(mesh)) +static Mesh *mesh_from_particles_state(BParticlesState state) { - NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md; - ensure_runtime_data(ctx->object, npmd, ctx->depsgraph); - RuntimeData *runtime = get_runtime_data(npmd); - - Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); - float current_frame = BKE_scene_frame_get(scene); - float fps = FPS; - - if (current_frame != runtime->last_simulated_frame) { - BParticlesDescription new_description = create_current_description( - ctx->object, npmd, ctx->depsgraph); - BParticlesSolver new_solver = BParticles_solver_build(new_description); - - if (current_frame == runtime->last_simulated_frame + 1) { - BParticles_state_adapt(new_solver, runtime->state); - - BParticles_solver_free(runtime->solver); - BParticles_description_free(runtime->description); - runtime->description = new_description; - runtime->solver = new_solver; - - BParticles_state_step(runtime->solver, runtime->state, 1.0f / fps); - } - else { - BParticles_state_free(runtime->state); - BParticles_solver_free(runtime->solver); - BParticles_description_free(runtime->description); - - runtime->description = new_description; - runtime->solver = new_solver; - runtime->state = BParticles_state_init(new_solver); - } - runtime->last_simulated_frame = current_frame; - } - - uint point_amount = BParticles_state_particle_count(runtime->solver, runtime->state); + uint point_amount = BParticles_state_particle_count(state); Mesh *mesh = BKE_mesh_new_nomain(point_amount, 0, 0, 0, 0); float(*positions)[3] = MEM_malloc_arrayN(point_amount, sizeof(float[3]), __func__); - BParticles_state_get_positions(runtime->solver, runtime->state, positions); + BParticles_state_get_positions(state, positions); for (uint i = 0; i < point_amount; i++) { copy_v3_v3(mesh->mvert[i].co, positions[i]); @@ -157,6 +97,37 @@ static Mesh *applyModifier(ModifierData *md, return mesh; } +static Mesh *applyModifier(ModifierData *md, + const struct ModifierEvalContext *ctx, + Mesh *UNUSED(mesh)) +{ + NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md; + RuntimeData *runtime = get_runtime_struct(npmd); + + if (runtime->state == NULL) { + runtime->state = BParticles_new_empty_state(); + } + + Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); + float current_frame = BKE_scene_frame_get(scene); + + if (current_frame == runtime->last_simulated_frame) { + /* do nothing */ + } + else if (current_frame == runtime->last_simulated_frame + 1.0f) { + BParticles_simulate_modifier(npmd, ctx->depsgraph, runtime->state); + runtime->last_simulated_frame = current_frame; + } + else { + free_modifier_runtime_data(npmd); + runtime = get_runtime_struct(npmd); + runtime->state = BParticles_new_empty_state(); + runtime->last_simulated_frame = current_frame; + } + + return mesh_from_particles_state(runtime->state); +} + static void initData(ModifierData *UNUSED(md)) { } @@ -164,7 +135,7 @@ static void initData(ModifierData *UNUSED(md)) static void freeData(ModifierData *md) { NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md; - clear_runtime_data(npmd); + free_modifier_runtime_data(npmd); } static void freeRuntimeData(void *runtime_data_v) @@ -172,8 +143,8 @@ static void freeRuntimeData(void *runtime_data_v) if (runtime_data_v == NULL) { return; } - RuntimeData *data = (RuntimeData *)runtime_data_v; - free_runtime_data(data); + RuntimeData *runtime = (RuntimeData *)runtime_data_v; + free_runtime_data(runtime); } static bool dependsOnTime(ModifierData *UNUSED(md)) diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h index 5fdc78a4b52..ca04093f3c9 100644 --- a/source/blender/simulations/BParticles.h +++ b/source/blender/simulations/BParticles.h @@ -8,29 +8,20 @@ extern "C" { #endif -struct Object; +struct Depsgraph; +struct NodeParticlesModifierData; -typedef struct OpaqueBParticlesDescription *BParticlesDescription; -typedef struct OpaqueBParticlesSolver *BParticlesSolver; typedef struct OpaqueBParticlesState *BParticlesState; -BParticlesDescription BParticles_playground_description(float control1, - float control2, - struct Object *object); -void BParticles_description_free(BParticlesDescription description); - -BParticlesSolver BParticles_solver_build(BParticlesDescription description); -void BParticles_solver_free(BParticlesSolver solver); - -BParticlesState BParticles_state_init(BParticlesSolver solver); -void BParticles_state_adapt(BParticlesSolver new_solver, BParticlesState state_to_adapt); -void BParticles_state_step(BParticlesSolver solver, BParticlesState state, float elapsed_seconds); +BParticlesState BParticles_new_empty_state(void); void BParticles_state_free(BParticlesState state); -uint BParticles_state_particle_count(BParticlesSolver solver, BParticlesState state); -void BParticles_state_get_positions(BParticlesSolver solver, - BParticlesState state, - float (*dst)[3]); +void BParticles_simulate_modifier(NodeParticlesModifierData *npmd, + Depsgraph *depsgraph, + BParticlesState state); + +uint BParticles_state_particle_count(BParticlesState state); +void BParticles_state_get_positions(BParticlesState state, float (*dst)[3]); #ifdef __cplusplus } diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt index 08770db1712..18d05de52b6 100644 --- a/source/blender/simulations/CMakeLists.txt +++ b/source/blender/simulations/CMakeLists.txt @@ -19,8 +19,8 @@ set(SRC bparticles/core.cpp bparticles/particles_container.hpp bparticles/particles_container.cpp - bparticles/playground_solver.hpp - bparticles/playground_solver.cpp + bparticles/simulate.hpp + bparticles/simulate.cpp bparticles/emitters.hpp bparticles/emitters.cpp bparticles/forces.hpp diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp index 238961a7c18..c5b471795a5 100644 --- a/source/blender/simulations/bparticles/c_wrapper.cpp +++ b/source/blender/simulations/bparticles/c_wrapper.cpp @@ -1,9 +1,9 @@ #include "BParticles.h" #include "core.hpp" #include "particles_container.hpp" -#include "playground_solver.hpp" #include "emitters.hpp" #include "forces.hpp" +#include "simulate.hpp" #include "BLI_timeit.hpp" #include "BLI_listbase.h" @@ -23,109 +23,64 @@ return (T2)value; \ } -using BParticles::AttributeArrays; -using BParticles::AttributeType; -using BParticles::Description; -using BParticles::Emitter; -using BParticles::EmitterHelper; -using BParticles::EmitterTarget; -using BParticles::ParticlesBlock; -using BParticles::Solver; -using BParticles::StateBase; -using BParticles::WrappedState; +using namespace BParticles; using BLI::ArrayRef; using BLI::float3; using BLI::SmallVector; using BLI::StringRef; -WRAPPERS(BParticles::Description *, BParticlesDescription); -WRAPPERS(BParticles::Solver *, BParticlesSolver); -WRAPPERS(BParticles::WrappedState *, BParticlesState); +WRAPPERS(ParticlesState *, BParticlesState); @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs