mesh.addFace() why is it so slow?


I am loading a quite big mesh (~70000 verts and ~200000 faces).
The verts are loaded (appended) almost instantly but it really takes ages for the faces. I timed 32 seconds per 1000 faces, meaning ~1.5 hours to load the entire mesh!

I put the code below (taken from the Wiki official tut), any idea to speed it up very welcome!



    for line in file.readlines():
	count +=1
	if count%1000 == 0:


            words = line.split()
            if len(words) == 0 or words[0].startswith('#'):
            elif words[0] == 'v':
                    x, y, z = float(words[1]), float(words[2]), float(words[3])
                    mesh.verts.append(Blender.NMesh.Vert(x, y, z))
            elif words[0] == 'f':
                    faceVertList = []
                    for faceIdx in words[1:]:
                            faceVert = mesh.verts[int(faceIdx)-1]
                    newFace = Blender.NMesh.Face(faceVertList)

Here is another observation:

The speed at which face are added depends on the number of verts in the mesh.
Before I had about 70000 verts and adding 1000 faces took ~32s, now, with another mesh, I’ve got 20000 verts and then adding 1000 faces takes less than 20s.

Also, the more faces it adds, the slower it gets.

I guess I’ll have to check in the source code to understand what happens.

if your interested NMesh is older and not as well maintained.
Mesh works differently and may be better for what you want.
me.faces.extend([(v1,v2,v3), …])