Fluid: Updated Mantaflow source files
New files include fixes for obj mesh import and minor cleanups.
This commit is contained in:
parent
98b1a716d6
commit
7e0289b618
|
@ -248,12 +248,14 @@ template<class S> class Vector3D {
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
//! helper to check whether float/double value is non-zero
|
//! helper to check whether value is non-zero
|
||||||
inline bool notZero(Real f)
|
template<class S> inline bool notZero(S v)
|
||||||
{
|
{
|
||||||
if (std::abs(f) > VECTOR_EPSILON)
|
return (std::abs(v) > VECTOR_EPSILON);
|
||||||
return true;
|
}
|
||||||
return false;
|
template<class S> inline bool notZero(Vector3D<S> v)
|
||||||
|
{
|
||||||
|
return (std::abs(norm(v)) > VECTOR_EPSILON);
|
||||||
}
|
}
|
||||||
|
|
||||||
//************************************************************************
|
//************************************************************************
|
||||||
|
|
|
@ -315,10 +315,14 @@ int readObjFile(const std::string &name, Mesh *mesh, bool append)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Real dx = mesh->getParent()->getDx();
|
||||||
|
const Vec3 gs = toVec3(mesh->getParent()->getGridSize());
|
||||||
|
|
||||||
if (!append)
|
if (!append)
|
||||||
mesh->clear();
|
mesh->clear();
|
||||||
int nodebase = mesh->numNodes();
|
int nodebase = mesh->numNodes();
|
||||||
int cnt = nodebase;
|
int cntNodes = nodebase, cntNormals = nodebase;
|
||||||
|
|
||||||
while (ifs.good() && !ifs.eof()) {
|
while (ifs.good() && !ifs.eof()) {
|
||||||
string id;
|
string id;
|
||||||
ifs >> id;
|
ifs >> id;
|
||||||
|
@ -333,19 +337,23 @@ int readObjFile(const std::string &name, Mesh *mesh, bool append)
|
||||||
}
|
}
|
||||||
else if (id == "vn") {
|
else if (id == "vn") {
|
||||||
// normals
|
// normals
|
||||||
if (!mesh->numNodes()) {
|
if (mesh->numNodes() != cntNodes) {
|
||||||
errMsg("invalid amount of nodes");
|
errMsg("invalid amount of nodes");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Node n = mesh->nodes(cnt);
|
Node *n = &mesh->nodes(cntNormals);
|
||||||
ifs >> n.normal.x >> n.normal.y >> n.normal.z;
|
ifs >> n->normal.x >> n->normal.y >> n->normal.z;
|
||||||
cnt++;
|
cntNormals++;
|
||||||
}
|
}
|
||||||
else if (id == "v") {
|
else if (id == "v") {
|
||||||
// vertex
|
// vertex
|
||||||
Node n;
|
Node n;
|
||||||
ifs >> n.pos.x >> n.pos.y >> n.pos.z;
|
ifs >> n.pos.x >> n.pos.y >> n.pos.z;
|
||||||
|
// convert to grid space
|
||||||
|
n.pos /= dx;
|
||||||
|
n.pos += gs * 0.5;
|
||||||
mesh->addNode(n);
|
mesh->addNode(n);
|
||||||
|
cntNodes++;
|
||||||
}
|
}
|
||||||
else if (id == "g") {
|
else if (id == "g") {
|
||||||
// group
|
// group
|
||||||
|
@ -408,7 +416,6 @@ int writeObjFile(const string &name, Mesh *mesh)
|
||||||
// write normals
|
// write normals
|
||||||
for (int i = 0; i < numVerts; i++) {
|
for (int i = 0; i < numVerts; i++) {
|
||||||
Vector3D<float> n = toVec3f(mesh->nodes(i).normal);
|
Vector3D<float> n = toVec3f(mesh->nodes(i).normal);
|
||||||
// normalize to unit cube around 0
|
|
||||||
ofs << "vn " << n.value[0] << " " << n.value[1] << " " << n.value[2] << " "
|
ofs << "vn " << n.value[0] << " " << n.value[1] << " " << n.value[2] << " "
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
#define MANTA_GIT_VERSION "commit d80d3c821de74315ab26b5efd153d41477b976c4"
|
#define MANTA_GIT_VERSION "commit 7395d36e3f504edbdabe34b30edc855b422c7baa"
|
||||||
|
|
Loading…
Reference in New Issue