Skip to content

Commit

Permalink
Merge pull request #117 from MaximeHerpin/release-2.8.0
Browse files Browse the repository at this point in the history
Release 2.8.0
  • Loading branch information
ekaj2 authored Oct 12, 2016
2 parents dacd49e + 6bb76e4 commit eaf2cba
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
23 changes: 22 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
bl_info = {
"name": "Modular trees",
"author": "Herpin Maxime, Jake Dube",
"version": (2, 7, 3),
"version": (2, 8, 0),
"blender": (2, 77, 0),
"location": "View3D > Tools > Tree > Make Tree",
"description": "Generates an organic tree with correctly modeled branching.",
Expand Down Expand Up @@ -205,6 +205,11 @@ def draw(self, context):

box = layout.box()
box.label("Trunk")
sbox = box.box()
sbox.prop(mtree_props, 'use_grease_pencil')
if mtree_props.use_grease_pencil:
sbox.prop(mtree_props, 'smooth_stroke')
sbox.prop(mtree_props, 'stroke_step_size')
box.prop(mtree_props, 'trunk_length')
box.prop(mtree_props, 'trunk_variation')
box.prop(mtree_props, 'trunk_space')
Expand Down Expand Up @@ -623,7 +628,23 @@ class ModularTreePropertyGroup(PropertyGroup):
min=0,
default=10,
description="The distance from the terrain that the wind effect is at its highest")

use_grease_pencil = BoolProperty(
name = "Use Grease Pencil",
default = False)

smooth_stroke = FloatProperty(
name = "Smooth Iterations",
min = 0.0,
max = 1,
default = .2)

stroke_step_size = FloatProperty(
name = "Step Size",
min = 0,
default = .5)


clear_mods = BoolProperty(name="Clear Modifiers", default=True)

wind_strength = FloatProperty(name="Wind Strength", default=1)
Expand Down
63 changes: 56 additions & 7 deletions tree_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,31 @@ def add_leaf(position, direction, rotation, scale):
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.shade_smooth()


def rehash_set(s, p_dist):
new_set = []
new_set.append(s[0])
i = 1
while i < len(s):
n_dist = (s[i] - new_set[-1]).length
if n_dist >= p_dist:
new_set.append(new_set[-1] + p_dist/n_dist * (s[i] - new_set[-1]))
else:
i+=1
return new_set



def smooth_stroke(iterations,smooth,points):

for i in range(iterations):
new_points = []
new_points.append(points[0])
for j in range (1,len(points)-1):
new_points.append(smooth/2*(points[j-1]+points[j+1]) + (1-smooth)* points[j])
new_points.append(points[-1])
points = new_points
return points

def create_tree(position, is_twig=False):
"""Creates a tree
Expand Down Expand Up @@ -979,7 +1003,18 @@ def create_tree(position, is_twig=False):

radius = mtree_props.radius
extremites = [(extr, radius, Vector((0, 0, 1)), extr[0], last_bone, trunk2, 0)]

curr_grease_point = 0
using_grease = False
gp = bpy.context.scene.grease_pencil
grease_points = []
save_trunk_length = mtree_props.trunk_length
save_trunk_space = mtree_props.trunk_space
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:
grease_points = rehash_set([i.co for i in gp.layers.active.active_frame.strokes[0].points], mtree_props.stroke_step_size)
grease_points = smooth_stroke(5,mtree_props.smooth_stroke,grease_points)
mtree_props.trunk_length = len(grease_points) -2
using_grease = True

# branches generation
print("Generating Branches...")
for i in range(mtree_props.iteration + mtree_props.trunk_length):
Expand Down Expand Up @@ -1017,10 +1052,22 @@ def create_tree(position, is_twig=False):

if i <= mtree_props.trunk_length:
branch_verts = [v for v in branch.verts]
ni, direction, nsi = join_branch(verts, faces, indexes, radius, mtree_props.trunk_space, branch_verts,
direction,
mtree_props.trunk_variation, s_index, seams2)
sortie = pos + direction * mtree_props.branch_length
if not using_grease:
ni, direction, nsi = join_branch(verts, faces, indexes, radius, mtree_props.trunk_space, branch_verts,
direction,
mtree_props.trunk_variation, s_index, seams2)
sortie = pos + direction * mtree_props.branch_length

else:
grease_dir = grease_points[curr_grease_point+1] - grease_points[curr_grease_point]
grease_length = grease_dir.length
grease_dir.normalize()
ni, direction, nsi = join_branch(verts, faces, indexes, radius,grease_length,
branch_verts,
grease_dir,
0, s_index, seams2)
sortie = pos + grease_dir * grease_length
curr_grease_point +=1

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

extremites = nextremites
# mesh and object creation
mtree_props.trunk_length = save_trunk_length
mtree_props.trunk_space = save_trunk_space
print("Building Object...")

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

mesh.from_pydata(verts, [], faces)
mesh.update(calc_edges=False)
obj = bpy.data.objects.new("tree", mesh)
obj.location = position
obj.location = position if not using_grease else grease_points[0] - Vector((0,0,1))
scene.objects.link(obj)
scene.objects.active = obj
obj.select = True
Expand Down

0 comments on commit eaf2cba

Please sign in to comment.