Skip to content

Release 2.8.1 #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 74 additions & 18 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
bl_info = {
"name": "Modular trees",
"author": "Herpin Maxime, Jake Dube",
"version": (2, 8, 0),
"version": (2, 8, 1),
"blender": (2, 77, 0),
"location": "View3D > Tools > Tree > Make Tree",
"description": "Generates an organic tree with correctly modeled branching.",
Expand Down Expand Up @@ -257,6 +257,13 @@ def draw(self, context):
box.prop_search(mtree_props, "obstacle", scene, "objects")
if bpy.data.objects.get(mtree_props.obstacle) is not None:
box.prop(mtree_props, 'obstacle_strength')
col1 = box.column()
col1.prop(mtree_props, 'use_force_field')
if mtree_props.use_force_field:
col1.prop(mtree_props, 'fields_point_strength')
col1.prop(mtree_props, 'fields_point_strength')
col1.prop(mtree_props, 'fields_strength_limit')
col1.prop(mtree_props, 'fields_radius_factor')


class AdvancedSettingsPanel(Panel):
Expand All @@ -271,6 +278,7 @@ class AdvancedSettingsPanel(Panel):
def draw(self, context):
mtree_props = context.scene.mtree_props
layout = self.layout
scene = context.scene

box = layout.box()
box.prop(mtree_props, 'mat')
Expand All @@ -285,6 +293,8 @@ def draw(self, context):
if mtree_props.particle:
box.prop(mtree_props, 'number')
box.prop(mtree_props, 'display')
box.prop_search(mtree_props, "twig_particle", scene, "objects")
box.prop(mtree_props, 'particle_size')


class WindAnimationPanel(Panel):
Expand Down Expand Up @@ -326,6 +336,7 @@ class MakeTwigPanel(Panel):
def draw(self, context):
mtree_props = context.scene.mtree_props
layout = self.layout
scene = context.scene

row = layout.row()
row.scale_y = 1.5
Expand All @@ -338,11 +349,12 @@ def draw(self, context):
box = layout.box()
box.label("Twig Options")
box.prop(mtree_props, "leaf_size")
box.prop_search(mtree_props, "leaf_object", scene, "objects")
box.prop(mtree_props, "leaf_chance")
box.prop(mtree_props, "leaf_weight")
box.prop(mtree_props, "TwigSeedProp")
box.prop(mtree_props, "twig_iteration")
box.prop_search(mtree_props, "twig_bark_material", bpy.data, "materials")
box.prop_search(mtree_props, "twig_leaf_material", bpy.data, "materials")


class MakeTreePresetsPanel(Panel):
Expand Down Expand Up @@ -542,10 +554,10 @@ class ModularTreePropertyGroup(PropertyGroup):
description="randomize the rotation of branches angle")

branch_min_radius = FloatProperty(
name = "Branches minimum radius",
default = .04,
min = 0,
description = "radius at which a branch breaks for being to small")
name="Branches minimum radius",
default=.04,
min=0,
description="radius at which a branch breaks for being to small")

particle = BoolProperty(
name="Configure Particle System",
Expand All @@ -559,6 +571,15 @@ class ModularTreePropertyGroup(PropertyGroup):
name="Particles in Viewport",
default=500)

twig_particle = StringProperty(
name='twig or leaf object',
default='')

particle_size = FloatProperty(
name="twig/leaf size",
min=0,
default=1.5)

break_chance = FloatProperty(
name="Break Chance",
default=0.02)
Expand All @@ -576,8 +597,11 @@ class ModularTreePropertyGroup(PropertyGroup):
min=0,
default=.5)

twig_leaf_material = StringProperty(
name="Leaf Material")
leaf_weight = FloatProperty(
name="Leaf Weight",
min=0,
max=1,
default=.2)

twig_bark_material = StringProperty(
name="Twig Bark Material")
Expand All @@ -592,6 +616,11 @@ class ModularTreePropertyGroup(PropertyGroup):
soft_max=10,
default=9)

leaf_object = StringProperty(
name="leaf object",
default="",
description="The object used for the leaves. \nThe leaf must be on Y axis and the rotation must be applied")

tree_number = IntProperty(
name="Tree Number",
min=2,
Expand Down Expand Up @@ -631,21 +660,48 @@ class ModularTreePropertyGroup(PropertyGroup):
description="The distance from the terrain that the wind effect is at its highest")

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

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

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

use_force_field = BoolProperty(
name="Use Force Field",
default=False)

fields_point_strength = FloatProperty(
name="Point Force Strength",
min=0.0,
default=1)

fields_wind_strength = FloatProperty(
name="Wind Force Strength",
min=0.0,
default=1)

fields_strength_limit = FloatProperty(
name="Strength Limit",
min=0,
default=10,
description="limits the force so that it can't approaches infinity")

fields_radius_factor = FloatProperty(
name="Radius Factor",
min=0,
max=1,
default=.5,
description="How the branch radius affects the force strength. "
"\n0 means big branches are as affected as small ones.")


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

wind_strength = FloatProperty(name="Wind Strength", default=1)
Expand Down
39 changes: 24 additions & 15 deletions generator_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ class MakeTwigOperator(Operator):
bl_options = {"REGISTER", "UNDO"}

def execute(self, context):
scene = context.scene
mtree_props = scene.mtree_props

# this block saves everything and cancels operator if something goes wrong
display_logo()
messages, message_lvls, status = save_everything()
messages, message_lvls, status = save_everything(twig=True)
for i, message in enumerate(messages):
self.report({message_lvls[i]}, message)
return {status}

scene = context.scene
mtree_props = scene.mtree_props

seed(mtree_props.TwigSeedProp)
save_preserve_trunk = mtree_props.preserve_trunk
save_trunk_split_angle = mtree_props.split_angle # This variable is never used! Should it be?
save_randomangle = mtree_props.randomangle
save_trunk_variation = mtree_props.trunk_variation
save_radius = mtree_props.radius
Expand Down Expand Up @@ -146,6 +146,7 @@ def execute(self, context):
save_number = mtree_props.number
save_display = mtree_props.display
save_break_chance = mtree_props.break_chance
save_use_grease_pencil = mtree_props.use_grease_pencil

mtree_props.preserve_trunk = False
mtree_props.trunk_split_angle = 0
Expand Down Expand Up @@ -180,6 +181,7 @@ def execute(self, context):
mtree_props.number = 0
mtree_props.display = 0
mtree_props.break_chance = 0
mtree_props.use_grease_pencil = False

if bpy.data.materials.get("twig bark") is None:
build_bark_material("twig bark")
Expand All @@ -191,16 +193,23 @@ def execute(self, context):

twig = bpy.context.active_object
twig.name = 'twig'
leafs = []
twig.active_material = bpy.data.materials.get(mtree_props.twig_bark_material)
for (position, direction, rotation) in twig_leafs:
for i in range(randint(1, 3)):
if random() < mtree_props.leaf_chance:
add_leaf(position + direction * .5 * random(), direction + Vector((random(), random(), random())),
rotation + random() * 5, (1 + random()) * mtree_props.leaf_size)
bpy.context.active_object.active_material = bpy.data.materials.get(mtree_props.twig_leaf_material)
twig.select = True
scene.objects.active = twig

for (position, direction) in twig_leafs:
if random() < mtree_props.leaf_chance:
for i in range(randint(1, 3)):
if random() < mtree_props.leaf_chance:
add_leaf(position+direction*random(), direction+Vector((random()-.5, random()-.5, 0))*.2, mtree_props.leaf_size*(2+random()), mtree_props.leaf_object, mtree_props.leaf_weight)
leafs.append(bpy.context.active_object)
if not bpy.context.active_object.data.materials.items():
mat = bpy.data.materials.get("leaf_mat")
if mat is None:
mat = bpy.data.materials.new(name="leaf_mat")
bpy.context.active_object.active_material = mat
twig.select = True
scene.objects.active = twig
for i in leafs:
i.select = True
bpy.ops.object.join()
bpy.ops.transform.rotate(value=-1.5708, axis=(1, 0, 0))
bpy.ops.transform.resize(value=(0.25, 0.25, 0.25))
Expand Down Expand Up @@ -240,6 +249,7 @@ def execute(self, context):
mtree_props.number = save_number
mtree_props.display = save_display
mtree_props.break_chance = save_break_chance
mtree_props.use_grease_pencil = save_use_grease_pencil

return {'FINISHED'}

Expand Down Expand Up @@ -315,7 +325,7 @@ class UpdateTwigOperator(Operator):
def execute(self, context):
# this block saves everything and cancels operator if something goes wrong
display_logo()
messages, message_lvls, status = save_everything()
messages, message_lvls, status = save_everything(twig=True)
for i, message in enumerate(messages):
self.report({message_lvls[i]}, message)
return {status}
Expand All @@ -332,7 +342,6 @@ def execute(self, context):
return {'CANCELLED'}

if is_tree_prop:
pos = obj.location # this is never used...should it be?
scale = obj.scale
rot = obj.rotation_euler
bpy.ops.mod_tree.add_twig()
Expand Down
10 changes: 7 additions & 3 deletions particle_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
# along with Modular Tree. If not, see <http://www.gnu.org/licenses/>.
# ##### END GPL LICENSE BLOCK #####

import bpy

def create_system(ob, number, display, vertex_group):

def create_system(ob, number, display, vertex_group, object_name, size):
""" Creates a particle system

Args:
Expand All @@ -31,7 +33,7 @@ def create_system(ob, number, display, vertex_group):
g = vertex_group

# customize the particle system
leaf = ob.modifiers.new("psys name", 'PARTICLE_SYSTEM')
leaf = ob.modifiers.new("leafs", 'PARTICLE_SYSTEM')
part = ob.particle_systems[0]
part.vertex_group_density = g.name
settings = leaf.particle_system.settings
Expand All @@ -46,7 +48,9 @@ def create_system(ob, number, display, vertex_group):
settings.use_rotations = True
settings.phase_factor = 1
settings.phase_factor_random = 1
settings.particle_size = 0.015
settings.particle_size = 0.1 * size
settings.size_random = 0.25
settings.brownian_factor = 1
settings.render_type = "OBJECT"
if bpy.data.objects.get(object_name) is not None:
settings.dupli_object = bpy.context.scene.objects[object_name]
16 changes: 13 additions & 3 deletions prep_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,21 @@ def always_save():
return "SUCCESS", None


def save_everything():
# save files
save_return, bad_file = always_save()
def save_everything(twig=False):
messages = []
message_lvls = []
scene = bpy.context.scene
mtree_props = scene.mtree_props

if twig:
# do illegal settings checks here
if mtree_props.leaf_object not in scene.objects:
messages += ["Requires a valid leaf object! Add one with the object selector in the twig UI."]
message_lvls += ['ERROR']
return messages, message_lvls, 'CANCELLED'

# save files
save_return, bad_file = always_save()
if save_return == "BLEND_ERROR":
messages += ["Save file or disable always save " + "in user prefs."]
message_lvls += ['ERROR']
Expand Down
Loading