UV map displaying incorrectly in babylonjs

Texture showed on model is different from blender.


I tried to adjust offet, scale but it not working.
Thank you

Is there any UV matrix transformation applied to UV?
Is back face culling disabled and geometry doubled? (doesn’t quite look like that but better check)
Did you export using gltf? did you try other format like obj?

cc @PatrickRyan

Does this error also happens in Sandbox?
Does it happen in other GLB viewers, like glTF Sample Viewer or https://gltf.report/ ?

you probably have multiple UV channels and the export somehow did not assign the texture to the correct channel. load your model in a sanbox , open the inspectors and check the textures uv channel

3 Likes

@Justinduy_nguyen we are all assuming that your texture is loaded through a glTF file which contains your material assignments. If you don’t do it that way - maybe you loaded an obj file and textures separately and created your material in Babylon - you could be running into an issue where you need to invert Y on your texture. We use the DirectX API for Babylon which expects the first pixel of an image to be at the top of the image. The glTF format assumes the OpenGL API which expects the first pixel of the image to be at the bottom of the image. If we load a glTF file with embedded textures, we take care of setting flags on the textures to enable them to display correctly. However if your textures were authored as OpenGL format and loaded separately, you will need to invertY on load.

If you have multiple UV’s delete the unused one (if you’re sure it isn’t used), or if you need more than one UV, try adding a UV map node to specify which one each image should use:

Here is an example, UV’s specified for each image.

After the GLB exports it’s fine, as can be seen from Sandbox:

Before I ran into a problem with older versions of Blender, which seemed to ignore the active/assigned default UV (the one with the camera icon active) when exporting GLBs. It would default to the first one.

So this would happen:

Manually adding the UV map node will make sure the image uses the correct UV.

1 Like

If there are multiple UV sets for a mesh - maybe they are needed or extra - you will want to tell each texture in your material which UV set to use. You can simply set the coordinatesIndex on the texture to the correct UV set index. The UV sets start at index 0 and are held in an array in the order they appear in your DCC tool.

2 Likes

@PatrickRyan
Good point, thanks! I’ve edited my post to make it more clear.

1 Like