a technical blog

Blender 2.6: Exporting UV Texture Coordinates

with 2 comments

There is nothing I admire more then a software development team that is not shy of reorganizing an API to the better even though it means stepping on some peoples feet. Well, I guess the Blender team stepped on my foot; because one of my export scripts was no longer working once I upgraded to Blender 2.6. Actually, I should have known; because it is more the rule then the exception that the Python API changes from release to release…

This time it took me some hours to find how to get to the UV texture coordinates of a mesh. After browsing through the API via the python console for some time I took the easy way out and peaked into the .OBJ model exporter coming with blender. So, here is how you get to the UV textures of a triangle for your mesh:

m = bpy.context.active_object.to_mesh(bpy.context.scene, True, 'PREVIEW')
uv1 =[0].uv1
uv2 =[0].uv2
uv3 =[0].uv3

The part of the data path that has changed (at least I was able to get to the UV coordindates differently in the past) is the tessface_uv_textures property.

Note that i am accessing index [0] here. The array indices correspond to the indices of the faces-array. So, this example is for face zero. Also note that the uv1 to uvx depend on how many vertices the face has. Often you would first triangulate the mesh to have only primitive polygons.

I hope t helps someone because also google mostly shows up with results for accessing the UV coordinates that are deprecated for some time by now and thus are no longer working.

Written by 38leinad

May 29, 2012 at 8:51 pm

Posted in blender

Tagged with

2 Responses

Subscribe to comments with RSS.

  1. The update to 2.6 fucked me up too but your post really made my day.
    I’m working on an Exporter for a 3DEngine and got a couple questions about the UV’s of a triangulated mesh.
    For the sake of simplicity I’m using a triangulated surface which contains 4 vertices and 6 indices. So we got 1 UV for each vertex. Let’s get to my Question: When I’m trying to use them in my application do I have to export just the 4 different UV’s or all 6?


    September 10, 2012 at 9:33 pm

  2. if you want to use the same texture for the mulitple uses of the vertex, you can export only the 4. but you might be constraint by this. think about a cube where the same vertex location is used for three different sides of the cube. here, you might consider exporting actually 3 verticies with 3 different texture coordinates (even though it is the same physical location for all three verticies).



    September 11, 2012 at 3:44 pm

Any thoughts?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: