Applying material and texture to blender geometry

I am using blender models for the meshes only: I would like to apply my own materials and textures in code. The problem I am having is that the material and texture seems to be ignored unless I define a material in blender.

Here is some sample code from a simpleInitApp:

	assetManager.registerLoader(BlenderLoader.class, "blend");
	Node features = (Node) assetManager.loadModel("Models/room-features.blend");
	Node table = (Node) features.getChild("Table");
	Geometry geom = (Geometry) table.getChild(0);
	Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
	material.setTexture("DiffuseMap", assetManager.loadTexture("Textures/roof-diffuse.jpg"));
	geom.setMaterial(material);
	rootNode.attachChild(geom);

This works correctly only if the blender model has a material added within blender. Even though I am setting a new material in code, it needs to exist in the model to work. That doesn’t make any sense to me given I’m ignoring the imported material - any other attributes of the imported material would be overwritten.

I’ve used a debugger to break after the model has loaded to check what is different in the geometry with and without a material in the blender model. I can’t spot the difference.

Any ideas of what I’m doing wrong?

1 Like

Ok I’ve got a theory now. I notice that when no material is included there is one fewer buffer in the loaded mesh (4 rather than 5). My theory is that the missing buffer is the UV Map and it’s not loaded if there’s no associated material.

Can anyone confirm that? if so, is there a way to load the UV Map from the .blend and associate it with the geometry?

1 Like

If it works with a material in Blender, doesn’t that suffice? (By material in blender I mean just select blender object and click new material)

The import is done by the BlenderLoader. Thus, if you would want to see what is exactly going on check the source code of the BlenderLoader.

You are also free to edit the loader if you’d like.

1 Like

I think it’s a bad idea to load blend models in jME directly :slight_smile:

2 Likes