Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

ofMesh not rendering when extracted from model

$
0
0

@Evan_Clark wrote:

I have loaded a model using Asimp and have been able to select a mesh that is included in the fbx file. However when I call mesh.drawFaces() nothing renders. When I do this for the model it renders correctly and it is textured on all the meshes. If I use a texture bind the selected mesh does not appear either.

void ofApp::setup(){
    ofDisableArbTex(); //Need in order to get proper texture loading.
    NDIlib_initialize(); //Self Explanatory
    ofBackground(0); //Sets an empty background
    ofSetFrameRate(60); //Self Explanatory
    
    //model.loadModel("/Users/djevanclark/Downloads/of_v0.11.0_osx_release/apps/myApps/NDIModel2/247_House 15_obj.obj");
    model.loadModel("/Users/djevanclark/Downloads/geom.fbx");
  //works // model.loadModel("/Users/djevanclark/Downloads/of_v0.11.0_osx_release/apps/myApps/NDIModel2/247_House 15_obj.obj");
   //model.loadModel("/Users/djevanclark/Downloads/skull-obj/skull.obj");
    //model.loadModel("/Users/djevanclark/Downloads/tonemapping-replication-dae/tonemapping-replication.dae");
   // model.loadModel("/Users/djevanclark/Downloads/Weaving Flag.fbx");
    model.disableMaterials();
  //  model.setPosition(ofGetWidth() * 0.5, (float)ofGetHeight() * 500 , 0);
    model.setPosition(0, 0, 0);
    model.setRotation(0,90,0,1,0); //Rotates the model on the y axis 90 degrees.
    model.setScale(1.0, 1.0, 1.0);
    easyCam.setTarget(model.getSceneCenter());
    mesh = model.getMesh("Video");
   // model.setLoopStateForAllAnimations(OF_LOOP_NORMAL);
   // model.playAllAnimations();
    std::cout << "Scene Center: " << model.getSceneCenter() << "\n";
   // model.disableMaterials();
    //model.loadModel("/Users/djevanclark/Documents/untitled.dae");
    if(model.hasMeshes()) {
      std::cout << "Number of meshes: " << model.getMeshCount() << "\n";
        for (int i = 0; i< model.getMeshCount(); i++) {
            std::cout << "Meshes: " << model.getMeshNames()[i] << "\n";
        }
      meshCount = model.getMeshCount();
    }
    auto findSource = [](const string &name_or_url) {
        auto sources = ofxNDI::listSources();
        if(name_or_url == "") {
            return make_pair(ofxNDI::Source(), false);
        }
        auto found = find_if(begin(sources), end(sources), [name_or_url](const ofxNDI::Source &s) {
            return ofIsStringInString(s.p_ndi_name, name_or_url) || ofIsStringInString(s.p_url_address, name_or_url);
        });
        if(found == end(sources)) {
            ofLogWarning("ofxNDI") << "no NDI source found by string:" << name_or_url;
            return make_pair(ofxNDI::Source(), false);
        }
        return make_pair(*found, true);
    };
    string name_or_url = "";    // Specify name or address of expected NDI source. In case of blank or not found, receiver will grab default(which is found first) source.
    auto result = findSource(name_or_url);
    if(result.second ? receiver_.setup(result.first) : receiver_.setup()) {
        video_.setup(receiver_);
    }
}

//--------------------------------------------------------------
void ofApp::update(){
    model.update();
    
    if(receiver_.isConnected()) {
        video_.update();
        if(video_.isFrameNew()) {
            video_.decodeTo(pixels_);
        }
    }
    float rta = model.getRotationAngle(1) + 1;
   // model.setRotation(1, rta, 0, 1, 0);
    mesh = model.getCurrentAnimatedMesh(0);
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofColor(255,255);
    model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0);
    if(pixels_.isAllocated()) {
        ofTexture tex = ofImage(pixels_).getTexture();

        //ofImage(pixels_).draw(0,0);
       // tex.setTextureWrap(GL_REPEAT, GL_REPEAT);
       // tex.generateMipmap();
       // tex.setTextureMinMagFilter(GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST);
        //tex.bind();
        //model.drawFaces();
       // tex.unbind();
     // ofMesh m = model.getMesh("Video");
       // cout << "tex coords count: " << m.getNumTexCoords() << " : " << endl;
        tex.bind();
        mesh.drawFaces();
        tex.unbind();
    }
    //model.drawWireframe();
    
}

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles