Using materials for several objects (.OBJ) from one (.MTL) file

Hello !

I’m working on a school project in which I’m trying to display with JMonkey a scene exported from another program.
In the other program, we made a plugin to export the models and the information that we need to display them, but we’re having troubles with the materials : the objects are defined with the OBJ format, and they have references to materials (with a line saying : usemtl xxx ), but there is no MTL file with the OBJ files.
By digging in the source files, we found that they are all included as a big string in one class, so we were able to copy/paste it to get a proper MTL file.

We are then stuck because we can’t find how to load the MTL file to use the materials defined inside so that the OBJ files can be decorated accordingly.
I looked for information on how to load MTL files separately form the OBJ, but I couldn’t find useful things.
Any ideas on how we’re supposed to do that ?

when importing an object into jme the materail file (once imported, is a .j3m file) gets enclosed inside of the .j3o file.

If you want to modify the materail of the object once imported in to the sdk. you can open it in the scene viewer (double click the j3o) then in the properties button there will be a button to generate a .j3m file from the j3o (its a part of a drop down)

You can use that if you want many j3o files to share the same j3m

i do not think there is a built in mechanism for just importing material files from other programs though. Thats kind of a weird usecase imo. usually you’ll want to be editing material files directly inside the jmonkey sdk as a material in one program will not look the same in your jme game because it uses different shaders.

“Materials” from external formats basically just reference the needed textures, as I’m sure you read the manual you know that there is no other parameters of the various 3D editors and 3D formats that import reliably apart from the textures.

For people with reading disabilities and / or ADHD I made a video:

Hum thanks for the answers, but yeah, I have a weird usecase, and importing in the SDK will not solve everything as we don’t have access to all the objects/materials that will be used.

To give more details on what we’re trying to do, the project is about connected houses.
We have access to a first program (called SweetHome3D) to make a house by putting furniture, walls, etc., and we’re developing a plugin for that program so that the user can add information to the scene to make a connected house (ex : select some blinds and add the URL used to send the signal to open/close it).
Then, we have to create an independent app (we choose JMonkey to do it, because it seemed to be an easy way to set up a 3D scene) to display the house so that the user can walk around his house, and interact with it (ex : look at the blind, click, and then the app will call the URL to open the blind in the real life).
The first program has some default furniture, but the user is also able to add his own creations, and the default furniture may be changed with a new version, so even if we import all the default furniture in the JMonkey SDK, we still need to handle the user-added furniture and the eventual changes in the default furniture.
And also, sorry @normen, the MTL description we found is not using any texture, it’s only plain colors defined with Ka/Kd/Ks/illum/d/NS . But we don’t really care if it’s not accurate in the JMonkey app, as long as it stays vaguely the same.

So far, we’re proceeding on the export side by making a zip package with some information to rebuild the scene (position, size, etc.) and the .OBJ models for the object that we were able to get access. We can import that successfully in the JMonkey app that I made, but I don’t have any colors to put on the objects.
Let’s say that we can hack a bit the first program via the plugin to get access to the material descriptions (a 950 line long String stored in one class), what would be our best option to export this data to get some colors in JMonkey ?

You really should move to using texture maps, also for plain colors. Else you lock yourself in in terms of lighting and other map types (normal, specular etc.).

@normen said: You really should move to using texture maps, also for plain colors. Else you lock yourself in in terms of lighting and other map types (normal, specular etc.).
Hum I'm not sure I understood correctly : you're suggesting me to code something to generate a bitmap texture for my models instead of the plain color indicated in the MTL description ?

Isn’t it a bit out of scope for my school project ? We don’t have requirements on the quality of the display app, vaguely resembling colors will do the trick, as long as it’s not too messed up. I would just like to do something that can apply some colors according to the materials defined in the OBJ files, so that in the bed for example, the blankets are white and the wooden parts are brown.