[Bf-blender-cvs] [ceba74dcd7b] master: Mantaflow [Part 8]: Customization for particle system

Sebastián Barschkis noreply at git.blender.org
Mon Dec 16 16:39:09 CET 2019


Commit: ceba74dcd7bb43c667ac8e8e18ed80f02d8ba8e6
Author: Sebastián Barschkis
Date:   Mon Dec 16 15:51:43 2019 +0100
Branches: master
https://developer.blender.org/rBceba74dcd7bb43c667ac8e8e18ed80f02d8ba8e6

Mantaflow [Part 8]: Customization for particle system

The particle system needs some tweaks so that it can be used for particles created in Mantaflow (i.e. to read both FLIP and secondary particles from Mantaflow).

Reviewed By: sergey

Maniphest Tasks: T59995

Differential Revision: https://developer.blender.org/D3857

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

M	source/blender/blenkernel/intern/particle_system.c

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

diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 5985d498606..26bfcdacc78 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -85,14 +85,11 @@
 
 #include "RE_shader_ext.h"
 
-/* fluid sim particle import */
-#ifdef WITH_MOD_FLUID
-#  include "DNA_object_fluidsim_types.h"
-#  include "LBM_fluidsim.h"
-#  include <zlib.h>
-#  include <string.h>
-
-#endif  // WITH_MOD_FLUID
+/* FLUID sim particle import */
+#ifdef WITH_FLUID
+#  include "DNA_fluid_types.h"
+#  include "manta_fluid_API.h"
+#endif  // WITH_FLUID
 
 static ThreadRWMutex psys_bvhtree_rwlock = BLI_RWLOCK_INITIALIZER;
 
@@ -594,8 +591,6 @@ static void initialize_particle_texture(ParticleSimulationData *sim, ParticleDat
       }
       pa->time = 0.f;
       break;
-    case PART_FLUID:
-      break;
   }
 }
 
@@ -4143,7 +4138,7 @@ static void cached_step(ParticleSimulationData *sim, float cfra, const bool use_
 }
 
 static void particles_fluid_step(ParticleSimulationData *sim,
-                                 int UNUSED(cfra),
+                                 int cfra,
                                  const bool use_render_params)
 {
   ParticleSystem *psys = sim->psys;
@@ -4153,80 +4148,223 @@ static void particles_fluid_step(ParticleSimulationData *sim,
     psys->totpart = 0;
   }
 
-  /* fluid sim particle import handling, actual loading of particles from file */
-#ifdef WITH_MOD_FLUID
+#ifdef WITH_FLUID
   {
-    FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(
-        sim->ob, eModifierType_Fluidsim);
+    Object *ob = sim->ob;
+    FluidModifierData *mmd = (FluidModifierData *)modifiers_findByType(ob, eModifierType_Fluid);
+
+    if (mmd && mmd->domain && mmd->domain->fluid) {
+      FluidDomainSettings *mds = mmd->domain;
 
-    if (fluidmd && fluidmd->fss) {
-      FluidsimSettings *fss = fluidmd->fss;
       ParticleSettings *part = psys->part;
       ParticleData *pa = NULL;
-      char filename[256];
-      char debugStrBuffer[256];
-      int curFrame = sim->scene->r.cfra - 1;  // warning - sync with derived mesh fsmesh loading
-      int p, j, totpart;
-      int readMask, activeParts = 0, fileParts = 0;
-      gzFile gzf;
-
-      // XXX          if (ob==G.obedit) // off...
-      //              return;
-
-      // ok, start loading
-      BLI_join_dirfile(
-          filename, sizeof(filename), fss->surfdataPath, OB_FLUIDSIM_SURF_PARTICLES_FNAME);
 
-      BLI_path_abs(filename, modifier_path_relbase_from_global(sim->ob));
-
-      BLI_path_frame(filename, curFrame, 0);  // fixed #frame-no
-
-      gzf = BLI_gzopen(filename, "rb");
-      if (!gzf) {
+      int p, totpart, tottypepart = 0;
+      int flagActivePart, activeParts = 0;
+      float posX, posY, posZ, velX, velY, velZ;
+      float resX, resY, resZ;
+      int upres = 1;
+      char debugStrBuffer[256];
+      float tmp[3] = {0}, tmp2[3] = {0};
+
+      /* Helper variables for scaling. */
+      float min[3], max[3], size[3], cell_size_scaled[3], max_size;
+
+      /* Sanity check: parts also enabled in fluid domain? */
+      if ((part->type & PART_FLUID_FLIP &&
+           (mds->particle_type & FLUID_DOMAIN_PARTICLE_FLIP) == 0) ||
+          (part->type & PART_FLUID_SPRAY &&
+           (mds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY) == 0) ||
+          (part->type & PART_FLUID_BUBBLE &&
+           (mds->particle_type & FLUID_DOMAIN_PARTICLE_BUBBLE) == 0) ||
+          (part->type & PART_FLUID_FOAM &&
+           (mds->particle_type & FLUID_DOMAIN_PARTICLE_FOAM) == 0) ||
+          (part->type & PART_FLUID_TRACER &&
+           (mds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER) == 0)) {
         BLI_snprintf(debugStrBuffer,
                      sizeof(debugStrBuffer),
-                     "readFsPartData::error - Unable to open file for reading '%s'\n",
-                     filename);
-        // XXX bad level call elbeemDebugOut(debugStrBuffer);
+                     "particles_fluid_step::error - found particle system that is not enabled in "
+                     "fluid domain\n");
         return;
       }
 
-      gzread(gzf, &totpart, sizeof(totpart));
-      totpart = (use_render_params) ? totpart : (part->disp * totpart) / 100;
+      /* Count particle amount. tottypepart is only important for snd particles. */
+      if (part->type & PART_FLUID_FLIP) {
+        tottypepart = totpart = manta_liquid_get_num_flip_particles(mds->fluid);
+      }
+      if (part->type &
+          (PART_FLUID_SPRAY | PART_FLUID_BUBBLE | PART_FLUID_FOAM | PART_FLUID_TRACER)) {
+        totpart = manta_liquid_get_num_snd_particles(mds->fluid);
+
+        /* tottypepart is the amount of particles of a snd particle type. */
+        for (p = 0; p < totpart; p++) {
+          flagActivePart = manta_liquid_get_snd_particle_flag_at(mds->fluid, p);
+          if ((part->type & PART_FLUID_SPRAY) && (flagActivePart & PARTICLE_TYPE_SPRAY))
+            tottypepart++;
+          if ((part->type & PART_FLUID_BUBBLE) && (flagActivePart & PARTICLE_TYPE_BUBBLE))
+            tottypepart++;
+          if ((part->type & PART_FLUID_FOAM) && (flagActivePart & PARTICLE_TYPE_FOAM))
+            tottypepart++;
+          if ((part->type & PART_FLUID_TRACER) && (flagActivePart & PARTICLE_TYPE_TRACER))
+            tottypepart++;
+        }
+      }
+      /* Sanity check: no particles present. */
+      if (!totpart || !tottypepart)
+        return;
+
+      /* How many particles to display? */
+      tottypepart = (use_render_params) ? tottypepart : (part->disp * tottypepart) / 100;
 
-      part->totpart = totpart;
+      part->totpart = tottypepart;
       part->sta = part->end = 1.0f;
       part->lifetime = sim->scene->r.efra + 1;
 
-      /* allocate particles */
+      /* Allocate particles. */
       realloc_particles(sim, part->totpart);
 
-      // set up reading mask
-      readMask = fss->typeFlags;
+      /* Set some randomness when choosing which particles to display. */
+      sim->rng = BLI_rng_new_srandom(31415926 + (int)cfra + psys->seed);
+      double r, dispProb = (double)part->disp / 100.0;
 
-      for (p = 0, pa = psys->particles; p < totpart; p++, pa++) {
-        int ptype = 0;
+      /* Loop over *all* particles. Will break out of loop before tottypepart amount exceeded. */
+      for (p = 0, pa = psys->particles; p < totpart; p++) {
 
-        gzread(gzf, &ptype, sizeof(ptype));
-        if (ptype & readMask) {
-          activeParts++;
+        /* Apply some randomness and determine which particles to skip. */
+        r = BLI_rng_get_double(sim->rng);
+        if (r > dispProb)
+          continue;
 
-          gzread(gzf, &(pa->size), sizeof(float));
+        /* flag, res, upres, pos, vel for FLIP and snd particles have different getters. */
+        if (part->type & PART_FLUID_FLIP) {
+          flagActivePart = manta_liquid_get_flip_particle_flag_at(mds->fluid, p);
 
-          pa->size /= 10.0f;
+          resX = (float)manta_get_res_x(mds->fluid);
+          resY = (float)manta_get_res_y(mds->fluid);
+          resZ = (float)manta_get_res_z(mds->fluid);
 
-          for (j = 0; j < 3; j++) {
-            float wrf;
-            gzread(gzf, &wrf, sizeof(wrf));
-            pa->state.co[j] = wrf;
-            // fprintf(stderr,"Rj%d ",j);
-          }
-          for (j = 0; j < 3; j++) {
-            float wrf;
-            gzread(gzf, &wrf, sizeof(wrf));
-            pa->state.vel[j] = wrf;
-          }
+          upres = 1;
+
+          posX = manta_liquid_get_flip_particle_position_x_at(mds->fluid, p);
+          posY = manta_liquid_get_flip_particle_position_y_at(mds->fluid, p);
+          posZ = manta_liquid_get_flip_particle_position_z_at(mds->fluid, p);
+
+          velX = manta_liquid_get_flip_particle_velocity_x_at(mds->fluid, p);
+          velY = manta_liquid_get_flip_particle_velocity_y_at(mds->fluid, p);
+          velZ = manta_liquid_get_flip_particle_velocity_z_at(mds->fluid, p);
+        }
+        else if (part->type &
+                 (PART_FLUID_SPRAY | PART_FLUID_BUBBLE | PART_FLUID_FOAM | PART_FLUID_TRACER)) {
+          flagActivePart = manta_liquid_get_snd_particle_flag_at(mds->fluid, p);
+
+          resX = (float)manta_liquid_get_particle_res_x(mds->fluid);
+          resY = (float)manta_liquid_get_particle_res_y(mds->fluid);
+          resZ = (float)manta_liquid_get_particle_res_z(mds->fluid);
+
+          upres = manta_liquid_get_particle_upres(mds->fluid);
+
+          posX = manta_liquid_get_snd_particle_position_x_at(mds->fluid, p);
+          posY = manta_liquid_get_snd_particle_position_y_at(mds->fluid, p);
+          posZ = manta_liquid_get_snd_particle_position_z_at(mds->fluid, p);
 
+          velX = manta_liquid_get_snd_particle_velocity_x_at(mds->fluid, p);
+          velY = manta_liquid_get_snd_particle_velocity_y_at(mds->fluid, p);
+          velZ = manta_liquid_get_snd_particle_velocity_z_at(mds->fluid, p);
+        }
+        else {
+          BLI_snprintf(debugStrBuffer,
+                       sizeof(debugStrBuffer),
+                       "particles_fluid_step::error - unknown particle system type\n");
+          return;
+        }
+#  if 0
+        /* Debugging: Print type of particle system and current particles. */
+        printf("system type is %d and particle type is %d\n", part->type, flagActivePart);
+#  endif
+
+        /* Type of particle must matche current particle system type (only important for snd
+         * particles). */
+        if ((flagActivePart & PARTICLE_TYPE_SPRAY) && (part->type & PART_FLUID_SPRAY) == 0)
+          continue;
+        if ((flagActivePart & PARTICLE_TYPE_BUBBLE) && (part->type & PART_FLUID_BUBBLE) == 0)
+          continue;
+        if ((flagActivePart & PARTICLE_TYPE_FOAM) && (part->type & PART_FLUID_FOAM) == 0)
+          continue;
+        if ((flagActivePart & PARTICLE_TYPE_TRACER) && (part->type & PART_FLUID_TRACER) == 0)
+          continue;
+#  if 0
+        /* Debugging: Print type of particle system and current particles. */
+        printf("system type is %d and particle type is %d\n", part->type, flagActivePart);
+#  endif
+     

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list