nodejs Posted February 3, 2018 Share Posted February 3, 2018 Hello folks, i try load an .obj file and modify the material/texture scaling. Loading goes well, but not scaling of the textures When i try to access the material object i get a undefined error. meshes[0].material is undefined, in the screen shot you can see the property is there. I dont know what i do wrong // first param: ["myMesh1", "myMesh2"] // https://doc.babylonjs.com/how_to/load_from_any_file_type BABYLON.SceneLoader.ImportMesh("", "./assets/temp/house/", "restaurant.obj", game.scene, function (meshes, particleSystems, skeletons) { // do something with the meshes and skeletons // particleSystems are always null for glTF assets //console.log(meshes, particleSystems, skeletons); console.log(meshes[0]); }); Quote Link to comment Share on other sites More sharing options...
brianzinn Posted February 3, 2018 Share Posted February 3, 2018 The material is loaded a bit later on OBJ and is in the MTL file loaded separately. I would suspect that the console was opening from existing reference, while the material is supplied on a delay. Quote Link to comment Share on other sites More sharing options...
nodejs Posted February 3, 2018 Author Share Posted February 3, 2018 @brianzinn you have a point, but i try after the successful loading (as you can see in the onSuccess callback) Quote Link to comment Share on other sites More sharing options...
brianzinn Posted February 4, 2018 Share Posted February 4, 2018 23 hours ago, nodejs said: meshes[0].material is undefined If this message in on the onSuccess callback then I would say that your materials are not yet loaded! I went through the loader to find where the MTL was loaded: https://github.com/BabylonJS/Babylon.js/blob/master/loaders/src/OBJ/babylon.objFileLoader.ts#L851 The comment above that line says "Load the file synchronously", but I think that's incorrect. Here's the code that loads the file: https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.tools.ts#L552 So, to answer your question - I don't think the onSuccess will have the materials. If you really need that then try another format with materials included or so a spin wait and check the materials or maybe it's in one of the progress callbacks? I use .OBJ, but I excluded the material export as I just found it easier to create my own materials. Otherwise somebody will hopefully correct me. Cheers. nodejs and GameMonetize 2 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.