One mesh.xml file but multiple MATERIAL files

Hey, I have created a 3D object on Blender, that object has 3 seperate materials. When I export the object into my Models/ folder I get the mesh.xml file, 3 material files, 3 images (the ones I used for the textures) and a .txml file.



In the hello assets tutorial it says when you are using .mesh.xml the material file has to have the same name as the mesh.xml but I can’t do that since there is 3 different materials.



I’ve looked all over the place for an answer and can’t find one. Any help would be great thanks.

Just pick one and name it the same as the .mesh.xml file. You will want to create your own .j3m material files, or at least tweak them. This can be done in the material editor in the SDK.

Thanks for the reply.



I picked one of the material files to change its name to match the mesh.xml file and that material displayed correctly on the mesh in the import asset window.



I just looked at this: https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:blender but I still don’t know how to add the 3 materials to my object. Any help would be appreciated. Thanks.

Geometries in jme only have one material. If you want to switch between several materials, you can just call myGeom.setMaterial(), but you can still only have one.

On that link I just posted above towards the bottom of the page in the table layout it shows how Blender features are mapped into jME3.



It says from Blender that meshes are mapped as List in jME3 because “One mesh can have several materials so that is why a list is needed here.”



Is that correct or incorrect? Thanks.

Ah this is specifically the blender loader then. Still a geometry in jme3 can only have one material. The list there in the blender loader is a list of Geometries, the same geometry each with its own material (I believe that’s how it works).

The mesh.xml file is produced from the ogre exporter, that is what you are using to export?



The blender importer imports .blend files directly and handles multiple materials.



So there are two different formats from blender that jme can read: mesh.xml (ogre exported), and .blend.

Yeah Im using the ogre exporter.



So if I want to have models with multiple materials I must create the same amount of Geometries, add the materials and then somehow add that list of Geometries to some sort of object? Which would then be another Geometry made up of multiple Geometries?



Also do you know if the Blender loader is efficient?

To make the materials just create a j3m file and edit it the SDK. Then in your code apply whatever texture you want to it (still only one at a time per geometry). You can almost copy the material properties 1 for 1 from the material file to the j3m file.

What are your separate materials? Different looks for the model? Or somehow combined to form one material to cover the model?



I have not used the blender loader, only the ogre exporter, so I cannot speak for its performance. I prefer to have my models in j3o format already so the game can load them as fast as possible without having to convert every time it launches.

I know this might sound stupid but how do I create a j3m file? I’ve read through so much stuff in the last few weesk everyday that I’ve totally confused myself with all the information. Is there a tutorial on it? I have more than likely come across one, maybe even a few times.



The materials are for a roundabout (the one on roads). I’ve got a circle object and in the middle is a grass material, outside that is a bricks material and then outside that is a concrete material.



Thanks for this help.

In the SDK right click on the Materials folder in your Assets directory, go to New->Other->Material, select ‘Empty Material File’. Then you can just double click on it to edit. There you can set what diffuse, normal, specular textures it uses, and material colors, plus many other settings.



I would suggest if you can make the roundabout a single model, it will increase the performance of the app (the fewer the objects the better). You can use UV unwrap to texture each part of the model (concrete, grass, and brick).



If you want them as separate models (grass area, brick area, concrete area) then you will have to extract 3 separate meshes, and give each its own material.

Ok cool thanks.



Yeha thats what I have done with the roundabout. Its one model and then in edit mode I used UV Mapping to apply my 3 materials to the 3 different parts of the roundabout and then when I export it gives me 3 materials.



If you did it that way how would you apply the 3 materials to the roundabout in jME to make it look like it looked in Blender?

You are still limited by the single material per geometry in jme. You will have to produce a single diffuse texture with the grass, brick, and concrete and map it with the UV coordinates.

Ok cool thanks for that I’ll give it a go. I can us the UV mapping but I don’t really know how to do what your saying I don’t think. Do you know how someone goes about using all the different materials that would be on a character mesh for a game?

There’s an option in the Blender exporter to write materials to a single file.

1 Like