[Bf-blender-cvs] [3d919e445a9] functions: add ability to cache the world state to avoid stepping effects
Jacques Lucke
noreply at git.blender.org
Tue Jul 9 18:01:08 CEST 2019
Commit: 3d919e445a928de872ac9c1aa27abca888139fb6
Author: Jacques Lucke
Date: Tue Jul 9 10:53:56 2019 +0200
Branches: functions
https://developer.blender.org/rB3d919e445a928de872ac9c1aa27abca888139fb6
add ability to cache the world state to avoid stepping effects
===================================================================
M source/blender/modifiers/intern/MOD_nodeparticles.c
M source/blender/simulations/BParticles.h
M source/blender/simulations/bparticles/c_wrapper.cpp
===================================================================
diff --git a/source/blender/modifiers/intern/MOD_nodeparticles.c b/source/blender/modifiers/intern/MOD_nodeparticles.c
index dc0410b4a75..9ed2baa5025 100644
--- a/source/blender/modifiers/intern/MOD_nodeparticles.c
+++ b/source/blender/modifiers/intern/MOD_nodeparticles.c
@@ -49,7 +49,8 @@
#include "BParticles.h"
typedef struct RuntimeData {
- BParticlesState state;
+ BParticlesState particles_state;
+ BParticlesWorldState world_state;
float last_simulated_frame;
} RuntimeData;
@@ -57,7 +58,8 @@ static RuntimeData *get_runtime_struct(NodeParticlesModifierData *npmd)
{
if (npmd->modifier.runtime == NULL) {
RuntimeData *runtime = MEM_callocN(sizeof(RuntimeData), __func__);
- runtime->state = NULL;
+ runtime->particles_state = NULL;
+ runtime->world_state = NULL;
runtime->last_simulated_frame = 0.0f;
npmd->modifier.runtime = runtime;
}
@@ -67,7 +69,8 @@ static RuntimeData *get_runtime_struct(NodeParticlesModifierData *npmd)
static void free_runtime_data(RuntimeData *runtime)
{
- BParticles_state_free(runtime->state);
+ BParticles_state_free(runtime->particles_state);
+ BParticles_world_state_free(runtime->world_state);
MEM_freeN(runtime);
}
@@ -80,13 +83,13 @@ static void free_modifier_runtime_data(NodeParticlesModifierData *npmd)
}
}
-static Mesh *point_mesh_from_particle_state(BParticlesState state)
+static Mesh *point_mesh_from_particle_state(BParticlesState particles_state)
{
- uint point_amount = BParticles_state_particle_count(state);
+ uint point_amount = BParticles_state_particle_count(particles_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(state, positions);
+ BParticles_state_get_positions(particles_state, positions);
for (uint i = 0; i < point_amount; i++) {
copy_v3_v3(mesh->mvert[i].co, positions[i]);
@@ -103,8 +106,9 @@ static Mesh *applyModifier(ModifierData *md,
NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md;
RuntimeData *runtime = get_runtime_struct(npmd);
- if (runtime->state == NULL) {
- runtime->state = BParticles_new_empty_state();
+ if (runtime->particles_state == NULL) {
+ runtime->particles_state = BParticles_new_empty_state();
+ runtime->world_state = BParticles_new_world_state();
}
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
@@ -114,17 +118,19 @@ static Mesh *applyModifier(ModifierData *md,
/* do nothing */
}
else if (current_frame == runtime->last_simulated_frame + 1.0f) {
- BParticles_simulate_modifier(npmd, ctx->depsgraph, runtime->state);
+ BParticles_simulate_modifier(
+ npmd, ctx->depsgraph, runtime->particles_state, runtime->world_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->particles_state = BParticles_new_empty_state();
+ runtime->world_state = BParticles_new_world_state();
runtime->last_simulated_frame = current_frame;
}
- return BParticles_test_mesh_from_state(runtime->state);
+ return BParticles_test_mesh_from_state(runtime->particles_state);
}
static void initData(ModifierData *UNUSED(md))
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 70cc46237f2..ebccf5c228c 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -13,18 +13,23 @@ struct Depsgraph;
struct NodeParticlesModifierData;
typedef struct OpaqueBParticlesState *BParticlesState;
+typedef struct OpaqueBParticlesWorldState *BParticlesWorldState;
BParticlesState BParticles_new_empty_state(void);
-void BParticles_state_free(BParticlesState state);
+void BParticles_state_free(BParticlesState particles_state);
+
+BParticlesWorldState BParticles_new_world_state(void);
+void BParticles_world_state_free(BParticlesWorldState world_state);
void BParticles_simulate_modifier(NodeParticlesModifierData *npmd,
Depsgraph *depsgraph,
- BParticlesState state);
+ BParticlesState particles_state,
+ BParticlesWorldState world_state);
-uint BParticles_state_particle_count(BParticlesState state);
-void BParticles_state_get_positions(BParticlesState state, float (*dst)[3]);
+uint BParticles_state_particle_count(BParticlesState particles_state);
+void BParticles_state_get_positions(BParticlesState particles_state, float (*dst)[3]);
-struct Mesh *BParticles_test_mesh_from_state(BParticlesState state_c);
+struct Mesh *BParticles_test_mesh_from_state(BParticlesState particles_state);
#ifdef __cplusplus
}
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 0665ae4dedc..db9d04e77d9 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -52,18 +52,33 @@ using BLI::StringRef;
WRAPPERS(ParticlesState *, BParticlesState);
-/* New Functions
- *********************************************************/
-
BParticlesState BParticles_new_empty_state()
{
ParticlesState *state = new ParticlesState();
return wrap(state);
}
-void BParticles_state_free(BParticlesState state)
+void BParticles_state_free(BParticlesState state_c)
+{
+ delete unwrap(state_c);
+}
+
+class WorldState {
+ public:
+ SmallMap<std::string, float4x4> m_cached_matrices;
+};
+
+WRAPPERS(WorldState *, BParticlesWorldState);
+
+BParticlesWorldState BParticles_new_world_state()
{
- delete unwrap(state);
+ WorldState *world_state = new WorldState();
+ return wrap(world_state);
+}
+
+void BParticles_world_state_free(BParticlesWorldState world_state_c)
+{
+ delete unwrap(world_state_c);
}
class EulerIntegrator : public Integrator {
@@ -205,7 +220,8 @@ class ModifierStepDescription : public StepDescription {
using EmitterInserter = std::function<void(bNode *bnode,
IndexedNodeTree &indexed_tree,
FN::DataFlowNodes::GeneratedGraph &data_graph,
- ModifierStepDescription &step_description)>;
+ ModifierStepDescription &step_description,
+ WorldState &world_state)>;
using EventInserter = EmitterInserter;
using ModifierInserter = EmitterInserter;
@@ -364,7 +380,8 @@ static std::unique_ptr<Action> build_action(SocketWithNode start,
static void INSERT_EMITTER_mesh_surface(bNode *emitter_node,
IndexedNodeTree &indexed_tree,
FN::DataFlowNodes::GeneratedGraph &UNUSED(data_graph),
- ModifierStepDescription &step_description)
+ ModifierStepDescription &step_description,
+ WorldState &world_state)
{
BLI_assert(STREQ(emitter_node->idname, "bp_MeshEmitterNode"));
bNodeSocket *emitter_output = (bNodeSocket *)emitter_node->outputs.first;
@@ -382,8 +399,15 @@ static void INSERT_EMITTER_mesh_surface(bNode *emitter_node,
continue;
}
+ std::string tranformation_key = emitter_node->name;
+ float4x4 last_transformation = world_state.m_cached_matrices.lookup_default(tranformation_key,
+ object->obmat);
+ float4x4 current_transformation = object->obmat;
+
+ world_state.m_cached_matrices.add_override(tranformation_key, current_transformation);
+
Emitter *emitter = EMITTER_mesh_surface(
- type_node->name, (Mesh *)object->data, object->obmat, object->obmat, 1.0f);
+ type_node->name, (Mesh *)object->data, last_transformation, current_transformation, 1.0f);
step_description.m_emitters.append(emitter);
}
}
@@ -391,7 +415,8 @@ static void INSERT_EMITTER_mesh_surface(bNode *emitter_node,
static void INSERT_EMITTER_point(bNode *emitter_node,
IndexedNodeTree &indexed_tree,
FN::DataFlowNodes::GeneratedGraph &UNUSED(data_graph),
- ModifierStepDescription &step_description)
+ ModifierStepDescription &step_description,
+ WorldState &UNUSED(world_state))
{
BLI_assert(STREQ(emitter_node->idname, "bp_PointEmitterNode"));
bNodeSocket *emitter_output = (bNodeSocket *)emitter_node->outputs.first;
@@ -416,7 +441,8 @@ static void INSERT_EMITTER_point(bNode *emitter_node,
static void INSERT_EVENT_age_reached(bNode *event_node,
IndexedNodeTree &indexed_tree,
FN::DataFlowNodes::GeneratedGraph &data_graph,
- ModifierStepDescription &step_description)
+ ModifierStepDescription &step_description,
+ WorldState &UNUSED(world_state))
{
BLI_assert(STREQ(event_node->idname, "bp_AgeReachedEventNode"));
bSocketList node_inputs(event_node->inputs);
@@ -442,7 +468,8 @@ static void INSERT_EVENT_age_reached(bNode *event_node,
static void INSERT_EVENT_mesh_collision(bNode *event_node,
IndexedNodeTree &indexed_tree,
FN::DataFlowNodes::GeneratedGraph &data_graph,
- ModifierStepDescription &step_description)
+ ModifierStepDescription &step_description,
+ WorldState &UNUSED(world_state))
{
BLI_assert(STREQ(event_node->idname, "bp_MeshCollisionEventNode"));
bSocketList node_inputs(event_node->inputs);
@@ -472,7 +499,8 @@ static void INSERT_EVENT_mesh_collision(bNode *event_node,
static voi
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list