From b7b99be387a8beb707d3b944697bd69455a1f697 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 7 Jun 2006 02:10:10 +0000 Subject: use f.area where possible over python function and use len(mface) over len(mface.v) --- release/scripts/archimap.py | 29 +++++++++-------------------- release/scripts/bpymodules/BPyMesh.py | 6 +++--- release/scripts/mesh_cleanup.py | 33 ++++++++++++++------------------- release/scripts/obj_export.py | 22 +++++++++++----------- 4 files changed, 37 insertions(+), 53 deletions(-) (limited to 'release') diff --git a/release/scripts/archimap.py b/release/scripts/archimap.py index b1881cf0938..36974d7df50 100644 --- a/release/scripts/archimap.py +++ b/release/scripts/archimap.py @@ -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 diff --git a/release/scripts/bpymodules/BPyMesh.py b/release/scripts/bpymodules/BPyMesh.py index 79bfd19452f..258cdcc0203 100644 --- a/release/scripts/bpymodules/BPyMesh.py +++ b/release/scripts/bpymodules/BPyMesh.py @@ -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 obSpacePt.z: # This is so the ray only counts if its above the point. diff --git a/release/scripts/mesh_cleanup.py b/release/scripts/mesh_cleanup.py index 2ee3642efe8..3d4caa50b1d 100644 --- a/release/scripts/mesh_cleanup.py +++ b/release/scripts/mesh_cleanup.py @@ -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 ) diff --git a/release/scripts/obj_export.py b/release/scripts/obj_export.py index 47e4f2bcde7..8a1c42e4e5b 100644 --- a/release/scripts/obj_export.py +++ b/release/scripts/obj_export.py @@ -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. -- cgit v1.2.3