How can I set UV coordinates for a mesh ?

Hello,

I’m getting vertices, faces and uv coordinates from a 3rd party app and need to recreate the mesh in Blender 2.49.

mesh = bpy.data.meshes.new('mesh')
mesh.verts.extend(coords)
mesh.faces.extend(faces)

Currently coords is a list containing lists of 3 items,
e.g coords = [[0.0,0.0,0.0],[0.1,0.1,0.1],[1.0,1.0,1.0]…etc.]

I’ve noticed the MVert(http://www.blender.org/documentation/249PythonDoc/Mesh.MVert-class.html) object has the uvco property.

How can I set UV coords to my Blender mesh ?

Thanks

It seems I need to make sure I work with a Mesh instance, not an NMesh, and have an UVLayer there.

something like:


fmesh.addUVLayer('uvw')
for f in range(0,len(fmesh.faces):
    fmesh.faces[f].uv = [myuvs[f],myuvs[f+1],myuvs[f+2],myuvs[f+3]]

where myuvs[f] would a 2d vector: Vector(0.0,0.0) from the Mathutils.

the snippet isn’t the best way to do it, but just a way to access and set uvs.