Problem importing textures with .obj files

I’m working on a project right now where I need to load several .obj files into my OF app and then use the app to orient them in space dynamically.

Right now I’m running into an issue when using the ofxAssimpModelLoader addon. I’m using the example provided in the examples folder and all the default models load fine, however when I try to import my own .obj files I can’t seem to get them to load with textures. the 3D mesh loads fine but they are all grey.

The .obj and .mtl files I’m using to test are available for free here: http://www.turbosquid.com/FullPreview/Index.cfm/ID/329830

I’m using cello.obj and cello.mtl. it seems to me when looking at the .obj file in a text editor that the .mtl file should be linked:

# Blender v242 OBJ File: cello.blend
# www.blender3d.org
mtllib cello.mtl
o cello_body_cello_body
v -0.000014 -0.977415 -0.010724
v -0.015459 -0.977114 -0.010725
...

I’ve made sure they are both in the bin/data folder.

Anyone have any idea what I’m doing wrong? The source code is exactly the same as the ofxAssimpModelLoader example in the examples folder and I’m using the latest version of OF.

Any help would be greatly appreciated!

As a followup, I’m actually interested in exporting the models from Cinema 4D, nothing fancy like lighting, just simple 3D models with textures. Is there another file format I should be using instead of .obj and .mtl if I want to use C4D?

I case it helps anyone, here is what the .mtl file looks like:

# Blender3D MTL File: cello.blend
# Material Count: 4
newmtl cello_metal
Ns 98.039216
Ka 0.000000 0.000000 0.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2


newmtl cello_string
Ns 98.039216
Ka 0.000000 0.000000 0.000000
Kd 0.680000 0.680000 0.680000
Ks 0.211226 0.211226 0.211226
Ni 1.000000
d 1.000000
illum 2


newmtl cello_body_cellowood.tga
Ns 98.039216
Ka 0.000000 0.000000 0.000000
Kd 0.537164 0.534051 0.534051
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd cellowood.tga


newmtl cello_black
Ns 98.039216
Ka 0.000000 0.000000 0.000000
Kd 0.112000 0.112000 0.112000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2

Hey, the problem you are facing actually has to do with materials rather than textures.
The included /obj importer is really limited.
Try this addon


I’m not sure if it is going to address your problem, I guess that it probably will.
best

I don’t know about obj loading with OF.
I successfully :

  • export with collada in Blender,
  • Load my collada with texture, materials, … in OF (using the assimp loader)

yeah, the collada will work with textures and materials but obj wont. at least out of the box.
If you can manage your workflow using collada files, then use them instead of obj. If not make sure you try out the ofxObjLoader addon.
Best!

Thanks for the feedback!

I’ve had some success with the ofx3DModelLoader loading 3ds files.

I’ll try .dae files with assimp as well.

Thanks again!

Also, that model you linked to is missing the external texture file. So won’t work in any format.

I was able to get this to work on 0.8.4 with a simple textured .obj by opening an obj file in MeshLab and exporting as *.dae rather than using .obj.