[SOLVED] Obj Model - mtl color problem

I’ve successfully loaded .obj models that use images for texturing, but I’m having some trouble figuring out how to get models setup when they’re supposed to be textured using color data from the .mtl file (see photo) .

game code:
Spatial spatial = assetManager.loadModel(“WillowTree.obj”);
spatial.setLocalScale(2f);
spatial.setLocalTranslation(0f, 0f, 0f);

.obj file contents:
mtllib Anvil.mtl
o Cube
v 1.000000 -0.000000 -1.000000
v 1.000000 0.000000 1.000000
v -1.000000 0.000000 1.000000 … etc (dozens of v lines)
usemtl Material.001
s 1
f 1/1/1 2/2/1 3/3/1 4/4/1
f 6/5/2 13/6/2 19/7/2 16/8/2
f 1/9/3 9/10/3 10/11/3 2/12/3 … etc (dozens of f lines)

.mtl file contents:
newmtl Material.001
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.147575 0.147575 0.147575
Ks 0.405263 0.405263 0.405263
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2

  1. Convert the obj to j3o in the SDK
  2. For both variants the mtl has to be in the same folder as the obj
  3. If using blender try the blender direct Import (Also in the sdk) or xbuf

I tried what you said and it looked like everything went fine, but when I started the game the tree is still untextured.

Converted in SDK (looks good)

Viewed using the SDK after converting (not sure why the tree is black)

No errors in console from what I can tell

When I run the game application

I’ve made sure to export everything into the same directory including the original obj and mtl files. When I read the “Hello Assets” page it looked like this line of code should do the trick. Am I supposed to add something else to this?
Spatial spatial = engine.getAssetManager().loadModel(“Models/WillowTree.j3o”);

(There’s no messages in the console about not being able to access/find a file. )

When in the SDK, click the Light Bulb, then the model shouldn’t be black anymore.
The Console is not your game output though, but the SDKs.

For the Game, make sure that the texture is also accessible (if it’s not baked into the j3o).
What is your lighting setup? maybe the ambient color is also white and you are using too much ambient lighting?

I ended up finding a kind-of-solution, where I texture the models with a 1x1 pixel of the colors the mtl files would have applied.

1 Like