Workaround for face.uv?

Greetings.

I’m spending this week on converting a Blitz3D exporter from Blender 2.4x to 2.58. So far, I’ve managed to solve most of the issues in renaming, but I’ve run into something of a stumbling block.

This code generates an error:

for face in data.faces:
                for iuvlayer,uvlayer in enumerate( data.uv_textures ):
                    if iuvlayer < 8:
                        data.uv_textures.active = uvlayer
                        layer_set[iuvlayer].append(face.uv)

The error is simply “‘MeshFace’ object has no attribute ‘uv’”

Apparently, it’s no longer possible to access uv data straight from a mesh face. So what do I need to do to get at the same data?

You can always look things up in the documentation API here.

I think the documentation is terrible, actually. It’s still in its infancy, of course, but scripting in Blender for the last few days has been the most frustrating coding experience in a long while.

In part because of the discrepancies between old and new, however, which isn’t something the documentation should accomodate for anyway. It’s also something I’ve come to know as an Open Source phenomenon, anyway: when anyone can write it also means no one has to. :wink:

Hi, from my experience (I yet still might be incorrect) you will find that;

“mesh_obj.data.uv_channel.face” is the UV data for “mesh_obj.data.faces”

There lengths will match (Verts)

Hope that helps

UV for faces are stored in a different location then before, they used to be part of the face, now they are stored in there own UV channel. :rolleyes:

interesting to get more info on this

is there a good description with this uv layers ect…
how to get size and relation to uv image may be!

can you re do your first example using the rught API commands
and working

thanks

Shagwana: can’t seem to find any “uv_channel” in ‘Mesh’ at all. Are you referring to something else?

Judging by your short code sample, how would you export multiple UV sets?

Here is some snippets from my exporter (not complete yet)


import bpy
import os
import math
import mathutils

import struct 
from mathutils import Vector

def CalcDegree(eu):
    degree_x, degree_y, degree_z = map(math.degrees, eu)
    return Vector([degree_x, degree_y, degree_z])
  
def CalcDegree(eu):
    degree_x, degree_y, degree_z = map(math.degrees, eu)
    return Vector([degree_x, degree_y, degree_z])





objs_list = bpy.context.selected_objects    # Selected object
mesh_obj=objs_list[0]                       # Presume its a mesh object with uv data

#Verts
Write_Longs(pFile, [len(mesh_obj.data.vertices)])
for tVert in mesh_obj.data.vertices:
    Write_Floats(pFile, tVert.co)                   # Coord
    Write_Floats(pFile, tVert.normal)               # Normal of vert



def Export_Face(pFile, tVerts, tFace):
    
    # These are the vertices to use (can be splitting!)
    iV1 = tVerts[0]
    iV2 = tVerts[1]
    iV3 = tVerts[2]
    
    # Save the details to do with the face
    Write_Longs(pFile,[tFace.vertices[iV1],tFace.vertices[iV2],tFace.vertices[iV3]]) 
    # Save the face normal as well
    Write_Floats(pFile, tFace.normal)
    # Save extra face details
    if tFace.use_smooth==False:
        Write_Bytes(pFile,[0])
    else:
        Write_Bytes(pFile,[1])        
    return


#Polygons
for tFace in mesh_obj.data.faces:         
    # All are at least a 3 vert face
    tVerts=(0,1,2)
    Export_Face(pFile, tVerts, tFace)

    if len(tFace.vertices)>=4:
        # This is 4? verts big, triangulate ...
        tVerts=(2,0,3)
        Export_Face(pFile, tVerts, tFace)
        
        
        
def Export_UVFace(pFile, tVerts, tFace):
    
    # These are the vertices to use (can be splitting!)
    iV1 = tVerts[0]
    iV2 = tVerts[1]
    iV3 = tVerts[2]
    
    # Save the details to do with the face
    Write_Floats(pFile,[tFace[iV1][0],tFace[iV1][1]])    #UV mapping of this polygon
    Write_Floats(pFile,[tFace[iV2][0],tFace[iV2][1]])
    Write_Floats(pFile,[tFace[iV3][0],tFace[iV3][1]])
        
    return         
        
        
#UV data of face        
if mesh_obj.data.uv_textures:        
    for uv_channel in mesh_obj.data.uv_textures:
        Write_String(pFile,uv_channel.name)         
            for tFace in uv_channel.data:
                
                # Calculate the texture id for this face
                iTextureID = 0                             # Default to no texture image
                if tFace.image:
                    iTextureID = (ltexture_list.index(tFace.image.name))+1  #Get the texture from the list, so we have its ID
                
                tVerts=(0,1,2)  
                Write_Longs(pFile, [iTextureID])            # Save the texture id       
                Export_UVFace(pFile, tVerts, tFace.uv)      # Save the UV mapping information

                if len(tFace.uv)>=4:
                    tVerts=(2,0,3)     
                    Write_Longs(pFile, [iTextureID])      
                    Export_UVFace(pFile, tVerts, tFace.uv)