# 2.49b face index order

I am using the following code to import a mesh into blender:

mesh = Blender.Mesh.New()
mesh.verts.extend([Vector(v.co) for v in self.verts])
mesh.faces.extend([f.vertex_index for f in self.faces])
for i in range(len(mesh.faces)):
ti = self.faces[i].texture_index
uv = [Vector(self.texcoords[ti[0]].uv()), Vector(self.texcoords[ti[1]].uv()), Vector(self.texcoords[ti[2]].uv())]
mesh.faces[i].uv = uv

For some reason blender is changing the face ordering messing up the uv coordinates.

Original face indices:

[0, 1, 2]
[0, 2, 5]
[6, 7, 8]
[5, 2, 11]
[10, 1, 0]
[10, 9, 1]
[4, 9, 10]
[4, 3, 9]
[8, 3, 4]
[8, 7, 3]

Blender mesh indices (the fifth face):

[MFace (0 1 2) 0]
[MFace (0 2 5) 1]
[MFace (6 7 8) 2]
[MFace (5 2 11) 3]
[MFace (1 0 10) 4]
[MFace (10 9 1) 5]
[MFace (4 9 10) 6]
[MFace (4 3 9) 7]
[MFace (8 3 4) 8]
[MFace (8 7 3) 9]

Is there a way to avoid this? Thanks.

Have solved the problem by remapping of the uv indices(i).

sf = self.faces[i]
mf = mesh.faces[i]
# fix face indices ordering
i = [0, 1, 2]
if mf.v[0].index == sf.vertex_index[1]:
i = [1, 2, 0]
elif mf.v[0].index == sf.vertex_index[2]:
i = [2, 0, 1]