Skip to content

Commit

Permalink
Merge pull request #53 from luketimothyjones/merge-vertices-after-mes…
Browse files Browse the repository at this point in the history
…h-conversion

Add option to automate vertex merging (works with manual mesh conversion)
  • Loading branch information
friggog authored Jul 26, 2021
2 parents 4ccb8bf + b9f8c1f commit 4e246ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class TreeGen(bpy.types.Operator):
# Convert selected tree to mesh
_scene.tree_gen_convert_to_mesh_input = _props.BoolProperty(name="Convert to Mesh After Generation", default=False,
description="After generation, automatically convert the branches from a curve to a mesh")
_scene.tree_gen_merge_verts_by_distance = _props.BoolProperty(name="Merge Nearby Vertices", default=False,
description="After mesh conversion, merge nearby vertices together")

# Create LODs
_scene.tree_gen_create_lods_input = _props.BoolProperty(name="Create LODs After Generation", default=False,
Expand Down Expand Up @@ -693,6 +695,7 @@ def label_row(label, prop, checkbox=False, dropdown=False, container=None):
box = layout.box()
box.row()
label_row('', 'tree_gen_convert_to_mesh_input', checkbox=True, container=box)
label_row('', 'tree_gen_merge_verts_by_distance', checkbox=True, container=box)
box.row()
box.operator(TreeGenConvertToMesh.bl_idname)
box.row()
Expand Down
14 changes: 14 additions & 0 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def update_log(msg):

return update_log

def update_log(msg):
pass

return lambda _: None


Expand All @@ -66,6 +69,9 @@ def convert_to_mesh(context):
Converts tree branches from curve to mesh
"""

from . import parametric
update_log = parametric.gen.update_log

try:
tree = context.object
except AttributeError:
Expand Down Expand Up @@ -108,6 +114,14 @@ def convert_to_mesh(context):
new_branches.matrix_world = tree.matrix_world
new_branches.parent = tree

if context.scene.tree_gen_merge_verts_by_distance:
update_log('Merging duplicate vertices; this will take a bit for complex trees.\n')

context.view_layer.objects.active = new_branches
bpy.ops.object.mode_set(mode='EDIT', toggle=True)
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.remove_doubles(threshold=0.0001)


def generate_lods(context, level_count=3):
from . import parametric
Expand Down

0 comments on commit 4e246ff

Please sign in to comment.