[Bf-blender-cvs] [9cb43962a7a] fluid-mantaflow: added c/c++ api functions and extended caching to account for particles
Sebastián Barschkis
noreply at git.blender.org
Fri Jun 2 22:38:09 CEST 2017
Commit: 9cb43962a7a807e9c9adfa09225c248c90757a64
Author: Sebastián Barschkis
Date: Fri Jun 2 22:36:18 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB9cb43962a7a807e9c9adfa09225c248c90757a64
added c/c++ api functions and extended caching to account for particles
===================================================================
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/strings/liquid_script.h
M source/blender/blenkernel/BKE_pointcache.h
M source/blender/blenkernel/intern/pointcache.c
M source/blender/makesdna/DNA_particle_types.h
M source/blender/makesrna/intern/rna_smoke.c
===================================================================
diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 3caac020fd0..7095fddf533 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -92,6 +92,7 @@ float *liquid_get_phiobs(struct FLUID *liquid);
float *liquid_get_phiout(struct FLUID *liquid);
void liquid_ensure_init(struct FLUID *liquid, struct SmokeModifierData *smd);
void liquid_save_mesh(struct FLUID *liquid, char *filename);
+void liquid_save_particles(struct FLUID *liquid, char *filename);
void liquid_save_data(struct FLUID *liquid, char *pathname);
void liquid_load_data(struct FLUID *liquid, char *pathname);
int liquid_get_num_verts(struct FLUID *liquid);
@@ -106,7 +107,13 @@ float liquid_get_normal_z_at(struct FLUID *liquid, int i);
float liquid_get_triangle_x_at(struct FLUID *liquid, int i);
float liquid_get_triangle_y_at(struct FLUID *liquid, int i);
float liquid_get_triangle_z_at(struct FLUID *liquid, int i);
+int liquid_get_num_particles(struct FLUID *liquid);
+int liquid_get_particle_flag_at(struct FLUID *liquid, int i);
+float liquid_get_particle_position_x_at(struct FLUID *liquid, int i);
+float liquid_get_particle_position_y_at(struct FLUID *liquid, int i);
+float liquid_get_particle_position_z_at(struct FLUID *liquid, int i);
void liquid_update_mesh_data(struct FLUID *liquid, char *filename);
+void liquid_update_particle_data(struct FLUID *liquid, char* filename);
void liquid_save_mesh_high(struct FLUID *liquid, char *filename);
void liquid_save_data_high(struct FLUID *liquid, char *pathname);
void liquid_load_data_high(struct FLUID *liquid, char *pathname);
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index fb7704ac673..e9831e69f3a 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -75,7 +75,7 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
mConstantScaling = 64.0f / mMaxRes;
mConstantScaling = (mConstantScaling < 1.0f) ? 1.0f : mConstantScaling;
mTotalCells = mResX * mResY * mResZ;
-
+
// Smoke low res grids
mDensity = NULL;
mHeat = NULL;
@@ -95,7 +95,7 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
mColorG = NULL;
mColorB = NULL;
mObstacle = NULL;
-
+
// Smoke high res grids
mDensityHigh = NULL;
mFlameHigh = NULL;
@@ -110,12 +110,12 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
mTextureU2 = NULL;
mTextureV2 = NULL;
mTextureW2 = NULL;
-
+
// Liquid low res grids
mPhiIn = NULL;
mPhiObs = NULL;
mPhiOut = NULL;
-
+
mNumVertices = 0;
mNumNormals = 0;
mNumTriangles = 0;
@@ -326,6 +326,7 @@ void FLUID::initLiquid(SmokeModifierData *smd)
+ liquid_bounds_low
+ liquid_init_phi
+ liquid_save_mesh_low
+ + liquid_save_particles_low
+ liquid_export_low
+ liquid_import_low
+ liquid_adaptive_step
@@ -388,7 +389,7 @@ FLUID::~FLUID()
tmpString += liquid_delete_variables_high;
tmpString += liquid_delete_grids_high;
-
+
// Smoke
tmpString += smoke_delete_variables_low;
tmpString += smoke_delete_grids_low;
@@ -411,7 +412,7 @@ FLUID::~FLUID()
// Solvers always have to be the last objects to be deleted
tmpString += fluid_delete_solver_low;
if (mUsingHighRes) tmpString += fluid_delete_solver_high;
-
+
// Just in case: gc again
tmpString += gc_collect;
@@ -1099,6 +1100,19 @@ void FLUID::saveMeshHigh(char *filename)
runPythonString(mCommands);
}
+void FLUID::saveParticles(char* filename)
+{
+ std::string path(filename);
+
+ mCommands.clear();
+ std::ostringstream save_particles_low;
+
+ save_particles_low << "save_particles_low_" << mCurrentID << "(r'" << path << "')";
+ mCommands.push_back(save_particles_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 c1a406f7b8a..f56350b31c9 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -70,6 +70,9 @@ public:
void saveSmokeData(char *pathname);
void saveSmokeDataHigh(char *pathname);
+ // Write files for particles
+ void saveParticles(char* filename);
+
// Load files for liquids
void loadLiquidData(char *pathname);
void loadLiquidDataHigh(char *pathname);
@@ -144,6 +147,13 @@ public:
inline int getTriangleYAt(int i) { return mTrianglesY[i]; }
inline int getTriangleZAt(int i) { return mTrianglesZ[i]; }
+ // Particle getters
+ inline int getNumParticles() { return mNumParticles; }
+ inline int getParticleFlagAt(int i) { return mParticleFlags[i]; }
+ inline float getParticlePositionXAt(int i) { return mParticlePositionsX[i]; }
+ inline float getParticlePositionYAt(int i) { return mParticlePositionsY[i]; }
+ inline float getParticlePositionZAt(int i) { return mParticlePositionsZ[i]; }
+
void updateMeshData(const char* filename);
void updateParticleData(const char* filename);
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index ea33c381ce1..e9fdb86c5be 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -500,6 +500,13 @@ extern "C" void liquid_save_mesh(FLUID *liquid, char *filename)
}
}
+extern "C" void liquid_save_particles(FLUID *liquid, char *filename)
+{
+ if (liquid) {
+ liquid->saveParticles(filename);
+ }
+}
+
extern "C" void liquid_save_mesh_high(FLUID *liquid, char *filename)
{
if (liquid) {
@@ -595,11 +602,41 @@ extern "C" float liquid_get_triangle_z_at(FLUID *liquid, int i)
return liquid->getTriangleZAt(i);
}
+extern "C" int liquid_get_num_particles(FLUID *liquid)
+{
+ return liquid->getNumParticles();
+}
+
+extern "C" int liquid_get_particle_flag_at(FLUID *liquid, int i)
+{
+ return liquid->getParticleFlagAt(i);
+}
+
+extern "C" float liquid_get_particle_position_x_at(FLUID *liquid, int i)
+{
+ return liquid->getParticlePositionXAt(i);
+}
+
+extern "C" float liquid_get_particle_position_y_at(FLUID *liquid, int i)
+{
+ return liquid->getParticlePositionYAt(i);
+}
+
+extern "C" float liquid_get_particle_position_z_at(FLUID *liquid, int i)
+{
+ return liquid->getParticlePositionZAt(i);
+}
+
extern "C" void liquid_update_mesh_data(FLUID *liquid, char* filename)
{
liquid->updateMeshData(filename);
}
+extern "C" void liquid_update_particle_data(FLUID *liquid, char* filename)
+{
+ liquid->updateParticleData(filename);
+}
+
extern "C" void liquid_manta_export(FLUID* liquid, SmokeModifierData *smd)
{
if (!liquid && !smd) return;
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 3022ac24cf6..9169ee21ba6 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -285,6 +285,10 @@ const std::string liquid_save_mesh_high = "\n\
def save_mesh_high_$ID$(path):\n\
mesh_xl$ID$.save(path)\n";
+const std::string liquid_save_particles_low = "\n\
+def save_particles_low_$ID$(path):\n\
+ pp_s$ID$.save(path)\n";
+
const std::string liquid_import_low = "\n\
def load_liquid_data_low_$ID$(path):\n\
flags_s$ID$.load(os.path.join(path, 'flags_s$ID$.uni'))\n\
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index 57cacad9f9a..bbe795c021d 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -126,6 +126,7 @@ enum {
PTCACHE_FILE_PTCACHE = 0,
PTCACHE_FILE_OPENVDB = 1,
PTCACHE_FILE_LIQUID = 2,
+ PTCACHE_FILE_PARTICLE = 3,
};
typedef struct PTCacheID {
@@ -146,26 +147,31 @@ typedef struct PTCacheID {
/* copies point data to cache data */
int (*write_point)(int index, void *calldata, void **data, int cfra);
- /* copies cache cata to point data */
+ /* copies cache data to point data */
void (*read_point)(int index, void *calldata, void **data, float cfra, float *old_data);
/* interpolated between previously read point data and cache data */
void (*interpolate_point)(int index, void *calldata, void **data, float cfra, float cfra1, float cfra2, float *old_data);
/* copies point data to cache data */
int (*write_stream)(PTCacheFile *pf, void *calldata);
- /* copies cache cata to point data */
+ /* copies cache data to point data */
int (*read_stream)(PTCacheFile *pf, void *calldata);
/* copies point data to cache data */
int (*write_openvdb_stream)(struct OpenVDBWriter *writer, void *calldata);
- /* copies cache cata to point data */
+ /* copies cache data to point data */
int (*read_openvdb_stream)(struct OpenVDBReader *reader, void *calldata);
- /* copies point data to cache data */
+ /* copies mesj data to cache data */
int (*write_liquid_stream)(void *calldata, char *filename, char *pathname);
- /* copies cache cata to point data */
+ /* copies cache data to mesh data */
int (*read_liquid_stream)(void *calldata, char *filename, char *pathname);
+ /* copies point data to cache data */
+ int (*write_particle_stream)(void *calldata, char *filename, char *pathname);
+ /* copies cache data to point data */
+ int (*read_particle_stream)(void *calldata, char *filename, char *pathname);
+
/* copies custom extradata to cache data */
void (*write_extra_data)(void *calldata, struct PTCacheMem *pm, int cfra);
/* copies custom extradata to cache data */
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 99c856fb59f..14d170b27d0 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1242,17 +1242,40 @@ static int ptcache_liquid_read(void *smoke_v, char *filename, char *pathname)
liquid_load_data(sds->fluid, pathname);
if (sds->flags & MOD_SMOKE_HIGHRES) {
-
+ liquid_load_data_high(sds->fluid, pathname);
+ }
+ liquid_update_mesh_data(sds->fluid, filename);
+ return 1;
+ }
+ return 0;
+}
+
+static int ptcache_manta
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list