diff options
Diffstat (limited to 'release/scripts/wizard_curve2tree.py')
-rw-r--r-- | release/scripts/wizard_curve2tree.py | 77 |
1 files changed, 59 insertions, 18 deletions
diff --git a/release/scripts/wizard_curve2tree.py b/release/scripts/wizard_curve2tree.py index 5b454578db1..1965f9a5070 100644 --- a/release/scripts/wizard_curve2tree.py +++ b/release/scripts/wizard_curve2tree.py @@ -46,12 +46,27 @@ from Blender.Noise import randuvec GLOBALS = {} GLOBALS['non_bez_error'] = 0 +''' +def debugVec(v1,v2): + sce = bpy.data.scenes.active + me = bpy.data.meshes.new() + me.verts.extend( [v1,v2] ) + me.edges.extend( [(0,1)] ) + sce.objects.new(me) +''' + def AngleBetweenVecsSafe(a1, a2): try: return AngleBetweenVecs(a1,a2) except: return 180.0 +# Python 2.3 has no reversed. +try: + reversed +except: + def reversed(l): return l[::-1] + # Copied from blender, we could wrap this! - BKE_curve.c # But probably not toooo bad in python def forward_diff_bezier(q0, q1, q2, q3, pointlist, steps, axis): @@ -257,7 +272,9 @@ class tree: brch.calcData() # Sort from big to small, so big branches get priority - self.branches_all.sort( key = lambda brch: -brch.bpoints[0].radius ) + # Py 2.3 dosnt have keywords in sort + try: self.branches_all.sort( key = lambda brch: -brch.bpoints[0].radius ) + except: self.branches_all.sort( lambda brch_a, brch_b: cmp(brch_b.bpoints[0].radius, brch_a.bpoints[0].radius) ) # py2.3 def closestBranchPt(self, co): @@ -360,7 +377,12 @@ class tree: pt_best_j, dist = brch_j.findClosest(brch_i.bpoints[0].co) # Check its in range, allow for a bit out - hense the sloppy - if dist < pt_best_j.radius * sloppy: + # The second check in the following IF was added incase the point is close enough to the line but the midpoint is further away + # ...in this case the the resulting mesh will be adjusted to fit the join so its best to make it. + if (dist < pt_best_j.radius * sloppy) or \ + ((brch_i.bpoints[0].co - pt_best_j.co).length < pt_best_j.radius * sloppy): + + brch_i.parent_pt = pt_best_j pt_best_j.childCount += 1 # dont remove me @@ -1130,7 +1152,8 @@ class tree: # Try sorting by other properties! this is ok for now for segments_level_current in segments_level: - segments_level_current.sort( key = lambda seg: -(seg.headCo-seg.tailCo).length ) + try: segments_level_current.sort( key = lambda seg: -(seg.headCo-seg.tailCo).length ) + except: segments_level_current.sort( lambda a,b: cmp((b.headCo-b.tailCo).length, (a.headCo-a.tailCo).length) ) # py2.3 for level in xrange(twig_fill_levels): if len(segments_level) > level: @@ -1356,18 +1379,23 @@ class tree: # Get the branches based on our selection method! if twig_select_mode==0: - branches_sorted.sort( key = lambda brch: brch.getLength()) + try: branches_sorted.sort( key = lambda brch: brch.getLength()) + except: branches_sorted.sort( lambda a,b: cmp(a.getLength(),a.getLength()) ) # py2.3 elif twig_select_mode==1: - branches_sorted.sort( key = lambda brch:-brch.getLength()) + try: branches_sorted.sort( key = lambda brch:-brch.getLength()) + except: branches_sorted.sort( lambda a,b: cmp(b.getLength(), a.getLength()) ) # py2.3 elif twig_select_mode==2: - branches_sorted.sort( key = lambda brch:brch.getStraightness()) + try: branches_sorted.sort( key = lambda brch:brch.getStraightness()) + except: branches_sorted.sort( lambda a,b: cmp(a.getStraightness(), b.getStraightness())) # py2.3 elif twig_select_mode==3: - branches_sorted.sort( key = lambda brch:-brch.getStraightness()) + try: branches_sorted.sort( key = lambda brch:-brch.getStraightness()) + except: branches_sorted.sort( lambda a,b: cmp(b.getStraightness(), a.getStraightness())) # py2.3 factor_int = int(len(self.branches_all) * twig_select_factor) branches_sorted[factor_int:] = [] # remove the last part of the list - branches_sorted.sort( key = lambda brch: len(brch.bpoints)) + try: branches_sorted.sort( key = lambda brch: len(brch.bpoints)) + except: branches_sorted.sort( lambda a,b: cmp(len(a.bpoints), len(b.bpoints)) ) # py2.3 branches_new = [] #for i in xrange(ratio_int): @@ -1487,7 +1515,7 @@ class tree: else: # our roll was set from the branches parent and needs no changing # set it to zero so the following functions know to interpolate. - brch.bpoints[0].roll_angle = 45.0 + brch.bpoints[0].roll_angle = 0.0 #brch.bpoints[1].roll_angle = 0.0 ''' @@ -1921,7 +1949,7 @@ class tree: mat_pitch = RotationMatrix( angle, 3, 'r', cross1) mat = mat * mat_pitch if leaf_branch_roll_rand: - mat_roll = RotationMatrix( leaf_branch_roll_rand * ((next_random_num(rnd_seed)-0.5)*360), 3, 'r', leaf_no * mat_pitch) + mat_roll = RotationMatrix( leaf_branch_roll_rand * ((next_random_num(rnd_seed)-0.5)*360), 3, 'r', leaf_no) mat = mat * mat_roll mat = mat.resize4x4() * TranslationMatrix(leaf_co) @@ -2407,6 +2435,7 @@ class bpoint(object): Roll the quad about its normal use for aurienting the sides of a quad to meet a branch that stems from here... ''' + # debugVec(self.co, self.co + self.no) mat = RotationMatrix(angle, 3, 'r', self.no) for i in xrange(4): @@ -2451,7 +2480,7 @@ class bpoint(object): def calcVerts(self): if self.prev == None: if self.branch.parent_pt: - cross = CrossVecs(self.no, self.branch.getParentFaceCent() - self.branch.parent_pt.getAbsVec( self.branch.getParentQuadIndex() )) + cross = CrossVecs(self.no, self.branch.parent_pt.no) * RotationMatrix(-45, 3, 'r', self.no) else: # parentless branch - for best results get a cross thats not the same as the normal, in rare cases this happens. @@ -2666,6 +2695,7 @@ class branch: co_on_line, fac = ClosestPointOnLine(co, pt.co, pt.next.co) print fac if fac >= 0.0 and fac <= 1.0: + return pt, (co-co_on_line).length return best, best_dist @@ -3041,7 +3071,7 @@ EVENT_REDRAW = 3 # Prefs for each tree PREFS = {} -PREFS['connect_sloppy'] = Draw.Create(1.0) +PREFS['connect_sloppy'] = Draw.Create(1.5) PREFS['connect_base_trim'] = Draw.Create(1.0) PREFS['seg_density'] = Draw.Create(0.5) PREFS['seg_density_angle'] = Draw.Create(20.0) @@ -3389,7 +3419,7 @@ def buildTree(ob_curve, single=False): if leaf_object: ob_leaf_dupliface.enableDupFaces = True ob_leaf_dupliface.enableDupFacesScale = True - ob_leaf_dupliface.makeParent([leaf_object]) + ob_leaf_dupliface.makeParent([leaf_object], 1) else: ob_leaf_dupliface.enableDupFaces = False @@ -3537,7 +3567,7 @@ def do_pref_clear(e,v): return for ob in objects: - try: del idprop[ID_SLOT_NAME] + try: del ob.properties[ID_SLOT_NAME] except: pass def do_tex_check(e,v): @@ -3620,8 +3650,18 @@ def do_tree_generate(e,v): Blender.Draw.PupMenu('Error%t|Nurbs and Poly curve types cant be used!') GLOBALS['non_bez_error'] = 0 +def do_tree_help(e,v): + url = 'http://wiki.blender.org/index.php/Scripts/Manual/Wizards/TreeFromCurves' + print 'Trying to open web browser with documentation at this address...' + print '\t' + url - + try: + import webbrowser + webbrowser.open(url) + except: + print '...could not open a browser window.' + + def evt(e,val): pass @@ -3957,7 +3997,7 @@ def gui(): xtmp = x # ---------- ---------- ---------- ---------- - PREFS['connect_sloppy'] = Draw.Number('Connect Limit',EVENT_UPDATE, xtmp, y, but_width*2, but_height, PREFS['connect_sloppy'].val, 0.1, 2.0, 'Strictness when connecting branches'); xtmp += but_width*2; + PREFS['connect_sloppy'] = Draw.Number('Connect Limit',EVENT_UPDATE, xtmp, y, but_width*2, but_height, PREFS['connect_sloppy'].val, 0.1, 3.0, 'Strictness when connecting branches'); xtmp += but_width*2; PREFS['connect_base_trim'] = Draw.Number('Joint Bevel', EVENT_UPDATE, xtmp, y, but_width*2, but_height, PREFS['connect_base_trim'].val, 0.0, 2.0, 'low value for a tight join, hi for a smoother bevel'); xtmp += but_width*2; Blender.Draw.EndAlign() y-=but_height+MARGIN @@ -3989,8 +4029,9 @@ def gui(): # ---------- ---------- ---------- ---------- Blender.Draw.BeginAlign() - Draw.PushButton('Exit', EVENT_EXIT, xtmp, y, but_width, but_height, '', do_active_image); xtmp += but_width; - Draw.PushButton('Generate from selection', EVENT_REDRAW, xtmp, y, but_width*3, but_height, 'Generate mesh', do_tree_generate); xtmp += but_width*3; + Draw.PushButton('Exit', EVENT_EXIT, xtmp, y, but_width, but_height, ''); xtmp += but_width; + Draw.PushButton('Help', EVENT_NONE, xtmp, y, but_width, but_height, '', do_tree_help); xtmp += but_width; + Draw.PushButton('Generate from selection', EVENT_REDRAW, xtmp, y, but_width*2, but_height, 'Generate mesh', do_tree_generate); xtmp += but_width*3; Blender.Draw.EndAlign() y-=but_height+MARGIN xtmp = x |