ofxAssimpModelLoader

I am loading an .obj file (with ofxAssimpModelLoader) with vertex colors which looks good in i.e. meshlab.
The mesh displays, but with no color (it is all white).

Load:

  
  
void App::setup(){  
  
	ofSetVerticalSync(true);  
  
	// this uses depth information for occlusion  
	// rather than always drawing things on top of each other  
	glEnable(GL_DEPTH_TEST);  
  
	// this sets the camera's distance from the object  
	cam.setDistance(100);  
  
	ofDisableDataPath();  
	body.loadModel(meshFilename);  
	body.enableColors();  
  
}  

Draw:

  
void App::draw(){  
  
	cam.begin();  
		ofRotateX(ofRadToDeg(.5));  
		ofRotateY(ofRadToDeg(-.5));  
  
		body.draw(OF_MESH_FILL);  
  
		ofBackground(0);  
  
        	ofCircle(100,100, 10);  
  
  	cam.end();  
}  

Some lines from body.obj:

  
v -0.324196 0.000971 3.432383 0.674510 0.541176 0.501961  
v -0.329203 0.020513 3.418003 0.670588 0.533333 0.490196  
v -0.329332 0.020358 3.418062 0.666667 0.525490 0.513725  
v -0.329460 0.020183 3.418081 0.650980 0.498039 0.541176  

Any ideas why my colors don’t show up?

Bump. Exact same problem here. I have a .MTL file that contains the material color info, but I don’t know how to confirm that it’s getting loaded, nor do I know how to make it actually color the mesh. My mesh is just white.

Here is a test OBJ and MTL for someone to try, I can confirm that the MTL material colors show up correctly in Photoshop/Blender, but I just see a white mesh in my app.

Archive.zip (7.7 KB)

I have also noticed that when I call model.getMeshNames(), it returns {, , , , }, which for my model is the correct number of meshes, but obviously not the correct names.

Are you guys on windows by any chance?

I’m on OS X 10.9.3.

To try and confirm that there’s nothing wrong with my OBJ/MTL files, I tried the spider.obj (including spider.mtl and SpiderTex.jpg in the same directory) test file from here: https://github.com/assimp/assimp/tree/master/test/models/OBJ

But I get the same results. White mesh, no textures or vertex colors at all.

Yep - i got the same results for your test model (on osx), it’s not the model. I’ve had problems with textures + materials in windows before. But this is different, I suspect a bug in ofMaterial or ofAssimpModelLoader. Even a simple coloured cube is not displaying the correct colours. (the assimp spider has more texture dependencies).

Also, there is another thread mentioning the same materials issue: AssimpLoader and materials

After a bit more investigating, I can confirm the .mtl file does not get loaded properly with the .obj (mac and windows). If you try printing out the value of the model’s ofMaterial diffuse colour it’s always the default 0.6,0.6,0.6. I posted this issue and a solution on github last year: https://github.com/openframeworks/openFrameworks/issues/2148

So if you change that aiImportFile line in ofxAssimpModelLoader::loadModel, you will get the correct values for the materials. This is only half of the problem though. I think there is a bug with ofMaterial (or maybe an OS/opengl issue with glMaterialfv), I can’t seem to apply any ofMaterial to any object anymore- even without assimp.

I may have figured it out. This comment on github led me to enable lighting and then immediately disable GL_COLOR_NORMALIZE at the beginning of my draw loop. Although, I’m not able to figure out from the discussion what is the correct default way to do it without making GL calls. After doing this, I get my materials back.

void ofApp::draw(){
    

    ofEnableDepthTest();
    ofEnableLighting();
    
    camera.begin();
    light.enable();
    glDisable(GL_COLOR_MATERIAL);
    
    blueMaterial.begin();
    mesh.drawFaces();
    blueMaterial.end();
    
    light.disable();
    camera.end();
    
    ofDisableDepthTest();
    ofDisableLighting();
}

Oh, and I forgot to mention, I had much more success getting materials to load from a COLLADA .dae file exported from Blender than an OBJ.