How to import textures of OBJ scenes

I cannot import obj scenes with their textures. I use the SceneLoader.AppendAsync function, and I pass the file extension, .obj to it as well. However the models are appended without textures.

What am I missing here?

Are you sure the .mat containing the material info for obj is accessible.

A repro would be great ?

I have used the babylonjs sandbox for dragging and dropping an obj system (with .obj, .mtl, and .png files). Although scene explorer shows the texture file in place the scene does not show it on the model.
I have shared here my model files, which are only 2MBs.
ev-tex1.zip (1.8 MB)

You are using a diffuse texture but with Kd 0.00 0.00 0.00 in the mtl meaning your texture is multiplied by a diffuse color of 0 so you do not see it.

I have manually changed the diffuse texture Kd value to Kd 0.50 0.50 0.50 now I see it as red and black grid over the model. I guess it is the obj loader used by the SceneLoader which utilizes HTML Image Elements to retrieve images from source and the source in my case needs some credentials in the http headers of requests. I know no way to change the request headers induced by an HTML Image Element. So I guess I need to circumvent the image loading mechanism available here. Normally I use WebRequest.CustomRequestHeaders to achieve this.
Should I edit the object loader code or are there any more direct way?

You can use FileTools.CorsBehavior = “credentials” to override it.

What credentials this make it include in the request? Does it change the crossOrigin of th eimage element as explained here?
The endpoint serves the resource for these files, and images expecting an Auth header in the request by the way. I think I need a header operation.

1 Like

sorry it should be use-credentials: The crossorigin attribute: Requesting CORS access to content - HTML: Hypertext Markup Language | MDN

This does not happen when I use gltf files with image files. I guess gltf loader dooes not use the same image eleemnt mechanism to load files.

It uses the WebRequest object to load images:

1 Like

I have repeated myself on another post without knowing. Sorry for that. Obj material's textures cannot be downloaded

I have reached to a solution posted there.