Skip to content

Instantly share code, notes, and snippets.

@hb3p8
Created December 14, 2015 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hb3p8/11c7d511b20e21489660 to your computer and use it in GitHub Desktop.
Save hb3p8/11c7d511b20e21489660 to your computer and use it in GitHub Desktop.
WriteMesh
void BRepMesh_RestoreOrientationTool::WriteMesh (const std::string& theFileName)
{
// write obj file
std::ofstream myfile;
myfile.open (theFileName);
const Handle(BRepMesh_TriangulatedPatch)& aPatch = myPatches.back();
for (int i = 0; i < aPatch->Vertices.size(); ++i) {
BVH_Vec3d aVert = aPatch->Vertices[i];
myfile << "v " << aVert.x() << " " << aVert.y() << " " << aVert.z() << "\n";
}
for (int i = 0; i < aPatch->Elements.size(); ++i) {
BVH_Vec4i aTriangle = aPatch->Elements[i];
if (aTriangle.w() >= 0) {
myfile << "f " << aTriangle.x() + 1 << " " << aTriangle.y() + 1 << " " << aTriangle.z() + 1 << "\n";
}
else {
myfile << "f " << aTriangle.z() + 1 << " " << aTriangle.y() + 1 << " " << aTriangle.x() + 1 << "\n";
}
}
myfile.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment