[Bf-blender-cvs] [580d50091cf] master: Particles: Create a simulation state for every Particle Simulation node

Jacques Lucke noreply at git.blender.org
Thu Jul 9 15:40:59 CEST 2020


Commit: 580d50091cfb0467cbde165058a6e78ef4898045
Author: Jacques Lucke
Date:   Thu Jul 9 15:40:27 2020 +0200
Branches: master
https://developer.blender.org/rB580d50091cfb0467cbde165058a6e78ef4898045

Particles: Create a simulation state for every Particle Simulation node

Every Particle Simulation node has a name (or a path when it is in a node group).
This name has to be used in the Simulation modifier on a point cloud to see
the particles.

Caching has been disabled for now, because it was holding back development
a bit. To reset the simulation, go back to frame 1.

Currently, there is no way to influence the simulation. There are just some
randomly moving points. Changing that is the next step.

===================================================================

M	source/blender/blenkernel/BKE_pointcache.h
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenkernel/intern/simulation.cc
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesdna/DNA_simulation_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_simulation.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index b0973ed458c..f919a31c165 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -296,7 +296,9 @@ void BKE_ptcache_id_from_dynamicpaint(PTCacheID *pid,
                                       struct Object *ob,
                                       struct DynamicPaintSurface *surface);
 void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw);
-void BKE_ptcache_id_from_sim_particles(PTCacheID *pid, struct ParticleSimulationState *state);
+void BKE_ptcache_id_from_sim_particles(PTCacheID *pid,
+                                       struct ParticleSimulationState *state_orig,
+                                       struct ParticleSimulationState *state_cow);
 
 PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache);
 void BKE_ptcache_ids_from_object(struct ListBase *lb,
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 76bc7a7bfb7..c11fa69db76 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1772,7 +1772,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
     /* 42: CD_SCULPT_FACE_SETS */
     {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
     /* 43: CD_LOCATION */
-    {sizeof(float[3]), "vec3f", 1, NULL, NULL, NULL, NULL, NULL, NULL},
+    {sizeof(float[3]), "vec3f", 1, "Location", NULL, NULL, NULL, NULL, NULL},
     /* 44: CD_RADIUS */
     {sizeof(float), "MFloatProperty", 1, NULL, NULL, NULL, NULL, NULL, NULL},
     /* 45: CD_HAIRCURVE */
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index dbd6d99c7fe..ce5402551b6 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1898,19 +1898,13 @@ static void ptcache_sim_particle_read(
   PTCACHE_DATA_TO(data, BPHYS_DATA_LOCATION, 0, positions + (index * 3));
 }
 
-void BKE_ptcache_id_from_sim_particles(PTCacheID *pid, ParticleSimulationState *state)
+void BKE_ptcache_id_from_sim_particles(PTCacheID *pid,
+                                       ParticleSimulationState *state_orig,
+                                       ParticleSimulationState *state_cow)
 {
   memset(pid, 0, sizeof(PTCacheID));
 
-  ParticleSimulationState *state_orig;
-  if (state->head.orig_state != NULL) {
-    state_orig = (ParticleSimulationState *)state->head.orig_state;
-  }
-  else {
-    state_orig = state;
-  }
-
-  pid->calldata = state;
+  pid->calldata = state_cow;
   pid->type = PTCACHE_TYPE_SIM_PARTICLES;
   pid->cache = state_orig->point_cache;
   pid->cache_ptr = &state_orig->point_cache;
@@ -2050,11 +2044,7 @@ static bool foreach_object_modifier_ptcache(Object *object,
         LISTBASE_FOREACH (SimulationState *, state, &smd->simulation->states) {
           switch ((eSimulationStateType)state->type) {
             case SIM_STATE_TYPE_PARTICLES: {
-              ParticleSimulationState *particle_state = (ParticleSimulationState *)state;
-              BKE_ptcache_id_from_sim_particles(&pid, particle_state);
-              if (!callback(&pid, callback_user_data)) {
-                return false;
-              }
+              /* TODO(jacques) */
               break;
             }
           }
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index c4a35141b0d..35ef664dce3 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -31,6 +31,7 @@
 #include "BLI_float3.hh"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_rand.h"
 #include "BLI_span.hh"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
@@ -44,6 +45,7 @@
 #include "BKE_lib_remap.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
+#include "BKE_node_tree_multi_function.hh"
 #include "BKE_pointcache.h"
 #include "BKE_simulation.h"
 
@@ -51,9 +53,18 @@
 
 #include "BLT_translation.h"
 
+#include "FN_attributes_ref.hh"
+#include "FN_cpp_types.hh"
+#include "FN_multi_function_network_evaluation.hh"
+#include "FN_multi_function_network_optimization.hh"
+
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
 
+extern "C" {
+void WM_clipboard_text_set(const char *buf, bool selection);
+}
+
 static void simulation_init_data(ID *id)
 {
   Simulation *simulation = (Simulation *)id;
@@ -63,14 +74,6 @@ static void simulation_init_data(ID *id)
 
   bNodeTree *ntree = ntreeAddTree(nullptr, "Simulation Nodetree", ntreeType_Simulation->idname);
   simulation->nodetree = ntree;
-
-  /* Add a default particle simulation state for now. */
-  ParticleSimulationState *state = (ParticleSimulationState *)MEM_callocN(
-      sizeof(ParticleSimulationState), __func__);
-  CustomData_reset(&state->attributes);
-
-  state->point_cache = BKE_ptcache_add(&state->ptcaches);
-  BLI_addtail(&simulation->states, state);
 }
 
 static void simulation_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
@@ -89,19 +92,19 @@ static void simulation_copy_data(Main *bmain, ID *id_dst, const ID *id_src, cons
   }
 
   BLI_listbase_clear(&simulation_dst->states);
+}
 
-  LISTBASE_FOREACH (const SimulationState *, state_src, &simulation_src->states) {
-    switch ((eSimulationStateType)state_src->type) {
-      case SIM_STATE_TYPE_PARTICLES: {
-        ParticleSimulationState *particle_state_dst = (ParticleSimulationState *)MEM_callocN(
-            sizeof(ParticleSimulationState), __func__);
-        CustomData_reset(&particle_state_dst->attributes);
+static void free_simulation_state_head(SimulationState *state)
+{
+  MEM_freeN(state->name);
+}
 
-        BLI_addtail(&simulation_dst->states, particle_state_dst);
-        break;
-      }
-    }
-  }
+static void free_particle_simulation_state(ParticleSimulationState *state)
+{
+  free_simulation_state_head(&state->head);
+  CustomData_free(&state->attributes, state->tot_particles);
+  BKE_ptcache_free_list(&state->ptcaches);
+  MEM_freeN(state);
 }
 
 static void simulation_free_data(ID *id)
@@ -119,13 +122,10 @@ static void simulation_free_data(ID *id)
   LISTBASE_FOREACH_MUTABLE (SimulationState *, state, &simulation->states) {
     switch ((eSimulationStateType)state->type) {
       case SIM_STATE_TYPE_PARTICLES: {
-        ParticleSimulationState *particle_state = (ParticleSimulationState *)state;
-        CustomData_free(&particle_state->attributes, particle_state->tot_particles);
-        BKE_ptcache_free_list(&particle_state->ptcaches);
+        free_particle_simulation_state((ParticleSimulationState *)state);
         break;
       }
     }
-    MEM_freeN(state);
   }
 }
 
@@ -166,59 +166,230 @@ void *BKE_simulation_add(Main *bmain, const char *name)
 
 namespace blender::bke {
 
-static MutableSpan<float3> get_particle_positions(ParticleSimulationState *state)
-{
-  return MutableSpan<float3>(
-      (float3 *)CustomData_get_layer_named(&state->attributes, CD_LOCATION, "Position"),
-      state->tot_particles);
-}
-
 static void ensure_attributes_exist(ParticleSimulationState *state)
 {
   if (CustomData_get_layer_named(&state->attributes, CD_LOCATION, "Position") == nullptr) {
     CustomData_add_layer_named(
         &state->attributes, CD_LOCATION, CD_CALLOC, nullptr, state->tot_particles, "Position");
   }
+  if (CustomData_get_layer_named(&state->attributes, CD_LOCATION, "Velocity") == nullptr) {
+    CustomData_add_layer_named(
+        &state->attributes, CD_LOCATION, CD_CALLOC, nullptr, state->tot_particles, "Velocity");
+  }
 }
 
-static void copy_particle_state_to_cow(ParticleSimulationState *state_orig,
-                                       ParticleSimulationState *state_cow)
+static void copy_states_to_cow(Simulation *simulation_orig, Simulation *simulation_cow)
 {
-  ensure_attributes_exist(state_cow);
-  CustomData_free(&state_cow->attributes, state_cow->tot_particles);
-  CustomData_copy(&state_orig->attributes,
-                  &state_cow->attributes,
-                  CD_MASK_ALL,
-                  CD_DUPLICATE,
-                  state_orig->tot_particles);
-  state_cow->current_frame = state_orig->current_frame;
-  state_cow->tot_particles = state_orig->tot_particles;
+  LISTBASE_FOREACH_MUTABLE (SimulationState *, state_cow, &simulation_cow->states) {
+    switch ((eSimulationStateType)state_cow->type) {
+      case SIM_STATE_TYPE_PARTICLES: {
+        BLI_remlink(&simulation_cow->states, state_cow);
+        free_particle_simulation_state((ParticleSimulationState *)state_cow);
+        break;
+      }
+    }
+  }
+  simulation_cow->current_frame = simulation_orig->current_frame;
+
+  LISTBASE_FOREACH (SimulationState *, state_orig, &simulation_orig->states) {
+    switch ((eSimulationStateType)state_orig->type) {
+      case SIM_STATE_TYPE_PARTICLES: {
+        ParticleSimulationState *particle_state_orig = (ParticleSimulationState *)state_orig;
+        ParticleSimulationState *particle_state_cow = (ParticleSimulationState *)MEM_callocN(
+            sizeof(*particle_state_cow), AT);
+        particle_state_cow->tot_particles = particle_state_orig->tot_particles;
+        particle_state_cow->head.name = BLI_strdup(state_orig->name);
+        CustomData_copy(&particle_state_orig->attributes,
+                        &particle_state_cow->attributes,
+                        CD_MASK_ALL,
+                        CD_DUPLICATE,
+                        particle_state_orig->tot_particles);
+        BLI_addtail(&simulation_cow->states, particle_state_cow);
+        break;
+      }
+    }
+  }
 }
 
-static void simulation_data_update(Depsgraph *depsgraph, Scene *scene, Simulation *simulation)
+using AttributeNodeMap = Map<fn::MFDummyNode *, std::pair<std::string, fn::MFDataType>>;
+
+static AttributeNodeMap deduplicate_attribute_nodes(fn::MFNetwork &network,
+                                                    MFNetworkTreeMap &network_map,
+                                                    const DerivedNodeTree &tree)
 {
-  int current_frame = scene-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list