Loading blender models with texture?

Hi

I’m not using the SDK because I’m using eclipse for my work and I’m getting really confused switching between two different IDEs. Wanted to make this clear upfront :slight_smile:

I created a really simple model in blender with one UV mapped image texture, and now I’m trying to import this into my jme3 game. I search this forum and googled and didn’t really find out how I can get the texture onto my model. I read through the documentation on how to create proper models in blender, how to use the BlenderModelLoader and so on, but in the end I’m kinda confused. How is the texture/material supposed to get onto the model in the game?
I also exported the model in blender to .obj, but in the resulting obj or mtl files there was no reference to the texture file, and there doesn’t seem to be an option in the obj blender exporter to do this. I also put the image file in the exact same folder as the blend file or the resulting obj file.
Any suggestions (besides using the SDK…)?

1 Like

You can use the SDK to import the model and pre-view it and save it to a j3o-file and then use that in your code. You don’t have to code in the SDK if you find it confusing.

1 Like

Can I only do this in the SDK (import and save as j3o)?

Can you upload the model and post the link here ?

I could check the loading. I managed to load models with textures without problems so either your model has something wrong or you found a bug in the importer that will need to be fixed :slight_smile:

The sdk uses only the code present in jme to load the blend files. and export them, no magic there

final Spatial model = this.assetManager.loadModel(toCompile);
final BinaryExporter exp = new BinaryExporter();
final File outName = new File(“wurst.j3o”);
exp.save(model, new FileOutputStream(outName));

Thank you for the code, had no idea that it was that easy. Here is a complete working examples:

public class J3OExporter {
public static void main(String[] args) {
	SimpleApplication app = new SimpleApplication() {
		@Override
		public void simpleInitApp() {
			assetManager.registerLoader(BlenderModelLoader.class, "blend");

			final Spatial model = assetManager.loadModel("SOURCE.blend");
			final BinaryExporter exp = new BinaryExporter();
			final File outName = new File("TARGET.j3o");

			try (FileOutputStream out = new FileOutputStream(outName)) {
				outName.createNewFile();
				exp.save(model, out);
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	};
	app.start(Type.Headless);

	app.stop();
}

}

Works like a charm :slight_smile:

But the texture is still missing from the model. I uploaded the model here (first time I use a free file upload service…):

http://www.qfpost.com/file/d?g=7ghdlZJBi

The texture is a simple 64x64 jpg.

Thanks for your help so far :slight_smile:

2 Likes

Thanks for the model. I will tak a look at it.

And sorry for my late response but I was unable to download the file during the weekend.
Looks like this file host service is only IE dependent and I do not have that browser at home :wink:

Paths, its all about paths. Thats why the SDK handles the project structure like it does:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:intermediate:multi-media_asset_pipeline#create_textures_and_materials
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:external:blender

Another thing is that you use nodes which are not (yet) supported by the importer.

Where do I use nodes in blender (and how can I not use them…?)? Or do you mean in the jme code?

<cite>@normen said:</cite> Paths, its all about paths. Thats why the SDK handles the project structure like it does: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:intermediate:multi-media_asset_pipeline#create_textures_and_materials https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:external:blender

The whole path thing didn’t do anything for me. After moving all assets into their respective folders the problem still occurs.
So it must be the way the model is made, right? But what should I do differently?

I was talking about nodes in blender.
The material nodes. You had them turned on and the material definition was stored inside the nodes editor in blender.

If you turn it off and define the material and textures in the ‘old way’ you will probably see the textures.
Another thing that you can do is to store the texture in the blend file. This way you can avoid path problems.

Ok, now you just need to tell me how to do this in blender ^^. I use version 2.68.

The node button is the 4’th button on the right of the material’s name field in the material tab.
Turn it off and then define your material and textures in the traditional way :slight_smile: