openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.96k stars 2.55k forks source link

ofxAssimpLoader::getMesh with texture only draws correctly with ofDisableArbTex() #6218

Open kylemcdonald opened 5 years ago

kylemcdonald commented 5 years ago

I thought that rendering a .obj model loaded by ofxAssimpLoader would be pretty simple, something like:

ofMesh mesh = loader.getMesh(0);
ofTexture tex = loader.getTextureForMesh(0);
tex.bind();
mesh.draw();
tex.unbind();

There's one more important step, ofMultMatrix(loader.getModelMatrix());, but even with this the texture map doesn't seem to work correctly. As far as I can tell, it has something to do with normalized vs unnormalized textures, but I don't have more details.

I made a full minimal example that works when ofDisableArbTex() is called, but uses the top left corner of the texture for the entire model when it is not called: https://gist.github.com/kylemcdonald/4ef96ffc1cc67c860fb35c38c71e6f51

With ofDisableArbTex():

screen shot 2019-01-27 at 12 02 43 pm

Without ofDisableArbTex():

screen shot 2019-01-27 at 12 03 17 pm

ofTheo commented 5 years ago

What if you do loader.draw() ?

I think ofxassimp tends to be higher level where is if you grab the mesh you will have to do more to get it to draw right.

Not sure if the Arb stuff is handed internally though. It could just pass on the texcoords as they are saved in the obj. So if the obj is 0-1 you would need to disable Arb.

On Jan 27, 2019, at 9:04 AM, Kyle McDonald notifications@github.com wrote:

I thought that rendering a .obj model loaded by ofxAssimpLoader would be pretty simple, something like:

ofMesh mesh = loader.getMesh(0); ofTexture tex = loader.getTextureForMesh(0); tex.bind(); mesh.draw(); tex.unbind(); There's one more important step, ofMultMatrix(loader.getModelMatrix());, but even with this the texture map doesn't seem to work correctly. As far as I can tell, it has something to do with normalized vs unnormalized textures, but I don't have more details.

I made a full minimal example that works when ofDisableArbTex() is called, but uses the top left corner of the texture for the entire model when it is not called: https://gist.github.com/kylemcdonald/4ef96ffc1cc67c860fb35c38c71e6f51

With ofDisableArbTex():

Without ofDisableArbTex():

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

kylemcdonald commented 5 years ago

loader.draw() works (as the example code shows). If it's too complicated to export the correct the same coordinates loader.draw() is using (which doesn't seem to disable ARB anywhere), well that's totally understandable. In that case this issue should be closed. Hopefully there's enough information here for other folks to find this when they run into the same problem.

ofTheo commented 5 years ago

Sorry - not sure I understand.

Does the texture render fine with calling loader.drawFaces()? without disabling ARB?

If it works fine there, but doesn't work when grabbing the tex and manually binding before drawing the mesh, that would be weird.

If you have to disable ARB in either case that would make more sense ( and I think thats what your gist implies ).

I wonder if we could autodetect the normalized coords and scale them up to the tex size if ARB is not disabled? Or the opposite, disable ARB for textures loaded for meshes with normalized coords... ?