[Bf-blender-cvs] [72311c6357e] fluid-mantaflow: more improvements for particle caching with pointcache

Sebastián Barschkis noreply at git.blender.org
Sat Jul 1 14:00:12 CEST 2017


Commit: 72311c6357e07e7bb4dc137c6706d9f510a5bce8
Author: Sebastián Barschkis
Date:   Sat Jul 1 13:59:38 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB72311c6357e07e7bb4dc137c6706d9f510a5bce8

more improvements for particle caching with pointcache

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

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	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenkernel/intern/smoke.c

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 96ef02c9b0d..29f749bdc25 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -44,7 +44,7 @@ void smoke_manta_export(struct FLUID* smoke, struct SmokeModifierData *smd);
 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, float **phi, float **pp, float **pvel, int *numParts);
+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, float **phi, float **pp, float **pvel);
 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);
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 8a9c5503f7c..956407c36c3 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -1083,8 +1083,8 @@ void FLUID::updatePointers()
 		mPhiOut = (float*) getDataPointer("phiOut" + solver_ext, solver);
 		mPhi    = (float*) getDataPointer("phi" + solver_ext, solver);
 
-		mParticleData      = (float*) getDataPointer("ppSnd" + solver_ext, solver);
-		mParticleVelocity  = (float*) getDataPointer("pVelSnd" + parts_ext, parts);
+		mParticleData     = (std::vector<pData>*) getDataPointer("ppSnd" + solver_ext, solver);
+		mParticleVelocity = (std::vector<pVel>*) getDataPointer("pVelSnd" + parts_ext, parts);
 	}
 	
 	// Smoke
@@ -1148,36 +1148,29 @@ void FLUID::updatePointersHigh()
 	}
 }
 
-// TODO (sebbas): Using struct in vectors would be nicer
-//void FLUID::setParticleData(float* buffer, int numParts)
-//{
-//	((std::vector<FLUID::pData>*) mParticleData)->resize(numParts*sizeof(FLUID::pData));
-//	FLUID::pData* bufferPData = (FLUID::pData*) buffer;
-//	for (int i = 0; i < numParts; ++i)
-//		((std::vector<FLUID::pData>*) mParticleData)->push_back(bufferPData[i]);
-//
-//}
-//
-//void FLUID::setParticleVelocity(float* buffer, int numParts)
-//{
-//	((std::vector<FLUID::pVel>*) mParticleVelocity)->resize(numParts*sizeof(FLUID::pVel));
-//	FLUID::pVel* bufferPVel = (FLUID::pVel*) buffer;
-//	for (int i = 0; i < numParts; ++i)
-//		((std::vector<FLUID::pVel>*) mParticleVelocity)->push_back(bufferPVel[i]);
-//}
-
 void FLUID::setParticleData(float* buffer, int numParts)
 {
-	((std::vector<float>*) mParticleData)->resize(numParts*3);
-	for (int i = 0; i < numParts*3; ++i)
-		((std::vector<float>*) mParticleData)->push_back(buffer[i]);
+	mParticleData->resize(numParts);
+	FLUID::pData* bufferPData = (FLUID::pData*) buffer;
+	for (std::vector<pData>::iterator it = mParticleData->begin(); it != mParticleData->end(); ++it) {
+		it->pos[0] = bufferPData->pos[0];
+		it->pos[1] = bufferPData->pos[1];
+		it->pos[2] = bufferPData->pos[2];
+		it->flag = bufferPData->flag;
+		bufferPData++;
+	}
 }
 
 void FLUID::setParticleVelocity(float* buffer, int numParts)
 {
-	((std::vector<float>*) mParticleVelocity)->resize(numParts*3);
-	for (int i = 0; i < numParts*3; ++i)
-		((std::vector<float>*) mParticleVelocity)->push_back(buffer[i]);
+	mParticleVelocity->resize(numParts);
+	FLUID::pVel* bufferPVel = (FLUID::pVel*) buffer;
+	for (std::vector<pVel>::iterator it = mParticleVelocity->begin(); it != mParticleVelocity->end(); ++it) {
+		it->pos[0] = bufferPVel->pos[0];
+		it->pos[1] = bufferPVel->pos[1];
+		it->pos[2] = bufferPVel->pos[2];
+		bufferPVel++;
+	}
 }
 
 void FLUID::saveMesh(char *filename)
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index 934c433f7c8..02f2a6a1d6a 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -166,8 +166,8 @@ public:
 	inline float getParticleVelocityYAt(int i) { return (mParticleVelocity) ? ((std::vector<pVel>*) mParticleVelocity)->at(i).pos[1] : 0.f; }
 	inline float getParticleVelocityZAt(int i) { return (mParticleVelocity) ? ((std::vector<pVel>*) mParticleVelocity)->at(i).pos[2] : 0.f; }
 
-	inline float* getParticleData()     { return mParticleData; }
-	inline float* getParticleVelocity() { return mParticleVelocity; }
+	inline float* getParticleData()     { return (float*) &mParticleData->front(); }
+	inline float* getParticleVelocity() { return (float*) &mParticleVelocity->front(); }
 
 	void updateMeshData(const char* filename);
 //	void updateParticleData(const char* filename);
@@ -257,8 +257,8 @@ private:
 	std::vector<int> mTrianglesZ;
 	
 	// Particle fields
-	float* mParticleData;
-	float* mParticleVelocity;
+	std::vector<pData>* mParticleData;
+	std::vector<pVel>* mParticleVelocity;
 
 	void initDomain(struct SmokeModifierData *smd);
 	void initDomainHigh(struct SmokeModifierData *smd);
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index d59cea908bc..0effdcadc57 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -134,7 +134,7 @@ extern "C" void smoke_dissolve_wavelet(FLUID *smoke, int speed, int log)
 }
 
 extern "C" void smoke_export(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 **obstacle, float **phi, float **pp, float **pvel, int *numParts)
+							 float **vx, float **vy, float **vz, float **r, float **g, float **b, int **obstacle, float **phi, float **pp, float **pvel)
 {
 	*dens = smoke->getDensity();
 	if (fuel)
@@ -161,8 +161,6 @@ extern "C" void smoke_export(FLUID *smoke, float *dt, float *dx, float **dens, f
 		*phi = smoke->getPhi();
 	if (pp)
 		*pp = smoke->getParticleData();
-	if (numParts)
-		*numParts = smoke->getNumParticles();
 	if (pvel)
 		*pvel = smoke->getParticleVelocity();
 }
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index b979e85ec89..53e0543b0b2 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -606,7 +606,8 @@ static int ptcache_smoke_write(PTCacheFile *pf, void *smoke_v)
 		int mode=1;		// light
 		if (sds->cache_comp == SM_CACHE_HEAVY) mode=2;	// heavy
 
-		smoke_export(sds->fluid, &dt, &dx, &dens, &react, &flame, &fuel, &heat, &vx, &vy, &vz, &r, &g, &b, &obstacles, &phi, &pp, &pvel, &numParts);
+		smoke_export(sds->fluid, &dt, &dx, &dens, &react, &flame, &fuel, &heat, &vx, &vy, &vz, &r, &g, &b, &obstacles, &phi, &pp, &pvel);
+		numParts = liquid_get_num_particles(sds->fluid);
 
 		if (dens) {
 			ptcache_file_compressed_write(pf, (unsigned char *)sds->shadow, in_len, out, mode);
@@ -632,9 +633,6 @@ static int ptcache_smoke_write(PTCacheFile *pf, void *smoke_v)
 		if (phi) {
 			ptcache_file_compressed_write(pf, (unsigned char *)phi, in_len, out, mode);
 		}
-		if (phi) {
-			ptcache_file_compressed_write(pf, (unsigned char *)phi, in_len, out, mode);
-		}
 		ptcache_file_write(pf, &dt, 1, sizeof(float));
 		ptcache_file_write(pf, &dx, 1, sizeof(float));
 		ptcache_file_write(pf, &sds->p0, 3, sizeof(float));
@@ -643,10 +641,11 @@ static int ptcache_smoke_write(PTCacheFile *pf, void *smoke_v)
 		ptcache_file_write(pf, &sds->shift, 3, sizeof(int));
 		ptcache_file_write(pf, &sds->obj_shift_f, 3, sizeof(float));
 		ptcache_file_write(pf, &sds->obmat, 16, sizeof(float));
-//		ptcache_file_write(pf, &sds->base_res, 3, sizeof(int));
+		ptcache_file_write(pf, &sds->base_res, 3, sizeof(int));
 		ptcache_file_write(pf, &sds->res_min, 3, sizeof(int));
 		ptcache_file_write(pf, &sds->res_max, 3, sizeof(int));
 		ptcache_file_write(pf, &sds->active_color, 3, sizeof(float));
+		ptcache_file_write(pf, &numParts, 1, sizeof(int));
 		if (pp && numParts) {
 			MEM_freeN(out);
 			printf("write numParts is %d\n", numParts);
@@ -741,7 +740,7 @@ static int ptcache_smoke_read_old(PTCacheFile *pf, void *smoke_v)
 		sds->active_color[2] = 0.7f;
 		
 		// TODO (sebbas): add support for liquid caching
-		smoke_export(sds->fluid, &dt, &dx, &dens, NULL, NULL, NULL, &heat, &vx, &vy, &vz, NULL, NULL, NULL, &obstacles, NULL, NULL, NULL, NULL);
+		smoke_export(sds->fluid, &dt, &dx, &dens, NULL, NULL, NULL, &heat, &vx, &vy, &vz, NULL, NULL, NULL, &obstacles, NULL, NULL, NULL);
 
 		ptcache_file_compressed_read(pf, (unsigned char *)sds->shadow, out_len);
 		ptcache_file_compressed_read(pf, (unsigned char*)dens, out_len);
@@ -861,11 +860,11 @@ static int ptcache_smoke_read(PTCacheFile *pf, void *smoke_v)
 	
 	if (sds->fluid) {
 		size_t res = sds->res[0]*sds->res[1]*sds->res[2];
-		float dt, dx, *dens, *react, *fuel, *flame, *heat, *vx, *vy, *vz, *r, *g, *b, *phi, *pp, *pvel;
+		float dt, dx, *dens, *react, *fuel, *flame, *heat, *vx, *vy, *vz, *r, *g, *b, *phi;
 		int *obstacles, numParts;
 		unsigned int out_len = (unsigned int)res * sizeof(float);
 		
-		smoke_export(sds->fluid, &dt, &dx, &dens, &react, &flame, &fuel, &heat, &vx, &vy, &vz, &r, &g, &b, &obstacles, &phi, &pp, &pvel, &numParts);
+		smoke_export(sds->fluid, &dt, &dx, &dens, &react, &flame, &fuel, &heat, &vx, &vy, &vz, &r, &g, &b, &obstacles, &phi, NULL, NULL);
 
 		if (dens) {
 			ptcache_file_compressed_read(pf, (unsigned char *)sds->shadow, out_len);
@@ -899,12 +898,12 @@ static int ptcache_smoke_read(PTCacheFile *pf, void *smoke_v)
 		ptcache_file_read(pf, &sds->shift, 3, sizeof(int));
 		ptcache_file_read(pf, &sds->obj_shift_f, 3, sizeof(float));
 		ptcache_file_read(pf, &sds->obmat, 16, sizeof(float));
-//		ptcache_file_read(pf, &sds->base_res, 3, sizeof(int));
+		ptcache_file_read(pf, &sds->base_res, 3, sizeof(int));
 		ptcache_file_read(pf, &sds->res

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list