Jump to content

load *.obj files and set texture scaling


nodejs
 Share

Recommended Posts

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]);

    });
     

5a75f23603d99_Bildschirmfotovom2018-02-0318-26-45.thumb.png.b3f1032280fd10fe8ef192f1dc3a1927.png

 

Link to comment
Share on other sites

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.

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...