Hey Mike
Here’s some code I’ve used in the past for exporting ofMesh objects in the form of a large sequence of .obj files. It’s been modified from some code I found in one of Kyle’s projects.
My function was little messy. I’ve tidied away most of the noise for you but not tested it so be prepared for it to break. There should be enough to get you started. Vertices and indices are saved but not normals. There is a commented line in there that should point you in the right direction.
void testApp::exportObjMesh()
{
ofstream obj;
string newObjPath = "myDir/myOBJ.obj";
obj.open(ofToDataPath(newObjPath).c_str(), ios::out);
obj << "# ========================================================================== \n"
<< "# OBJ exported by James Alliban \n"
<< "# Application built using openFrameworks \n"
<< "# ========================================================================== \n";
if (obj.is_open())
{
for (int i = 0; i < myMesh.getVertices().size(); i++)
{
obj << "v " << myMesh.getVertex(i).x << " " << myMesh.getVertex(i).y << " " << myMesh.getVertex(i).z << endl;
}
for (int i = 0; i < myMesh.getIndices().size() / 3; i++)
{
obj << "f " << myMesh.getIndex(i*3) + 1 << " " << myMesh.getIndex(i*3+1) + 1 << " " << myMesh.getIndex(i*3+2) + 1 << endl;
}
//normal
//obj << "vn " << x << " " << y << " " << z << endl;
if (myMesh.getVertices().size() == 0 || myMesh.getIndices().size() == 0)
{
obj << "v " << 0 << " " << 1 << " " << 2 << endl;
obj << "v " << 2 << " " << 3 << " " << 4 << endl;
obj << "v " << 4 << " " << 5 << " " << 6 << endl;
obj << "f " << 1 << " " << 2 << " " << 3 << endl;
}
}
myMesh.clear();
}