mesh_edges2curves - edge key optimize and made use of scn.objects rather then Object.New()..

Object.py - passIndex mistake
This commit is contained in:
2006-12-12 21:38:04 +00:00
parent 80ee52e444
commit 824f391c75
2 changed files with 29 additions and 33 deletions

View File

@@ -42,8 +42,13 @@ Supported:<br>
from Blender import * from Blender import *
def sortPair(a,b): def edkey(ed):
return min(a,b), max(a,b) i1 = ed.v1.index
i2 = ed.v2.index
if i1>i2:
return (i2,i1), ed
else:
return (i1,i2), ed
def polysFromMesh(me): def polysFromMesh(me):
# a polyline is 2 # a polyline is 2
@@ -51,10 +56,17 @@ def polysFromMesh(me):
polyLines = [] polyLines = []
# Get edges not used by a face # Get edges not used by a face
edgeDict= dict([ (sortPair(ed.v1.index, ed.v2.index), ed) for ed in me.edges ]) edgeDict= dict([ edkey(ed) for ed in me.edges ])
for f in me.faces: for f in me.faces:
for i in xrange(len(f.v)): fvi = [v.index for v in f]
key= sortPair(f.v[i].index, f.v[i-1].index) for i in xrange(len(fvi)):
i1 = fvi[i]
i2 = fvi[i-1]
if i1>i2:
key = i2,i1
else:
key = i1,i2
try: try:
del edgeDict[key] del edgeDict[key]
except: except:
@@ -62,21 +74,6 @@ def polysFromMesh(me):
edges= edgeDict.values() edges= edgeDict.values()
'''
# build vert connectivite
vertConnex= [list() for i in xrange(len(me.verts))]
for ed in edges:
i1= ed.v1.index
i2= ed.v2.index
vertConnex[i1].append(i2)
vertConnex[i2].append(i1)
# verts without 2 users are none.
vertConnex=[ [None,vc][len(vc)==2] for vc in vertConnex
'''
while edges: while edges:
currentEdge= edges.pop() currentEdge= edges.pop()
startVert= currentEdge.v2 startVert= currentEdge.v2
@@ -94,25 +91,25 @@ def polysFromMesh(me):
polyLine.append(ed.v2) polyLine.append(ed.v2)
endVert= polyLine[-1] endVert= polyLine[-1]
ok=1 ok=1
edges.pop(i) del edges[i]
#break #break
elif ed.v2 == endVert: elif ed.v2 == endVert:
polyLine.append(ed.v1) polyLine.append(ed.v1)
endVert= polyLine[-1] endVert= polyLine[-1]
ok=1 ok=1
edges.pop(i) del edges[i]
#break #break
elif ed.v1 == startVert: elif ed.v1 == startVert:
polyLine.insert(0, ed.v2) polyLine.insert(0, ed.v2)
startVert= polyLine[0] startVert= polyLine[0]
ok=1 ok=1
edges.pop(i) del edges[i]
#break #break
elif ed.v2 == startVert: elif ed.v2 == startVert:
polyLine.insert(0, ed.v1) polyLine.insert(0, ed.v1)
startVert= polyLine[0] startVert= polyLine[0]
ok=1 ok=1
edges.pop(i) del edges[i]
#break #break
polyLines.append((polyLine, polyLine[0]==polyLine[-1])) polyLines.append((polyLine, polyLine[0]==polyLine[-1]))
print len(edges), len(polyLines) print len(edges), len(polyLines)
@@ -121,10 +118,10 @@ def polysFromMesh(me):
def mesh2polys(): def mesh2polys():
scn= Scene.GetCurrent() scn= Scene.GetCurrent()
for ob in scn.getChildren(): for ob in scn.objects:
ob.sel= 0 ob.sel= 0
meshOb= scn.getActiveObject() meshOb= scn.objects.active
if meshOb==None or meshOb.getType() != 'Mesh': if meshOb==None or meshOb.type != 'Mesh':
Draw.PupMenu( 'ERROR: No Active Mesh Selected, Aborting' ) Draw.PupMenu( 'ERROR: No Active Mesh Selected, Aborting' )
return return
Window.WaitCursor(1) Window.WaitCursor(1)
@@ -133,13 +130,12 @@ def mesh2polys():
polygons= polysFromMesh(me) polygons= polysFromMesh(me)
w=t=1 w=t=1
cu= Curve.New() cu= Curve.New()
cu.name = me.name
cu.setFlag(1) cu.setFlag(1)
ob= Object.New('Curve', me.name)
ob.link(cu) ob = scn.objects.new(cu)
scn.link(ob)
ob.Layers= meshOb.Layers
ob.setMatrix(meshOb.matrixWorld) ob.setMatrix(meshOb.matrixWorld)
ob.sel= 1
i=0 i=0
for poly, closed in polygons: for poly, closed in polygons:
if closed: if closed:

View File

@@ -438,7 +438,7 @@ class Object:
@type DupOff: int @type DupOff: int
@ivar passIndex: Index # for the IndexOB render pass. @ivar passIndex: Index # for the IndexOB render pass.
Value is clamped to [0,1000]. Value is clamped to [0,1000].
@type DupOff: int @type passIndex: int
@ivar drawSize: The size to display the Empty. @ivar drawSize: The size to display the Empty.
Value clamped to [0.01,10.0]. Value clamped to [0.01,10.0].
@type drawSize: float @type drawSize: float