Jump to content

obj loader - loading material


satguru
 Share

Recommended Posts

Looks like the obj loader is not finished loading material when the BABYLON.SceneLoader.ImportMesh() onSuccess function is called.

see

https://github.com/BabylonJS/Babylon.js/blob/master/loaders/src/OBJ/babylon.objFileLoader.ts#L231

I need to make changes to the mesh material after the mesh is loaded by the obj loader.

How would i know when the obj loader is done loading the material?

what is the most reliable method for doing that?

Link to comment
Share on other sites

I can't tell without a PG example. This is simple to troubleshoot if you simply load your OBJ into the playground. You may need to edit your OBJ and/or material file, or perhaps there's not time to load the texture - however this is rare.

DB

Is your OBJ, MTL, and image file int the same directory? Are you using power of 2 texturing?

EDIT - In looking further at your code, I can see allot of declarations that perhaps won't allow the mapping of a texture. I haven't figured out why you're addressing UVs, but the OBJ importer is simple yet fickle if you make one error. Also, if the issue is not the texture and it is the material, then edit your OBJ file to remove reference to the material, and reference in the MTL file to a texture if necessary. Eliminating the reference to the MTL file in the OBJ file will provide a very nice default texture - which could be your issue depending on how the OBJ was generated and if you already applied any materials.

Link to comment
Share on other sites

Here's a PG example.

http://www.babylonjs-playground.com/#UKNERM#11

This loads a small obj file "TallWall.obj". The obj file has a small mtl file "TallWall.mtl".
No textures, just colors.

The files are located here  https://github.com/ssatguru/obj-samples

In the PG example I print "mesh.material" from two places

1) from inside the   ImportMesh() OnSuccess  method and

2) outside it after waiting 2 secs.

Inside I get undefined , outside, after 2 sec, I get the material

Link to comment
Share on other sites

I've ran into this before as well.  The comment that it's loaded syncronously (Calls synchronously the MTL file attached to this ob) was what confused me last time I checked - I found it to be async.
https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.tools.ts#L634

Check here as well:
https://github.com/BabylonJS/Babylon.js/blob/master/loaders/src/OBJ/babylon.objFileLoader.ts#L860
Notice the onSuccess() just attaches the material and if I recall correctly the onSucess() you are working with is just that the OBJ file loaded, where material is async.  I don't see a way to wire into material loading except manually checking in a loop (2 seconds is not a guarantee on a slower connection) or updating the loader itself to trigger (additional) events.

One easy solution is to switch from OBJ...  I'm using OBJ files, but not MTL materials.  Other standards include material in original file.

edit: If you want to work on the loader to delay onSuccess until materials are loaded, it could be added as an option.  ie: { onSuccessWithMaterials: true }, which defaults to false.  I think you need to get importMesh(...) to not return until materials are loaded, probably not done as it could block for a while.

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