How to import `.obj` file with `.mtl` that contains multiple material?

Hey all,

I am trying to import an .obj model that has has a .mtl file with several textures/materials. For reference, here is a link to the resource I am trying to import:

I’ve been able to import the .obj but am having trouble getting all of the textures to apply as you can see here:

Can anyone point me in the right direction? Thank you so much!

Which results do you have if you drop all files (.obj, .mtl, all textures) to Sandbox?

Ah very interesting it looks the same in the sandbox. Does that mean it’s likely a problem with the model?

Yup the normal map AKA bump textures are all missing

1 Like

Hey @sebavan! Wow, that’s something I had no idea about. So that I can learn a thing or two from this experience, could you comment on how you could tell from the files:

  1. that this model needed a normal map/bump textures to render correctly and
  2. that the normal map/bump textures were missing?

For example, did you realize 1) because - I’m making this up because I just don’t know - all .mtl files always require a ‘normal map’ and there was no normal map?

I looked at the material in the inspector and it looks like the map where broken.

Digging into it more, this is using an unsupported flag in babylon “-bm 0.4000” in the mtl file so the name happens to be wrong but anyway the bump in use is incorrect as it is using the same texture than diffuse.

I would advise to remove map_bump lines from the mtl.

I have done a bit of work on the obj loader… I wonder if it’s some functionality missing in the loader itself. Does it load in other software correctly? The sandbox isn’t reliable from my experience as it won’t be able to load the MTL files as separate downloads or possibly I was uploading incorrectly :laughing:

@brianzinn we are definitely missing the -bm support for map_bump, would you be willing to add it ?

Removing the map_bump lines seems like it did something! (though not everything, unfortunately). Here’s an updated sandbox image:

For a multi-textured multi-component 3d model like this, what would be the preferred way for me to load such a model in Babylon? Is this a limitation of the .obj format?

UPDATE 2: And the winner is .glTF file format (at least in the sandbox) :tada:

UPDATE 1: here is what the model looks like in Blender now. It seems to have all the textures so I will try exporting as .glTF file and see how that goes

1 Like

looks “solved” with glTF, but I’ll have a look to see anyway.

Sounds good! Let me know if there’s anything I can do to help. I can confirm that I could successfully import the textured model in my own code using the .glb format :rocket:

How did you generate your MTL file? There were some file names incorrect (spaces that should be underscore and underscores that should be dashes). Other than that it looks like there may be a parameter (-bm 0.4000) we may need to apply to the bump map instead using as a rootUrl.

Looks like those are unsupported parameters that should be passed through. I think -bm may need to be assigned to: detailMap.bumpLevel. Other parameters like scaling and offset are also not handled it looks like.
Can you look at, for example your wood texture bump map and see if you have adjusted the bump scale/level?

Should be able to support that once I know where to map those parameters.

edit: or if you can share the glTF and I can look in inspector :smile:

edit2: looks like that file was created in 2013 in 3ds Max :joy: In that case maybe just your file names in the zip were wrong? (still I can add support for bm parameter)!

1 Like

Yeah, I found those meshes on the internet but I didn’t realize they were that old! But since I didn’t make them unfortunately I can’t comment on the bump maps / the build process. Here’s are the .glbs in if they would still be helpful!

Thanks again for the help with this!

Thanks for the .glb files. I did a PR - I was expecting the bump map to be the spiral pattern on those posts, but from the wireframe mesh looks to be part of geometry.

Meanwhile I did not see a bump texture on the GLB file. I suspect the ‘level’ may not be correct place to set, but see how the PR goes.

1 Like

You are the best :slight_smile: