I’m writing a script which removed overhangs from molds. As my algorithm only deals with trigons, one of the first things I do is triangulate faces. This doubles the amoung of faces in the mesh, however, when my script iterates through the list of faces in the mesh, it only detects half as many of them as it should. I think it’s failing to recognise that I just split every face in two and thinks that there’s the old number of faces.
Is there a line of code I’m missing to update it?
Main function, contains the code which triangulates faces (among other things):
def main (draftAngle, direction, applyBooleans, preservePrisms):
#Opening Variables
zBoundary = findZBoundary(direction)
faceList = []
prismList = []
moldObject = bpy.context.scene.objects.active
#Select all
bpy.ops.mesh.select_all(action = "SELECT")
#Convert to tris
bpy.ops.mesh.quads_convert_to_tris(quad_method='BEAUTY', ngon_method='BEAUTY')
#Generate list of upward/downward oriented faces
faceList = findFaces (direction)
#Create prisms
prismList = createPrisms(faceList, moldObject, draftAngle, direction, zBoundary)
#Remove overhangs
removeOverhangs (prismList, moldObject, applyBooleans, preservePrisms)
#Clean up mold
cleanUpMold ()
print ("Mold cleaned up")
#Return to execute
return
And the code that runs through the faces:
def findFaces(direction):
#Opening Variables
faceList = []
faceIndex = 0
moldObject = bpy.context.scene.objects.active
#Deleteme
x = 0
print ("############################################")
print ("#### Find Faces ####")
print ("############################################")
#Loop through faces, determining which ones face up
for poly in moldObject.data.polygons:
#Deleteme
v1 = moldObject.data.vertices[poly.vertices[0]]
v2 = moldObject.data.vertices[poly.vertices[1]]
v3 = moldObject.data.vertices[poly.vertices[2]]
#Deleteme
print ("Polygon no." + str(x))
print ("V1 = " + str(v1.co))
print ("V2 = " + str(v2.co))
print ("V3 = " + str(v3.co))
x += 1
#Convert local normal to global
normal = moldObject.matrix_world * poly.normal
#Deleteme
print("Normal = ", str(normal))
#Determines global orientation of polygon
if normal.z > 0 and direction == "Up":
#Add index to facelist
faceList.append(faceIndex)
#Deleteme
print("This polygon faces up!")
elif normal.z < 0 and direction == "Down":
#Add index to facelist
faceList.append(faceIndex)
#Deleteme
print("This polygon faces down!")
#Iterate index
faceIndex += 1
#Return result
return faceList