PolyFill problems

I have been writing a python script that needs to fill in faces as part of the program and I tried to use Blender.Geometry.PolyFill() to do this. However, PolyFill isn’t working the way I thought it would work and the program I am writing does not work right when I use PolyFill.

I created a sample python script here which shows the problem. The script is supposed to fill in the mesh in the first picture. The result of the script is the second picture. However, when I pushed Shift+F (Edit > Faces > Fill) on the mesh in the first picture, was filled the way I wanted it to, which is the third picture.

Is Blender.Geometry.PolyFill supposed to work the same way as Edit > Faces > Fill (Shift+F)? If not, is there a way to do what Shift+F does from a python script?


import Blender
from Blender import Mathutils
Vector = Blender.Mathutils.Vector
p1 = [Vector(1,1,0),Vector(-1,1,0),Vector(-1,-1,0),Vector(1,-1,0)]
p2 = [Vector(0.5,0.5,0),Vector(-0.5,0.5,0),Vector(-0.5,-0.5,0),Vector(0.5,-0.5,0)]
p3 = [Vector(4,1,0),Vector(2,1,0),Vector(2,-1,0),Vector(4,-1,0)]
#p3 = [Vector(3,1,0),Vector(1,1,0),Vector(1,-1,0),Vector(3,-1,0)]
#p4 = [Vector(3.5,0.5,0),Vector(2.5,0.5,0),Vector(2.5,-0.5,0),Vector(3.5,-0.5,0)]
fill = Blender.Geometry.PolyFill([p1,p2,p3])
m = Blender.Mesh.New("Mesh")
for i in [p1,p2,p3]:
 m.verts.extend(i)
m.faces.extend(fill)
scn = Blender.Scene.GetCurrent()
o = scn.objects.new(m)
Blender.Redraw()

Pictures:
1: http://img9.imageshack.us/img9/5223/polyfilltest20091202at1.th.jpg

  1. http://img198.imageshack.us/img198/5223/polyfilltest20091202at1.th.jpg

  2. http://img4.imageshack.us/img4/5223/polyfilltest20091202at1.th.jpg

I think shift-F is not polyfill() but correspond to the fill() function of the mesh module :
http://www.blender.org/documentation/249PythonDoc/Mesh.Mesh-class.html

both functions need a little help when there’s >90 angles and when the shape tends to be complex.