Use ed.key and face.edge_keys to build connectivity data faster.
This commit is contained in:
parent
3a84791b53
commit
08e3f8b1da
@ -446,14 +446,6 @@ def pickMeshGroupVCol(me, orig, dir):
|
||||
f_colvecs= [col2vec(f_c[i]) for i in idxs]
|
||||
return f_colvecs[0]*w0 + f_colvecs[1]*w1 + f_colvecs[2]*w2
|
||||
|
||||
# reuse me more.
|
||||
def sorted_edge_indicies(ed):
|
||||
i1= ed.v1.index
|
||||
i2= ed.v2.index
|
||||
if i1>i2:
|
||||
i1,i2= i2,i1
|
||||
return i1, i2
|
||||
|
||||
def edge_face_users(me):
|
||||
'''
|
||||
Takes a mesh and returns a list aligned with the meshes edges.
|
||||
@ -461,17 +453,11 @@ def edge_face_users(me):
|
||||
would be the equiv for having ed.face_users as a property
|
||||
'''
|
||||
|
||||
face_edges_dict= dict([(sorted_edge_indicies(ed), (ed.index, [])) for ed in me.edges])
|
||||
face_edges_dict= dict([(ed.key, (ed.index, [])) for ed in me.edges])
|
||||
for f in me.faces:
|
||||
fvi= [v.index for v in f]# face vert idx's
|
||||
for i in xrange(len(f)):
|
||||
i1= fvi[i]
|
||||
i2= fvi[i-1]
|
||||
|
||||
if i1>i2:
|
||||
i1,i2= i2,i1
|
||||
|
||||
face_edges_dict[i1,i2][1].append(f)
|
||||
for edkey in f.edge_keys:
|
||||
face_edges_dict[edkey][1].append(f)
|
||||
|
||||
face_edges= [None] * len(me.edges)
|
||||
for ed_index, ed_faces in face_edges_dict.itervalues():
|
||||
@ -489,21 +475,13 @@ def face_edges(me):
|
||||
face_edges[i][j] -> list of faces that this edge uses.
|
||||
crap this is tricky to explain :/
|
||||
'''
|
||||
face_edges= [ [None] * len(f) for f in me.faces ]
|
||||
face_edges= [ [-1] * len(f) for f in me.faces ]
|
||||
|
||||
face_edges_dict= dict([(sorted_edge_indicies(ed), []) for ed in me.edges])
|
||||
face_edges_dict= dict([(ed.key, []) for ed in me.edges])
|
||||
for fidx, f in enumerate(me.faces):
|
||||
fvi= [v.index for v in f]# face vert idx's
|
||||
for i in xrange(len(f)):
|
||||
i1= fvi[i]
|
||||
i2= fvi[i-1]
|
||||
|
||||
if i1>i2:
|
||||
i1,i2= i2,i1
|
||||
|
||||
edge_face_users= face_edges_dict[i1,i2]
|
||||
for i, edkey in enumerate(f.edge_keys):
|
||||
edge_face_users= face_edges_dict[edkey]
|
||||
edge_face_users.append(f)
|
||||
|
||||
face_edges[fidx][i]= edge_face_users
|
||||
|
||||
return face_edges
|
||||
@ -671,19 +649,12 @@ def edgeFaceUserCount(me, faces= None):
|
||||
|
||||
edge_users= [0] * len(me.edges)
|
||||
|
||||
edges_idx_dict= dict([(sorted_edge_indicies(ed), ed.index) for ed in me.edges])
|
||||
edges_idx_dict= dict([(ed.key, ed.index) for ed in me.edges])
|
||||
|
||||
for f in faces:
|
||||
fvi= [v.index for v in f]# face vert idx's
|
||||
for i in xrange(len(f)):
|
||||
i1= fvi[i]
|
||||
i2= fvi[i-1]
|
||||
|
||||
if i1>i2:
|
||||
i1,i2= i2,i1
|
||||
|
||||
edge_users[edges_idx_dict[i1,i2]] += 1
|
||||
|
||||
for edkey in f.edge_keys:
|
||||
edge_users[edges_idx_dict[edkey]] += 1
|
||||
|
||||
return edge_users
|
||||
|
||||
|
||||
@ -1004,16 +975,10 @@ def meshCalcNormals(me, vertNormals=None):
|
||||
edges={}
|
||||
for f in me.faces:
|
||||
f_v = 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
|
||||
|
||||
try:
|
||||
edges[i1, i2].append(f.no)
|
||||
except:
|
||||
edges[i1, i2]= [f.no]
|
||||
|
||||
for edkey in f.edge_keys:
|
||||
try: edges[edkey].append(f.no)
|
||||
except: edges[edkey]= [f.no]
|
||||
|
||||
# Weight the edge normals by total angle difference
|
||||
for fnos in edges.itervalues():
|
||||
|
||||
|
@ -52,11 +52,6 @@ def col_key_mix(col1, col2, w1, w2):
|
||||
# Weighted mix. w1+w2==1.0
|
||||
return int(w1*col1[0] + w2*col2[0]), int(w1*col1[1] + w2*col2[1]), int(w1*col1[2]+col2[2]*w2)
|
||||
|
||||
def ed_key(ed):
|
||||
i1= ed.v1.index
|
||||
i2= ed.v2.index
|
||||
if i1<i2: return i1,i2
|
||||
return i2,i1
|
||||
|
||||
def redux(ob, REDUX=0.5, BOUNDRY_WEIGHT=2.0, REMOVE_DOUBLES=False, FACE_AREA_WEIGHT=1.0, FACE_TRIANGULATE=True, DO_UV=True, DO_VCOL=True, DO_WEIGHTS=True, VGROUP_INF_REDUX= None, VGROUP_INF_WEIGHT=0.5):
|
||||
"""
|
||||
@ -153,7 +148,7 @@ def redux(ob, REDUX=0.5, BOUNDRY_WEIGHT=2.0, REMOVE_DOUBLES=False, FACE_AREA_WEI
|
||||
self.init_from_edge(ed) # So we can re-use the classes without using more memory.
|
||||
|
||||
def init_from_edge(self, ed):
|
||||
self.key= ed_key(ed)
|
||||
self.key= ed.key
|
||||
self.length= ed.length
|
||||
self.faces= []
|
||||
self.v1= ed.v1
|
||||
|
@ -156,16 +156,11 @@ def main():
|
||||
edges = {}
|
||||
for f in faces_sel:
|
||||
f_v= f.v
|
||||
for i in xrange(len(f_v)):
|
||||
i1=f_v[i].index
|
||||
i2=f_v[i-1].index
|
||||
if i1>i2: edge_key= i2, i1
|
||||
else: edge_key= i1, i2
|
||||
|
||||
if edges.has_key(edge_key):
|
||||
edges[edge_key]= None
|
||||
for i, edgekey in enumerate(f.edge_keys):
|
||||
if edges.has_key(edgekey):
|
||||
edges[edgekey]= None
|
||||
else:
|
||||
edges[edge_key] = f, f_v, i, i-1
|
||||
edges[edgekey] = f, f_v, i, i-1
|
||||
|
||||
# Edges are done. extrude the single user edges.
|
||||
for edge_face_data in edges.itervalues():
|
||||
|
@ -171,21 +171,10 @@ def island2Edge(island):
|
||||
f_uvkey= map(tuple, f_uv)
|
||||
|
||||
|
||||
for vIdx in xrange(len(f_v)):
|
||||
|
||||
for vIdx, edkey in enumerate(f.edge_keys):
|
||||
unique_points[f_uvkey[vIdx]] = f_uv[vIdx]
|
||||
|
||||
|
||||
if f_v[vIdx].index > f_v[vIdx-1].index:
|
||||
i1= vIdx-1; i2= vIdx
|
||||
else:
|
||||
i1= vIdx; i2= vIdx-1
|
||||
|
||||
try:
|
||||
edges[ f_uvkey[i1], f_uvkey[i2] ] *= 0 # sets eny edge with more then 1 user to 0 are not returned.
|
||||
|
||||
except:
|
||||
edges[ f_uvkey[i1], f_uvkey[i2] ] = (f_uv[i1] - f_uv[i2]).length,
|
||||
try: edges[ f_uvkey[edkey[0]], f_uvkey[edkey[1]] ] *= 0 # sets eny edge with more then 1 user to 0 are not returned.
|
||||
except: edges[ f_uvkey[edkey[0]], f_uvkey[edkey[1]] ] = (f_uv[i1] - f_uv[i2]).length,
|
||||
|
||||
# If 2 are the same then they will be together, but full [a,b] order is not correct.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user