Using import script, texture is sometimes upside down


I am trying to fix an error in an import script.

Sometimes when I import, the a texture is upside down. But it works correctly most of the time.

The entire script is here:

I suspect this line (397) to be the culprit:

me.tessfaces.foreach_set(“vertices_raw”, unpack_face_list(self.face_list))

Has there been any known bugs in using that, maybe that it messes around the vertex order? (I am using Blender 2.69 at the moment)

I really would like to see it solved, it seems to be the last bug in the script, and solving it, would be awesome.

Any help appreciated.

Okay, it seems that line was the culprit. But now I have another problem plus a question:

I replaced the line with this:

theFaces = []
for aFace in self.face_list:
if(len(aFace) == 3):
theFaces.extend([aFace[0], aFace[1], aFace[2], 0])
elif(len(aFace) == 4):
theFaces.extend([aFace[0], aFace[1], aFace[2], aFace[3]])

		me.tessfaces.foreach_set("vertices_raw", theFaces)

And now the textures are correct, BUT one face is missing (a triangle). So what could be wrong?

Secondly when a face has only 3 vertices I read I should put in 0 as last index as I have done above. But how does Blender know that that last 0 is not a index to vertex number 0?