[Bf-blender-cvs] [8810490a2c2] fluid-mantaflow: added particle file reader function
Sebastián Barschkis
noreply at git.blender.org
Fri Jun 2 22:38:08 CEST 2017
Commit: 8810490a2c23dcba34c157d527dd0dc65ce7e708
Author: Sebastián Barschkis
Date: Thu Jun 1 23:30:54 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB8810490a2c23dcba34c157d527dd0dc65ce7e708
added particle file reader function
reading from .uni files. this function is an adapted version of the load() function for particles in Mantaflow
===================================================================
M intern/mantaflow/intern/FLUID.cpp
M intern/mantaflow/intern/FLUID.h
===================================================================
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index e4ece416b07..fb7704ac673 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -853,7 +853,7 @@ void FLUID::updateMeshData(const char* filename)
gzf = (gzFile) BLI_gzopen(filename, "rb1"); // do some compression
if (!gzf)
- std::cout << "readBobj: unable to open file" << std::endl;
+ std::cout << "updateMeshData: unable to open file" << std::endl;
// Num vertices
mNumVertices = 0;
@@ -917,7 +917,71 @@ void FLUID::updateMeshData(const char* filename)
}
}
- gzclose( gzf );
+ gzclose(gzf);
+}
+
+void FLUID::updateParticleData(const char* filename)
+{
+ gzFile gzf;
+ float fbuffer[3];
+ int ibuffer;
+
+ gzf = (gzFile) BLI_gzopen(filename, "rb1"); // do some compression
+ if (!gzf)
+ std::cout << "updateParticleData: unable to open file" << std::endl;
+
+ char ID[5] = {0,0,0,0,0};
+ gzread(gzf, ID, 4);
+
+ if (!strcmp(ID, "PB01")) {
+ std::cout << "particle uni file format v01 not supported anymore" << std::endl;
+ return;
+ }
+
+ // pdata uni header
+ const int STR_LEN_PDATA = 256;
+ int elementType, bytesPerElement; // type id and byte size
+ char info[STR_LEN_PDATA]; // mantaflow build information
+ unsigned long long timestamp; // creation time
+
+ // read particle header
+ gzread(gzf, &mNumParticles, sizeof(int));
+ gzread(gzf, &ibuffer, sizeof(int)); // Skipping dimX
+ gzread(gzf, &ibuffer, sizeof(int)); // Skipping dimY
+ gzread(gzf, &ibuffer, sizeof(int)); // Skipping dimZ
+ gzread(gzf, &elementType, sizeof(int));
+ gzread(gzf, &bytesPerElement, sizeof(int));
+ gzread(gzf, &info, sizeof(info));
+ gzread(gzf, ×tamp, sizeof(unsigned long long));
+
+ std::cout << "num particles: " << mNumParticles << std::endl;
+
+ // Sanity check
+ const int partSysSize = sizeof(float) * 3 + sizeof(int);
+ if (! (bytesPerElement == partSysSize) && (elementType == 0)){
+ std::cout << "particle type doesn't match" << std::endl;
+ }
+
+ if (mNumParticles)
+ {
+ mParticlePositionsX.resize(mNumParticles);
+ mParticlePositionsY.resize(mNumParticles);
+ mParticlePositionsZ.resize(mNumParticles);
+ mParticleFlags.resize(mNumParticles);
+
+ for (int i = 0; i < mNumParticles; ++i) {
+ gzread(gzf, fbuffer, sizeof(float) * 3);
+
+ mParticlePositionsX[i] = fbuffer[0];
+ mParticlePositionsY[i] = fbuffer[1];
+ mParticlePositionsZ[i] = fbuffer[2];
+
+ gzread(gzf, &ibuffer, sizeof(int));
+ mParticleFlags[i] = ibuffer;
+ }
+ }
+
+ gzclose(gzf);
}
void FLUID::updatePointers()
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index 25a4a61487a..c1a406f7b8a 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -145,6 +145,7 @@ public:
inline int getTriangleZAt(int i) { return mTrianglesZ[i]; }
void updateMeshData(const char* filename);
+ void updateParticleData(const char* filename);
private:
// simulation constants
@@ -227,6 +228,13 @@ private:
std::vector<int> mTrianglesY;
std::vector<int> mTrianglesZ;
+ // Particle fields
+ int mNumParticles;
+ std::vector<int> mParticleFlags;
+ std::vector<float> mParticlePositionsX;
+ std::vector<float> mParticlePositionsY;
+ std::vector<float> mParticlePositionsZ;
+
void initDomain(struct SmokeModifierData *smd);
void initDomainHigh(struct SmokeModifierData *smd);
void initSmoke(struct SmokeModifierData *smd);
More information about the Bf-blender-cvs
mailing list