How to access UV maps after gltf exports from blender in threejs

I am trying to access UV3 (uvmap) of mesh to apply a particular texture, however its not being named anything by my gltf exporter. How do I access these UV maps or change their relative name?

also the gltf exporter in blender doesnt assign names to the UV maps. is this normal?

i tried to access with the name uv3 itself but apparently that’s not possible.

I am trying to achieve application of textures with different UV on the same mesh.

You can change their names by changing the attributes on the geometry itself.
geometry.addAttributes(‘snoopyTheUV’,geometry.attributes.uv3);
geometry.deleteAttributes(‘uv3’);
https://threejs.org/docs/#api/en/core/BufferGeometry.addAttribute
https://threejs.org/docs/#api/en/core/BufferGeometry.deleteAttribute
What do you need to rename them for?

I wanted to change the uv3 name so that i can search for it in a easier way.

Anyways i have a MeshStandardMaterial with diffuse, normal and roughness maps. And i have a mesh with 3 UVs (1,2,3). Is it possible to apply diffuse to the mesh using uv3 and roughness & normal using uv1 to the mesh?

There is a custome shader solution but im sure there must be an easier way.

Yes it’s possible, but may require hacking the built in materials shaders.
Texture selection for those parameters is super complex already… since it has to handle, for instance: roughness float value, roughness map as single texture, roughness map packed into a shared texture with metalness+ao, etc. etc.

Sorry to interfere, I’m just dropping two ideas, which I have never used, so I have no clue whether they will work. Apologies if they don’t.

In respect to giving a custom name to the uv3 attribute, I assume you want to change the .name property of the attribute, not the name of the attribute itself (as a JS variable). If this is so, then I’d first try:

myObject.geometry.attributes.uv3.name = 'uv3';

In respect to using diffuse with uv3, roughness & normal with uv1, I’d try the texture.channel property. If it is not working, only then I’d dive into shader limbo.

3 Likes

Yaaa this is the way! ^
I forgot about texture.channel and I didn’t know you could rename attributes like that?! TIL :smiley:

1 Like

The .name property just holds some user-defined name, which is not used internally by Three.js. Just like the .name property of a mesh. So, if the code says:

myObject.geometry.attributes.uv3.name = 'Shakespeare';

Three.js and its shaders will still use the name uv3.

Ohh… ok i thought it relabeled the attribute in the shader. nvm :smiley:

could you explain the process a little bit on .channel as I cant find much regarding using texture. Channel to apply textures within a material with multiple UVs.

As I said, I have never tried the .channel property. I only know that it exists. In the past, texture maps were bound do fixed UV coordinates. With this property you can define what UV set to be used for each texture map. For example, if the normal map has channel=1, then it uses UVs from buffer attribute uv1. If channel=0, the it uses uv0. Theoretically.

1 Like

yes. Just changing the values of the texture’s channel attribute to 0,1 or 2 works just as expected!

1 Like