Skip to content

Commit eaf2cba

Browse files
authored
Merge pull request #117 from MaximeHerpin/release-2.8.0
Release 2.8.0
2 parents dacd49e + 6bb76e4 commit eaf2cba

File tree

2 files changed

+78
-8
lines changed

2 files changed

+78
-8
lines changed

__init__.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
bl_info = {
3636
"name": "Modular trees",
3737
"author": "Herpin Maxime, Jake Dube",
38-
"version": (2, 7, 3),
38+
"version": (2, 8, 0),
3939
"blender": (2, 77, 0),
4040
"location": "View3D > Tools > Tree > Make Tree",
4141
"description": "Generates an organic tree with correctly modeled branching.",
@@ -205,6 +205,11 @@ def draw(self, context):
205205

206206
box = layout.box()
207207
box.label("Trunk")
208+
sbox = box.box()
209+
sbox.prop(mtree_props, 'use_grease_pencil')
210+
if mtree_props.use_grease_pencil:
211+
sbox.prop(mtree_props, 'smooth_stroke')
212+
sbox.prop(mtree_props, 'stroke_step_size')
208213
box.prop(mtree_props, 'trunk_length')
209214
box.prop(mtree_props, 'trunk_variation')
210215
box.prop(mtree_props, 'trunk_space')
@@ -623,7 +628,23 @@ class ModularTreePropertyGroup(PropertyGroup):
623628
min=0,
624629
default=10,
625630
description="The distance from the terrain that the wind effect is at its highest")
631+
632+
use_grease_pencil = BoolProperty(
633+
name = "Use Grease Pencil",
634+
default = False)
635+
636+
smooth_stroke = FloatProperty(
637+
name = "Smooth Iterations",
638+
min = 0.0,
639+
max = 1,
640+
default = .2)
641+
642+
stroke_step_size = FloatProperty(
643+
name = "Step Size",
644+
min = 0,
645+
default = .5)
626646

647+
627648
clear_mods = BoolProperty(name="Clear Modifiers", default=True)
628649

629650
wind_strength = FloatProperty(name="Wind Strength", default=1)

tree_creator.py

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,31 @@ def add_leaf(position, direction, rotation, scale):
880880
bpy.ops.object.mode_set(mode='OBJECT')
881881
bpy.ops.object.shade_smooth()
882882

883-
883+
def rehash_set(s, p_dist):
884+
new_set = []
885+
new_set.append(s[0])
886+
i = 1
887+
while i < len(s):
888+
n_dist = (s[i] - new_set[-1]).length
889+
if n_dist >= p_dist:
890+
new_set.append(new_set[-1] + p_dist/n_dist * (s[i] - new_set[-1]))
891+
else:
892+
i+=1
893+
return new_set
894+
895+
896+
897+
def smooth_stroke(iterations,smooth,points):
898+
899+
for i in range(iterations):
900+
new_points = []
901+
new_points.append(points[0])
902+
for j in range (1,len(points)-1):
903+
new_points.append(smooth/2*(points[j-1]+points[j+1]) + (1-smooth)* points[j])
904+
new_points.append(points[-1])
905+
points = new_points
906+
return points
907+
884908
def create_tree(position, is_twig=False):
885909
"""Creates a tree
886910
@@ -979,7 +1003,18 @@ def create_tree(position, is_twig=False):
9791003

9801004
radius = mtree_props.radius
9811005
extremites = [(extr, radius, Vector((0, 0, 1)), extr[0], last_bone, trunk2, 0)]
982-
1006+
curr_grease_point = 0
1007+
using_grease = False
1008+
gp = bpy.context.scene.grease_pencil
1009+
grease_points = []
1010+
save_trunk_length = mtree_props.trunk_length
1011+
save_trunk_space = mtree_props.trunk_space
1012+
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:
1013+
grease_points = rehash_set([i.co for i in gp.layers.active.active_frame.strokes[0].points], mtree_props.stroke_step_size)
1014+
grease_points = smooth_stroke(5,mtree_props.smooth_stroke,grease_points)
1015+
mtree_props.trunk_length = len(grease_points) -2
1016+
using_grease = True
1017+
9831018
# branches generation
9841019
print("Generating Branches...")
9851020
for i in range(mtree_props.iteration + mtree_props.trunk_length):
@@ -1017,10 +1052,22 @@ def create_tree(position, is_twig=False):
10171052

10181053
if i <= mtree_props.trunk_length:
10191054
branch_verts = [v for v in branch.verts]
1020-
ni, direction, nsi = join_branch(verts, faces, indexes, radius, mtree_props.trunk_space, branch_verts,
1021-
direction,
1022-
mtree_props.trunk_variation, s_index, seams2)
1023-
sortie = pos + direction * mtree_props.branch_length
1055+
if not using_grease:
1056+
ni, direction, nsi = join_branch(verts, faces, indexes, radius, mtree_props.trunk_space, branch_verts,
1057+
direction,
1058+
mtree_props.trunk_variation, s_index, seams2)
1059+
sortie = pos + direction * mtree_props.branch_length
1060+
1061+
else:
1062+
grease_dir = grease_points[curr_grease_point+1] - grease_points[curr_grease_point]
1063+
grease_length = grease_dir.length
1064+
grease_dir.normalize()
1065+
ni, direction, nsi = join_branch(verts, faces, indexes, radius,grease_length,
1066+
branch_verts,
1067+
grease_dir,
1068+
0, s_index, seams2)
1069+
sortie = pos + grease_dir * grease_length
1070+
curr_grease_point +=1
10241071

10251072
if i <= mtree_props.bones_iterations:
10261073
bones.append((Lb[0], len(bones) + 2, Lb[1], sortie))
@@ -1096,14 +1143,16 @@ def create_tree(position, is_twig=False):
10961143

10971144
extremites = nextremites
10981145
# mesh and object creation
1146+
mtree_props.trunk_length = save_trunk_length
1147+
mtree_props.trunk_space = save_trunk_space
10991148
print("Building Object...")
11001149

11011150
mesh = bpy.data.meshes.new("tree")
11021151

11031152
mesh.from_pydata(verts, [], faces)
11041153
mesh.update(calc_edges=False)
11051154
obj = bpy.data.objects.new("tree", mesh)
1106-
obj.location = position
1155+
obj.location = position if not using_grease else grease_points[0] - Vector((0,0,1))
11071156
scene.objects.link(obj)
11081157
scene.objects.active = obj
11091158
obj.select = True

0 commit comments

Comments
 (0)