@@ -1024,8 +1024,8 @@ def create_tree(position, is_twig=False):
10241024 save_trunk_space = mtree_props .trunk_space
10251025 if mtree_props .use_grease_pencil and gp is not None and gp .layers .active is not None and gp .layers .active .active_frame is not None and len (gp .layers .active .active_frame .strokes ) > 0 and len (gp .layers .active .active_frame .strokes [0 ].points ) > 2 :
10261026 grease_points = rehash_set ([i .co for i in gp .layers .active .active_frame .strokes [0 ].points ], mtree_props .stroke_step_size )
1027- grease_points = smooth_stroke (5 ,mtree_props .smooth_stroke ,grease_points )
1028- mtree_props .trunk_length = len (grease_points ) - 2
1027+ grease_points = smooth_stroke (5 , mtree_props .smooth_stroke , grease_points )
1028+ mtree_props .trunk_length = len (grease_points ) - 2
10291029 using_grease = True
10301030
10311031 # branches generation
@@ -1044,15 +1044,15 @@ def create_tree(position, is_twig=False):
10441044 new_rotation = (curr_rotation + mtree_props .branch_rotate + 2 * (1 - random ()) * mtree_props .branch_random_rotate ) % 360
10451045
10461046 if i > mtree_props .preserve_end :
1047- trunk2 = False
1048- pos = Vector ((0 ,0 , 0 ))
1047+ trunk2 = False # shadows name "trunk2" from outer scope
1048+ pos = Vector ((0 , 0 , 0 ))
10491049
10501050 for k in indexes :
10511051 pos += verts [k ]
10521052 pos /= len (indexes )
10531053 direction .normalize ()
10541054
1055- if is_twig and i > 2 :
1055+ if is_twig and i > 2 :
10561056 twig_leafs .append ((pos , direction ))
10571057
10581058 end = pos + direction * 10
@@ -1104,23 +1104,28 @@ def create_tree(position, is_twig=False):
11041104 sortie = pos + direction * mtree_props .branch_length
11051105
11061106 else :
1107- grease_dir = grease_points [curr_grease_point + 1 ] - grease_points [curr_grease_point ]
1107+ gp1 = grease_points [curr_grease_point + 1 ]
1108+ gp2 = grease_points [curr_grease_point ]
1109+ grease_dir = gp1 - gp2
11081110 grease_length = grease_dir .length
11091111 grease_dir .normalize ()
11101112 ni , direction , nsi = join_branch (verts , faces , indexes , radius ,grease_length ,
11111113 branch_verts ,
11121114 grease_dir ,
11131115 0 , s_index , seams2 )
11141116 sortie = pos + grease_dir * grease_length
1115- curr_grease_point += 1
1117+ curr_grease_point += 1
11161118
11171119 if i <= mtree_props .bones_iterations :
11181120 bones .append ((Lb [0 ], len (bones ) + 2 , Lb [1 ], sortie ))
11191121
11201122 nb = (len (bones ) + 1 , sortie )
11211123 nextremites .append ((ni , radius * 0.98 , direction , nsi , nb , trunk2 , curr_rotation ))
11221124
1123- elif i == mtree_props .iteration + mtree_props .trunk_length - 1 or random () < mtree_props .break_chance or real_radius < mtree_props .branch_min_radius :
1125+ elif i == mtree_props .iteration + mtree_props .trunk_length - 1 \
1126+ or random () < mtree_props .break_chance \
1127+ or real_radius < mtree_props .branch_min_radius :
1128+
11241129 end_verts = [Vector (v ) for v in end_cap .verts ]
11251130 end_faces = [f for f in end_cap .faces ]
11261131
@@ -1134,7 +1139,10 @@ def create_tree(position, is_twig=False):
11341139 if real_radius < mtree_props .radius / 4 :
11351140 leafs_weight_indexes .append (len (verts )- 1 )
11361141
1137- elif i < mtree_props .iteration + mtree_props .trunk_length - 1 and i == mtree_props .trunk_length + 1 or random () < split_probability :
1142+ elif i < mtree_props .iteration + mtree_props .trunk_length - 1 \
1143+ and i == mtree_props .trunk_length + 1 \
1144+ or random () < split_probability :
1145+
11381146 variation = mtree_props .trunk_variation if trunk2 else mtree_props .randomangle
11391147 rand_j = randint (1 ,5 )
11401148 rand_T = randint (0 ,4 )
@@ -1206,8 +1214,9 @@ def create_tree(position, is_twig=False):
12061214 obj .select = False
12071215
12081216 vgroups = obj .vertex_groups
1209- # add vertex group for the leaves particle system
1210- leaves_group = obj .vertex_groups .new ("leaf" )
1217+
1218+ # add vertex group for the leaves particle system
1219+ obj .vertex_groups .new ("leaf" )
12111220 vgroups .active_index = vgroups ["leaf" ].index
12121221 bpy .ops .object .mode_set (mode = 'EDIT' )
12131222 bpy .ops .mesh .select_all (action = 'DESELECT' )
0 commit comments