Skip to content

Instantly share code, notes, and snippets.

@vvzen
Created August 5, 2017 08:33
Show Gist options
  • Save vvzen/4921a6227f0c8612ac559fb77a8e69d9 to your computer and use it in GitHub Desktop.
Save vvzen/4921a6227f0c8612ac559fb77a8e69d9 to your computer and use it in GitHub Desktop.
Export .ply from mesh (openframeworks)
void ofApp::exportPlyCloud(ofMesh pcMesh, string filename){
ofFile ply;
if(ply.open(filename, ofFile::WriteOnly)){
// write the header
ply << "ply" << endl;
ply << "format binary_little_endian 1.0" << endl;
ply << "element vertex " << pcMesh.getVertices().size() << endl;
ply << "property float x" << endl;
ply << "property float y" << endl;
ply << "property float z" << endl;
ply << "end_header" << endl;
// write all the vertices
vector<ofVec3f>& surface = pcMesh.getVertices();
for(int i = 0; i < surface.size(); i++){
if(surface[i].z != 0){
// write the raw data as if it were a stream of bytes
ply.write((char *) &surface[i], sizeof(ofVec3f));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment