texture UV coordinates with bmesh

Hi - I’m writing my own exporter and I’ve reached the stage where I need to extract vertex UV texture coordinates. I’m using 2.63RC1 and bmesh but I can’t seem to find a way to get the UV’s for each vertex ?

Can someone point me in the right direction pls ?

Thanks.

Apologies… After reading some more docs I’ve found that uv’s are stored in bmesh face loops.

same problem, i posted a thread like your but i’ve got no answer :(…

you can also calc_tessface() and obtain the uv data from tessface_uv_textures!

Here is some code which should get the uv’s for a bmesh:


import bpy
import bmesh

obj = bpy.data.objects["textured bit"]

bm = bmesh.new()
bm.from_mesh( obj.data )

uv_lay = bm.loops.layers.uv.active

for face in bm.faces:
    print("-face-")
    for loop in face.loops:
        uv = loop[uv_lay].uv
        print("Loop UV: %f, %f" % (uv.x, uv.y))

don’t work… it said that bmesh as no attribute loops…

import bpy

def printUvs(me, index):
    try:
        uvloop = me.uv_loop_layers[index]
    except:
        print("No UV loop layer")
        return
    n = 0
    for f in me.polygons:
        for vn in f.vertices:
            loop = uvloop.data[n]
            n += 1
            print(loop.uv[0], loop.uv[1])

printUvs(bpy.context.object.data, 0)