Jump to content

Load more than one .mtl for the same .obj


tomer
 Share

Recommended Posts

Hello,

I'm looking for a way to change a loaded mesh texture after it been loaded, without fetching new obj file.

for example -  I have the same chair in different textures, when the user does something I want to change the chair's texture.

I can create a different .mtl file for each variant, but is it possible to load just the .mtl file after the obj already been loaded?

 

Thanks,

Tomer.

Link to comment
Share on other sites

Hi Tomer,

wouldn't it be simpler if you created a map of textures and load them using code?

Having said that - you can technically use the MTL parser class (https://github.com/BabylonJS/Babylon.js/blob/master/loaders/src/OBJ/babylon.objFileLoader.ts#L8) to parse a downloaded MTL file (which you will need to download yourself). This will provide you with a list of materials that you will need to associated with your selected mesh.

Link to comment
Share on other sites

Awesome thank you very much for your help.

Anyway, I thought maybe it will be better for me to use .babylon format instead of .obj, from few simple tests I did I saw a significant difference in rendering times in favor of .babylon.

That's might be a different question, but...

1. Do you have any insights regarding .babylon vs .obj? especially in terms of performance and file size.

2. I have 2 identical .babylon files besides the materials, is it possible to change loaded mesh materials somehow?

I mean .babylon doesn't have .mtl file so I can't download just the materials.

Maybe I can create a different UV map for each variant?

BTW, the problem with creating a map of materials myself is that I have lots of 3d models and I don't want to programmatically create such map for each variant, maybe I can write a script that can extract the materials out of the .babylon file.

 

Thanks again!  much appreciated

Link to comment
Share on other sites

Hi Tomer,

 

the .babylon file format is JSON-based text file, that contains information about the entire scene. It is much more detailed than an OBJ file. OBJ contains only vertex data and materials definitions, but relatively limits. You can't define special materials (like PBR for example), and you are restricted to the OBJ limitations.

In terms of performance - there shouldn't be any different between the two. The vertex data should be the same on both files. Both files are text-based, so both are compressable. Whereas OBJ is line-based (\n is the delimiter) and cannot really be "minified", a JSON can be minified and can, eventually, be a bit smaller. The .babylon might be a bit larger in terms of file size (I would say 10% more, but this is just a guess) because of the scene data that is always exported with the meshes. This information is optional if you use ImportMesh, and is only being used if you use the Append or Load functions of the SceneLoader.

With a .babylon file you can define more materials that you actually need. so, the .babylon file of a single mesh CAN contain all matrials that can somehow be connected to this mesh. When importing the .babylon files, those materials will be loaded to the babylon scene, and can be found using the scene.getMaterialById function. This way you don't need to load another mesh just to change materials.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...