Skip to content

Commit 3068d6a

Browse files
committed
Added Remesh preprocessing tool
This tool remeshes all selected objects by converting them to convex hulls. This can help clean up 'bad' geometry that can cause problems with tools like Discretize. Members of an object group 'bcb_noRemesh' will be skipped if present.
1 parent 7b5a761 commit 3068d6a

File tree

8 files changed

+73
-2
lines changed

8 files changed

+73
-2
lines changed

kk_bullet_constraints_builder.zip

429 Bytes
Binary file not shown.

kk_bullet_constraints_builder/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def do(cmd, *arg):
232232
OBJECT_OT_bcb_preproc_tool_apply_all_modifiers,
233233
OBJECT_OT_bcb_preproc_tool_center_model,
234234
OBJECT_OT_bcb_preproc_tool_separate_loose,
235+
OBJECT_OT_bcb_preproc_tool_remesh,
235236
OBJECT_OT_bcb_preproc_tool_discretize,
236237
OBJECT_OT_bcb_preproc_tool_apply_all_modifiers_2,
237238
OBJECT_OT_bcb_preproc_tool_enable_rigid_bodies,

kk_bullet_constraints_builder/build_data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def storeConfigDataInScene(scene):
6565

6666
scene["bcb_prop_preprocTools_sep"] = props.preprocTools_sep
6767

68+
scene["bcb_prop_preprocTools_rem"] = props.preprocTools_rem
69+
6870
scene["bcb_prop_preprocTools_dis"] = props.preprocTools_dis
6971
scene["bcb_prop_preprocTools_dis_siz"] = props.preprocTools_dis_siz
7072
scene["bcb_prop_preprocTools_dis_cel"] = props.preprocTools_dis_cel
@@ -221,6 +223,9 @@ def getConfigDataFromScene(scene):
221223
if "bcb_prop_preprocTools_sep" in scene.keys():
222224
props.preprocTools_sep = scene["bcb_prop_preprocTools_sep"]
223225

226+
if "bcb_prop_preprocTools_rem" in scene.keys():
227+
props.preprocTools_rem = scene["bcb_prop_preprocTools_rem"]
228+
224229
if "bcb_prop_preprocTools_dis" in scene.keys():
225230
props.preprocTools_dis = scene["bcb_prop_preprocTools_dis"]
226231
if "bcb_prop_preprocTools_dis_siz" in scene.keys():

kk_bullet_constraints_builder/global_props.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class bcb_props(bpy.types.PropertyGroup):
8383

8484
preprocTools_sep = bool_(default=1)
8585

86+
preprocTools_rem = bool_(default=0)
87+
8688
preprocTools_dis = bool_(default=1)
8789
preprocTools_dis_siz = float_(name="Minimum Size Limit", default=2.9, min=0.0, max=1000, description="Discretization size in m this tool tries to reach by discretization. To enforce regularity at all times, elements afterwards can deviate in size to some extent from the target size. For booleans (default method): The minimum dimension value serves as limit for an element still being considered for subdivision, at least two dimension axis must be above this size. After discretization no element will be larger than this value anymore, although they can be smaller up to 50%")
8890
preprocTools_dis_cel = bool_(name="Use Voxel Method (Faster)", default=0, description="Enables the voxel based discretizaton method and geometry is converted into cuboid-shaped cells. While this method has the disadvantage that it can't keep mesh details such as curved surfaces, round columns or mural reliefs, it is very fast compared to the default boolean based method. Also note that this method is limited to odd subdivision level numbers [1,3,5,7..], so you basically can't split an element into two for instance but only into three, five and so on")

kk_bullet_constraints_builder/global_vars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
################################################################################
3636

3737
### Vars:
38-
bcb_version = (3, 5, 5)
38+
bcb_version = (3, 5, 6)
3939

4040
### Customizable element group presets
4141
presets = [

kk_bullet_constraints_builder/gui.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ def draw(self, context):
206206
box = split.box()
207207
box.operator("bcb.preproc_tool_apply_all_modifiers", icon="DOT")
208208

209+
row = col.row(align=1); split = row.split(percentage=.06, align=0)
210+
split.prop(props, "preprocTools_rem", text="")
211+
box = split.box()
212+
box.operator("bcb.preproc_tool_remesh", icon="DOT")
213+
209214
row = col.row(align=1); split = row.split(percentage=.06, align=0)
210215
split.prop(props, "preprocTools_ctr", text="")
211216
box = split.box()

kk_bullet_constraints_builder/gui_buttons.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ def execute(self, context):
588588
if props.preprocTools_grp: tool_createGroupsFromNames(scene); props.preprocTools_grp = 0
589589
if props.preprocTools_sep: tool_separateLoose(scene); props.preprocTools_sep = 0
590590
if props.preprocTools_mod: tool_applyAllModifiers(scene); props.preprocTools_mod = 0
591+
if props.preprocTools_rem: tool_remesh(scene); props.preprocTools_rem = 0
591592
if props.preprocTools_ctr: tool_centerModel(scene); props.preprocTools_ctr = 0
592593
if props.preprocTools_sep2: tool_separateLoose(scene); props.preprocTools_sep2 = 0
593594
if props.preprocTools_dis: tool_discretize(scene); props.preprocTools_dis = 0
@@ -719,7 +720,7 @@ def execute(self, context):
719720
class OBJECT_OT_bcb_preproc_tool_separate_loose_2(bpy.types.Operator):
720721
bl_idname = "bcb.preproc_tool_separate_loose_2"
721722
bl_label = "Separate Loose"
722-
bl_description = "Separates all loose (not connected) mesh elements within an object into separate objects, this is done for all selected objects"
723+
bl_description = "Separates all loose (not connected) mesh elements within an object into separate objects, this is done for all selected objects. Members of an object group 'bcb_noSeparateLoose' will be skipped if present"
723724
def execute(self, context):
724725
props = context.window_manager.bcb
725726
scene = bpy.context.scene
@@ -729,6 +730,19 @@ def execute(self, context):
729730

730731
########################################
731732

733+
class OBJECT_OT_bcb_preproc_tool_remesh(bpy.types.Operator):
734+
bl_idname = "bcb.preproc_tool_remesh"
735+
bl_label = "Remesh"
736+
bl_description = "Remeshes all selected objects by converting them to convex hulls. This can help clean up 'bad' geometry that can cause problems with tools like Discretize. Members of an object group 'bcb_noRemesh' will be skipped if present"
737+
def execute(self, context):
738+
props = context.window_manager.bcb
739+
scene = bpy.context.scene
740+
tool_remesh(scene)
741+
props.preprocTools_rem = 0
742+
return{'FINISHED'}
743+
744+
########################################
745+
732746
class OBJECT_OT_bcb_preproc_tool_discretize(bpy.types.Operator):
733747
bl_idname = "bcb.preproc_tool_discretize"
734748
bl_label = "Discretize"

kk_bullet_constraints_builder/tools.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,50 @@ def tool_separateLoose(scene):
462462

463463
################################################################################
464464

465+
def tool_remesh(scene):
466+
467+
print("\nRemeshing geometry...")
468+
469+
# Leave edit mode to make sure next operator works in object mode
470+
try: bpy.ops.object.mode_set(mode='OBJECT')
471+
except: pass
472+
473+
# Backup selection
474+
selection = [obj for obj in bpy.context.scene.objects if obj.select]
475+
selectionActive = bpy.context.scene.objects.active
476+
477+
### Sort out user-defined objects (members of a specific group)
478+
grpName = "bcb_noRemesh"
479+
selectionSkip = []
480+
for grp in bpy.data.groups:
481+
if grpName in grp.name:
482+
for obj in selection:
483+
if obj.name in grp.objects:
484+
obj.select = 0
485+
selectionSkip.append(obj)
486+
selection = [obj for obj in selection if obj.select]
487+
if len(selectionSkip): print("Elements skipped by '%s' group:" %grpName, len(selectionSkip))
488+
489+
count = 0
490+
for obj in selection:
491+
sys.stdout.write('\r' +"%d %s... " %(count, obj.name))
492+
bpy.context.scene.objects.active = obj
493+
try: bpy.ops.object.mode_set(mode='EDIT')
494+
except: pass
495+
try: bpy.ops.mesh.select_all(action='SELECT')
496+
except: pass
497+
try: bpy.ops.mesh.convex_hull()
498+
except: pass
499+
try: bpy.ops.object.mode_set(mode='OBJECT')
500+
except: pass
501+
count += 1
502+
print('\r ')
503+
504+
# Reselect previously deselected objects
505+
for obj in selectionSkip: obj.select = 1
506+
507+
################################################################################
508+
465509
def objInObjects(obj, objects):
466510

467511
# Find an object reference instead of the name within an .objects attribute of a scene or group

0 commit comments

Comments
 (0)