UV Maps

I can’t seem to find an answer to this question, re: accessing the UVs for materials which contain multiple texture maps. I see references to uv_layers.active.data, but this seems to only represent a single texture layer. Do UVs for a material which has multiple textures need to share the same UV map?

How is the actual UV map for the actual material (or face) actually looked up? There seems to be various redundancy in the software which makes things massively confusing. Is the texture information pulled from uv_textures[], or can it still be accessed through materials[].texture_slots? I’m guessing I have to do a big reverse lookup to match texture information from uv_textures[] back up to a face, and inevitably to an actual material?

So I’m assuming that textures and materials are two completely different entities now, and that for every texture which is bound to the the object is represented in uv_textures[], and that in order to find faces which share those textures, I have to index into each of the uv_texture[] elements, and check whether it has an entry for the specified face index?

There’s a bit of a mess with UVs, that’s true.

uv_textures contains one part of the UV map data - the image assignments per face. uv_textures.active gives you the current UV map, every entry in .data matches a polygon (same index), e.g. uv_textures.active.data[123].image is a reference to an image datablock for polygon with index 123. It does NOT store a material or texture!

uv_layers contains another part of the UV map data - the UV locations per loop. uv_layers.active gives you the current UV map (should usually match with uv_textures.active), every entry in .data matches a loop (per-face vertex data). uv_layers.active.data[456].uv is a float value pair (Vector2), the uv coord of loop 456. This index does NOT match a vertex index!

The above are relevant for rendering, but for the viewport, the material and texture assignment matters as well. Polygon.material_index stores the material index, and the material needs to have an image texture with tex coords set to UV. You may use the Materal Utils addon to transfer uv_texture / uv_layer data from UV Editor to material assignments or vice versa.

Multiple image textures per material may cause trouble, although it’s possible to have different images in uv editor (uv_textures) per face in a single UV map.

If you really need to lookup textures / materials / images, create a python dictionary for fast lookup.

Thanks for the reply, CoDEmanX. :slight_smile: So from my understanding of your information above:

 Mesh.uv_textures => Collection of MeshTexturePolyLayer, which describes a collection of MeshTexturePoly objects referencing the texture applied to each face for that layer.  This object also "links" to a UVmap via the 'name' attribute, eg: Mesh.uv_layers[Mesh.uv_textures[0].name], which represents per-vertex texture coordinates.

 If I can assume correctly, a single MeshTexturePolyLayer is synonymous with a texture stage, and having a multi-textured face would require a single entry (per the multi-texture face) in several MeshTexturePolyLayer's.  Eg:

 uv_textures[0].data[15].image
 uv_textures[1].data[15].image

Would represent the 2 texture layers for the face?

How is the texture information related back to the images obtained via uv_textures? Does Material.texture_slots[] have a reference to those images?

Mesh.uv_layers[Mesh.uv_textures[0].name]

Names SHOULD match, but I believe it’s not always guaranteed. Maybe use the index instead? I’m not sure.

which represents per-vertex texture coordinates.

No, it’s per-loop. Here’s an example why loops are needed (vertex colors - they are actually loop colors):


http://wiki.blender.org/index.php/Dev:2.6/Source/Modeling/BMesh/Design