Skip to content

Commit

Permalink
#449 Convert Collider from Name
Browse files Browse the repository at this point in the history
  • Loading branch information
Weisl committed Feb 1, 2024
1 parent afafe14 commit 69fc768
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions collider_conversion/convert_from_name.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import bpy
from bpy.types import Operator
import re

from bpy.types import Operator
from ..groups.user_groups import get_groups_color, set_object_color

class OBJECT_OT_convert_from_name(Operator):
"""Convert selected colliders to mesh objects"""
bl_idname = "object.convert_from_name"
bl_label = "Collider from Naming"
bl_description = 'Assign collider attributes from the object naming.'


@classmethod
def poll(cls, context):
return len(context.selected_objects) > 0
Expand All @@ -20,34 +21,46 @@ def execute(self, context):
prefs = context.preferences.addons[__package__.split('.')[0]].preferences

for obj in bpy.context.selected_objects.copy():
name = obj.name

col_suffix = prefs.collision_string_suffix
col_prefix = prefs.collision_string_prefix

isCollider = False

user_group_01 = prefs.user_group_01,
user_group_02 = prefs.user_group_02,
user_group_03 = prefs.user_group_03

# skip if invalid object
if obj is None:
continue

regexp = re.compile(str(user_group_03))
if regexp.search(name):
obj['collider_group'] = 'USER_03'
name = obj.name

isCollider = True
isCollider = False

regexp = re.compile(str(user_group_02))
if regexp.search(name):
obj['collider_group'] = 'USER_02'
if name.endswith(prefs.collision_string_suffix):
isCollider = True

regexp = re.compile(str(user_group_01))
if regexp.search(name):
obj['collider_group'] = 'USER_01'
if name.startswith(prefs.collision_string_prefix):
isCollider = True

user_group_01 = prefs.user_group_01,
user_group_02 = prefs.user_group_02,
user_group_03 = prefs.user_group_03
color = [0, 0, 0]

if prefs.collider_groups_enabled:
regexp = re.compile(str(user_group_03))
if regexp.search(name):
obj['collider_group'] = 'USER_03'
color = get_groups_color('USER_03')
isCollider = True

regexp = re.compile(str(user_group_02))
if regexp.search(name):
obj['collider_group'] = 'USER_02'
color = get_groups_color('USER_02')
isCollider = True

regexp = re.compile(str(user_group_01))
if regexp.search(name):
obj['collider_group'] = 'USER_01'
color = get_groups_color('USER_01')
isCollider = True

alpha = prefs.user_groups_alpha
set_object_color(obj, (color[0], color[1], color[2], alpha))

shape = prefs.box_shape
regexp = re.compile(str(shape))
Expand Down Expand Up @@ -82,10 +95,9 @@ def execute(self, context):
if isCollider:
obj['isCollider'] = True


if count == 0:
self.report({'WARNING'}, 'No collider has been detected')
else:
self.report({'INFO'}, f"{count} colliders have been converted")

return {'FINISHED'}
return {'FINISHED'}

0 comments on commit 69fc768

Please sign in to comment.