Page 1 of 1

How to retrieve the texture associated with a texture uv?

Posted: Thu Jan 17, 2013 9:15 pm
by MrTeapot
I am writing an exporter that among other things exports uv coordinates and the associated image name.

Back in the 2.4x day I retrieved this image information by "['UVMap'].data[0].image.filepath" (I just took whatever the first uv was associated with).

I am now using 2.65 and have updated the uv export part to use the new "uv_layers and loops" interface which works fine. However, I am unable to find the image and its filename. As I understand from the documentation it should be available through "['UVMap'].data.image", but my "tessface_uv_textures" is empty. I have also looked in the uv_layer, vertex and uv data structs but I am unable to find it.

To clarify, the image I am looking for is the one shown in the UVImageEditor when an object is in edit mode and its vertices selected.

If anyone can point me in the right direction it would be really appreciated.


Posted: Fri Jan 18, 2013 11:07 am
by CoDEmanX
you seem to use the tessellated geometry (tessfaces), therefore no loops are involved. But Blender works with loops, and tessfaces are only available on demand.

So make sure you update the mesh before accessing tessface* data.

- Make sure you are not in edit-mode, or uv_* and tessface_uv_* won't be available

- Ensure tessfaces are available (once they are available, they should stay in sync with the mesh...)

Code: Select all

me =
if me.polygons and not me.tessfaces:
    # could also use me.update(calc_tessface=True)
- This isn't correct:['UVMap'].data.image

if the variable "mesh" is a mesh object, you should call it "ob", and its data "mesh" / "me"

instead of ['UVMap'], you should use ...

to access a tessface' image, you need to use the face index:[#num].image
(e.g. [0] for the image of the first face)

Posted: Fri Jan 18, 2013 11:48 am
by MrTeapot
Hi CoDEmanX,

Thanks for the super-quick and useful reply!

Indeed, what I had failed to do was generate the tessface data. After I added the calc_tessface() command it all works nicely, hooray!

I also discovered that it is actually still possible to use the old interface so['UVMap'].data[0].image and['UVMap'].data[0].image gives the same object, I just assumed it wasn't available since the uv data was removed from (assumption really is the mother of all f#"!-ups!).