[Bf-blender-cvs] [d67e728] fluid-mantaflow: added mesh (.bobj.gz files) read functionality to fluid class

Sebastián Barschkis noreply at git.blender.org
Sat Jun 18 13:06:10 CEST 2016


Commit: d67e7284b9080d2d60e2f09f93daa921ce19a95d
Author: Sebastián Barschkis
Date:   Wed Jun 15 16:36:21 2016 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBd67e7284b9080d2d60e2f09f93daa921ce19a95d

added mesh (.bobj.gz files) read functionality to fluid class

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

M	intern/mantaflow/extern/manta_smoke_API.h
M	intern/mantaflow/intern/SMOKE.cpp
M	intern/mantaflow/intern/SMOKE.h
M	intern/mantaflow/intern/manta_smoke_API.cpp

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

diff --git a/intern/mantaflow/extern/manta_smoke_API.h b/intern/mantaflow/extern/manta_smoke_API.h
index 0a84e40..e1ac7d1 100644
--- a/intern/mantaflow/extern/manta_smoke_API.h
+++ b/intern/mantaflow/extern/manta_smoke_API.h
@@ -105,6 +105,7 @@ float liquid_get_normal_z_at(struct SMOKE *liquid, int i);
 float liquid_get_triangle_x_at(struct SMOKE *liquid, int i);
 float liquid_get_triangle_y_at(struct SMOKE *liquid, int i);
 float liquid_get_triangle_z_at(struct SMOKE *liquid, int i);
+void liquid_update_mesh_data(struct SMOKE *liquid, char *filename);
 
 #ifdef __cplusplus
 }
diff --git a/intern/mantaflow/intern/SMOKE.cpp b/intern/mantaflow/intern/SMOKE.cpp
index 52e9ae6c..665fa7d 100644
--- a/intern/mantaflow/intern/SMOKE.cpp
+++ b/intern/mantaflow/intern/SMOKE.cpp
@@ -30,6 +30,7 @@
 #include <sstream>
 #include <fstream>
 #include <iostream>
+#include <zlib.h>
 
 #include "SMOKE.h"
 #include "registry.h"
@@ -39,6 +40,7 @@
 
 #include "BLI_path_util.h"
 #include "BLI_utildefines.h"
+#include "BLI_fileops.h"
 
 #include "DNA_scene_types.h"
 #include "DNA_modifier_types.h"
@@ -692,6 +694,89 @@ void* SMOKE::getGridPointer(std::string gridName, std::string solverName)
 	return gridPointer;
 }
 
+void SMOKE::updateMeshData(char* filename)
+{
+	float dx =  1.0f / mMaxRes;
+	float fbuffer[3];
+	int ibuffer[3];
+
+	gzFile gzf = BLI_gzopen(filename, "rb1"); // do some compression
+	if (!gzf)
+		std::cout << "readBobj: unable to open file" << std::endl;
+	
+	// Num vertices
+	mNumVertices = 0;
+	gzread(gzf, &mNumVertices, sizeof(int));
+	
+	std::cout << "read mesh , verts " << mNumVertices << std::endl;
+
+	if (mNumVertices)
+	{
+		mVerticesX.resize(mNumVertices);
+		mVerticesY.resize(mNumVertices);
+		mVerticesZ.resize(mNumVertices);
+		
+		// Vertices
+		for (int i = 0; i < mNumVertices; i++) {
+			gzread(gzf, fbuffer, sizeof(float)  * 3);
+			
+			mVerticesX[i] = fbuffer[0];
+			mVerticesY[i] = fbuffer[1];
+			mVerticesZ[i] = fbuffer[2];
+
+			// convert to grid space
+			mVerticesX[i] /= dx;
+			mVerticesX[i] += mResX*0.5;
+			mVerticesY[i] /= dx;
+			mVerticesY[i] += mResY*0.5;
+			mVerticesZ[i] /= dx;
+			mVerticesZ[i] += mResZ*0.5;
+		}
+	}
+	
+	// Num normals
+	mNumNormals = 0;
+	gzread(gzf, &mNumNormals, sizeof(float));
+	
+	if (mNumNormals)
+	{
+		mNormalsX.resize(mNumNormals);
+		mNormalsY.resize(mNumNormals);
+		mNormalsZ.resize(mNumNormals);
+		
+		// Normals
+		for (int i = 0; i < mNumNormals; i++) {
+			gzread(gzf, fbuffer, sizeof(float) * 3);
+			
+			mNormalsX[i] = fbuffer[0];
+			mNormalsY[i] = fbuffer[1];
+			mNormalsZ[i] = fbuffer[2];
+		}
+	}
+	
+	// Num triangles
+	mNumTriangles = 0;
+	gzread(gzf, &mNumTriangles, sizeof(int));
+	
+	if (mNumTriangles)
+	{
+		mTrianglesX.resize(mNumTriangles);
+		mTrianglesY.resize(mNumTriangles);
+		mTrianglesZ.resize(mNumTriangles);
+		
+		// Triangles
+		for (int i = 0; i < mNumTriangles; i++) {
+			gzread(gzf, ibuffer, sizeof(int) * 3);
+			
+			mTrianglesX[i] = ibuffer[0];
+			mTrianglesY[i] = ibuffer[1];
+			mTrianglesZ[i] = ibuffer[2];
+		}
+	}
+
+	gzclose( gzf );
+}
+
 void SMOKE::updatePointers(SmokeModifierData *smd)
 {
 	std::cout << "Updating pointers low res" << std::endl;
diff --git a/intern/mantaflow/intern/SMOKE.h b/intern/mantaflow/intern/SMOKE.h
index c2c5e39..81887da 100644
--- a/intern/mantaflow/intern/SMOKE.h
+++ b/intern/mantaflow/intern/SMOKE.h
@@ -132,6 +132,8 @@ public:
 	inline int getTriangleXAt(int i) { return mTrianglesX[i]; }
 	inline int getTriangleYAt(int i) { return mTrianglesY[i]; }
 	inline int getTriangleZAt(int i) { return mTrianglesZ[i]; }
+	
+	void updateMeshData(char* filename);
 
 private:
 	// simulation constants
diff --git a/intern/mantaflow/intern/manta_smoke_API.cpp b/intern/mantaflow/intern/manta_smoke_API.cpp
index d96c390..45f7c15 100644
--- a/intern/mantaflow/intern/manta_smoke_API.cpp
+++ b/intern/mantaflow/intern/manta_smoke_API.cpp
@@ -564,3 +564,8 @@ extern "C" float liquid_get_triangle_z_at(SMOKE *liquid, int i)
 	return liquid->getTriangleZAt(i);
 }
 
+extern "C" void liquid_update_mesh_data(SMOKE *liquid, char* filename)
+{
+	liquid->updateMeshData(filename);
+}
+




More information about the Bf-blender-cvs mailing list