[Bf-blender-cvs] [3718200a22e] fluid-mantaflow: added support for obj mesh caching
Sebastián Barschkis
noreply at git.blender.org
Wed May 2 00:47:57 CEST 2018
Commit: 3718200a22e53b5aabe518bffd813fd69e46c258
Author: Sebastián Barschkis
Date: Wed May 2 00:47:45 2018 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB3718200a22e53b5aabe518bffd813fd69e46c258
added support for obj mesh caching
===================================================================
M intern/mantaflow/intern/FLUID.cpp
M intern/mantaflow/intern/FLUID.h
M intern/mantaflow/intern/strings/liquid_script.h
M source/blender/blenkernel/intern/smoke.c
===================================================================
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 6e9913a2b26..6caa7dc5bbc 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -1563,8 +1563,8 @@ void FLUID::updateMeshData(const char* filename)
if (extension.compare("gz")==0)
updateMeshDataFromBobj(filename);
-// else if (extension.compare("obj")==0)
-// updateMeshDataFromObj(filename);
+ else if (extension.compare("obj")==0)
+ updateMeshDataFromObj(filename);
else
std::cerr << "updateMeshDataFrom: invalid file extension in file: " << filename << std::endl;
}
@@ -1652,6 +1652,85 @@ void FLUID::updateMeshDataFromBobj(const char* filename)
gzclose(gzf);
}
+void FLUID::updateMeshDataFromObj(const char* filename)
+{
+ std::ifstream ifs (filename);
+ float fbuffer[3];
+ int ibuffer[3];
+
+ mNumNormals = 0;
+ mNumVertices = 0;
+ mNumTriangles = 0;
+
+ mNormalsX.clear();
+ mNormalsY.clear();
+ mNormalsZ.clear();
+
+ mVerticesX.clear();
+ mVerticesY.clear();
+ mVerticesZ.clear();
+
+ mTrianglesX.clear();
+ mTrianglesY.clear();
+ mTrianglesZ.clear();
+
+ if (!ifs.good())
+ std::cerr << "updateMeshDataFromObj: unable to open file: " << filename << std::endl;
+
+ while(ifs.good() && !ifs.eof()) {
+ std::string id;
+ ifs >> id;
+
+ if (id[0] == '#') {
+ // comment
+ getline(ifs, id);
+ continue;
+ }
+ if (id == "vt") {
+ // tex coord, ignore
+ } else if (id == "vn") {
+ // normals
+ ifs >> fbuffer[0] >> fbuffer[1] >> fbuffer[2];
+ mNormalsX.push_back(fbuffer[0]);
+ mNormalsY.push_back(fbuffer[1]);
+ mNormalsZ.push_back(fbuffer[2]);
+ mNumNormals++;
+ } else if (id == "v") {
+ // vertex
+ ifs >> fbuffer[0] >> fbuffer[1] >> fbuffer[2];
+ mVerticesX.push_back(fbuffer[0]);
+ mVerticesY.push_back(fbuffer[1]);
+ mVerticesZ.push_back(fbuffer[2]);
+ mNumVertices++;
+ } else if (id == "g") {
+ // group
+ std::string group;
+ ifs >> group;
+ } else if (id == "f") {
+ // face
+ std::string face;
+ for (int i=0; i<3; i++) {
+ ifs >> face;
+ if (face.find('/') != std::string::npos)
+ face = face.substr(0, face.find('/')); // ignore other indices
+ int idx = atoi(face.c_str()) - 1;
+ if (idx < 0)
+ std::cerr << "updateMeshDataFromObj: invalid face encountered" << std::endl;
+ ibuffer[i] = idx;
+ }
+ mTrianglesX.push_back(ibuffer[0]);
+ mTrianglesY.push_back(ibuffer[1]);
+ mTrianglesZ.push_back(ibuffer[2]);
+ mNumTriangles++;
+ } else {
+ // whatever, ignore
+ }
+ // kill rest of line
+ getline(ifs, id);
+ }
+ ifs.close();
+}
+
void FLUID::updateParticleData(const char* filename, bool isSecondary)
{
if (with_debug)
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index 440c93e592f..b9fd118a3e8 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -383,6 +383,8 @@ private:
std::string parseLine(const std::string& line, SmokeModifierData *smd);
std::string parseScript(const std::string& setup_string, SmokeModifierData *smd);
void updateMeshDataFromBobj(const char* filename);
+ void updateMeshDataFromObj(const char* filename);
+
};
#endif
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 5c702cfe157..3595060c5fb 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -332,7 +332,7 @@ def liquid_load_mesh_$ID$(path, framenr, file_format):\n\
try:\n\
mantaMsg('Liquid load mesh')\n\
framenr = fluid_cache_get_framenr_formatted_$ID$(framenr)\n\
- mesh_xl$ID$.load(os.path.join(path, 'liquid_mesh_' + framenr + '.bobj.gz'))\n\
+ mesh_xl$ID$.load(os.path.join(path, 'liquid_mesh_' + framenr + file_format))\n\
#pp_xl$ID$.load(os.path.join(path, 'pp_xl_' + framenr + file_format))\n\
except RuntimeError as e:\n\
mantaMsg(str(e))\n\
@@ -396,7 +396,7 @@ def liquid_save_mesh_$ID$(path, framenr, file_format):\n\
\n\
phi_xl$ID$.setBound(0.5,int(((upres_sm$ID$)*2)-2) )\n\
phi_xl$ID$.createMesh(mesh_xl$ID$)\n\
- mesh_xl$ID$.save(os.path.join(path, 'liquid_mesh_' + framenr + '.bobj.gz'))\n\
+ mesh_xl$ID$.save(os.path.join(path, 'liquid_mesh_' + framenr + file_format))\n\
#pp_xl$ID$.save(os.path.join(path, 'pp_xl_' + framenr + file_format))\n";
const std::string liquid_save_particles = "\n\
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 1a730d0b7d9..1c1cf3cd44a 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -2984,7 +2984,7 @@ static DerivedMesh *createLiquidMesh(SmokeDomainSettings *sds, DerivedMesh *orgd
// printf("num_verts: %d, num_normals: %d, num_faces: %d\n", num_verts, num_normals, num_faces);
- if (!num_verts || !num_normals || !num_faces)
+ if (!num_verts || !num_faces)
return NULL;
dm = CDDM_new(num_verts, 0, 0, num_faces * 3, num_faces);
@@ -3051,6 +3051,8 @@ static DerivedMesh *createLiquidMesh(SmokeDomainSettings *sds, DerivedMesh *orgd
// printf("mloops[0].v: %d, mloops[1].v: %d, mloops[2].v: %d\n", mloops[0].v, mloops[1].v, mloops[2].v);
}
+ if (!num_normals)
+ CDDM_calc_normals(dm);
CDDM_calc_edges(dm);
CDDM_apply_vert_normals(dm, (short (*)[3])normals);
More information about the Bf-blender-cvs
mailing list