tomer Posted November 19, 2017 Share Posted November 19, 2017 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. Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 20, 2017 Share Posted November 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
tomer Posted November 20, 2017 Author Share Posted November 20, 2017 Hi Raanan That's exactly what I was looking for, thanks. Anyway, not sure I totally understand what you mean by "map of textures"? Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 21, 2017 Share Posted November 21, 2017 I meant a sort of key-value structure in which you define a lite of URLs for each object, and load those textures when needed. If the MTL parser works for your usecase, it should be more than enough Quote Link to comment Share on other sites More sharing options...
tomer Posted November 21, 2017 Author Share Posted November 21, 2017 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 Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 23, 2017 Share Posted November 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
tomer Posted November 23, 2017 Author Share Posted November 23, 2017 Thanks again, that's a great idea. RaananW 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.