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.