forked from bartvdbraak/blender
use f.area where possible over python function and use len(mface) over len(mface.v)
This commit is contained in:
parent
2222e4cbc1
commit
b7b99be387
@ -167,15 +167,6 @@ def pointInTri2D(v, v1, v2, v3):
|
||||
uvw = (v - v1) * mtx
|
||||
return 0 <= uvw[0] and 0 <= uvw[1] and uvw[0] + uvw[1] <= 1
|
||||
|
||||
|
||||
def faceArea(f):
|
||||
if len(f.v) == 3:
|
||||
return TriangleArea(f.v[0].co, f.v[1].co, f.v[2].co)
|
||||
elif len(f.v) == 4:
|
||||
return\
|
||||
TriangleArea(f.v[0].co, f.v[1].co, f.v[2].co) +\
|
||||
TriangleArea(f.v[0].co, f.v[2].co, f.v[3].co)
|
||||
|
||||
|
||||
def boundsIsland(faces):
|
||||
minx = maxx = faces[0].uv[0][0] # Set initial bounds.
|
||||
@ -214,11 +205,11 @@ def island2Edge(island):
|
||||
edges = {}
|
||||
|
||||
for f in island:
|
||||
for vIdx in range(len(f.v)):
|
||||
for vIdx in xrange(len(f)):
|
||||
if f.v[vIdx].index > f.v[vIdx-1].index:
|
||||
edges[((f.uv[vIdx-1][0], f.uv[vIdx-1][1]), (f.uv[vIdx][0], f.uv[vIdx][1]))] =\
|
||||
(Vector([f.uv[vIdx-1][0], f.uv[vIdx-1][1]]) - Vector([f.uv[vIdx][0], f.uv[vIdx][1]])).length
|
||||
else:
|
||||
else: # 3
|
||||
edges[((f.uv[vIdx][0], f.uv[vIdx][1]), (f.uv[vIdx-1][0], f.uv[vIdx-1][1]) )] =\
|
||||
(Vector([f.uv[vIdx-1][0], f.uv[vIdx-1][1]]) - Vector([f.uv[vIdx][0], f.uv[vIdx][1]])).length
|
||||
|
||||
@ -279,7 +270,7 @@ def pointInIsland(pt, island):
|
||||
if pointInTri2D(pt, vec1, vec2, vec3):
|
||||
return True
|
||||
|
||||
if len(f.v) == 4:
|
||||
if len(f) == 4:
|
||||
vec1.x, vec1.y = f.uv[0]
|
||||
vec2.x, vec2.y = f.uv[2]
|
||||
vec3.x, vec3.y = f.uv[3]
|
||||
@ -436,15 +427,13 @@ def optiRotateUvIsland(faces):
|
||||
# Rotate 90d
|
||||
# Work directly on the list, no need to return a value.
|
||||
testNewVecLs2DRotIsBetter(uvVecs, ROTMAT_2D_POS_90D)
|
||||
|
||||
|
||||
|
||||
|
||||
# Now write the vectors back to the face UV's
|
||||
i = 0 # count the serialized uv/vectors
|
||||
for f in faces:
|
||||
f.uv = [uv for uv in uvVecs[i:len(f.v)+i] ]
|
||||
i += len(f.v)
|
||||
f.uv = [uv for uv in uvVecs[i:len(f)+i] ]
|
||||
i += len(f)
|
||||
|
||||
|
||||
# Takes an island list and tries to find concave, hollow areas to pack smaller islands into.
|
||||
@ -974,15 +963,15 @@ def main():
|
||||
faceListProps = []
|
||||
|
||||
for f in meshFaces:
|
||||
area = faceArea(f)
|
||||
area = f.area
|
||||
if area <= SMALL_NUM:
|
||||
f.uv = [Vector(0.0, 0.0)] * len(f.v) # Assign dummy UV
|
||||
for uv in f.uv: # Assign Dummy UVs
|
||||
uv.x= uv.y= 0.0
|
||||
print 'found zero area face, removing.'
|
||||
|
||||
else:
|
||||
# Store all here
|
||||
n = f.no
|
||||
faceListProps.append( [f, area, Vector(n)] )
|
||||
faceListProps.append( [f, area, Vector(f.no)] )
|
||||
|
||||
del meshFaces
|
||||
|
||||
|
@ -358,7 +358,7 @@ def meshCalcNormals(me, vertNormals=None):
|
||||
|
||||
edges={}
|
||||
for f in me.faces:
|
||||
for i in xrange(len(f.v)):
|
||||
for i in xrange(len(f)):
|
||||
i1, i2= f.v[i].index, f.v[i-1].index
|
||||
if i1<i2:
|
||||
i1,i2= i2,i1
|
||||
@ -427,7 +427,7 @@ def pointInsideMesh(ob, pt):
|
||||
ymax= max(ymax, co.y)
|
||||
ymin= min(ymin, co.y)
|
||||
|
||||
if len(f.v)==4:
|
||||
if len(f)==4:
|
||||
co= f.v[3].co
|
||||
xmax= max(xmax, co.x)
|
||||
xmin= min(xmin, co.x)
|
||||
@ -447,7 +447,7 @@ def pointInsideMesh(ob, pt):
|
||||
|
||||
def faceIntersect(f):
|
||||
isect = Intersect(f.v[0].co, f.v[1].co, f.v[2].co, ray, obSpacePt, 1) # Clipped.
|
||||
if not isect and len(f.v) == 4:
|
||||
if not isect and len(f) == 4:
|
||||
isect = Intersect(f.v[0].co, f.v[2].co, f.v[3].co, ray, obSpacePt, 1) # Clipped.
|
||||
|
||||
if isect and isect.z > obSpacePt.z: # This is so the ray only counts if its above the point.
|
||||
|
@ -42,8 +42,9 @@ def rem_free_edges(me, limit=None):
|
||||
edgeDict= {} # will use a set when python 2.4 is standard.
|
||||
|
||||
for f in me.faces:
|
||||
for i in xrange(len(f.v)):
|
||||
edgeDict[sortPair(f.v[i].index, f.v[i-1].index)]= None
|
||||
v= f.v
|
||||
for i in xrange(len(v)):
|
||||
edgeDict[sortPair(v[i].index, v[i-1].index)]= None
|
||||
|
||||
edges_free= []
|
||||
for e in me.edges:
|
||||
@ -58,14 +59,7 @@ def rem_free_edges(me, limit=None):
|
||||
|
||||
def rem_area_faces(me, limit=0.001):
|
||||
''' Faces that have an area below the limit '''
|
||||
def faceArea(f):
|
||||
if len(f.v) == 3:
|
||||
return TriangleArea(f.v[0].co, f.v[1].co, f.v[2].co)
|
||||
elif len(f.v) == 4:
|
||||
return\
|
||||
TriangleArea(f.v[0].co, f.v[1].co, f.v[2].co) +\
|
||||
TriangleArea(f.v[0].co, f.v[2].co, f.v[3].co)
|
||||
rem_faces= [f for f in me.faces if faceArea(f) <= limit]
|
||||
rem_faces= [f for f in me.faces if f.area <= limit]
|
||||
if rem_faces:
|
||||
me.faces.delete( 0, rem_faces )
|
||||
return len(rem_faces)
|
||||
@ -73,17 +67,18 @@ def rem_area_faces(me, limit=0.001):
|
||||
def rem_perimeter_faces(me, limit=0.001):
|
||||
''' Faces whos combine edge length is below the limit '''
|
||||
def faceEdLen(f):
|
||||
if len(f.v) == 3:
|
||||
v= f.v
|
||||
if len(v) == 3:
|
||||
return\
|
||||
(f.v[0].co-f.v[1].co).length +\
|
||||
(f.v[1].co-f.v[2].co).length +\
|
||||
(f.v[2].co-f.v[0].co).length
|
||||
elif len(f.v) == 4:
|
||||
(v[0].co-v[1].co).length +\
|
||||
(v[1].co-v[2].co).length +\
|
||||
(v[2].co-v[0].co).length
|
||||
else: # 4
|
||||
return\
|
||||
(f.v[0].co-f.v[1].co).length +\
|
||||
(f.v[1].co-f.v[2].co).length +\
|
||||
(f.v[2].co-f.v[3].co).length +\
|
||||
(f.v[3].co-f.v[0].co).length
|
||||
(v[0].co-v[1].co).length +\
|
||||
(v[1].co-v[2].co).length +\
|
||||
(v[2].co-v[3].co).length +\
|
||||
(v[3].co-v[0].co).length
|
||||
rem_faces= [f for f in me.faces if faceEdLen(f) <= limit]
|
||||
if rem_faces:
|
||||
me.faces.delete( 0, rem_faces )
|
||||
|
@ -253,8 +253,8 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
|
||||
Mesh.Mode(Mesh.SelectModes['FACE'])
|
||||
quadcount = 0
|
||||
for f in m.faces:
|
||||
if len(f.v) == 4:
|
||||
f.sel = 1
|
||||
if len(f) == 4:
|
||||
f.sel = True
|
||||
quadcount +=1
|
||||
|
||||
if quadcount:
|
||||
@ -350,7 +350,7 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
|
||||
|
||||
uvIdx = 0
|
||||
for f in faces:
|
||||
|
||||
f_v= f.v
|
||||
# MAKE KEY
|
||||
if EXPORT_UV and m.faceUV and f.image: # Object is always true.
|
||||
key = materialNames[min(f.mat,len(materialNames)-1)], f.image.name
|
||||
@ -405,21 +405,21 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
|
||||
if m.faceUV and EXPORT_UV:
|
||||
if EXPORT_NORMALS:
|
||||
if f.smooth: # Smoothed, use vertex normals
|
||||
for vi, v in enumerate(f.v):
|
||||
for vi, v in enumerate(f_v):
|
||||
file.write( ' %d/%d/%d' % (\
|
||||
v.index+totverts,\
|
||||
globalUVCoords[ tuple(f.uv[vi]) ],\
|
||||
globalNormals[ tuple(v.no) ])) # vert, uv, normal
|
||||
else: # No smoothing, face normals
|
||||
no = globalNormals[ tuple(f.no) ]
|
||||
for vi, v in enumerate(f.v):
|
||||
for vi, v in enumerate(f_v):
|
||||
file.write( ' %d/%d/%d' % (\
|
||||
v.index+totverts,\
|
||||
globalUVCoords[ tuple(f.uv[vi]) ],\
|
||||
no)) # vert, uv, normal
|
||||
|
||||
else: # No Normals
|
||||
for vi, v in enumerate(f.v):
|
||||
for vi, v in enumerate(f_v):
|
||||
file.write( ' %d/%d' % (\
|
||||
v.index+totverts,\
|
||||
globalUVCoords[ tuple(f.uv[vi])])) # vert, uv
|
||||
@ -428,18 +428,18 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
|
||||
else: # No UV's
|
||||
if EXPORT_NORMALS:
|
||||
if f.smooth: # Smoothed, use vertex normals
|
||||
for v in f.v:
|
||||
for v in f_v:
|
||||
file.write( ' %d//%d' % (\
|
||||
v.index+totverts,\
|
||||
globalNormals[ tuple(v.no) ]))
|
||||
else: # No smoothing, face normals
|
||||
no = globalNormals[ tuple(f.no) ]
|
||||
for v in f.v:
|
||||
for v in f_v:
|
||||
file.write( ' %d//%d' % (\
|
||||
v.index+totverts,\
|
||||
no))
|
||||
else: # No Normals
|
||||
for v in f.v:
|
||||
for v in f_v:
|
||||
file.write( ' %d' % (\
|
||||
v.index+totverts))
|
||||
|
||||
@ -449,8 +449,8 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
|
||||
if EXPORT_EDGES:
|
||||
edgeUsers = {}
|
||||
for f in faces:
|
||||
for i in xrange(len(f.v)):
|
||||
faceEdgeVKey = sortPair(f.v[i].index, f.v[i-1].index)
|
||||
for i in xrange(len(f_v)):
|
||||
faceEdgeVKey = sortPair(f_v[i].index, f_v[i-1].index)
|
||||
|
||||
# We dont realy need to keep count. Just that a face uses it
|
||||
# so dont export.
|
||||
|
Loading…
Reference in New Issue
Block a user