Just don't get textures onto my models


I'm searching and trying a lot to get textures on my models. But nothing seems to work.

The models are created with Misfit Model 3D, where I also apply the textures to the model.

These models have several textures (so there is no way of just putting a texture-state at

my importet Spatial-Model…) which are in the same directory as the model. I tried to use

SimpleResourceLocator, but I just don't know how to use it right. Maybe its just a wrong

path… I just don't get it and its really getting frustrating. Here is my code I'm using:

public static Spatial getModel(String modelPath) {
      try {
         URL modelFile = Main.class.getClassLoader().getResource(modelPath + "model.obj");
         URL modelFolder = Main.class.getClassLoader().getResource(modelPath);
         SimpleResourceLocator sr1 = new SimpleResourceLocator(modelFile);
         ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_MODEL, sr1);
         SimpleResourceLocator sr2 = new SimpleResourceLocator(modelFolder);
         ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, sr2);
         FormatConverter converter = new ObjToJme();
         converter.setProperty("mtllib", modelFolder);
         converter.setProperty("texdir", modelFolder);
         ByteArrayOutputStream BO = new ByteArrayOutputStream();
         converter.convert(modelFile.openStream(), BO);
         Spatial model = (Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
         model.setModelBound(new BoundingSphere());
         return model;
      } catch (Exception e) {
         return null;

Well, there is another anoying problem: When I load a model in jME, "round" parts of the models
are not rendered well. That means, if I move around with the mouse, the surfaces switching
between "light" and "dark", looks like some kind of Z-Fighting, but I don't think its such a
problem. Is there any problem with round parts of models in jME? Could it be Misfit Model 3D?

I hope you can help me with these problems, its getting really anoyint :/

First off, I probably wouldn't be using the obj format to load your models, that could be the cause of the faceting you're experiencing, or it may have something to do with normals? It could even be that you ahven't set a material so you ahve no ambient property on the models material…

I would probably use ogre for static meshes (as you don't need to atatch to a bone like you do with MD5) and probably for animated meshes as well, or you could alternatively use MD5 for animated, it's up to you.

With regards to the resource locater, you need to enter the folder for where the models and textures are stored etc. The other thing you need to make sure is that the folder is in the classpath, otherwise it won't be able to locate anything. You then use it like this to get a  texture:

ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "name of the texture");

I'm pretty sure that the obj format doesn't work with textures, at least I could never get it to work. The maggie model in the jmetest is using materials with diffuse colours I believe, if you want textures, use either ogre or MD5.

Thanks for your answer, but I didn't found model-editors f

You can use any model editor with support for bone animation and export into the format.

See those links for export scripts for various model editors:



Well, mm3d cannot handle MD5 at all. I searched, but didn't found any free model editor

for MD5. Maybe Blender could export it, but only with a plugin. Using Blender is something

more difficult… I tried but I think I'm not able to handle this O.o

Is there nothing else? Maybe something where I can import a *.obj file and simply

attach textures and then export into a format the simply supports textures?

Sry but this is anoying me, too…

Course you can do that.

The model format you choose is simply a means of getting stuff in to jme.

Everyone has their opinions because it can be one of the most frustrating parts.

Back to the point, you can apply a texture to your .obj imported model just like you would any jme primitive.

Here is an example I made just to check it with your code (as I don't usually use .obj):

Spatial s = getModel("data/models/model.obj");
try {
           MultiFormatResourceLocator texture_locator = new MultiFormatResourceLocator(ResourceLocatorTool.class.getResource("/data/models/"), ".jpg", ".png", ".tga");
           ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, texture_locator);
  } catch (URISyntaxException e) {
Texture texture = TextureManager.loadTexture(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE,"atexture.jpg"),
TextureState ts = display.getRenderer().createTextureState();

However, I also just tried this:

Spatial s = getModel("data/models/test.obj");

And it also worked, even handling multiple textures perfectly.
So as far as I can see, the obj importer works fine, albeit in jme1.
Do you have any errors in the log for failing to find resources etc.

Whilst you can apply the texture manually, I was referring to the use of obj  material (.mtl) files, never could get them working and I quickly moved on to MD5.

Manually add a single texture would work fine, but my model has several textures. So

this is completely useless, because I think its not possible to tell the TextureStates, where

the textures shall be. And well, the SimpleResourceLocator didn't raise any exception or so.

There were just no textures on the model.

different parts of the model are represented by different children of the node you imported.

You can add a different texture to each child.

But the obj importer can handle complex models with multiple textures. I have tested this. What exactly are you expecting?

I take it this means you need to break your model up into submeshes with one texture per submesh? Possibly Wasserleiche has applied multiple textures to a single mesh in the modelling program without breaking up the mesh…

Alric said:

different parts of the model are represented by different children of the node you imported.
You can add a different texture to each child.
But the obj importer can handle complex models with multiple textures. I have tested this. What exactly are you expecting?

I didn't know that the model is splited into different nodes. That would be a possibility, but you first have
to test which node exactly is what mesh... very complicated with complex models.
And which code do you exactly take for model-loading with textures? And how do the paths has to be?
Is the *.mtl-file important? I would be pleased if you could show me the code you're using :)
Still thanks for your replies ;)

Is there really nobody who can show me an working code-example? The fact that this thread had

a lot of hits tells me, that this topic does keep other people busy, too :confused:

Finally… I got it… but with strange things.

I tried out to add a TextureState to each child of the model. First, the model-importer

wanted to return a TriMesh, so there were no children g. By searching here in the

forum I found out, that it's only returning a Node, when more than one materials are

at the model. So I added materials my model-editor. But it's still making TriMeshs. After

a long and frustrating search I discovered that the model-importer gives me Nodes if

the materials are equally named like the children… omg. At least it works now.

I also had to make a trick to get the textures where I wanted them: The names of

the model's children are has numbers, so I can decide to which child I attach what

TextureState. Else it would randomly add the TextureStates to the children if I would

iteratore of getChildren()… It's not the best solution, but at least I got textures onto

my models :slight_smile:

Bit late now, glad you got it working.

Both pieces of code I posted were working code (for me) with nothing important left out - the ony thing I snipped was a basic class extending simplegame, and the method you had already posted, which I used unmodified.

The model I used was a human figure with different textures for face, body, hair, clothes. I did not do anything to prepare the model for jme, only exported it as an obj.

I don't know the innards of the obj importer, guess it just handles some models better than others.