From 7627b76d64e9161dbb4d7d0f7d2deca22a57ad78 Mon Sep 17 00:00:00 2001 From: "florentin.luce" Date: Tue, 21 Nov 2023 11:40:15 +0100 Subject: [PATCH] replace layers with collections --- core/picker.py | 72 ++++++++++++++++++++++----------------------- operators/picker.py | 7 ++--- 2 files changed, 38 insertions(+), 41 deletions(-) diff --git a/core/picker.py b/core/picker.py index 6c2e71c..83623ca 100644 --- a/core/picker.py +++ b/core/picker.py @@ -29,9 +29,9 @@ class Shape: self.press = False - self.shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') + self.shader = gpu.shader.from_builtin('UNIFORM_COLOR') - #self.hover_shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') + #self.hover_shader = gpu.shader.from_builtin('UNIFORM_COLOR') #self.hover_shader.uniform_float("color", [1, 1, 1, 0.1]) self.hover_color = [1, 1, 1, 0.1] @@ -124,33 +124,8 @@ class BoneShape(Shape): self.type = 'bone' self.bone = bone self.active_color = [1, 1, 1, 0.1] - #self.contour_shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') - #self.contour_batches = [] - - #self.line_batch = - #for loop in edges: - # loop_points = [points[i] for i in loop] - # batch = batch_for_shader(self.shader, 'LINE_LOOP', {"pos": loop_points}) - # #self.contour_batches.append(batch) - - theme = bpy.context.preferences.themes['Default'] - self.bone_colors = { - 'select': [*theme.view_3d.bone_pose, 1], - 'normal': [0.05, 0.05, 0.05, 1], - 'active': [*theme.view_3d.bone_pose_active, 1], - 'hide': [0.85, 0.85, 0.85, 0.2], - } - - if bone and bone.bone_group: - normal_color = bone.bone_group.colors.normal.copy() - normal_color.s *= 0.75 - self.bone_colors['normal'] = [*normal_color, 1] - self.bone_colors['select'] = [*bone.bone_group.colors.select, 1] - self.bone_colors['active'] = [*bone.bone_group.colors.active, 1] - self.bone_colors['hide'] = [*normal_color, 0.1] - - #self.color = [i for i in self.color] + self.bone_colors = self.get_bone_colors() @property def select(self): @@ -172,20 +147,14 @@ class BoneShape(Shape): return False #return self.bone not in (bpy.context.visible_pose_bones or []) - bl = [i for i, l in enumerate(self.bone.bone.layers) if l] - rl = [i for i, l in enumerate(self.rig.data.layers) if l] - return self.bone.bone.hide or not len(set(bl).intersection(rl)) + + return self.bone.bone.hide or not any(l.is_visible for l in self.bone.bone.collections) @property def bone_color(self): if not self.bone: return [0, 0, 0, 1] - bone = self.bone.bone - - bl = bone.layers - rl = self.rig.data.layers - if self.select and self.active: return self.bone_colors['active'] elif self.select: @@ -195,6 +164,35 @@ class BoneShape(Shape): else: return self.bone_colors['normal'] + def get_bone_colors(self): + + theme = bpy.context.preferences.themes['Default'] + bone_colors = { + 'select': [*theme.view_3d.bone_pose, 1], + 'normal': [0.05, 0.05, 0.05, 1], + 'active': [*theme.view_3d.bone_pose_active, 1], + 'hide': [0.85, 0.85, 0.85, 0.2], + } + + if not self.bone: + return bone_colors + + if self.bone.color.palette == 'CUSTOM': + bone_color = self.bone + + elif self.bone.color.palette == 'DEFAULT': + bone_color = self.bone.bone + + normal_color = bone_color.color.custom.normal.copy() + normal_color.s *= 0.75 + + bone_colors['normal'] = [*normal_color, 1] + bone_colors['select'] = [*bone_color.color.custom.select, 1] + bone_colors['active'] = [*bone_color.color.custom.active, 1] + bone_colors['hide'] = [*normal_color, 0.1] + + return bone_colors + def draw(self): gpu.state.blend_set('ALPHA') @@ -393,7 +391,7 @@ class Picker: self.shapes = [] self.box_select = None self.hover_shape = None - self.shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') + self.shader = gpu.shader.from_builtin('UNIFORM_COLOR') self.tooltip_shape = None self.tooltip_mouse = None diff --git a/operators/picker.py b/operators/picker.py index a6de955..e5006f0 100644 --- a/operators/picker.py +++ b/operators/picker.py @@ -98,7 +98,7 @@ class RP_OT_box_select(bpy.types.Operator): mode: EnumProperty(items=[(i, i.title(), '') for i in ('SET', 'EXTEND', 'SUBSTRACT')]) - color_shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') + color_shader = gpu.shader.from_builtin('UNIFORM_COLOR') dash_shader = gpu.types.GPUShader(vertex_shader, fragment_shader) @classmethod @@ -324,9 +324,8 @@ class RP_OT_toogle_bone_layer(bpy.types.Operator): hide = picker.hover_shape.hide if bone: - for i, l in enumerate(bone.bone.layers): - if l: - ob.data.layers[i] = hide + for layer in bone.bone.collections: + layer.is_visible = hide context.region.tag_redraw() -- 2.40.1