Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Weisl committed Jul 10, 2023
1 parent 88fc15e commit b512135
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
3 changes: 0 additions & 3 deletions collider_shapes/add_bounding_capsule.py
Expand Up @@ -159,9 +159,6 @@ def execute(self, context):

# Calculate the radius and height of the bounding capsule
radius, height = Capsule.calculate_radius_height(verts_loc)
#height, radius = calculate_bounding_capsule(verts_loc)
print("Optimal bounding capsule height:", height)
print("Optimal bounding capsule radius:", radius)
data = Capsule.create_capsule(longitudes=self.current_settings_dic['capsule_segments'], latitudes=int(self.current_settings_dic['capsule_segments']), radius=radius, depth=height, uv_profile="FIXED")
bm = Capsule.mesh_data_to_bmesh(
vs=data["vs"],
Expand Down
20 changes: 10 additions & 10 deletions collider_shapes/add_bounding_primitive.py
Expand Up @@ -821,7 +821,7 @@ def create_collection(collection_name):

# Collections
@classmethod
def add_to_collections(cls, obj, collection_name, hide=False):
def add_to_collections(cls, obj, collection_name, hide=False, color='NONE'):
col = cls.create_collection(collection_name)
if hide:
col.hide_viewport = True
Expand All @@ -830,6 +830,7 @@ def add_to_collections(cls, obj, collection_name, hide=False):
col.objects.link(obj)
except RuntimeError as err:
pass
col.color_tag = color

return col

Expand Down Expand Up @@ -917,9 +918,9 @@ def restore_obj_mod_from_dic(modifier_dic):
modifier.show_viewport = mod_entry["show_viewport"]
modifier.show_in_editmode = mod_entry["show_in_editmode"]

@classmethod
def convert_to_mesh(cls, context, object, use_modifiers = False):
mods = cls.store_obj_mod_in_dic(object)

def convert_to_mesh(self, context, object, use_modifiers=False):
mods = self.store_obj_mod_in_dic(object)

for mod in object.modifiers:
mod.show_viewport = use_modifiers
Expand All @@ -928,10 +929,9 @@ def convert_to_mesh(cls, context, object, use_modifiers = False):
deg = context.evaluated_depsgraph_get()
me = bpy.data.meshes.new_from_object(object.evaluated_get(deg), depsgraph=deg)
new_obj = bpy.data.objects.new(object.name + "_mesh", me)
col = cls.add_to_collections(new_obj, 'tmp_mesh', hide=False)
col.color_tag = 'COLOR_03'
col = self.add_to_collections(new_obj, 'tmp_mesh', hide=False, color=self.prefs.col_tmp_collection_color)

cls.restore_obj_mod_from_dic(mods)
self.restore_obj_mod_from_dic(mods)

new_obj.matrix_world = object.matrix_world
context.view_layer.objects.active = new_obj
Expand All @@ -949,7 +949,7 @@ def primitive_postprocessing(self, context, bounding_object, base_object_collect

if self.prefs.use_col_collection:
collection_name = self.prefs.col_collection_name
self.add_to_collections(bounding_object, collection_name)
self.add_to_collections(bounding_object, collection_name, color=self.prefs.col_collection_color)

if self.use_remesh:
self.add_remesh_modifier(context, bounding_object)
Expand Down Expand Up @@ -1039,8 +1039,8 @@ def get_pre_processed_mesh_objs(self, context, default_world_spc=True, use_local
split_objs = create_objs_from_island(base, use_world=default_world_spc)

for split in split_objs:
col = self.add_to_collections(split, 'tmp_mesh', hide=False)
col.color_tag = 'COLOR_03'
col = self.add_to_collections(split, 'tmp_mesh', hide=False, color=self.prefs.col_tmp_collection_color)
col.color_tag = self.prefs.col_tmp_collection_color
objs.append((base_ob, split))
self.tmp_meshes.extend(split_objs)

Expand Down
24 changes: 24 additions & 0 deletions preferences/preferences.py
Expand Up @@ -16,6 +16,17 @@
from ..ui.properties_panels import label_multiline
from .keymap import remove_key

collection_colors = [
("NONE", "White", "", "OUTLINER_COLLECTION", 0),
("COLOR_01", "Red", "", "COLLECTION_COLOR_01", 1),
("COLOR_02", "Orange", "", "COLLECTION_COLOR_02", 2),
("COLOR_03", "Yellow", "", "COLLECTION_COLOR_03", 3),
("COLOR_04", "Green", "", "COLLECTION_COLOR_04", 4),
("COLOR_05", "Blue", "", "COLLECTION_COLOR_05", 5),
("COLOR_06", "Violet", "", "COLLECTION_COLOR_06", 6),
("COLOR_07", "Pink", "", "COLLECTION_COLOR_07", 7),
("COLOR_08", "Brown", "", "COLLECTION_COLOR_08", 8),
]

def add_key(self, km, idname, properties_name, collision_pie_type, collision_pie_ctrl, collision_pie_shift, collision_pie_alt, collision_pie_active):
kmi = km.keymap_items.new(idname=idname, type=collision_pie_type, value='PRESS',
Expand Down Expand Up @@ -220,6 +231,17 @@ class CollisionAddonPrefs(bpy.types.AddonPreferences):
description='Name of the collider collection newly created collisions are added to',
default='Collisions')

col_collection_color: bpy.props.EnumProperty(name='Collection Color',
items=collection_colors,
description='Choose the color for the collider collections.',
default='COLOR_05',
)
col_tmp_collection_color: bpy.props.EnumProperty(name='Temp Collection Color',
items=collection_colors,
description='Choose the color for the collider collections.',
default='COLOR_03',
)

###################################################################
# KEYMAP

Expand Down Expand Up @@ -592,6 +614,8 @@ class CollisionAddonPrefs(bpy.types.AddonPreferences):
col_props = [
"use_col_collection",
"col_collection_name",
"col_collection_color",
"col_tmp_collection_color",
]

ui_col_colors = [
Expand Down

0 comments on commit b512135

Please sign in to comment.