Using ofAssimpModelLoader with ofLight and ofMaterial

I’ve spent a couple of days searching for an answer to this but have had no luck. When applying lighting to an imported model (the dog.3ds model supplied in the modelNoiseExample), the lighting looks blown out (little contrast on surfaces of the model). I suspect this has to do with not having a material assigned to model, but I’m unsure how to remedy it. I can set a color with ofSetColor; for example, I set red with ofSetColor(255, 0, 0), but the model shows up as a very light shade of pink. Here are my setup and draw methods (proper declarations in .h, of course):

void testApp::setup(){
     model.loadModel("dog.3ds");
     light.enable();
 }

void testApp::draw(){
    ofEnableDepthTest();
    ofDisableLighting();
    ofBackgroundGradient(ofColor(128), ofColor(0));
    ofEnableLighting();
    ofPushMatrix();
    float time = ofGetElapsedTimef();
    float angle = 30 * time;
    ofTranslate(ofGetWidth()/2, ofGetHeight()*.5,-500);
    ofRotate(angle, 0,1,0);
    ofSetColor(128, 0, 0);
    model.drawFaces();
    ofPopMatrix();
}

I’m a new to the forum, so can’t upload an image of what the above produces. I’m running openframeworks v0.8.0 with a Code::Blocks svn build on Ubuntu 12.04. Any insight anyone might be able to lend would be greatly appreciated.

not sure to understood your problem, but maybe you should create a ofLight, assign to it a diffuse color, and enabling it in draw() something like this:

in testApp.h
ofLight light; 

in testApp.cpp
//setup()
light.setDiffuse(ofColor(120,0,10));
light.setDirectional();

draw()
light.enable();

//your model here.

light.disable();

but i think if there is no texture in the model you could have some issues…

Thank you for the suggestion. I had enabled an ofLight but had not assigned a diffuse color. Doing so does improve the scene considerably. However, using setDirectional makes the model appear almost black. Apparently the dog.3ds model does not have a texture, as I’m seeing errors in the debugger that confirm as much. Is there not a way to define a material to be used when drawing an imported model? If I attempt to create a material, assign properties to it (like shininess) and use it , I see no effect. I assume creating a mesh from the model might remedy that? Perhaps I’m not using ofMaterial correctly. Here’s what I’m attempting now:

   void testApp::setup(){
        ofSetVerticalSync(true);
        ofSetFrameRate(60);
        model.loadModel("dog.3ds");
        model.calculateDimensions();
        model.setPosition(ofGetWidth()/2, ofGetHeight()*0.75, 0);
        light.setDiffuseColor( ofFloatColor(.9, 0.0, 0.0) );
        light.setSpecularColor( ofFloatColor(0.8f, 0.5f, 0.5f));
    //    light.setDirectional();
    
        light.enable();
       material.setShininess( 255 );
    
    
        // the light highlight of the material //
       material.setSpecularColor(ofColor(255, 255, 255, 255));
    }
    
    //--------------------------------------------------------------
    void testApp::draw(){
        ofEnableDepthTest();
        ofDisableLighting();
        ofBackgroundGradient(ofColor(255), ofColor(128));
        ofEnableLighting();
        ofPushMatrix();
        float time = ofGetElapsedTimef();
        float angle = 30 * time;
    
         model.setRotation(0,angle, 0, 1, 0);
    
         ofSetColor(255, 0, 0);
         material.begin();
         model.drawFaces();
         material.end();
         ofPopMatrix();
    
        ofDisableDepthTest();
        ofSetColor(255);
        stringstream ss;
        ss <<  "Framerate: " << ofToString(ofGetFrameRate(),0) << "\n";
        ofDrawBitmapString(ss.str().c_str(), 20, 20);
    }

I’ve made some progress. I created a pair of ofVboMeshes from the model meshes (there are two), created a material and applied it to said meshes (in a manner similar to that used in the drawWithMesh() function in the modelNoiseExample code), paying close attention to the light and material specular and diffuse colors. It looks beautiful now and solves the light/material issue for a simple model like dog.3ds, but with a more complex model my framerate goes from ~53 fps max when using model.drawfaces() to 5 (or worse) when using ofVboMesh! That’s obviously unacceptable. What could account for such a dramatic difference? Surely not just applying a material. Duplicate vertices, perhaps?

Same issue?

Well, don’t I feel silly. It helps to not recreate the vboMesh ever frame. Back to 53 fps, with material applied. Beautiful.

I don’t think it’s quite the same issue. If I follow that thread correctly, his model had a material when loaded that didn’t render properly when using ofLight. The models I’m attempting to use don’t have a material, but I also can’t apply a material without first creating a mesh from the model and drawing the mesh vice the model. I would think that distinction’s important?

@gash Thanks so much - I spent so much time trying to light a 3DS and your comments and answers were really helpful