Skip to content

Commit

Permalink
Merge pull request #338 from Weisl/#320PhysicsMaterialsOff
Browse files Browse the repository at this point in the history
#320 physics materials off
  • Loading branch information
Weisl committed Apr 12, 2023
2 parents ef0fd2b + f1d7d19 commit e4f8fee
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Expand Up @@ -2,7 +2,7 @@
"name": "Collider Tools",
"description": "Collider Tools is a Blender addon to create physics colliders for games and real-time applications.",
"author": "Matthias Patscheider",
"version": (1, 2, 2),
"version": (1, 2, 3),
"blender": (3, 2, 0),
"location": "View3D > Collider Tools",
"doc_url": "https://weisl.github.io/collider-tools_overview/",
Expand Down
1 change: 1 addition & 0 deletions collider_conversion/conversion_operators.py
Expand Up @@ -73,6 +73,7 @@ def __init__(self):
self.is_mesh_to_collider = True
self.use_creation_mode = False
self.shape = 'mesh_shape'
self.use_keep_original_materials = True

def invoke(self, context, event):
super().invoke(context, event)
Expand Down
49 changes: 38 additions & 11 deletions collider_shapes/add_bounding_primitive.py
Expand Up @@ -139,6 +139,7 @@ def draw_viewport_overlay(self, context):
value = str(get_groups_name(self.collision_groups[self.collision_group_idx]))
i = draw_modal_item(self, font_id, i, vertical_px_offset, left_margin, label, value=value, key='(T)', type='enum')

# creation mode == SELECTION or INDIVIDUAL
if self.use_creation_mode:
label = "Creation Mode "
value = self.creation_mode[self.creation_mode_idx]
Expand All @@ -164,6 +165,14 @@ def draw_viewport_overlay(self, context):
i = draw_modal_item(self, font_id, i, vertical_px_offset, left_margin, label, value=value, key='(P)',
type='bool')

# mode check is here because keep original mesh doesn't work for EDIT mode atm.
if self.use_keep_original_materials and self.obj_mode == 'OBJECT':
label = "Keep Original Materials"
value = str(self.keep_original_material)
i = draw_modal_item(self, font_id, i, vertical_px_offset, left_margin, label, value=value, key='(O)', type='bool')



label = "Toggle X Ray "
value = str(self.x_ray)
i = draw_modal_item(self, font_id, i, vertical_px_offset, left_margin, label, value=value, key='(C)', type='bool')
Expand Down Expand Up @@ -750,7 +759,9 @@ def primitive_postprocessing(self, context, bounding_object, base_object_collect
else: # No default material is selected
mat_name = self.prefs.physics_material_name

set_physics_material(bounding_object, mat_name)
# The or self.obj_mode == 'OBJECT' is here because the keep_original_material is currently not supported for 'EDIT' mode.
if self.keep_original_material == False or self.obj_mode != 'OBJECT':
set_physics_material(bounding_object, mat_name)

bounding_object['isCollider'] = True
bounding_object['collider_group'] = self.collision_groups[self.collision_group_idx]
Expand Down Expand Up @@ -858,12 +869,12 @@ def cancel_cleanup(self, context):
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
except ValueError:
pass

def create_debug_object_from_verts(self, context, verts):
bm = bmesh.new()
for v in verts:
bm.verts.new(v) # add a new vert

me = bpy.data.meshes.new("mesh")
bm.to_mesh(me)
bm.free()
Expand All @@ -872,27 +883,32 @@ def create_debug_object_from_verts(self, context, verts):
debug_obj = bpy.data.objects.new('temp_debug_objects', me)
# root_collection.objects.link(debug_obj)
self.add_to_collections(debug_obj, 'Debug')

return debug_obj


def __init__(self):
# has to be in --init

# operator settings
self.is_mesh_to_collider = False

# modal settings
self.use_decimation = False
self.use_geo_nodes_hull = False

self.use_vertex_count = False
self.use_modifier_stack = False
self.use_weld_modifier = False

self.use_space = False
self.use_cylinder_axis = False
self.use_global_local_switches = False
self.use_sphere_segments = False
self.shape = ''
self.use_shape_change = False
self.use_creation_mode = True
self.use_keep_original_materials = False

# default shape init
self.shape = ''

# UI/UX
self.ignore_input = False
Expand Down Expand Up @@ -972,6 +988,9 @@ def invoke(self, context, event):
self.creation_mode = ['INDIVIDUAL', 'SELECTION']
self.creation_mode_idx = self.creation_mode.index(colSettings.default_creation_mode)

#Should physics materials be assigned or not.
self.keep_original_material = colSettings.default_keep_original_material

self.collision_groups = collider_groups
self.collision_group_idx = self.collision_groups.index(colSettings.default_user_group)

Expand All @@ -993,7 +1012,7 @@ def invoke(self, context, event):
self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_viewport_overlay, args, 'WINDOW', 'POST_PIXEL')
# add modal handler
context.window_manager.modal_handler_add(self)

self.execute(context)

def modal(self, context, event):
Expand Down Expand Up @@ -1107,6 +1126,10 @@ def modal(self, context, event):
self.creation_mode_idx = (self.creation_mode_idx + 1) % len(self.creation_mode)
self.execute(context)

elif event.type == 'O' and event.value == 'RELEASE' and self.use_keep_original_materials == True and self.obj_mode == 'OBJECT':
self.keep_original_material = not self.keep_original_material
self.execute(context)

elif event.type == 'S' and event.value == 'RELEASE':
self.displace_active = not self.displace_active
self.opacity_active = False
Expand Down Expand Up @@ -1222,7 +1245,11 @@ def execute(self, context):
# reset naming count:
self.name_count = 0

self.obj_mode = context.object.mode
# Bug:
try:
self.obj_mode = context.object.mode
except AttributeError:
print("AttributeError: bug #328")

# Remove objects from previous generation
self.remove_objects(self.new_colliders_list)
Expand Down
2 changes: 2 additions & 0 deletions collider_shapes/add_collision_mesh.py
Expand Up @@ -15,8 +15,10 @@ def __init__(self):
self.use_decimation = True
self.use_modifier_stack = True
self.use_weld_modifier = True
self.use_keep_original_materials = True
self.shape = "mesh_shape"


def invoke(self, context, event):
super().invoke(context, event)
return {'RUNNING_MODAL'}
Expand Down
6 changes: 6 additions & 0 deletions preferences/properties.py
Expand Up @@ -108,6 +108,12 @@ class ColliderTools_Properties(bpy.types.PropertyGroup):
default=False,
description="Set the default for using the modifier stack or not when creating colliders.")

default_keep_original_material: bpy.props.BoolProperty(name="Keep Original Materials",
default=False,
description="Set the default for using the modifier stack or not when creating colliders.")



default_user_group: bpy.props.EnumProperty(name="Default User Group",
items=(('USER_01', "User Group 01",
"Show/Hide all objects that are part of User Group 01", '', 4),
Expand Down
2 changes: 2 additions & 0 deletions ui/properties_panels.py
Expand Up @@ -346,6 +346,8 @@ def draw(self, context):

row = layout.row(align=True)
row.prop(colSettings, "default_modifier_stack")
row = layout.row(align=True)
row.prop(colSettings, "default_keep_original_material")
col = layout.column(align=True)
row = col.row(align=True)
row.prop(colSettings, "default_space")
Expand Down

0 comments on commit e4f8fee

Please sign in to comment.