ofMesh.ply > Meshlab > .stl

Hi guys,

I am trying to generate a shape using ofMesh that I can send to print. I need to convert my exported mesh.ply to .stl using meshlab. For some reason my .ply model in meshlab isn’t enclosed… there are tons of holes and I am not sure why. The shape looks great in oF.

Any help appreciated!

Setup():

mesh.setMode(OF_PRIMITIVE_TRIANGLES);
mesh.setupIndicesAuto();

draw():

mesh.draw();

Save:

void ofApp::keyReleased(int key){

//spacebar to export
switch (key) {
    case ' ':
    mesh.save("mesh.ply");
    break;
}}

Meshlab render:

oF (wireframe):

it might be something with wrong winding of the faces, if some triangles are drawn clockwise and other counter clockwise then if you have culling enabled (which meshlab does) some triangles won’t show. you can check if it’s the case by enabling culling in OF with glEnable(GL_CULL_FACE). also you should draw the faces, the wireframe will look correct.

Thanks Arturo, I really appreciate it.

I tried culling and get the same results… The faces also look fine in OF.

OF drawfaces:

Meshlab:

My full code (ofMesh cylinder in .h) I am using a cylinder primitive and making the mesh from that in buildshape()… could I be doing something wrong there?

#include "ofApp.h"


//--------------------------------------------------------------

void ofApp::setup(){
    
    ofSetFrameRate(30);
    mesh.setMode(OF_PRIMITIVE_TRIANGLES);
    //mesh.setupIndicesAuto();
    glEnable(GL_CULL_FACE);
    
    //set cylinder segs
    cylinder.setResolution(16, 2);
    
}

//--------------------------------------------------------------

float lastEventTime;

void ofApp::update(){
    
    //update cylinder/mesh every second
    if(ofGetElapsedTimef() - lastEventTime >= 1.0f){
        lastEventTime = ofGetElapsedTimef();
        buildshape();
    }

}

//--------------------------------------------------------------

void ofApp::draw(){
    
    ofBackgroundGradient(ofColor(140),  ofColor(100));

    ofPushMatrix();
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);

    easyCam.begin();
    ofRotateZ(90);
    ofSetColor(20,20,20);
    mesh.drawFaces();
    easyCam.end();
    
    ofPopMatrix();
 
}


//--------------------------------------------------------------

int startwidth = 100;
int startheight = 40;
int segs = 2;

void ofApp::buildshape(){
    
    //set height
    int newheight = startheight + 20;
    cylinder.set(startwidth, newheight);
    startheight = newheight;
    
    //set cylinder res
    int newsegs = segs + 2;
    cylinder.setResolution(16, newsegs);
    segs = newsegs;
    
    mesh = cylinder.getMesh();
    
    for(int i=0; i < mesh.getNumVertices(); i++){
        
        ofVec3f tmpvec = mesh.getVertex(i);
        tmpvec.x = tmpvec.x;
        tmpvec.y = tmpvec.y;
        tmpvec.z = tmpvec.z + ofRandom(0, 0);
        mesh.setVertex(i, tmpvec);
        
    }
    
}

//--------------------------------------------------------------

void ofApp::keyReleased(int key){
    
    //spacebar to export
    switch (key) {
        case ' ':
        mesh.save("mesh.ply", false);
        break;
    }

}

//--------------------------------------------------------------

OMG I got it… durrr. I needed

cylinder.setMode(OF_PRIMITIVE_TRIANGLES); 

in setup(); Thanks Arturo! You rule.