Commit: c1fb55b44b6c99248d38a7578e92ea79d95fae36
Author: Sebastián Barschkis
Date:   Tue Oct 3 14:08:58 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBc1fb55b44b6c99248d38a7578e92ea79d95fae36

big fluid particles update

- refactored original snd particle functions on mantaflow side
- bug fixes for particle reading (fixes disappearing issue when using
various ptypes at once)
- added support (esp. in caching) for future particle life vector (on
mantaflow it's side already in use. todo: copy values to blender
particle systems)
- memory optimization: only allocate particle fields when they're
actually enabled in UI
- fixed standalone script export (snd particle system, pdata fields)

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

M       intern/mantaflow/extern/manta_fluid_API.h
M       intern/mantaflow/intern/FLUID.cpp
M       intern/mantaflow/intern/FLUID.h
M       intern/mantaflow/intern/manta_fluid_API.cpp
M       intern/mantaflow/intern/manta_pp/omp/particle.h
M       intern/mantaflow/intern/manta_pp/omp/plugin/flip.cpp
M       intern/mantaflow/intern/manta_pp/omp/python/defines.py.reg
M       intern/mantaflow/intern/manta_pp/omp/python/defines.py.reg.cpp
M       intern/mantaflow/intern/manta_pp/omp/registration.cpp
M       intern/mantaflow/intern/manta_pp/tbb/particle.h
M       intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp
M       intern/mantaflow/intern/manta_pp/tbb/python/defines.py.reg
M       intern/mantaflow/intern/manta_pp/tbb/python/defines.py.reg.cpp
M       intern/mantaflow/intern/manta_pp/tbb/registration.cpp
M       intern/mantaflow/intern/strings/liquid_script.h
M       intern/mantaflow/intern/strings/shared_script.h
M       intern/mantaflow/intern/strings/smoke_script.h
M       source/blender/blenkernel/intern/particle_system.c
M       source/blender/blenkernel/intern/pointcache.c
M       source/blender/blenkernel/intern/smoke.c
M       source/blender/makesdna/DNA_particle_types.h

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h 
b/intern/mantaflow/extern/manta_fluid_API.h
index 9af20ff4ccb..5309b99d07e 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -45,7 +45,7 @@ void smoke_step(struct FLUID *smoke, int framenr);
 void smoke_dissolve(struct FLUID *smoke, int speed, int log);
 void smoke_dissolve_wavelet(struct FLUID *smoke, int speed, int log);
 void smoke_export(struct FLUID *smoke, float *dt, float *dx, float **dens, 
float **react, float **flame, float **fuel, float **heat, float **vx, float 
**vy, float **vz, float **r, float **g, float **b, int **obstacles);
-void liquid_export(struct FLUID *liquid, float **phi, float **pp, float 
**pvel, float **ppSnd, float **pvelSnd, int **ptypeSnd);
+void liquid_export(struct FLUID *liquid, float **phi, float **pp, float 
**pvel, float **ppSnd, float **pvelSnd, int **ptypeSnd, int **plifeSnd);
 void smoke_turbulence_export(struct FLUID *smoke, float **dens, float **react, 
float **flame, float **fuel, float **r, float **g, float **b , float **tcu, 
float **tcv, float **tcw, float **tcu2, float **tcv2, float **tcw2);
 float *smoke_get_density(struct FLUID *smoke);
 float *smoke_get_fuel(struct FLUID *smoke);
@@ -154,6 +154,7 @@ void liquid_set_snd_particle_data(struct FLUID* liquid, 
float* buffer, int numPa
 void liquid_set_flip_particle_velocity(struct FLUID* liquid, float* buffer, 
int numParts);
 void liquid_set_snd_particle_velocity(struct FLUID* liquid, float* buffer, int 
numParts);
 void liquid_set_snd_particle_type(struct FLUID* liquid, int* buffer, int 
numParts);
+void liquid_set_snd_particle_life(struct FLUID* liquid, int* buffer, int 
numParts);
 
 // Fluids in general
 int *fluid_get_num_obstacle(struct FLUID *fluid);
@@ -166,6 +167,7 @@ int fluid_get_res_z(struct FLUID *fluid);
 void fluid_ensure_obstacle(struct FLUID *fluid, struct SmokeModifierData *smd);
 void fluid_ensure_guiding(struct FLUID *fluid, struct SmokeModifierData *smd);
 void fluid_ensure_invelocity(struct FLUID *fluid, struct SmokeModifierData 
*smd);
+void fluid_ensure_sndparts(struct FLUID *fluid, struct SmokeModifierData *smd);
 
 #ifdef __cplusplus
 }
diff --git a/intern/mantaflow/intern/FLUID.cpp 
b/intern/mantaflow/intern/FLUID.cpp
index 77c50ebcc23..d2547d3c72c 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -67,7 +67,11 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : 
mCurrentID(++solverID)
        mUsingHighRes  = smd->domain->flags & MOD_SMOKE_HIGHRES;
        mUsingLiquid   = smd->domain->type == MOD_SMOKE_DOMAIN_TYPE_LIQUID;
        mUsingSmoke    = smd->domain->type == MOD_SMOKE_DOMAIN_TYPE_GAS;
-       
+       mUsingDrops    = smd->domain->particle_type & MOD_SMOKE_PARTICLE_DROP;
+       mUsingBubbles  = smd->domain->particle_type & MOD_SMOKE_PARTICLE_BUBBLE;
+       mUsingFloats   = smd->domain->particle_type & MOD_SMOKE_PARTICLE_FLOAT;
+       mUsingTracers  = smd->domain->particle_type & MOD_SMOKE_PARTICLE_TRACER;
+
        // Make sure that string vector does not contain any previous commands
        mCommands.clear();
 
@@ -147,6 +151,7 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : 
mCurrentID(++solverID)
        mSndParticleData       = NULL;
        mSndParticleVelocity   = NULL;
        mSndParticleType       = NULL;
+       mSndParticleLife       = NULL;
 
        // Only start Mantaflow once. No need to start whenever new FLUID 
objected is allocated
        if (!mantaInitialized)
@@ -161,6 +166,9 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : 
mCurrentID(++solverID)
                if (mUsingGuiding)  initGuiding(smd);
                if (mUsingInvel)    initInVelocity(smd);
 
+               if (mUsingDrops || mUsingBubbles || mUsingFloats || 
mUsingTracers)
+                       initSndParts(smd);
+
                updatePointers();
                
                if (mUsingHighRes) {
@@ -228,6 +236,7 @@ void FLUID::initDomain(SmokeModifierData *smd)
                + fluid_obstacle_export_low
                + fluid_guiding_export_low
                + fluid_invel_export_low
+               + fluid_sndparts_export_low
                + fluid_adaptive_time_stepping_low;
        std::string finalString = parseScript(tmpString, smd);
        mCommands.clear();
@@ -442,6 +451,18 @@ void FLUID::initInVelocity(SmokeModifierData *smd)
        }
 }
 
+void FLUID::initSndParts(SmokeModifierData *smd)
+{
+       if (!mSndParticleData) {
+               std::string tmpString = fluid_alloc_sndparts_low;
+               std::string finalString = parseScript(tmpString, smd);
+               mCommands.clear();
+               mCommands.push_back(finalString);
+
+               runPythonString(mCommands);
+       }
+}
+
 void FLUID::step(int framenr)
 {
        // manta_write_effectors(this);                         // TODO in 
Mantaflow
@@ -495,6 +516,9 @@ FLUID::~FLUID()
        // Initial velocity
        tmpString += fluid_delete_invel_low;
 
+       // Snd parts
+       tmpString += fluid_delete_sndparts_low;
+
        // Cleanup multigrid
        tmpString += fluid_multigrid_cleanup_low;
        tmpString += fluid_guiding_cleanup_low;
@@ -581,6 +605,7 @@ FLUID::~FLUID()
        mSndParticleData       = NULL;
        mSndParticleVelocity   = NULL;
        mSndParticleType       = NULL;
+       mSndParticleLife       = NULL;
 
        // Reset flags
        mUsingHeat     = false;
@@ -951,6 +976,10 @@ void FLUID::exportLiquidScript(SmokeModifierData *smd)
        bool obstacle = smd->domain->active_fields & SM_ACTIVE_OBSTACLE;
        bool guiding  = smd->domain->active_fields & SM_ACTIVE_GUIDING;
        bool invel    = smd->domain->active_fields & SM_ACTIVE_INVEL;
+       bool drops    = smd->domain->particle_type & MOD_SMOKE_PARTICLE_DROP;
+       bool bubble   = smd->domain->particle_type & MOD_SMOKE_PARTICLE_BUBBLE;
+       bool floater  = smd->domain->particle_type & MOD_SMOKE_PARTICLE_FLOAT;
+       bool tracer   = smd->domain->particle_type & MOD_SMOKE_PARTICLE_TRACER;
 
        std::string manta_script;
        
@@ -968,7 +997,8 @@ void FLUID::exportLiquidScript(SmokeModifierData *smd)
                manta_script += fluid_alloc_guiding_low;
        if (invel)
                manta_script += fluid_alloc_invel_low;
-
+       if (drops || bubble || floater || tracer)
+               manta_script += fluid_alloc_sndparts_low;
 
        if (highres) {
                manta_script += fluid_variables_high
@@ -987,7 +1017,9 @@ void FLUID::exportLiquidScript(SmokeModifierData *smd)
                manta_script += fluid_guiding_import_low;
        if (invel)
                manta_script += fluid_invel_import_low;
-       
+       if (drops || bubble || floater || tracer)
+               manta_script += fluid_sndparts_import_low;
+
        manta_script += liquid_pre_step_low;
        manta_script += liquid_post_step_low;
        
@@ -1015,19 +1047,25 @@ void FLUID::exportLiquidData(SmokeModifierData *smd)
        bool obstacle = smd->domain->active_fields & SM_ACTIVE_OBSTACLE;
        bool guiding  = smd->domain->active_fields & SM_ACTIVE_GUIDING;
        bool invel    = smd->domain->active_fields & SM_ACTIVE_INVEL;
+       bool drops    = smd->domain->particle_type & MOD_SMOKE_PARTICLE_DROP;
+       bool bubble   = smd->domain->particle_type & MOD_SMOKE_PARTICLE_BUBBLE;
+       bool floater  = smd->domain->particle_type & MOD_SMOKE_PARTICLE_FLOAT;
+       bool tracer   = smd->domain->particle_type & MOD_SMOKE_PARTICLE_TRACER;
 
        char parent_dir[1024];
        BLI_split_dir_part(smd->domain->manta_filepath, parent_dir, 
sizeof(parent_dir));
        
        FLUID::saveLiquidData(parent_dir);
+       if (highres)
+               FLUID::saveLiquidDataHigh(parent_dir);
        if (obstacle)
                FLUID::saveFluidObstacleData(parent_dir);
        if (guiding)
                FLUID::saveFluidGuidingData(parent_dir);
        if (invel)
                FLUID::saveFluidInvelData(parent_dir);
-       if (highres)
-               FLUID::saveLiquidDataHigh(parent_dir);
+       if (drops || bubble || floater || tracer)
+               FLUID::saveFluidSndPartsData(parent_dir);
 }
 
 void* FLUID::getDataPointer(std::string varName, std::string parentName)
@@ -1282,9 +1320,13 @@ void FLUID::updatePointers()
 
                mFlipParticleData     = (std::vector<pData>*) 
getDataPointer("pp" + solver_ext, solver);
                mFlipParticleVelocity = (std::vector<pVel>*)  
getDataPointer("pVel" + parts_ext, parts);
-               mSndParticleData      = (std::vector<pData>*) 
getDataPointer("ppSnd" + solver_ext, solver);
-               mSndParticleVelocity  = (std::vector<pVel>*)  
getDataPointer("pVelSnd" + parts_ext, parts);
-               mSndParticleType      = (std::vector<int>*)   
getDataPointer("pTypeSnd" + parts_ext, parts);
+
+               if (mUsingDrops || mUsingBubbles || mUsingFloats || 
mUsingTracers) {
+                       mSndParticleData     = (std::vector<pData>*) 
getDataPointer("ppSnd" + solver_ext, solver);
+                       mSndParticleVelocity = (std::vector<pVel>*)  
getDataPointer("pVelSnd" + parts_ext, parts);
+                       mSndParticleType     = (std::vector<int>*)   
getDataPointer("pTypeSnd" + parts_ext, parts);
+                       mSndParticleLife     = (std::vector<int>*)   
getDataPointer("pLifeSnd" + parts_ext, parts);
+               }
        }
        
        // Smoke
@@ -1408,6 +1450,16 @@ void FLUID::setSndParticleType(int* buffer, int numParts)
        }
 }
 
+void FLUID::setSndParticleLife(int* buffer, int numParts)
+{
+       mSndParticleLife->resize(numParts);
+       int* bufferPType = buffer;
+       for (std::vector<int>::iterator it = mSndParticleLife->begin(); it != 
mSndParticleLife->end(); ++it) {
+               *it = *bufferPType;
+               bufferPType++;
+       }
+}
+
 void FLUID::saveMesh(char *filename)
 {
        std::string path(filename);
@@ -1496,6 +1548,18 @@ void FLUID::saveFluidInvelData(char *pathname)
        runPythonString(mCommands);
 }
 
+void FLUID::saveFluidSndPartsData(char *pathname)
+{
+       std::string path(pathname);
+
+       mCommands.clear();
+       std::ostringstream save_fluid_sndparts_data_low;
+       save_fluid_sndparts_data_low <<  "save_fluid_sndparts_data_low_" << 
mCurrentID << "(r'" << path << "')";
+       mCommands.push_back(save_fluid_sndparts_data_low.str());
+
+       runPythonString(mCommands);
+}
+
 void FLUID::saveSmokeData(char *pathname)
 {
        std::string path(pathname);
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index 16885870a87..aaf1b00ec6a 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -58,6 +58,7 @@ public:
        void initObstacle(SmokeModifierData *smd);
        void initGuiding(SmokeModifierData *smd);
        void initInVelocity(SmokeModifierData *smd);
+       void initSndParts(SmokeModifierData *smd);
 
        // Pointer transfer Mantaflow -> Blender
        void updatePointers();
@@ -79,6 +80,7 @@ public:
        void saveFluidObstacleData(char *pathname);
        void saveFluidGuidingData(char *pathname);
        void saveFluidInvelData(char *pathname);
+       void saveFluidSndPartsData(char *pathname);
 
        // Write files for particles
        void saveParticles(char* filename);
@@ -169,8 +171,8 @@ public:
        inline int

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to